I just learned about some basic terminal commands and it was a great experience!
It might not be as instinctive as a graphical user interface, still there are some good reasons to start using your terminal.
🔷 High performance
🔷 Real control of what is happening under the hood
🔷 Task automation
Note: We will only walk through the basic commands of Linux/macOS terminal.
If you are using Linux or macOS as your operating system, you are very likely to use bash shell which is the most widely used shell.
Once you opened up your terminal, should have something that look like this:
The cd (change directory) command lets you navigate through your computer's file system.
# Go to target folder cd /target # Go to parent folder cd .. # Go to home folder cd ~
The ls (list) command print files and directories.
# Print files located in the current directory. ls # Print files located in the target directory ls targetparent/target
You can add some options to most of existing commands by simply appending your command with -[option]
# Print files located in the current directory with more details. ls -l # Print every files located in the current directory (hidden files as well). ls -a
The mkdir (make directory) command create a new directory.
# Make a new directory in current directory. mkdir directoryName
The touch command create a new file.
# Make a new file in current directory. touch fileName
The rm/rmdir (remove) commands delete file/directory.
# Delete an empty directory. rmdir myDirectory # Delete a file. rm myFile # Delete a directory recursively. rm -r myDirectory
The pwd (print working directory) command display your current location.
# Display current location in terminal. pwd
The cp (copy) command lets you copy and paste your files.
# Create a copy of a file to target location. cp myFile target/
The mv (move) command moves a file to another location OR rename it if you stay in current directory.
# move file to target location. mv myFile target/ # rename file. mv myFile newName
The head/tail commands print a part of the file.
# Print 10 first lines of a file. head myFile # Print 10 last lines of a file. tail myFile # Print 30 first lines of a file. head -n 30 myfile
The cat (concatenate) command can print content of a file, concatenate multiple files together, create and edit files, ...
# Print content of a file in terminal. cat myFile # Print content of a file with numbers. cat myFile -n # Combine multiple files ogether. cat fileOne fileTwo > target
The grep (get regular expression) search for a given expression.
# Look for a word in a file. grep word fileName # Look for a word in a file without case sensitivity. grep -i word fileName
Here is my personal cheat sheet for bash commands!
Thank you for reading 😇