Basic+Unix+terminal+usage+(bash)

Using a UNIX terminal (most commonly, the one called "bash") is a useful skill in many different types of activity. It may be a useful way of completing operations on your personal computer. It is sometimes the only way of configuring certain things on a web server, database system, or content management system. It is sometimes useful in the performance of laptop orchestra compositions, and some people even make a live coding performance art directly from the terminal. Note: the only way to learn this is to try it - so fire up a terminal (see next paragraph) and try things out!

To get started on Mac OS X: open the Terminal application. It's under Utilities - or you could find it in the Spotlight (type Terminal in the Spotlight in the upper right corner). To get started on Windows: I'm not sure right now how "compliant" the DOS command prompt is with these more universal Unix ideas. Does anyone want to suggest some text to include here? In the meantime, if you are just looking to explore the command line you might find a Mac OS X computer of some sort to work with. To get started on Linux: if you are using Linux you probably already know the answer to this question (and in any case, it would depend on which flavour of Linux you are running).

In general terms, a terminal is something that can send and receive text, and displays the text sent and received. When I start Terminal in the Mac OS X computer in the ESP studio, this is the first text it gives to me:

Last login: Thu Mar 1 11:04:34 on console mac-208:~ multimedia$

A most important concept when working with the shell/terminal is the idea of the current directory (sometimes people call it the "current working directory"). With the terminal on Mac OS X it tells you the current directory (i.e. folder you are in) - in the text above the ~ is a short way of saying "the current user's home directory". At the prompt (represented by the $) I can type commands that are built in to this Unix shell, and I can also type the name of programs to launch. For example, type "ls" (no quotes) and press enter. You will see a list of the names of the files in the user's home directory. On Mac OS X these are mostly the names of standard folders, like so:

Desktop Downloads Movies Pictures Sites Documents Library Music Public mac-208:~ multimedia$

The command "ls -l" will also give you the list of files in the current directory, but with considerable details beyond simply the filenames. It's often a good habit to use "ls -l" instead. It will give you results more like this - don't worry if you don't understand right away what all of the "details" are:

drwx--+ 16 multimedia staff 544 1 Mar 11:10 Desktop drwx--@ 35 multimedia staff 1190 26 Jan 14:09 Documents drwx--+ 73 multimedia staff 2482 29 Feb 20:53 Downloads drwx--+ 39 multimedia staff 1326 10 Jan 2011 Library drwx--+ 4 multimedia staff 136 20 Aug 2009 Movies drwx--+ 7 multimedia staff 238 1 Feb 10:04 Music drwx--+ 5 multimedia staff 170 20 Aug 2009 Pictures drwxr-xr-x+ 5 multimedia staff 170 5 Aug 2009 Public drwxr-xr-x+ 5 multimedia staff 170 5 Aug 2009 Sites mac-208:~ multimedia$

After displaying the list, the terminal gives you the prompt again ($) to let you know you can enter a new command. To change the current directory to one of the directories listed (in the current directory) use the cd command. "cd Downloads" will change you to the Downloads directory. Do that, and then use the ls command to list the contents of that directory:

mac-208:~ multimedia$ cd Downloads mac-208:Downloads multimedia$ ls 28500__sazman__070112_LIX_children_playground.wav 2G03-lecture-10.pptx 2G03-lecture-11.pptx 2G03-lecture-2.pdf mac-208:Downloads multimedia$

Notice how the prompt line has changed to reflect the new current directory. To change to the directory _above_ the current directory use "cd .." - The two dots are a shorthand for "the directory above", whatever its name may be.

Deleting files: To delete a file, use the rm command followed by the name of the file: rm 2G03-lecture-10.pptx

Deleting directories: To delete a whole directory/folder use the rm command but with the "option" -R as follows: rm -R someDirectoryName

Copying files: To copy files use the "cp" command followed by the location/name of the "source" (the file to copy) and then the location/name of the destination. For example, "cp myFile.pdf .." would copy the PDF file called myFile.pdf to the directory above the current directory.

Auto-completion: At any point while you are writing a filename or path into a shell command, you can press Tab to activate "auto-completion". The shell will either suggest possible filenames that start with the letters you've typed so far, or

Showing what is running on the machine in question: Type "ps" to get a list of the processes that are running on the machine in question. In practice "ps -ax" (with the options a and x) will give you information about all of the processes running on the machine in question, not just the processes attached to your particular username.

There's a lot more you can do with the Unix shell/terminal/command line/command prompt/Bash (all basically names for the same thing) - but this is enough to get you started and assist with common website management tasks (and sometimes, laptop orchestra tasks)!

-Dr. O