Helpful Terminal Commands Every Developer Should Know (Mac)

Yahjaira Vasquez
5 min readOct 13, 2020

--

Today I wanted to provide you all with a list of helpful commands that can be used in your terminal on a mac (some of these commands may be written differently on other systems). Knowing how to navigate through your terminal is very important, especially as a developer, because it will allow you to be more efficient and faster when navigating through your system. In the beginning, it may seem like a slow process, but the more you use your terminal and start to remember what commands do what and which commands you tend to use the most, it will all come more naturally and faster. So let’s get into it!

Photo by Fernando Hernandez on Unsplash

cd

First up, we have cd, also known as “change directory”. This command is used to navigate through your folders. There are numerous combinations to use this command.

We can cd into a specific folder by writing cd and the folder path:

cd development/code/test_path

We can cd up one folder in our current path by typing “..” after the cd command:

cd ..

We can also go back to the top of our directory by just typing cd:

cd

pwd

This command stand for “print working directory”. When we type pwd the terminal will return the current path for the folder/file you are in.

pwd => /Users/username/development/code/test_path

This command will prove helpful when you are unsure of the direct path to your current folder/file.

ls

When we type the ls command into our terminal, it will return a list (hence the abbreviation) of all of the folders/files that are in your current folder. Sometimes you may be unsure of what is available to you in your current directory, remembering all folders and their paths is almost impossible, so using this command will come in handy.

ls => test_project1 test_project2 test_file.js

clear

Sometimes your terminal can start to look overwhelming from all of your previous commands that you’ve ran. While you may scroll up to look at your previous commands, there is no way to scroll down to clear your view. That is where the clear command comes in. When we type clear into the terminal, the current view will be cleared and you will now have a blank slate to work with, still in the same directory you were in. And even though you have cleared the view, you can still scroll up and view your terminal history.

clear

Photo by Tracy Adams on Unsplash

touch

This command allows you to create a new file straight from your terminal within your current directory.

touch terminal_blog.js

Or if you’d like to create a file within a different folder in your current directory you can do so by providing the path as well.

touch test_blog/terminal_blog.js

rm

If you would like to delete a file you can run the rm command followed by the file you would like to remove.

rm terminal_blog.js

Photo by Ilya Pavlov on Unsplash

mkdir

To create a folder in your current directory, the mkdir command, which stands for “make directory” can be ran followed by the folder name.

mkdir test_blog

Just as we could with touch, if you need to create a nested folder within a folder in your current directory, we can do so by providing the path.

mkdir development/code/test_blog

rmdir

If you need to remove a directory (folder), you can do so by running the rmdir command and the folder will be deleted.

rmdir test_blog

The above commands are commands you will use all of the time and if not already familiar, will become very familiar as you use your terminal more and more. Now I just wanted to throw in a few fun ones that could be pretty useful, but please master the previous ones first!

mv

Did you accidentally create the folder/file in the wrong directory? No need to delete and create a new one in the right directory. You can run mv followed by the file you want to move and then the new directory path you would like to move the folder to.

mv move_this my_new_home

less

Want to see what is in a file without having to open the entire file? This command will allow you to do so by following the command with the name of file you would like to open. This will pull up the file contents, which you can scroll through and once you are done viewing it’s contents type “q” and hit enter to be returned to the previous terminal view.

less terminal_blog.js

history

The history command will provide you with a numbered history list of commands you have used. You can pair the number of the command you want to use with a bang symbol before it to run the command.

history

!1276

man

If ever you are unsure what a specific command does, you can run man followed by the command in question and a detailed description will be provided to you through the terminal. To return to the previous view you can run ”q” + enter.

man ls

And just like that, you have mastered the terminal! There are many more commands that can be used, these are just some of the every day commands you should be comfortable with. As always, I encourage you to do some research and explore new commands outside of this list. An extensive list can be found here. Also, bookmark this blog for future reference! Until next time! Happy Coding :)

--

--

Yahjaira Vasquez
Yahjaira Vasquez

Written by Yahjaira Vasquez

Seeking and spreading knowledge within the world of tech!

No responses yet