Unix Crib Sheet (Linux and SGI)


Unix is the operating system running on all of the facility's workstations and servers. The SGIs run their own version of Unix called IRIX, while the Pentium 4 workstations run the public-domain version of Unix called LINUX. The underlying operating system in Apple's OSX is also Unix - try opening Terminal.app to get a shell.

Unix has a number of useful features:

The latter feature is especially useful because it's the habit of other applications overwriting operating system memory that makes PCs and older Macs crash with monotonous regularity. Apple's new OSX operating system has an underlying Unix core, thus providing all the above advantages. PC hardware running Linux crashes about once every 3-4 months, at most. A PC running Windows crashes about 10x more often.

Other sources of beginner Unix guides are:

The Unix Filesystem

Basic File Manipulation Commands

Command Description Usage example
cd Change directory cd subdir
pwd Print working/current directory pwd
mkdir Make directory mkdir subdir
rmdir Remove (delete) directory rmdir subdir
ls List directory contents ls *.img
cp Copy (duplicate) file cp a.pdb b.pdb
rm Delete file (permanently!) rm a.pdb
mv Move (rename) file mv a.pdb b.pdb
cat Concatenate (list) file to screen cat a.pdb
more Page through a file more a.pdb
head Show top of file head a.pdb
tail Show end of file tail a.pdb
grep Search for string in file grep "HIS" a.pdb
file Try and determine type of file file /bin/ls
Home directory is the top of your personal file tree. Abbrevations for home are "~" for your home and "~user" for the home directory of "user". The directory "." is always the current directory. The directory ".." is the parent directory. Directories in a filename are separated with the forward slash "/" in Unix (":" in a Mac, "\" in Windows/DOS) e.g. ~phil is synonymous with /ximpact1/usr1/phil. There is no Trash in Unix. Once you delete a file it is gone forever.

Simple Shell Commands

alias Make command alias alias ls 'ls -alF'
echo Echo string to output echo "This data is bad"
exit Exit the shell exit
history Show command history history
logout Exit the (login) shell logout
set Set variable to value set a = 1
setenv Set environment variable to value setenv DISPLAY ximpact1:0
See ~phil/.cshrc for examples of this usage, and other stuff.

More Simple Unix Commands

date Show date and time date
df Display filesystem data df -k
du Disk usage du -sk *
man Manual (help) man cat
script Record EVERYTHING you type/see script really_big_logfile
who Who is logged into the system who
whoami Who the Hell am I ? whoami
which Which command will I execute? which denzo

Job Control

& Run process in background gzip *img &
^Z Suspend (stop) process ^Z
^C Interrupt (kill) process ^C
bg Run (suspended) process in background bg
fg Run process in foreground fg
ps Show processes ps, ps -efl
jobs Show jobs (process under shell control) jobs
kill Kill process kill process_id
killall Kill all named processes killall netscape
nice Run processes at reduced priority nice gzip *img
If a process is running in the foreground, the shell waits for it to complete before accepting more command input. In the background, the process runs semi-independently of the shell - even if the shell exits the process keeps running (you may need "set nohup" in your .cshrc for this).

File Redirection

> Write output to file ls > listing
>> Append output to file ls .. >> listing
| Piple output to input of next command ls * | grep img
< Take input from file molscript < ms.in
<< String Read data from input until "String" peek2 << EOF
If you have noclobber set in tcsh, then > and >> will not overwrite existing files or create new ones. Use the forms >! and >>! to override this option.

Printing

lp Print to default printer lp mydata.ps
cancel Cancel print job cancel request-ID
lpstat Show status of printer queue lpstat -PHP4si

Advanced File Manipulation

chown Change owner chown phil.user myfile.dat
chmod Change mode (permissions) chmod a+x my_script_file.csh
ln Soft or hard links ln -s ../mbsd39.fobs my_local_clone.fobs
cut Cut file by columns cut -c1-30 file1
paste Paste files back together by columns paste file1 file2
diff Show file differences diff peek2.f peek2_old.f
sort Sort a file sort -n +7 -8 water.pdb
tee Copy output to screen and file simultaneously ls | tee listing
touch Create empty file/update access time touch file1
wc Count characters/words/lines wc file1
find Powerful file finder find . -size +3000 -print
Use of any of these commands without consulting the manual first (e.g. "man find") is likely to result in disaster.

File Transfer and Archiving

gzip Efficient file compression gzip *.img ; gunzip *.img.gz
compress Less efficient file compression compress *.img ; uncompress *.img.Z
tar Make tape/disk archive tar -cvf /dev/tape my_data/.
ftp File transfer between remote machines ftp xray2.mskcc.org
telnet Login to remote machine telnet xray2.mskcc.org

Simple Graphics Commands - LINUX

acroread Adobe Acrobat Reader (PDF) acroread paper.pdf
gs View Postscript/PDF files gs paper.ps
display Display graphics file display image.jpg
convert Convert between file formats convert image.jpg image.pict
gimp Photoshop-like image manipulation gimp

Simple Graphics Commands - SGI

acroread Adobe Acrobat Reader (PDF) acroread paper.pdf
xpsview View Postscript files xpsview paper.ps
display Display graphics file display image.jpg
xv Display graphics file xv image.jpg
ipaste Display graphics file (SGI format only) ipaste image.sgi
convert Convert between file formats convert image.jpg image.pict
imgworks SGI-format image manipulation imgworks image.sgi
cedit Interactive color editor cedit
makemap Restore colormap after cedit mangling makemap