Introduction
As a developer, I find myself using the terminal all the time. In this article, I'll list the top 10 commands I use the most for speed and productivity, along with some examples.
ls
The ls
command is used to list the contents of a directory. It is a very basic command but it is a lot quicker than using the Finder to list the contents of a directory.
cd
Next we'll look at the cd
command. This command is used to change the current working directory. Again, it is a very basic command but it is a lot quicker than using the Finder to change the current working directory.
pwd
pwd
is used to print the current working directory. This command is very useful when you want to know where you are in a directory structure.
cat
Getting into the more advanced commands is the cat
command. This command is used to read the contents of a file without opening it. Here is an example:
cat README.md
Output:
# This is a markdown file
In this example, we are assuming that README.md
has the contents # This is a markdown file
.
head
The head
command is used to print the first few lines of a file. Here is an example:
head README.md
tail
Similarly to head
, the tail
command is used to print the last few lines of a file. Here is an example:
tail README.md
grep
Next is the grep
command. This command is used to search for a pattern in a file. Here is an example:
grep -i "markdown" README.md
Explanation
In this example, we are searching for the word markdown
in the file README.md
. We are also searching for the word markdown
ignoring case, which is the -i
flag.
mkdir
The mkdir
command is used to create a new directory. Here is an example:
mkdir new-directory
touch
The touch
command is used to create a new file. Here is an example:
touch newfile.txt
rm
The last command is the rm
command. This command is used to delete a file or directory. Here is an example:
rm newfile.txt
Bonus 11th Tip!
As a bonus, you can use the &&
operator to run multiple commands in one line. Here is an example:
mkdir new-directory && cd new-directory && touch newfile.txt
You can see we can make a new folder, change to the new folder, and create a new file all in one line!
Conclusion
That's it for this article! I hope you find this article useful and that you can use it to speed up your development process. Here is a lsit of all the mac terminal commands we went over:
ls
cd
pwd
cat
head
tail
grep
mkdir
touch
rm
&&