The Terminal, (AKA
CLI, or “Command-Line Interface”) is super-powerful and allows you to interface directly with the underlying workings of your operating system. It’s pretty essential you learn how to use the Terminal if you’re going to be developing software or doing any more advanced operations within your operating system as many operations are done exclusively through the Terminal.
In this post, I’ll give you a quick run-down on how to navigate your file system in Terminal. At the end, there is a bonus tip for altering the appearance of your Terminal to make things more efficient for you.
You can find Terminal by going to your
/Applications/Utilities/ directory in Finder.
Alternatively, you can open it by pressing
cmd + space on your keyboard to bring up Spotlight Search, and begin typing
terminal. When the application shows, just press
enter and up pops the Terminal.
When you open your Terminal, you’ll be greeting with a screen similar to this one:
Starting Components Explained
The first part of input prompt, before the colon, is your computer’s name. This can be changed to whatever you want in
System Preferences > Sharing.
The tilde (
~) represents your home directory.
And finally, the part before the dollar sign (
$) is the name of the user account you’re logged in as.
You perform actions in Terminal by inputting a command and pressing
enter. Here, I will go through the basics of navigating Terminal with some of the most common commands.
Start by typing
ls into Terminal and pressing
ls is the command for “listing directory contents”. As you are in your home directory, the
ls command will show you all the directories inside of your
Let’s move into one of the folders. You do this with the
cd command. Simple type
cd and the folders name, like so:
While a “folder” and “directory” are not exactly the same thing, please note that in this tutorial, the terms may be used interchangably, and in general, they refer to practically the same thing.
As you can see now, instead of being in your
~) directory, you’re now in your
If you want to make a new directory inside
Documents, you use the
mkdir, followed by a space, followed by the name of the new directory you want to create. In this example, we type
ls now, you see there is a new directory inside of
If you type
pwd now and press
enter, you can confirm the full path of where you are inside Terminal.
pwd stands for “Print Working Directory”.
To delete the
blog directory you just created, you type
rm -R followed by the name of the directory. Confirm the directory is gone by using the
ls command once again.
Be careful when using the
rm -Rcommand, as this will delete your directory, plus all of its contents… for good, without confirmation. There is no “Trash Can” in Terminal.
-R is what is called an “Option”, “Switch” or “Argument”. Commands usually have many Options avialable. To find out more about any command in Terminal, you can do so by typing
man (for Manual), followed by the command. This opens up the manual page for the command, where you can read about all the options.
Exit the manual by pressing
Finally, to move up one directory, just type
cd .. and you’ll move up a directory. Alternatively, if you want to go back to your
Home directory from anywhere, just type
This concludes the basic Terminal Navigation tutorial. Following is a bonus tip I promised you…
Bonus Terminal Tip
Normally when you use Terminal, you’re presented with this screen, as you saw from the beginning of this tutorial.
This contains unnecessary information when using Terminal on a daily basis, so with a very simple command, you can hide the computer name and username in your Terminal. Producing this instead:
I think you’d agree, this makes things a lot more tidy for you and removes additional clutter and distraction – Minimalist.
To accomplish this, simply type (or copy & paste) this command into Terminal and press
enter. After this, open a new Terminal window by pressing
cmd + n to see your new Terminal prompt.
echo "export PS1='\W \$ '" >> ~/.bash_profile
What this commands does is it appends the line
export PS1'\W \$' into a hidden system file in your
Home directory called
.bash_profile. This file controls what is presented to you when you open a new Terminal window.
This is only barely touching the surface of what can be accomplished in Terminal. As I said before, getting familiar with the Terminal is essential if you’re interesting in going deeper into what is possible with your computer. In other words… becoming a Power User. I hope this tutorial can help you in making those first steps.