Tutorial: Navigating Terminal
What is Terminal?
Terminal.app is an application that’s been included with macOS since its first release. It allows the user to gain command line access to the operating system, which means instead of using a cursor to click on buttons and checkboxes you have to manually enter commands. While using the standard graphical user interface in many cases is quicker and much simpler to learn, these interfaces necessarily have to sacrifice options to meet this simplicity. Terminal, however, offers a wider range of options when interacting with data and files.
How to open Terminal
Terminal is located in the Utilities folder, which is a subfolder of Applications. Instead of using Finder, you may also choose to open Terminal via Spotlight: Simply press cmd + space once and start writing “Terminal”. Once the application has been found, press return to launch.
How to navigate
Your whole interaction with Terminal will be done through typed commands. There are many commands available, for example my current installation of macOS lists a total of 1589, but don’t let that discourage you: you will never need to know all these commands by heart, and in most cases just knowing a few will suffice. So here’s a quick rundown of the most important commands to navigate Terminal.
When you open Terminal, you’ll start in your users home directory. There’ll be just one line of text looking something like this: “[nameofyourmac]:~ [yourusername]$”. The tilde behind the colon is the symbol for your home directory. If you were in any other directory, its name would be displayed in that place instead.
The first command we’re going to learn is ls: in short, ls simply lists all the content of the directory you’re browsing.
So if you enter “ls” and hit return, you’ll get a list consisting of “Applications”, “Desktop”, “Documents”, etc.
This itself might be helpful in some cases, but what if you want to know the sizes of your files, or the date when a file was last modified? ls can do this, too, with the help of operands, which means adding a blank space and some modifiers to the command, such as: “ls -l”, which gives us a much more detailed list of the contents, including sizes, file owners and modification times.
Most commands have a huge list of operands that can be used, and if you’re curious about those, our next command will help you find and understand those operands.
man is short for manual, and as the name already states it can be used to show us the manual to all those commands available. Entering man by itself won’t do anything useful; it needs to know which manual you want to see. So the best way of invoking man is to enter something like:
Manual pages always look quite similar: there’s a short description of the command, followed by all available options and modifiers, and then a detailed explanation of all the operands. If you’re done reading the first page, you can simply hit the space bar to display the next page; and if you found what you were looking for, simply enter “q” for quit and you’ll be returned to the command line.
Now that we know how to get help on commands and how to display the contents of a folder, it might be nice to move to another directory.
Notice that the tilde in front of your username changed to “Documents”, confirming you are now browsing this directory. If you want to double-check:
will display a list of all your documents.
There are some symbols you should know when using cd and other commands:
As we learned before, the tilde symbolises your home directory, so entering
will promptly bring you home, wherever you were before.
The slash is referring to the root directory of your system. This means while
will look for a folder named “Documents” in the directory you’re in,
will look for a “Documents” folder in the root directory, and most likely display an error.
The “.” is referring to the directory you’re in. When you want to open the Documents folder, you might also type
Whenever you’re using “..”, you are talking about the parent directory of the one you’re in. If you’re currently in your Documents folder, entering
will bring you to your home directory.
All those symbols can be combined. Although unnecessary, you can enter something like:
to simply move to the parent directory of your home folder.
We already know how to browse all your documents and folders, but what if you want to interact with the data, for example create a file? While not the only option, touch arguably is the simplest:
will simply create a new file called lsmanual.txt in the folder you’re currently in.
By default, many terminal commands are displaying their output directly in the Terminal window; but this behaviour can be changed with another useful little tool:
If, for example, you want to have a file of the manual for ls to take with you on a flash drive, you can redirect the output of the command man to a file:
man ls > lsmanual.txt
Want to read the text file you just created? Use less to display the contents:
less ls manual.txt
Once less is showing you the content, you navigate in the same way as in man. Hit space to move to the next page, q to quit.
When ending a session in Terminal, you might want to hide what you’ve been up to, for example when using a public computer. To do so, just type:
which will clear the contents of your terminal window.
And if you’re done with Terminal all together:
will close your terminal window.
So now you know the basics of navigation in Terminal. If you have any thoughts on this, or questions, feel free to add them to the comments.