Unix Guide

Opening Comments
Before you start, you should know:
- Unix is case-sensitive
- pressing the Tab button will fill in the remainder of a command, directory or filename, if the choice is unambiguous.
- symbol * represents a wildcard whose length can be any number of characters
- symbol ? is a one character wildcard

In this guide:
- italicized words represent parts of commands that should be filled in with appropriate file or directory names

Simple Operations
clear clears the screen
exit exits the window
man accesses the built in manual
entering "man man" will give you information on how to use the manual
once inside, press q to exit

Using Commands
Commands usually come in the form:

command -char filename or directory

The second character is usually one letter which modifies the command in some way. Both the character and filename are optional, but may be necessary for some operations. Commands can be executed on files or directories that are not in your current location. (See Directories for more information)

One command that you will use a lot is ls. It lists what's inside your current directory. You can add things to modify what you see:
-l allows you to see a "long" listing of each item
-a allows you to see the system files (whose names start with a ".") that you wouldn't normally see with "ls"
-la allows you to accomplish both (equivalent to "ls -l -a")

Try using man ls for a full listing of options you can use with the "ls" command.

Directory Structure
When you get the command prompt, you have some "location" where you are able to list, access, or modify files. If you know the locations of other files, you can access them from your home directory (which is where the command prompt will always start you.) You can also change your location by moving around the various directories.

Here are some commands associated with moving about:
pwd "print working directory" - shows the path to your current directory
cd path-to-directory takes you to another directory; note that you have to specify the path with your current directory as a starting point
cd entering "cd" alone will automatically take you back to your home directory

More on navigation:
~ indicates your home directory
When you are located in your home directory, you can access other directories using "~/path-to-directory". (For example, "ls -l ~/Desktop" will print a long listing of objects inside the child directory labeled "Desktop")
/ indicates the starting directory. (There are no directories above it).
If you know particular pathway starting from the highest directory, you can access that location by entering the pathway. (ex: /usr/local/bin)
../ refers to parent directory, moves you backwards by one directory
Using the example above, if you are in the "bin" directory, and you want to move to another directory, "newdir", located in "/usr/local", you can type "cd ../newdir" instead of "cd /usr/local/newdir."

Creating and Manipulating Directories and Files

mv filename path moves a file titled "filename" to a new directory to which "path" points; you may use * symbol to move more than one file (e.g. "mv foo* ../" will move all the files in the current directory whose names start for "foo" to the parent directory)
mv filename filename2 renames the file titled "filename" to "filename2" ("filename" will no longer exist); "filename2" may be a simple file name or start with a path to a different directory, e.g. "../foo2"
mv dir path moves a directory named "dir" and its contents to a new location specified by "path";
cp filename filename2 copies a file titled "filename" to a file "filename2"; as for mv command, "filename2" may be a filename or a path ("filename" itself is unchanged by this command)
cp filename path copies a file titled "filename" to a new directory to which "path" points, retaining the same file name; this format will work with the mv command as well
cp -r dir path copies a directory "dir" and its contents to a new location indicated by "path";
the -r stands for "recursively" and (in contrast to the "mv" command) is necessary for the contents to be copied
rm filename removes the file titled "filename" from the current directory;
to access a file in directories outside your current location, just enter the correct path (ex: "rm ~/dir/foo" removes the file "foo" from the directory titled "dir")
rm -r dir removes a directory "dir" and its contents.
The -r stands for "recursively". If you try to delete a directory that has files or other directories inside, UNIX will not remove it without this modifier. One of the most dangerous commands in unix is
"rm -r *"! Always think before you use rm.
mkdir dir creates a directory "dir"; alternatively, you can enter a path if you want to create a directory somewhere other than in your current location)
rmdir dir removes a directory "dir"; this only works if this directory is empty (again, you can use a path)

Useful Applications

emacs & opens emacs, a text editor
acroread & opens acrobat reader, which allows you to view pdf files
gv & opens ghost viewer, which allows you to view post script files (.ps)
ds9 & opens DS9, which allows you to view images (.fit)
Adding "&" causes the application to run in the background. Otherwise, you will not be able to use the command prompt in the original window without closing the application.
You can open a particular file by inserting the filename (or path) in between the command and the "&"

A Few Other Useful Commands

file filename shows what type of file "filename" is
more filename displays the contents of a text file without having to open emacs or some other text editor
less filename does essentially the same thing as the more command
zip filename creates a compresses file "filename.zip"
unzip filename.zip uncompresses a zipped file
gzip filename creates a compresses file "filename.gz"
gunzip filename.gz uncompresses a gzipped file

The Basics of Networking

While the home directories are located on a disk which is cross-mounted (i.e. directly accessible) from any computer in the astro cluster, sometimes you will have to access one of our computers from another, or login to a cluster computer from outside (note that the latter is only possible from another Mudd machine for security reasons). Here are the two commands that you will find very useful:

ssh -X username@machineaddress stands for "secure shell"; allows remote login. Let's say a person with username "mright" wants to access the cluster computer named "goofy". In this case the proper command would be ssh -X mright@goofy.physics.hmc.edu
The modifier -X is necessary to allow you to open new windows from "goofy" on the local screen (works only if your local machine has Xwindows package installed).
scp -r dir username@machineaddress:path copies the directory "dir" and its contents from the local machine to the computer specified by "machineaddress" into the directory specified by "path" owned by "username".
scp username@machineaddress:path/filename localpath copies the file "filename" from the directory specified by "path" owned by "username" and located on the remote computer specified by "machineaddress" into the directory on the local machine specified by "localpath". In these circumstances "*" CANNOT be used to copy multiple files, however, "-r" will still work.