Some Essentials of UNIX, for Astronomy Research F. A. Ringwald updated version: 1998 November 11 The most common computers used in research astronomy throughout the 1990s are SUN workstations, running the UNIX operating system. These often use a graphical user interface such as OpenWindows or Solaris, with Xwindows graphics. Two common image processing systems that run under UNIX (and a variety of other machines) are IRAF, the Image Reduction and Analysis Facility, which is distributed free from the National Optical Astronomy Observatories, and IDL, which is a commercial program and costs money. This makes IRAF by far the more widely used. Since IRAF runs under UNIX, let's take a closer look at UNIX. When you log into a Sun running UNIX, such as galileo, kepler, or zach, four files are run: .openwin-init which controls the OpenWindows graphical user interface .Xdefaults which stores parameters used by Xwindows .login which initiates UNIX .cshrc the C shell resource file, which is run whenever you boot up a text window, such as an xterm window. In this file you should put your aliases (see below). Some common commands used in UNIX: man (command) - the online manual (help file) describing the command. The best thing to do, of course, is just to type the command in yourself, and see what it does! ls - list files in your current directory ls -l - list files in current directory in long format, showing permissions ls -a - list files in your current directory, including "hidden" files (which have filenames starting with . and so don't show up) ls -alt - list hidden and regular files in long format, sorted by time last modified cat filename - list contents of a file, without stopping more filename - list contents of a file, stopping at each screenful head filename - list just the first few lines of a file tail filename - list just the last few lines of a file alias command1 command2 - changes name of command1 to command2. Your .cshrc file is a good place to put ones you use all the time, but you may use the alias command any time. Example: alias dir ls will evoke ls by typing dir. alias - lists all aliases alias command1 - tell what command1 is aliased at. unalias command1 - stop using alias for command1 cp filename1 filename2 - copy a file mv filename1 filename2 - rename a file, or move it to another directory rm filename - delete a file WARNING: in UNIX, the defaults are to copy over or delete all your files, unprompted!! Therefore, whenever opening up a new UNIX account, put the following aliases into your .cshrc file, if they're not there already: alias cp 'cp -i' alias mv 'mv -i' alias rm 'rm -i' This at least give you prompts, e.g., you type: rm file and before deleting your file, the machine returns, rm: remove .cshrc? to which you reply either y on n. Uncompressing files: uncompress *.Z - uncompresses files compressed by program compress, which adds the suffix .Z tar xvf *.tar - unpacks the tape archive *.tar, in which one can bundle many files together (like a zip disk). One can also make tar files, with other qualifiers for tar: type "man tar" and see for yourself. Permissions: chmod 755 filename - Change permissions on filename, to make it available to anyone in the world (great for www files) chmod 400 filename - Change permissions on filename, to make it only readable to you and to no one else. man chmod - Read more about how to change permissions on files. ls -l will show permissions. r is read, w is write, x is ececute (for compiled programs), for the owner (u), group (g), and other (o). Directories: cd (directory) - enter the directory specified cd .. - go up one directory cd - go to your home directory mkdir (directory) - make a new directory rmdir (directory) - delete a directory (will work only if empty) pwd - print working directory: show which directory you're currently in ~ (the tilde symbol) stands for the home directory. Disk space: df - disk free du - disk usage Wildcards: * - wildcard (substitute for any character string) ? - wildcard for only one letter grep string (file) - Find a string of characters in a file. Very useful! find /*/* -name "(file)" -print - Find file in sub-directory /*/* History commands: history - show the last several commands you typed. !c - recall the most recent command beginning with a c. !14 - recall command number 14. !! - recall the most recent command (also up arrow in an xterm). Pipline commands: command > file - direct output of the command into a file (overwrites) command >> file - append output of the command to the file command1 | command2 - perform command2 on the output of command1 Job control: ps - see what processes are running ps -aux - fancy way to see what processes are running jobs - look to see what jobs are running in background (batch) command & - run the command in background (and free up the window) nice +20 nohup csh (program) & - run program in background on slow queue bg %1 - put job number 1 into background fg %1 - put job number 1 into foreground control-z - suspend a forground job (but don't kill it) kill (job number) - kill a job (stop it from running) kill -9 (job number) - kill with extreme malice abort - kill a job, running in background (batch) Network programs: w - who's on the system now finger - check to see who's on another machine (now often disabled) whoami - just to make sure hostname - tells you which machine you're on pine - a really good e-mail program; uses the pico editor telnet - login to another machine rlogin - basically the same as telnet ftp - file transfer program Example of using ftp (to get data files for dwarf nova outbursts): Type: ftp kepler.pss.fit.edu anonymous (your e-mail address) ? [List all commands] help [command] [Explain each command] cd /pub/incoming/ringwald/dne/zc [This picks out the directory you want] binary [Only necessary if transferring binary files; not for text] prompt n [Turn prompt off; optional, but useful for transferring many files] ascii [Get ready to transfer a text file: don't use for binary!] get belgianzcs.txt [get the file belgianzcs.txt, a text file] cd robozcs [Go into another directory] mget * [Get everything in there] quit [Quit the ftp program.] Compiling c programs: cc myprog.c - compile "myprog.c"; writes output as "a.out" cc myprog.c -o myprog -lm - compile "myprog.c", write output as myprog, and link it to the math library make - organize a series of programs (read man make) Text editors: pico - Clearly the best text editor for UNIX, although rather basic. emacs - A much more powerful editor, which addles my brain. vi - The worst text editor ever written: use only if desperate. Other utilities: sort - sorts files perl, sed, awk - text manipulation programs (read man pages( sm - The SuperMONGO plotting program. Type help for list of commands. Printing: lpr filename - print a file lpr -Plw? filename - print a file, on printer lw? lpq - check the printer queue lprm - remove a job from the printer queue Logging out: exit - logout lo - common alias for logout bye - common alias for logout =========================================================================== Another example of transferring files from an ftp archive, uncomressing and untarring them, and compiling c is skycalc, John Thorstensen's *great* astronomical calculator program, which he wrote in c so it would run on just about anything (at observatories most anywhere in the world): SKYCAL.TAR.Z -- Astronomical almanac calculator and calendar programs: V4 To obtain from the NOAO FTP archive via INTERNET: % ftp iraf.noao.edu (or 140.252.1.1) login: anonymous password: [email address] ftp> cd contrib ftp> binary ftp> get skycal.tar.Z ftp> quit To extract, compile, and link (under UNIX): % zcat skycal.tar | tar xf - % $cc skycalc.c -lm -o skycalc % $cc skycalendar.c -lm -o skycalendar where $cc is a C compiler. Note that skycalc.c requires an ANSI c-compiler as noted below. =========================================================================== REVISIONS -- 1994 September --- bug fix (V4.1) Works around a problem with incorrect dates (all zeros) printed on Silcon Graphics and perhaps others. REVISIONS -- 1994 September version (V4) The calendar-printing program is unchanged from V3. The calculator program is considerably revised; the most important revisions are: 1) Can read a file of objects; user can then set to coordinates of an object by name or have the object list sorted according to a number of different criteria. Very useful while observing. 2) Can produce a log file of output results while running interactively. [N. B. -- This feature requires a working ANSI c-compiler; the standard Sun "cc" compiler fails, and the ANSI version "acc" fails because of a known compiler bug. However, the Open Software Foundation's "gcc" compiler *does* create working code for sparcstations. A binary version is distributed for those who need it.]