General Unix Commands

Unix is case sensitive, and most commands are lower case. Basic commands for Unix include:

ls [directory]
list files in a named directory (default is current directory, uses * for wild anything and ? for one wild character)
pwd
gives name of current directory
jobs
lists jobs running in the current shell
ps -ux
lists all processes you are running
man command name
gives cryptic unix help notes on a command
cat filename
prints the contents of a file to the screen (like type in DOS)
more filename
prints the contents of a file to the screen, stopping at the bottom of each page so that you can read the file. Uses spacebar to continue, q to quit.
head -n filename
shows the first n lines of a file (default n=10)
tail -n filename
shows the first n lines of a file (default n=10)
lpr filename
sends a file to the printer
lpq
lists the print queue (good for seeing why printing is so slow and to get job numbers to use with lprm)
lprm job #
removes a job from the print queue (must belong to you)
cp filename1 directory/[filename2]
copies a file to a directory
mv filename1 directory/[filename2]
moves a file, used also for renaming
rm filename
deletes a file
mkdir directory
create a directory
rmdir directory
removes a directory
finger username
checks to see if someone is logged on
chmod code filename
sets protection levels, needed to make a script (file of unix commands) executable
history
lists the last commands used
xterm
opens a new xwindow
Any program which doesn't need direct input can be run in the background by putting & at the end of the command line. If you ever start a program without the &, but want it to run in the background, type C-Z (meaning control Z - hold down control and hit Z) to pause the program, then bg (return) to start it again in the background. To return it to the foreground, use jobs to get the job number n, then fg %n. C-C stops programs running in the foreground. You can find the jobs you are running with a jobs command, and all processes with the ps -ux command. To stop a process type kill -9 processid.

Dos lovers: it's easy to make scripts so that you can use your favorite DOS commands with unix. Here's an example so that dir will give a directory. First, create a file called dir to contain the unix commands needed.
cat >dir
ls $1 $2

Control-D
Explanation: cat with the right arrow directs input from the keyboard into a file. So file dir now contains ls $1 $2 . The $1 and $2 are storage markers for things you might want to type after dir, for instance when looking for all TeX files you could type dir *.tex. Or to get the full listing broken into pages we could "pipe" the output through more with command: dir *.tex |more. The control-D tells unix that we are done with keyboard input. Now dir is not an executable file, we have to use chmod on it:
chmod u+x dir
This command tells unix to allow the user (owner) to execute the file. Other choices for chmod are g for group or o for other (anyone) instead of u, and w for write or r for read instead of x. Finally, we should move the file into the bin directory to get it out of the way and put it where unix expects executable files, so use mv:
mv dir ~/bin

Other DOS scripts:
cat > del
rm $1 $2
Control-D

cat > type
cat $1 $2
Control-D

You can copy text from one window to another (or within a window) by marking with the left mouse button, then clicking the middle button to insert.

More Help:

Unix help from University of Edinburgh courtesy of MSU's ITC.
Information about emacs, the most-used unix editor.

Stat package demos for unix packages:


Author: Jim Robison-Cox
Last Updated: January 16, 1998