This series is targeted at intermediate Mac users. It is assumed that you have some familiarity with OS X’s filesystem and the directory structure. Some assumptions will be made with terminology and although CLI (command line interface) specific terms will be explained, not all concepts will be described in detail.
Perusing the Utilities folder, you might have stumbled across the Terminal application. Having little knowledge of what it was for, you ignored it. I don’t blame you – for 98% of Mac users, it is of little value. Or is it? This series of articles investigates the value of the command line and introduces you to the power it can provide you.
As a word of warning, with this power comes some responsibility on your part. The command line is incredibly powerful but there is the potential for mistakes that may be beyond repair. It is for this reason that I have created a virtual machine that I will be using for the purpose of this series. You can get it here. There is a very simple reason that we will be using a virtual machine – any mistakes that occur will be limited to the virtual machine and will leave your OS X install in tip top shape. Consider it a safe sandbox to play in.
It’s important to know that this is a Linux virtual machine. Now, you’re probably asking “aren’t we going to learn about using the command line in OS X?” The answer to this question is yes but Linux was used here for three reasons: it’s free, I’m legally allowed to distribute it and 99% of the commands in Linux are common to OS X. When there is a difference, I will make that clear but this won’t be the case all that often. You may also be saying, “I don’t know how to configure Linux!” Don’t worry – all the hard work is done for you. Simply boot from this virtual disk and you’ll be ready to go.
As you’ll see, the virtual machine hard disk file is a vmdk. This will work in VMWare Fusion and VirtualBox. If you’re a Parallels user, you’re out of luck (I don’t own a license) unless you install one of the other two (VirtualBox is free). You’ll also see that I didn’t include the whole virtual machine configuration but instead, I only included the hard disk file. I will leave configuration up to you. I do however recommend that you run the virtual machine with at least 768MB of memory (1GB+ is ideal). If you’ve never setup a VM, you can get instructions here for Fusion and here for VirtualBox. Remember that you need to use the hard disk file included here so you’ll want to copy it to you Mac somewhere.
VirtualBox users, this is the screen where you will choose the vmdk file included:
Booting into Our Tutorial VM
Start the virtual machine with your chosen virtualizing software. Once the boot is complete, you’ll be presented with something similar to the following:
The characters in your password will not show up when you type it – this is a security precaution. Don’t worry, the keypresses are being registered. Once you’ve logged in, you’re ready to go. Feel free to execute commands with impunity – all actions taken in the VM are limited to the virtual machine (unless of course you log into your Mac remotely from the VM but we won’t be doing that).
Here are some of the basic commands that you’ll see used frequently:
cd <directory> – this will change the working directory to <directory>. Example:
pwd – this will tell you the current working directory. Example:
That should be enough to let you explore the filesystem and see where files/folders are located.
It’s important to know that you’ll always be working out of a directory. Think of the command line as Finder without the GUI (logically this doesn’t make much sense but it should help to provide a better sense of how the CLI works). When you first login, you’ll be in your user directory1 and can move around the filesystem from there.
There is much more to explore and we will start exploring the wonderful power that the CLI interface affords us in the next article. For now, use the aforementioned commands to explore the filesystem and acquaint yourself with the VM and the CLI. To shut the VM down, execute the following and when prompted, enter the password (mfcli):
In the next article, we’ll be learning the basics of file management. More specifically, we’ll learn how to copy, move, create and delete files.
1 There is a difference between Linux and OS X with regards to the home/user directory (sorry to start with the differences so early!). In Linux, your home/user directory is located at /home/<user> while in OS X, your home/user directory is located at /Users/<user>. While there is a difference, you don’t really need to remember the difference because there is a shortcut for the home/user directory that works across platforms. If you want to get to the home/user directory, you can replace the home/user directory with the tilde (~). For example, if you wanted to change to the home/user directory, you could execute the following:
This will work in both operating systems. In Linux, it will change your working directory to /home/<user> and in OS X, it will change it to /Users/<user>. This is why you don’t really need to know the difference (at least for the sake of this tutorial series). This will be elaborated on in greater detail in part two.