Introductory Unix Guide

These commands are some of the most basic and commonly used commands in UNIX. Learning these commands will allow you to get around more quickly in your new account, and also give you a good idea of some of the things you are able to do on a UNIX system. Hopefully the commands included in this document are useful to you. If there is anything you think could be added or changed to make it better, feel free to make changes to this document, or (if you're not comfortable or knowledgeable enough) email your suggestions to the [Head Consultant].


For Starters

The commands below can be typed in any shell you have running in your account. A shell is the basic user-interface in UNIX. You will recognize it as a window which displays a prompt (for example, "~ ->"), where you can type commands. For the commands listed below, parameters enclosed in [ ] means that they are optional. Parameters enclosed in < > must be provided for the command to work correctly. For clarity and completeness, the most commonly used options for many of the commands below have been listed to give you a better idea of the power and abilities of some of the unix tools you have available to you.

You will notice that for some of the commands you type below, your shell will continue to run them until they are completely done. When it does this, it will "steal" your prompt, and you will be unable to use the shell again until the program it is running has finished execution. In order to continue using the shell effectively (that is, to get your prompt back so you can type in more commands), you can put any program in the background.

To make a program run in the background, you can type an '&' after the command you wish to run and then hit return. The prompt should return immediately. If you would like to background an program after it has been started, you can do so by hitting CTRL-z (also abbreviated as C-z or ^Z) which suspends the process, and then typing 'bg' when the prompt has returned. Typing ^Z without typing 'bg' will "freeze" the program. Typing 'bg' will allow it to continue what it is doing but not take over your shell. To bring any program you have backgrounded back into the foreground, simply type 'fg'.

You can find out more information about most of these commands by using the man pages. These pages give detailed information and lists all of the different possible options that are available for most UNIX commands. To view the man page for a specific command, simply type 'man <command>'. You can even type 'man man' for more information about the man command itself. If you have more questions or need some help in deciphering the man page, feel free to ask the Sun Lab Consultant for assistance.

Supported vs. Unsupported Software

All of the software available in the CS department falls into two catagories: supported software and unsupported software. Supported software includes those applications which are maintained by the Technical Staff (tstaff). This means that tstaff will do everything possible to fix problems or catastophes that occur when you are using one of those applications. Unsupported software is generally maintained by fellow students, who try to make their projects as stable as possible, but no guarantees are given if the application should break.

Check out for an explanation of tstaff software support. You can also figure out which applications are supported by using the which command (see below for full description). Any applications whose path begins with "/local/bin", "/usr/bin", or "/usr/local/bin" are supported, while any applications that begin with "/contrib" are not.

New students are strongly encouraged to use supported software. Any problems which users may have with supported software should be mailed to and will be taken care of by tstaff as quickly as possible. Problems with unsupported software should be mailed to the owners of the project.

Basic UNIX Commands

alias <shortcut> "<full command>"
This is a useful way to create shortcut commands for those long commands you find yourself typing a lot. For instance, if I wanted to make every remove I do be interactive (see below for rm), I can type alias rm "rm -i" so every subsequent time I type rm, it will remove a file interactively. If your full command is only one word long, you can leave out the quotations.  :: Examples: :: ~ -> alias rm "rm -i"  :: ~ -> alias ls "ls -F"  :: ~ -> alias dir ls
cat <filename>
Prints out the contents of a file to the screen. Usually used for text files. More commonly used are more and less which pause the printing of a file after a screen has been filled.  :: ~ -> cat file1.txt
cd [directory]
Changes your current working directory to the directory specified. If 'cd' is typed without any arguments, it will take you back to your home directory.  :: ~ -> cd mail/  :: ~ -> cd wave/src/SnowPerson/  :: ~ -> cd
cp [options] <source filename> <new filename or target directory>
Copies the first file by creating a second file with the second file name given. If a directory is specified instead of a new filename, then the source file will be copied into the directory with the original filename. You can also copy a file into a directory with a new filename if you follow the target directory with the new name of the file.
cp -i will make copy interactive, i.e. confirm and give warnings if you are about to overwrite an existing file.
cp -r will make the copy recursive. Useful if you wish to copy the contents of an entire directory.  :: ~ -> cp  :: ~ -> cp tmp/  :: ~ -> cp -i tmp/  :: ~ -> cp -r tmp/ backups/
du [options] [directory]
Displays information about files and their sizes. Used most often to check the total size of one's account. du -k lists the sizes and total of all the child directories
du -a lists all the files
du -s prints just the sum of the sizes of the files  :: ~ -> du -k  :: ~ -> du -ka  :: ~ -> du -ka tmp/  :: ~ -> du -ks
echo [string]
Prints the string out in your shell. Be careful when trying to print special characters like single quotes.  :: ~ -> echo hello there  :: ~ -> echo boo hoo there is nothing to do  :: ~ -> echo "boo hoo there's nothing to do"
Exits the shell. Or, if logged in remotely, will log you out.
finger [name or account or @machinename]
Looks for the user with the given name or account. Displays information about their login and mail status. If `finger' is typed without any arguments, it will display all of the users currently logged in on your machine.  :: ~ -> finger  :: ~ -> finger jwc  :: ~ -> finger George  :: ~ -> finger @9a  :: ~ -> finger
grep <word> <filename(s)> or grep "<string>" <filename(s)>
Looks for the word or string in the files specified. Use the quote to encase your string when you want to search for a string which contains spaces or other special characters.
grep -i will ignore the case of the string.
grep -c will give the count of the number of lines where the string appears
grep -v prints all lines except those that contain the pattern
 :: ~ -> grep class  :: ~ -> grep -i cs015  :: ~ -> grep -c ";"  :: ~ -> grep "Aren't SnowPeople cute?"
groups [user]
The groups command will list all of the groups a specified user belongs to. If a user is not specified, the groups for the current user will be listed.
gzip/gunzip <filename(s)>
gzip/gunzip compresses/uncompresses specified files. The compressed version of the file will have a .gz extension at the end of the filename. The uncompressed version will not. Note that gzip will delete the original file after it creates the compressed file. Similarly, gunzip will delete the .gz file after it restores the original file.  :: ~ -> gzip  :: ~ -> gunzip
ls [options] [filename(s)]
Lists all of the files in the specified directory. If no arguments are specified, it lists the files in the current working directory.
ls -a lists all the files in the directory
ls -F formats list with symbols so you can distinguish types of files. Put a slash (/) at the end of a directory, an asterisk (*) if the file is an executable, and an at-sign (@) if the file is a symbolic link.
 :: ~ -> ls  :: ~ -> ls -F  :: ~ -> ls tmp/  :: ~ -> ls -aF tmp/
man <UNIX command>
Displayes the man page about the specified UNIX command. man can be typed for all of the commands in this section for more information about the options and capabilities of each of these commands. If you feel confused by the man pages, feel free to ask the consultant to give you an explanation in human terms.
mkdir <directory name>
Creates a new directory with the specified name.
more <filename>
Similar to cat, in that it prints the file to the screen, but pauses when the bottom of the screen is reached. Press the spacebar to move forward through the file by another screen-page, and press 'b' to move backwards one screen-page.  :: ~ -> more file1.C
mv <source filename> <new filename or target directory>
Changes the name of a file from the first filename to the second filename. The file will then no longer exist as the first filename, but will only exist as the second. If a directory is specified instead of a new filename, then the source file will be moved into the directory with the original filename. You can also move a file into a directory with a new filename if you follow the target directory with the new name of the file. Everything works the same if you wish to move entire directories as well.
mv -i will make the command interactive, i.e. confirm and warn you if you are about to overwrite an existing file.  :: ~ -> mv file1.txt file2.txt  :: ~ -> mv -i file1.txt file2.txt  :: ~ -> mv -i file1.txt tmp/  :: ~ -> mv -i file1.txt tmp/file2.txt  :: ~ -> mv tmp/ foo/
ps [options]
Prints information about active processes.
ps -u <account> will list the process running from that account. Especially useful if you are trying to figure out if you are already running a program in the background. ps without any options will print out the programs that were started in the current shell and are still running.
 :: ~ -> ps  :: ~ -> ps -u jwc
Not to be mistaken with passwd, this command stands for print working directory. Your working directory is the full path name of the directory in which you are currently working.
rm <filenames>
Removes or deletes a specified file. This command should be used with caution because after a file is deleted, it cannot be immediately recovered. It should almost always be used in conjunction with the -i option. rm -i makes the command interactive, i.e. it will confirm that you really want to remove the file before completing the task.  :: ~ -> rm -i
rmdir <directory name>
Removes the specified directory. The directory should be empty before running this command.  :: ~ -> rmdir tmp/
ssh [options] <hostname>
Will log you into another computer specified by the hostname. Without any options, ssh will simply log you into the other computer.
ssh -l <account> <hostname> will log you in as the specified user.
 :: ~ -> ssh 9a  :: ~ -> ssh -l jwc 9a
tar [options] <outputfile> <filenames or directory>
Concatenates or archives the files or entire directory listed into a single file. Most often used in conjunction with gzip to compress the resulting tar file.
The options on tar are a little unusual in that they are not preceded with a '-'. Below are the most common ways that tar is used, and the necessary options. If you have more questions about tar, please ask a consultant.
tar cvf will create a tar file. After tarring is complete, the files you tarred will still exists. Tarring does not eliminate the files, just copies them into one larger file.
tar xvf will extract the files which are contained in the tarfile. After untarring is complete, the tar file will still exist in addition to the files that have been extracted. This is nice especially if you just wanted to look up something. You will not need to retar the files all over again.  :: ~ -> tar cvf myoldfiles.tar file1.C file2.C file3.C  :: ~ -> tar cvf oldmail.tar mail/  :: ~ -> tar xvf myoldfiles.tar  :: ~ -> tar xvf oldmail.tar
wc [options] [filename(s)]
Does a word count on the specified file(s). Can be modified to count other things, based on the options you give it. With no options, wc will print out the number of lines, the number of words, and the number of bytes (in that order) in the file(s).
wc -l counts the number of lines in a file
wc -w counts the number of words.
wc -c counts the number of bytes.
wc -m counts the number of characters.
 :: ~ -> wc  :: ~ -> wc -l  :: ~ -> wc -lwc
which <UNIX command>
Displays the entire path name of the specified command. This is useful when you want to find out exactly which command you are using when two programs exist in different directories but share the same name.  :: ~ -> which man  :: ~ -> which vim
Prints out the account name of who you are currently logged in as.

Web Browsers, E-Mail Programs, and Newsgroup Readers

Web browser
Mail reader


xemacs [filename(s)]
Xemacs is the most commonly used editor for writing and debugging code. It has several advanced features that make it a versatile all-in-one application, including the ability to be a web-browser, a news reader, an email reader, as well as a shell and ftp client in addition to its editing capabilities.  :: ~ -> xemacs file1.txt file3.C  :: ~ -> xemacs-19 file3.C &  :: ~ -> xemacs &
vim [filename]
A very powerful editor, but not as intuitive pico or emacs. Great for getting around a file quickly when one knows the commands, but a little more difficult to learn.
pico [filename]
Simple editor. Menu of commands listed at the bottom for easy use. This is the editor used in pine, so if you feel comfortable with pico, you might like pine, and vice versa.)

==Printing and Print Queue Commands== All printouts by default spool to the CIS printer. Printouts generally take five to ten minutes before they can be picked up at the CIS Distribution Window in the CIT Atrium.

a2ps [options] <filename(s)>
A nice program for formatting and printing source code (or any other plain text files). Use this when you want to print out lots of files or when handing in assignments. a2ps has lots of useful options and formatting modes.
a2ps -P display will preview the output (with gv) instead of sending it to the printer.
a2ps -1 will fill the whole page in portrait mode.
a2ps -2 (the default) will print two columns per page in landscape mode.
a2ps -3 uses three columns.
a2ps -4 prints 4 "pages" per page, arranged in a rectangle.
a2ps -B gets rid of the headers that a2ps puts at the top and bottom of your page, if you want a cleaner printout.
lpr [options] <filename>
Prints text and postscript files. Should be used when printing only one file at a time.  :: ~ -> lpr file1.txt  :: ~ -> lpr
lprm [options] <job number>
This command is used to remove a print job from a print queue. After typing lpq, find the process id of your print job, and then type lprm with the process id of your print job to remove it from the queue.
lpq [options]
Useful tool when checking the status of your printout. Will show you the list of waiting jobs for a particular printer.

Useful Commands and Applications (Unsupported)

Provides a graphical interface for playing cds.
Provides a graphical interface to adjust the sound volume.
grplist [options] <group>
The grplist command will list all the users in a specified group.
gv [filename]
Used to view postscript and pdf files.
 :: ~ -> gv  :: ~ -> gv mypdffile.pdf &
less <filename>
Similar to more (see above for more). Will display the contents of a file to the screen, and then pause. Less allows for the user to move upwards and downwards through the files by line using the arrow keys. Like more, the spacebar will display the next screen, and 'b' will move back a screen.
loc [options] [users]
Locates a user on the system. If `loc' is typed without any arguments, all of the users currently logged in anywhere in the department will be displayed. Loc automatically limits your search by ignoring users who have been idle for more than an hour. You can further limit this search with the available options.
loc -a lists all the users, regardless of idle time
loc -g <groupname> finds all of the people who are in a specified group
 :: ~ -> loc  :: ~ -> loc -a  :: ~ -> loc -g consult
lw [options]
Displays the layout and current users of the lab. Below are some useful options. To find out all of the options, type lw -h. The default is lw -fb.
lw -f prints the full name of the users in the lab
lw -n prints the login of each node lw -i prints the idle times for each node in the lab  :: ~ -> lw  :: ~ -> lw -fntilb
praliases <mail alias>
Prints out the names included in any mail alias. This is useful if you are wondering exactly who will receive email which is sent to, or some other mail alias within the CS department.  :: ~ -> praliases cs015tas
Tells you if there is a waitlist running, and if so, how much time you have before your machine will be assigned to another user.
xanim <filename>
Views QuickTime movies (.mov files), .avi files, and .mpeg files.  :: ~ -> xanim myfirstfilm.avi &
xlock [options]
Locks a node and requiring the user to type in their password before being allowed access to reaccess their account. There are several different modes available. See the man page for more information.
xlock -mode will lock the account with the given display mode  :: ~ -> xlock  :: ~ -> xlock -mode swarm
xmms [options] [files]
Modelled closely after Winamp, it provides a graphical interface for playing songs as well as a playlist. You can play just about any type of music file from the local machine or you can stream music from the web.
xv [filename]
Application used to view graphics, and make simple modifications. Can open .gif, .jpg (.jpeg), .tiff, and .bmp files.  :: ~ -> xv &  :: ~ -> xv mypic.gif &  :: ~ -> xv mypic.jpeg &
zwrite <user>
Send an instant message to another user. This will only work if the receiving person is running a zephyr client. Anyone can run a zephyr client by typing zwgc in a shell while logged in on console, or zwgc -ttymode if logged in remotely or on a terminal.
 :: ~ -> zwrite cs015001  :: ~ -> zwrite dl scs