Unix/Linux Primer


``Unix is user friendly! It's just picky about who its friends are"

The various flavours of unix and linux provide an extremely powerful operating system.  This very brief introduction highlights just a fraction of its power and complexity.

Unix manual pages -  your biggest friend. Type man  foo to get full details on the command foo and to see all the multiple options that are often allowed.
 
 

Directories and Moving Around

Current directory:   type pwd to see what directory you are in.

Home directory: this is where you start from when you login; full path name is /cita/h/home-?/<username> where ? is 1, 2, or 3

Make directory:    mkdir JUNK  will create a directory called JUNK in the current directory

Changing directory:   cd JUNK will move you into the subdirectory JUNK in the current directory (a relative pathname)
                                  cd ..    moves you up one directory from wherever you are now (2 dots after the cd)
                                  cd        returns you to your home directory
                                  cd   /cita/local/bin  moves you into /cita/local/bin no matter where you start from (an absolute pathname)
 

Files and File Manipulation:

list files:           ls         lists all the files in current directory
                        ls -lh    shows long listing (includes permissions and ownership information)  and size
                        ls -a     shows all files including hidden files (those with names beginning with a dot)

copy files:         cp foo1 foo2  makes a new file foo2 that is a copy of foo1
                         cp foo1  TEMP/foo2 copies the file into the directory TEMP and calls it foo2

move files:        mv foo1 foo2  renames foo1 to be foo2  (only foo2 remains after issuing this command)

creating files:   start an editor (like nedit, vi, or emacs) and save the file you create
                              e.g. nedit junk& opens a window, type in something,  click save (under file) and now you have a file
                           - nedit is simple to use but only available on our Intel linux machines
                           - vi is virtually universal  and works in text-only mode (good reasons to learn some basics)  but
                              commands are difficult to remember

                           - emacs - very popular and powerful but not as simple to use as nedit
 

delete files:         rm foo       deletes foo; there is NO way to recover a file once you delete it! (unless it miraculously
                                                   happens to be on a backup tape).

                          rm -i foo   this form interactively asks you if you really want to delete the file (your account probably aliases the rm command to always do this)
                           rm -f foo    this form forces the deletion without prompting you to see if you really mean it
 

delete directories:         rm -r  FOO deletes the directory FOO and all its contents (again, no way to recover!)
                                   (
rm -rf FOO forces the deletion with no prompting)

wildcards:         ls   ab*   lists only those files that begin with ab
                         ls *ab      lists the files that end in ab
                         ls ab?      lists only those files that begin with ab followed by a single character

        BEWARE:    rm *  deletes every file in the current directory; be sure you mean to do this!
 

look at a file:       cat junk   lists the file junk in your window
                           more junk and less junk let you page through the file (hit spacebar to advance)
 
 
 
 
 

Space - how big are my files? How much space is left in this file system?

ls -lh   shows (among other things) the size of files in human-readable form

du -h  shows the size of all subdirectories in kilobytes

du -sh just gives the grand total usage (in kB) for the current directory and all its contents

df -h .  returns the size of the partition in which you are sitting (need that dot at the end!) as well as how much free space is left
 

Compiling and Running Code:

-to be filled in.... checkout the fortran compiler page for now

 
Processes - is my job running? What is this machine doing?

ps -edlf     shows all processes running on a machine as well as key info like size and CPU time used
ps -edlf |grep cloken  lists only those processes which have the string cloken somewhere in them (good way to find your own jobs)

top   displays the top CPU-using jobs;  type q to quit the resultant display

kill  pid   kills the job with process ID pid (get the pid from the ps listing) but only works if the process belongs to you
 
 

Timesavers:

grep blah *        will locate all occurrences of the string blah in files in the current directory

grep -ir  blah *  will do a case-INsensitive, recursive find for the string blah in this directory and below
 

awk  - extremely useful  pattern scanning and processing language great for extracting and processing tabular files
     e.g., try this

     ls -l  > junk1     lists all the files in the current directory and puts this info into a new file called junk1
     cat junk1            shows this new file
     awk '{print $9}' <junk1 >junk2 copies column 9 from file junk1 into file junk2
     awk '{print "total is:",$2+$7}' <junk1 >junk3  adds together the numbers in column 2 and 7 and prints this (along with text) into new file junk3
 

find . -name '*foo*'   finds all files in the current directory and below that have the string foo in their name
 
 

Word Processing

tex and latex are the typesetting programs most widely used in our community.  Difficult to learn at first but almost infinitely powerful . Typesets equations far better than microsoft has ever managed (and far more quickly with symbols and  commands that are intuitive for scientists).  Get a tex (or latex) file that works from somebody else and then hack it up to put in your own text. This is the way everybody learns it....

latex junk      processes the file junk.tex which you created with your favourite editor, creates junk.dvi as well as
                       some other files

xdvi junk      displays junk.dvi and shows you the result of the typesetting just done (assuming it was successfull)
dvips -o junk.ps junk    converts the file junk.dvi into a postscript file called junk.ps (MUST do this in order to print
                                          the document)

ghostview junk.p     display the new postscript file on your monitor
lpr  junk.ps                  print it out!
 

Data Analysis and Visualization

Can't go wrong if you learn IDL.  Kind of like interactive fortran90 and a debugger. Write analysis routines with lots of built-in math routines. astron library routines let you easily read FITS images, do photometry, image deconvolutions, yada-yada. Slice and dice 3D datasets, make isosurfaces etc. Type idldemo at Unix prompt for a tour. idlhelp at the prompt brings up the manuals.

mathematica, matlab and maple (but maple runs only on mouse) are also supported at CITA.