Fundamental UNIX utilities


As a prelude to next week's scripting assignment, here is an introduction to some commonly-used UNIX utilities (and hopefully the beginning of understanding "the UNIX way"). You are encouraged to read the man pages for each of these commands for more details (many commands have lots more options than described below).

Simple text manipulation:

cat filename1 [filename2 ...]
(Con)catenate the named files and write to stdout. The following commands typically take one or more filename arguments, or read from stdin if no filename is specified.
head -N, tail -N
Show the first or last N lines of a file (10 if no N is given).
cut -dchar -ffields
Treating char as a delimiter, extract and output a field or range of fields from each line of input. Example: cut -d: -f6 /etc/passwd will print all the home directories in the passwd file.
tr fromlist tolist
Transliterate characters (a character in fromlist is changed to the corresponding character in tolist).
sort
Sort lines in input (has many options to specify things like sort keys and different sorting orders).
uniq
Remove contiguous identical lines from input
cmp file1 file2, diff file1 file2
Check whether two files are different; diff shows details about differences.
find, xargs
find (which has many options) descends directory trees and outputs names of files that match specified criteria; xargs is often used as a companion tool to find to apply a command to a list of files it reads from its standard input.

Next ->


Steve VanDevender
Last modified: Thu Jul 26 14:28:27 PDT 2007