Home Open Source Classics Basic Terminal Commands

About

Open Source Classics is a directory and how-to guide for free and open source programs and resources useful to classicists, as well as a place for musings about the relationship of scholarship to free and open source principles. Continue the conversation at the Open Source Classics Forum and Technology Forum. Have a recommendation for an article? Interested in becoming a contributor? Email the editors.

Login

Basic Terminal Commands
Written by David Andrew Collier   
Saturday, 26 July 2008 03:32

Before I continue my series "The Terminal and Classics," perhaps we should work on our fluency with the terminal environment. I know that many people have never used the terminal before, so here is a basic introduction.

 

Open the Terminal using Finder (Finder > Applications > Utilities > Terminal). A window should open with a basic prompt:

terminal


On my terminal window, the text in the window reads:

Last login: Sat Jul 26 15:01:41 on ttys003
Macintosh-3:~dave$

This tells us some basic information. First of all, it provides the last login time. For most situations, this is not that important -- though if you share your computer, you can see if someone else has used the terminal more recently than you.

The next line is the prompt. The default prompt on my MacBook Pro (with Intel and Leopard) is 'Macintosh-3:', and likely yours will be something similar. Finally, after the prompt, we see "~ dave$". This part is important, as it specifies our current directory. I am logged into my Mac as Dave, and so the default position for terminal is in the '/users/dave/' folder. The default user folder is noted by the tilde ~. Since I am logged in as Dave, the default prompt after the directory location is 'dave$'.

Don't know what a directory is? Think of a Finder window -- all the 'Folders' with files and other folders within them are known as 'directories' in your terminal. Let's take a look at the contents of '~'. From this point on, all commands will look like this.

Type ls -G and you should see something like this (n.b., capitalization of the G is important):


lsgcommand

 

As you can see, ls is the list command, and as we might expect from its name, it lists the contents of your current directory. By using the -G option, the terminal automatically colors the contents according to type. In the case of my terminal, we see that the directories are blue, and files remain the default white.

Let's try to change directories using the cd command:

 

cdcommand


You can see that I typed cd downloads and switched to my "Downloads" directory. The prompt then switches from "~ dave$:" to "downloads dave$:". This is confirmation of the successful switch. If I type ls -G again, I am given a very short list of files I have in my "Downloads" directory.

There are a few other convenient cd commands that are worth noting. At any time, you can type cd ~ and it will return you to your home directory. You can see below that after using this command, my prompt again says '~ dave$:'.


cdtildecommand


If you already know the location of a directory, it is easy to change directly to it by simply using cd and then typing the entire path. For example, if I want to find a picture that I know I have stored with my album cover art, then I can switch directly to that directory by typing cd pictures/album\ art/ (notice that if your folder name has a space, you need to insert a backslash character for the terminal to process it correctly). If the directory I want is somewhere outside of my parent directory (pictures/album art is nested beneath /users/dave/), then I can also change to that directory directly by putting a forward slash before the path: e.g. cd /applications/utitlities/. You'll see below that I switched directly to the utilities directory from the album art directory with this command:


cdjump


Another useful cd shortcut is the cd .. command, which will automatically take you back to the directory above the one you are currently in. For example, if I am in ~/pictures/album\ art/ and I type cd .. then I will arrive back in the pictures directory. If I do this one more time, then I return to the home ~ directory.


cddotdot


You can also use terminal to quickly open applications. If you need to open a picture quickly, but don't feel like using Finder, you can also use terminal. This is done by using the open command. Simply type the full path name after the command, e.g. open pictures/album\ art/janis.jpg.


janisexample2


Or, just like with cd, if your file or application is not beneath your current directory, you can begin with a forward slash: open /applications/textedit.app.


texteditexample


On the other hand, if you happen to already be in the directory where your file is located, you can simply type open <filename>.


janisexample


I'll stop here and leave you to explore some of these basic commands. More help with the terminal and other useful commands can be found at this online tutorial. In my next post, I'll show how to customize the appearance of your terminal and make it your own. The series will culminate in showing the power of the grep command to easily word search or produce concordances and will demonstrate how useful the terminal can be for a Classicist.