NIU Department of Mathematical Sciences
Basic Unix Commands


After logging in to a Unix system, you are in a login shell, which is a program that displays a prompt such as behr.muir% and waits for you to type a command. It then interprets the command to see what it means, executes suitable programs, and goes back to the prompt. This cycle stops when you log out.

Nearly all commands have the form

command-name options arguments
where `options' and `arguments' might or might not be present. Options modify the command's behavior, and are usually prefixed with the minus sign. Arguments specify what the command is supposed to act on (e.g. name of the file which the command should somehow process).


Unix files can have names composed of letters, digits, and several other characters. Some symbols have a special meaning to the Unix command interpreter (the shell), and should be avoided like a plague; they include: the space, ! / \ * & ? $ ` ' " ^. Some characters are perfectly OK, and are commonly used to make filenames more readable by separating the words: _ - . ~, e.g. this_is_example.1

Frequently used shell commands

(unless indicated otherwise, f, f1, etc. denote file names, while dir denotes a directory name)

Form: Meaning:
exit, logout terminate the shell (exit is preferred)
ls list files in the current directory
ls -l list files in the long format (sizes etc.)
ls dir list files in directory dir
mv f1 f2 move (rename) file f1 to f2
mv f dir move file into directory dir
mv f1 f2 f3 dir move several files to dir at once
mv dir1 dir2 rename directory dir1 to dir2, if dir2 doesn't exist; if dir2 exists, this will move dir1 inside dir2
cp f1 f2 copy file f1 onto f2 (what was in f2 disappears...)
cp -R dir1 dir2 copy dir1 onto dir2 recursively (i.e. with contents)
rm f1 f2 ... remove (delete) specified files
rm -f f1 f2 remove specified files, don't ask for confirmation
rm -f *.dvi remove all files ending with .dvi (but if you make a mistake and type a space in a wrong place, as in rm -f * .dvi, you'll zap all files! be careful!)
rm doc[0-9] remove all files with names doc0, doc1, ..., doc9
rmdir dir remove directory dir (must be empty)
rm -rf dir recursively and forcibly remove dir and its contents (be careful!!!)
mkdir dir create new directory dir
cd dir change to (move to) directory dir
pwd ``print working directory'' (its full pathname)
cd move to the home directory
cd ~/Mail move to the Mail subdirectory of home directory
cd .. move one level up in the directory tree
cat f display contents of the file f, all at once
cat f1 f2 f3 display contents of the files f1, f2, f3
cat f1 f2 f3 > f4 copy contents of f1, f2, f3 into f4
more f display contents of f in screenfuls
head f display the first 10 lines of file f
tail f display the last 10 lines of file f
tail -30 f display the last 30 lines of file f
!! repeat the last command (careful! might not be what you want...)
!la repeat the last command whose name starts with `la'
history show the last several commands that were run (in some shells)
!15 repeat command number 15 on the history list
ps list current processes belonging to the user
ps -aux list all current processes
w, who list current users
apropos keyword list commands whose description contains keyword
man command display the on-line documentation for command

Last modified: 7/20/2011 by