If you’ve been using a Mac for a long time, you know that it’s more than just a nice point-and-click window and icon interface. Beneath the surface of the operating system is a whole world that you can only access from the command line. Terminal (in the folder / Applications / Utilities) is the default port of that command line on a Mac. With that, instead of pointing and clicking, you enter your commands and your Mac bids.
Why do you want to do that? For almost all your data needs, the usual graphical user interface is enough. But the command line can be useful when it comes to troubleshooting your Mac, to turn on “hidden” settings and other advanced chores. It is a good idea for anyone who is not a complete beginner to be familiar with it.
If you are not already familiar with the Mac command line interface. First up: How to navigate the file system from the command prompt.
By default, when you open Terminal, the first thing you see is something like this:
Last login: Tue Apr 23 13:40:35 on ttys000 walden:~ kirk$
The first line shows the last time you logged in to your Mac via the command line; it is the current time when you use Terminal. The second line is the command prompt, and although it may change from system to system depending on configuration, it contains several bits of information by default.
In my message, Walden is the name of my Mac (same as the name in the System Preferences sharing pane), and kirk is my username. The ~ shows where I am in the file system on my Mac; ~ is a shortcut that means the current user’s home directory. (In the Finder, there is the folder with the username and the house icon.) Finally, $ is a character that the bash shell (the default interface that Terminal uses) displays to indicate that it is ready to accept a command.
What’s in a folder
Once you get to the command line, you are in your home folder. While you are there – or when you are in any folder (catalog in Unix speech) – you may want to know what’s in it. To do that, use
ls (or list) command. Type
ls and press the Return key, and you will see the folders (and / or files) in the current directory.
The exit from the plain
ls the command is quite sparse; it shows you the names of the files and folders found in the current directory (including some known ones like movies, music, pictures and so on). Fortunately, you can add a number of optional switches to
ls command that allows you to see more information. So try writing, for example
ls -l (there are lowercase letters L), and then press Enter. You see something like this:
walden:~ kirk$ ls -l total 0 drwx------+ 4 kirk kirk 136 Mar 31 14:56 Desktop drwx------+ 17 kirk kirk 578 Apr 2 12:20 Documents drwx------+ 18 kirk kirk 612 Apr 23 13:06 Downloads drwx------@ 19 kirk admin 646 Apr 22 09:59 Dropbox drwx------+ 98 kirk kirk 3332 Mar 30 19:29 Library drwx------+ 6 kirk kirk 204 Dec 4 09:04 Movies drwx------+ 9 kirk kirk 306 Mar 23 09:52 Music drwx------+ 19 kirk kirk 646 Apr 5 17:34 Pictures drwxr-xr-x+ 7 kirk kirk 238 Mar 6 07:51 Public drwxr-xr-x+ 8 kirk kirk 272 Jul 19 2012 Sites
Don’t worry too much about what all that means right now; we just get our feet wet. The point is that
ls may provide additional information about files and folders, depending on the options you specify. In this case, this additional information includes the name of the user who owner each item in the directory. (That ownership is part of the Unix system file permission regime.)
kirk kirk next to most of these items above means that each one is owned by the user kirk, who is in the group kirk. The other understandable information next to each file and folder is the date and time each one was last changed.
Another convenient option: You can see invisible files – files that Finder does not normally show you – by typing
ls -a. (These hidden files all have dots (.) In front of the names.)
When you are in the Finder and you want to move to another folder, find that folder and double-click on it. From the command line, use
cd (or change directory) command instead. So let’s say you’re in your home folder and want to look in the download folder. To do that, you would write
cd Downloads. (Remember to always type a space after a command that has an additional argument, such as the name of a directory in the previous example.) Once you have done that,
ls shows you the contents of your download folder.
Here are some quick tricks to get around the Mac file system.
- If you write
cdand press the Return key – without directory specified – you will return to the Home folder. (You can also write
cd ~to go there.)
- If you write
cd /, go to the root level of the boot disk.
- If you write
cd ..(there are two periods), go to the directory of the one you are in. So if you are in the home folder, type
cd .., go to the Mac / User folder.
- And if you write
cd -(hyphen) you will return to the directory you were in before the last one you published
To learn more Terminal commands, see our articles on how to copy and move folders, as well as delete files and folders using the command line and get help when you need it from man pages.