Unix Commands

With the exception of a few commands that are built directly into the shell, all Unix commands are standalone executable programs. When you type the name of a command, the shell will search through all the directories listed in the PATH environment variable for an executable of the same name. If found, the shell will execute the command. Otherwise, it will give a "command not found" error.

Most commands live in /bin, /usr/bin, or /usr/local/bin.

Getting Information About Commands

The man command will give a brief synopsis of the command:

(~) 76% man wc
Formatting page, please wait...
WC(1)                                                       WC(1)

NAME
       wc - print the number of bytes, words, and lines in files

SYNOPSIS
       wc [-clw] [--bytes] [--chars] [--lines] [--words] [--help]
       [--version] [file...]

DESCRIPTION
       This manual page documents the  GNU  version  of  wc.   wc
       counts  the  number  of bytes, whitespace-separated words,
...

Finding Out What Commands are There

The apropos command will search for commands matching a keyword or phrase:

(~) 100% apropos column
showtable (1)        - Show data in nicely formatted columns
colrm (1)            - remove columns from a file
column (1)           - columnate lists
fix132x43 (1)        - fix problems with certain (132 column) graphics
modes

Arguments and Command Switches

Many commands take arguments. Arguments are often (but not inevitably) the names of one or more files to operate on. Most commands also take command-line "switches" or "options" which fine-tune what the command does. Some commands recognize "short switches" that consist of a single character, while others recognize "long switches" consisting of whole words.

The wc (word count) program is an example of a command that recognizes both long and short options. You can pass it the -c, -w and/or -l options to count the characters, words and lines in a text file, respectively. Or you can use the longer but more readable, --chars, --words or --lines options. Both these examples count the number of characters and lines in the text file /var/log/messages:

(~) 102% wc -c -l /var/log/messages
     23     941 /var/log/messages
(~) 103% wc --chars --lines /var/log/messages
     23     941 /var/log/messages

You can cluster short switches by concatenating them together, as shown in this example:

(~) 104% wc -cl /var/log/messages
     23     941 /var/log/messages

Many commands will give a brief usage summary when you call them with the -h or --help switch.

Spaces and Funny Characters

The shell uses whitespace (spaces, tabs and other nonprinting characters) to separate arguments. If you want to embed whitespace in an argument, put single quotes around it. For example:

mail -s 'An important message' 'Lincoln Stein <lstein@cshl.org>'

This will send an e-mail to me. The -s switch takes an argument, which is the subject line for the e-mail. Because the desired subject contains spaces, it has to have quotes around it. Likewise, my e-mail address, which contains embedded spaces, must also be quoted in this way.

Certain special non-printing characters have escape codes associated with them:

Escape CodeDescription
\n new line character
\t tab character
\r carriage return character
\a bell character (ding! ding!)
\nnn the character whose ASCII code in octal is nnn

Useful Commands

Here are some commands that are used extremely frequently. Use man to learn more about them. Some of these commands may be useful for solving the problem set ;-)

Manipulating Directories

ls
Directory listing. Most frequently used as ls -F (decorated listing) and ls -l (long listing).
mv
Rename or move a file or directory.
cp
Copy a file.
rm
Remove (delete) a file.
mkdir
Make a directory
rmdir
Remove a directory
ln
Create a symbolic or hard link.
chmod
Change the permissions of a file or directory.

Manipulating Files

cat
Concatenate program. Can be used to concatenate multiple files together into a single file, or, much more frequently, to send the contents of a file to the terminal for viewing.
more
Scroll through a file page by page. Very useful when viewing large files. Works even with files that are too big to be opened by a text editor.
less
A version of more with more features.
head
View the head (top) of a file. You can control how many lines to view.
tail
View the tail (bottom) of a file. You can control how many lines to view. You can also use tail to view a growing file.
wc
Count words, lines and/or characters in one or more files.
tr
Substitute one character for another. Also useful for deleting characters.
sort
Sort the lines in a file alphabetically or numerically.
uniq
Remove duplicated lines in a file.
cut
Remove sections from each line of a file or files.
fold
Wrap each input line to fit in a specified width.
grep
Filter a file for lines matching a specified pattern. Can also be reversed to print out lines that don't match the specified pattern.
gzip (gunzip)
Compress (uncompress) a file.
tar
Archive or unarchive an entire directory into a single file.
pico
Run the pico text editor (good for beginners).
emacs
Run the Emacs text editor (good for experts).

Networking

telnet
Log into a remote host machine.
rlogin
Almost the same as telnet, but uses a different protocol.
ping
See if a remote host is up.
ftp
Transfer files using the File Transfer Protocol.
netscape
Run the Netscape web browser.
trn
Read Internet News.
pine
Read your mail using a full-screen display.
mail
Read your mail using an ancient command-line program.
who
See who else is logged in.
talk
Talk to someone else who is current logged in.
lp
Send a file or set of files to a printer.
<< Previous
Contents >> Next >>

Lincoln D. Stein, lstein@cshl.org
Cold Spring Harbor Laboratory
Last modified: Mon Sep 20 16:18:00 EDT 1999