In this appendix, you’ll find a fairly thorough reference on Unix commands and flags as well as examples and descriptions of each. We organized this appendix to generally parallel the book, so that you can easily reference key commands and related flags without being overwhelmed with long lists of commands.
Table A.a summarizes what you’ll find in this appendix.
Tables A.1–A.15 contain commands and flags that relate to the topics covered by the similarly numbered chapter (Chapters 16 and 17 do not introduce many new commands, so the commands from those chapters are included with similar commands in the other appendixes). In addition to the commands and flags discussed in the chapters, you’ll also find related commands and options that you might find useful in your Unix adventures, reference information that will jog your memory, and ideas to help you get off and running on additional projects. If you’re looking for a thorough command flag reference, check out Appendix C.
COMMAND | DESCRIPTION |
---|---|
chgrp | Change the group association of files or directories. |
chgrp groupname filename | Change the group association of filename to groupname. |
chgrp -R group directory | Recursively change the group association of directory and all subdirectories and files within it to group. |
chmod | Change the permissions for a file or directory. |
chmod a-w file | Remove write permission for file for all (everyone). |
chmod g+w file | Add write permission for file for the owning group. |
chmod -R go-rwx * | Revoke all permissions from everyone except the user for all files in the current directory and all subdirectories and their contents. |
chmod u=rwx, g=rx, o=r file | Set the permissions on file to user read, write, and execute, group read and write, and others read. |
chmod ugo= * | Revoke all permissions for everything in the current directory from everyone. |
chown | Change the ownership of files or directories. |
chown -R user Directory | Recursively change the ownership of Directory and all contents to user. |
chown user file | Change the ownership of file to user. |
umask 022 | Specify the default permissions for all created files. |
COMMAND | DESCRIPTION |
---|---|
awk | Manipulate a file as a database. |
awk /CA/'{ print $2 $1 $7 }' file | Select (and display) three fields in each record in file on lines that contain “CA”. |
awk '{ print $1 }' file | Select (and display) the first field in each record in file. |
awk -f script.awk file | Run an awk command from a script called script.awk on file. |
awk -F, '{ print $1 }' file > newfile | Select the first field in each record in file, specifying that a “,” separates fields, and redirect the output to newfile. |
awk -F: '{ print $2 "" $1 "in" $7 }' file | Select (and display) several fields and some text for each record in file, using a colon (:) as a field delimiter. |
basename | Remove the path from a filename, leaving only the name proper. Good to use in scripts to display just a filename. |
cmp newfile oldfile | Compare newfile to oldfile. |
crypt | Encrypt or decrypt a password-protected file. |
csplit | Divide files based on line number or other characteristics. |
diff -b newfile oldfile | Find differences (ignoring white space) between newfile and oldfile. |
diff Directory Newdirectory | Find differences between Directory and Newdirectory. |
diff -i newfile oldfile | Find differences (except in case) between newfile and oldfile. |
diff -iBw file1 file2 | Find all differences between file1 and file2 except those involving blank lines, spaces, tabs, or lowercase/uppercase letters. |
diff newfile oldfile | Find the differences between newfile and oldfile. |
diff -w newfile oldfile | Find differences (ignoring spaces) between newfile and oldfile. |
fmt file | Reformat file so it has even lines and a nicer appearance. |
fold -w 60 file | Reformat file so no lines exceed a specified length (60 characters here). |
grep expression file | Find expression in file and view the lines containing expression. |
grep -c expression file | Count how many times expression appears in file. |
grep -i expression file | Find all lines containing expression in file, using any capitalization (case-insensitive). |
grep -n expression file | Display each found line and a line number. |
grep 'Nantucket$' limerick* | Find the lines in the limerick files that end with “Nantucket”. |
grep -v expression file | Find all lines in file that do not contain expression. |
grep '^[A-Z, a-z]' limerick | Find all the lines in limerick that start with any letter, but not with a number or symbol. |
grep '^[A-Z]' limerick | Find all the lines in limerick that start with a capital letter. |
grep '^There' limerick* | Find all the lines in the limerick files that start with “There”. |
grep -5 'word[1234]' file | Find word1, word2, word3, or word4 in file and view the surrounding five lines as well as the lines containing the words. |
head -20 file | View the first 20 lines of file. |
head file | View the first 10 lines of file. |
pr file | Reformat file for printing, complete with headers and footers. |
pr –-columns=2 file | Reformat file for printing, complete with headers and footers and two columns. |
sdiff newfile oldfile | View the differences between newfile and oldfile. |
sdiff -s newfile oldfile | View the differences between newfile and oldfile, without showing identical lines. |
sed | Make changes throughout a file according to command-line input or a sed script. |
sed '/old/new/g' file.htm > file.htm | Search through file.htm and replace every occurrence of “old” with “new”. |
sed -f script.sed file > file.new; → mv file.new file | Run the commands in script.sed, apply them to file, and replace file with the manipulated content. |
split –b 500k file | Split file into 500 KB chunks. |
sort file | uniq | Sort file and send it to uniq to eliminate duplicates. |
sort file > sortedfile | Sort the lines in file alphabetically and present the sorted results in sortedfile. |
sort file1 | tee sorted | mail [email protected] | Sort file1 and, with tee, send it both to the file sorted and to standard output, where it gets mailed to the boss. |
sort file1 file2 | uniq -d | Sort file1 and file2 together and find all the lines that are duplicated. |
sort file1 file2 file3 > bigfile | Sort and combine the contents of file1, file2, and file3 and put the sorted output in bigfile. |
sort -n file | Sort file numerically. |
sort -t, +2 file | Sort on the third (really) field in the comma-delimited file. |
sort -t, file | Sort fields in the comma-delimited file; the character following -t (, ) indicates the delimiter. |
spell file | Check the spelling of all words in file. Returns a list of possibly misspelled words. |
tail -15 file | View the last 15 lines of file. |
tail file | View the last 10 lines of file. |
tidy file.html | Clean file.html to make it “good” HTML, and optionally also easier to read and maintain. |
tr A-Za-z a-zA-Z < file | Change uppercase to lowercase and lowercase to uppercase. |
uniq | Use with sorted files to eliminate duplicate lines. |
wc -b file | Count the bytes in file. |
wc file | Count the lines, words, and bytes in file. |
wc -l file | Count the lines in file. |
wc -w file | Count the words in file. |
COMMAND | DESCRIPTION |
---|---|
df | See what file systems are mounted where, and how much space is used and available. |
df /usr/local/src | Find out where /usr/local/src is mounted and how much space is available on it. |
df -k /home | View the file system for /home with the usage reported in 1 KB, not 512-byte, blocks. |
df -h /home | View the file system for /home with the usage reported in human-readable terms. |
du | Get information about disk usage in the current directory as well as in all subdirectories. |
du /home | Get information about disk usage in the /home directory. |
du -k | Get information about disk usage, measured in 1 KB blocks. |
du -h | Get information about disk usage, displayed in human-readable terms. |
file /usr/bin/pico | Find out the file type of /usr/bin/pico. |
finger | See who else is logged into the system and get a little information about them. |
finger @stc.org | Find out who is logged into the stc.org system. |
finger ejr | Get information about user ejr on your system. |
finger [email protected] | Get information about user [email protected]. |
id | Find out the numeric value of your userid and what groups (by name and numeric userid value) you belong to. |
id otheruser | Check someone else’s status to find out what groups they’re in. |
quota | Find out if you’re over quota. |
quota -v | View your current quota settings and space usage. |
uname | Use to find out what kind of Unix system |
uname -a | Print all system information, including the Unix system type, host name, version, and hardware. |
uname -sr | Find both the system type and release level. |
watch | Monitor a file or other data for changes. |
w | Get information about other users on the system and what |
who | Get information about the other users on the system. |
whoami | Find out what userid you’re currently logged in as. |
COMMAND | DESCRIPTION |
---|---|
elm | Start the elm mail program and read, respond to, or send email. |
elm [email protected] | Start a new elm mail message to [email protected]. |
elm [email protected],[email protected] | Start a new elm mail message to [email protected] and [email protected]. |
Start the mail program. (Use pine or mutt rather than mail if possible.) | |
mail [email protected] < file | Send file to [email protected]. |
mail [email protected] -s "For you!" < file | Send file to [email protected] with the subject "For you!". |
mail [email protected] | Start a simple mail message to [email protected]. |
mail [email protected],[email protected] | Start a simple mail message to [email protected] and [email protected]. |
mutt | Start the mutt mail program and read, respond to, or send email. |
mutt [email protected] | Start a new mutt mail message to [email protected]. |
mutt [email protected] -a file.tgz | Start a new mutt mail message to [email protected] and attach file.tgz. |
mutt [email protected],[email protected] | Start a new mutt mail message to [email protected] and [email protected]. |
pine | Start the pine mail program and read, respond to, or send email, or to read Usenet newsgroups. |
pine [email protected],[email protected] | Start a pine mail message to [email protected] and [email protected]. |
pine [email protected] | Start a pine mail message to [email protected]. |
procmail | Filter and sort mail according to a “recipe.” Run from the .forward file or automatically by the system. |
vacation | Initialize vacation and edit the message template. |
vacation -I | Start vacation and tell it to respond to incoming messages. |
vacation -j | Start vacation and automatically respond to all messages. |
COMMAND | DESCRIPTION |
---|---|
dig @nameserver.some.net www.raycomm.com | Look up the name www.raycomm.com from the name server nameserver.some.net. |
dig –x 192.168.12.52 | Look up the name corresponding to the IP number 192.168.12.52. |
ftp ftp.raycomm.com | Transfer files to or from ftp.raycomm.com using the FTP protocol. |
irc wazoo irc.netcom.com | Connect to the irc server at irc.netcom.com and use the nickname wazoo. |
links | Start the links Web browser. |
links http://www.google.com/ | Start the links Web browser at http://www.google.com/. |
lynx -dump http://url.com > newname.txt | Get a spiffy plain text file named newname.txt out of an HTML document from http://url.com. |
lynx | Start the lynx Web browser. |
lynx http://www.yahoo.com/ | Start the lynx Web browser on http://www.yahoo.com/. |
mesg n | Refuse talk and write messages. |
mesg y | Accept talk and write messages. |
nn | Read Usenet news. |
nslookup www.raycomm.com → nameserver.some.net | Look up the name www.raycomm.com from the name server nameserver.some.net. |
nslookup www.raycomm.com | Look up the IP number for the host www.raycomm.com. |
ping www.raycomm.com | Test the connection to the host www.raycomm.com. |
rn | Read Usenet news. |
ssh somewhere.com | Securely connect to and use a computer on the Internet named somewhere.com. |
slrn | Read Usenet news. |
talk deb | Talk interactively with the owner of the ID deb. |
talk [email protected] | Talk interactively with a user id the system wherever.com. |
telnet somewhere.com | Connect to and use a computer on the Internet named somewhere.com. |
tin | Read Usenet news. |
tin comp.unix.userfriendly | Read Usenet news from the comp.unix.userfriendly group. |
tn3270 library.wherever.edu | Connect to a host computer named library.wherever.edu that uses an IBM-mainframe-type operating system, like many library card catalogs. |
traceroute www.yahoo.com | Identify the computers and other devices between you and the host www.yahoo.com. |
traceroute -n hostname | Check the path to hostname without resolving the intervening host names for faster results. |
trn | Read Usenet news. |
trn comp.unix.shell | Read Usenet news from the comp.unix.shell group. |
wall | Send a write-type message to all users on the system. |
wget http://www.example.com/ | Download the file found at http://www.example.com/. |
wget –r –l 2 http://www.example.com/ | Download the files found at http://www.example.com/ for two levels down in the Web structure. |
write otherid | Send a message to the user otherid on the same system. |