Tutorial: Basic Mac terminal commands

Avatar

Mac Terminal Main

The OS X Terminal is a fantastic and very powerful tool that every Mac user should know about. If you want to go beyond the basics in your Mac, you will undoubtedly need to use the Terminal at one point or the other. Although there are some very complex applications to the Terminal, we are here to talk about the basics so I am going to outline the few very important first commands that you need to master before doing anything else.

First steps

To access the Terminal, go to Applications > Utilities and open it. The terminal window will automatically display some information like your user name but you need not worry abou that right now. To enter commands, simply click on the terminal window, type the command and press Enter.

Note: I recommend you use an administrator account for the purposes of this guide.

Basic commands

Root access: The most powerful command and one that must be used with care. The following command will allow you to log in as the root user, enabling you to make any changes you want to the operating system. As you can imagine, this can be dangerous as you might break something unexpected if you do not follow the commands to the letter. With that in mind, here is the command:

sudo -s

After entering that, you will be asked to enter the user password. Just type it in, press Enter and you are good to go. This command should only be used if a guide specifically asks you to. If it does, make sure you follow its steps with precision otherwise something might get damaged accidentally.

Navigating directories: As you can understand already, navigating your computer through the Terminal is fundamentally different than the Graphical User Interface (GUI) of your Mac. The Terminal requires typed commands for everything you want to do, including navigating between different directories in your computer. Thankfully, the command is very simple. For example:

cd /Desktop

If the directory has spaces, e.g. My awesome photos, you will need to use quotation marks like this:

cd /Desktop/”My awesome photos”

To move to another volume, use this example, replacing it with your own names of course:

cd /volumes/Adam

As a final note, you can drag and drop files/folders in the Terminal in order to immediately get where you want.

Listing directories: This simple command will list all the directories in the current folder the Terminal is in:

ls

There are various values you can attach to this command in order to get exactly what you want. For example:

ls -a

This will list everything in the directory, including hidden files and folders.

Copying files:

cp FileName CopyFileName

Example: cp Amazing.txt EvenBetter.txt

Moving files:

mv FileName /Destination

Example: mv Amazing.txt /Desktop/”Best stuff”

Deleting files: This command differs a bit depending on whether you want to delete something in the same directory you are in or in another directory.

rm Filename

Example: rm Amazing.txt

rm /Desktop/Amazing.txt

Conclusion

I think this is pretty much it for now. Although you might not use this commands frequently, they are a very good way to get yourself acquainted with the Terminal as they are fairly simple and not very likely to break something. Apart from the root access command, of course but I hope you already understand the potential dangers of it.