Search: Advanced search
Browse by category:
Introduction to the Mac OS X Command Line
This is a command line tutorial primarily conducted in in the OS X command line. Because of OSX’s unix heritage, much of the info here is also useful in other unix inspired systems, like the Linux command line.
The command line can be a scary place when you first encounter it. When you read some instructions that tell you to open up a terminal window and type some cryptic words and phrases, it can seem like you’ve been sucked into the matrix, expected to decrypt an endless stream of indecipherable characters.
Fear not, it’s really not that difficult to use. In fact, when you see an experienced user looking at a terminal that is scrolling line after line of text faster than you can even read it, they aren’t really reading it either. For the most part they may be scanning for some key words, but mostly they are just waiting for it to stop.
Check out our full library of learning courses.
How to open the command line.
Before you can use it, you need to be able to find it.
So what we need to do is open the terminal. On OS X, open your Applications folder, then open the Utilities folder. Open the Terminal application. You may want to add this to your dock. I like to launch terminal by using Spotlight search in OS X, searching for “terminal”.
Anatomy of the Console
First let’s clarify a few terms.
Console: This is the system as a whole. This is both the command line as well as the output from previous commands.
Command Line: This is the actual line in a console where you type your command.
Prompt: This is the beginning of the command line. It usually provides some contextual information like who you are, where you are and other useful info. It typically ends in a $ . After the prompt is where you will be typing commands.
Terminal: This is the actual interface to the console. The program we use to interact with the console is actually a “terminal emulator”, providing us the experience of typing into an old school terminal from the convenience of our modern graphical operating system.
Running a Command.
Nearly all commands follow a common pattern with 3 main parts. The program, the options, and the arguments. Let’s see an example.
Type the code above. Do not type the leading
The program is the verb. It describes what you want to do. In our example
Options are like the adverb. They usually modify the way the program will run. In our example
The arguments are what’s left. In our case the
Where Are You?
In the console, you are always working in a directory, or folder, on your computer. We call this your working directory. You can see where you are using
This command will print out your current location. You can change your directory with
You’ll notice that I just passed it a directory named Documents, because I was in my home directory, that contains a directory called Documents. This is relative path, because I specified my destination relative to my current directory. I can provide an absolute path by providing the full path beginning with the
If you want to navigate “up”, that is to the directory that contains your current directory, you can use the special name
From my Documents directory, this command will take me up to my home directory.
Get Some Help, man!
Even when you learn what commands you can use, there is still a lot of power in each command or program. There are often dozens of available options, and depending on your arguments, your command could behave in several different ways.
Fortunately, most commands have a manual. To read, use the
The manual can be scrolled with the arrow keys or space bar. Pressing q will quit.
Want to know more about man? Run
Some more commands.
There are a ton of different commands you can use, but only a couple dozen will get you pretty effective in the command line.
We learned about
Try using the man command to learn about these commands