Tuesday, September 23, 2008

Power Tip #3: A Beginner's Guide to Terminal

Hooray, a new post! Get ready for some reading!

But before I get into any actual instructions, it's important to realize that Mac OS X is fundamentally different from OS 9 and all previous revisions of the macintosh operating system. The key difference being that OS X is based on BSD Unix.

But what exactly does that mean for us? Well whereas before OS X the command line was completely absent, in Apple's new OS it makes its proud debut. The "Terminal" application is an application for typing in the command line. So instead of clicking buttons with our mouse, we'll be typing text, or commands. There are innumerable things that can be done in Terminal, but today I'll stick to the basics.

One of the most simple, yet probably most important commands you'll ever learn is the "Change Directory" command, abbreviated "cd." "Change Directory" is just a fancy way of saying "move from one folder to the next." Thankfully, navigating in the command line is very reminiscent of column view in Finder.
So fire up Terminal and type the following: "cd desktop"
What that'll do is move you from your starting folder (by default your home folder: the folder that has your name on it) to your desktop. To go back, just type: "cd .." and you'll be moved back up one directory. Just like pressing the left arrow in column view.

Now that's great, but what if you don't have every folder in your computer memorized; what if you need to see the names of all the folders in your current directory? That's where the "ls" command comes into play. Type "ls" and you'll get the name of every folder or file in your current directory.

After you've played around a bit, and you're feeling a bit more comfortable, try launching or opening something through the command line. For our purposes, let's try opening "Activity Monitor." Type "cd .." until you're at what's called the "root directory" (you can be sure you are if after running "ls" you can see the applications folder). The "root directory" is commonly abbreviated "/" so keep that in mind. It's the folder where you can't back up anymore. Now, type "cd applications" and after that "cd utilities." You can use the command "open" followed by your target file to open it. Having trouble? You should be! There are two problems. The first is that spaces aren't commonly recognized in the command line. There are two ways to get around this. One is by typing a backslash (\) before the space, and the other is by putting quotations around the two words separated by the space. The second problem is that when opening a file or application, you have to add the extension. For applications, ".app" will do the trick.
So to open "Activity Monitor," type either "open "activity monitor.app"" or "open activity\ monitor.app"
Success! If you did that, you have every right to be very proud of yourself.

Now that you've hopefully got the basics of moving through folders and opening files via the command line, next I'll teach you a few specialized commands.

Just as a note, you'll often see the paths (locations) of files referred to as "/application/utilities/activity\ monitor.app." That's a major thing to remember, especially for future posts.

No comments: