Computer Basics for BGSU Image Analysis: UNIX

Unix is the operating system used on Sun workstations we use for image processing and photometry. Unix uses a "command line" interface, where you type commands into a line on the screen (rather than a "GUI" graphical user interface with windows filled with buttons you control with your mouse). Most commands are like a sentence, with the commands being the verbs, and nouns and adjectives to modify the verb/command. A good example is the list command:

% ls [list all the files in your current directory]
% ls -la [gives "long" info on each file including last-modified date, size in kb, access permissions, etc]

(FYI: the "%" in the lines above is the Unix "prompt" -- it often also includes the name of the computer you are on, e.g., "baade%". It reminds you that you are in the Unix environment).

The "wildcard" character helps you specify files with a range of parameters (as opposed to specific filenames) and can be useful for searching for files (with ls) or more advanced applications. The "*" wildcard substitutes for any block of 1 or more characters (no length limit), while the "?" substitutes for a single character. Here are some examples:

% ls bob*.dat [this wildcard would find files named bob.dat, bob2.dat, bob22.dat, and bobisagreatguy.dat]
% ls bob?.dat [this would find only bob2.dat out of the list of images above]

Unix uses a tree-like directory structure much like folders within folders. To see which directory you are currently in, do:

% pwd [show the full "path" to your current directory]

For example, it may return "/data/jdoe/PHOT/07MAY22". The first two bits are the "home directory" -- /data is the name of the big user disk on baade and jdoe is the username of the hypothetical user. She is currently two directories "below" her home directory; PHOT is a subdirectory of jdoe, and 07MAY22 is a subdirectory of PHOT.

I usually name all my directories in CAPITALS so it is easy to see (when you do ls) which names belong to files and which to directories.

If jdoe wants to move up a directory into PHOT, she types

% cd .. [change directories going up one level]

(FYI: the ".." is shorthand for "up one level" and works for ls and other commands. You can use it in directory paths too, e.g., "cd ../../PROGS/" will take you up two directory levels and then down a level into a directory called PROGS).

To go down one level into an existing directory called RAW, type:

% cd RAW

To make a new directory called NEWDIR and move into it:

% mkdir NEWDIR

To jump straight to your home directory:

% cd

New files are created either as the result of a command, or using a file editor (we use "emacs"). Let's create a new file named junk:

% emacs junk & [create and edit a new file named "junk"]

A new "emacs window" should pop up (the "&" opens it as a "background job" so the terminal you ran the command in is not "locked" -- a good habit to develop). You can type into it, delete, move around with the arrow keys, and do a variety of more sophisticated jobs that we will discuss later. For now, save the file (in the header menus, select FILES/SaveBuffer) and exit emacs (FILES/ExitEmacs).

To move (or rename) a file (e.g., from junk to junk2):

% mv junk junk2 [rename a file from source-name to destination-name]

To copy a file (make an identical file with a different name):

% cp junk2 bob [make a new file named "bob" that is identical to "junk2", in the same directory]

To list the contents of a file (your account is setup so "page" will do the same thing):

% more junk2 [list the contents of "junk2" to the screen; in long files, "d" = go down 1/2-screen, "space-bar" = go down whole screen, "q" = quit out of more.]

To delete a file (careful, you can't get it back!), use the rm command (this example removes the file "junk2"). Your account should be set up so the computer prompts you to double check the name of the file -- answer yes or no (y or n is sufficient) to the query.

% rm junk2 [delete an existing file named "junk2"]
rm: remove junk2?

You may want to send files to the printer. I have bad luck with the one in the computer lab, so send them to the printer in the physics office (104 Overman).

% enscript bob [create a "postscript" version of the text file (ASCII-format) named "bob" and flush it to the printer]
% lpq [lists the contents of the printer queue, so you can be sure your file is being worked on]

There are many other Unix commands. You can get detailed info about different commands (and ideas about other similar commands) by using the "man" (short for manual) command followed by the command name (gory detail, but potentially helpful). Eg to get help on the ls command:

% man ls [view manual for command "ls"]

There are also much more user-friendly (but chattier) guides for different levels (beginner to advanced) at . I encourage you to scan through at least the beginner level to really master the basic Unix command. You can also search commands and get additional help from the above site -- it is very helpful. Of course, if you have any questions you can't easily find the answer to, ask a more senior student or Andy.

Andy Layden, 2007 May 23.