Basic Unix Commands
|cmp file1 file2
Compares the contents of two files. Says whether or not the two files are identical. Useful for getting rid of unwanted duplicates and for verifying that a file that has been there and back to a distant host is identical to the original and therefore arrived at the other end intact. Works for both text and binary files.
|diff file1 file2
Compares the contents of two text files. Shows lines that are different or have been added to one of the files.
|sort file1 > file2
Sorts the contents of 'file1' into ASCII order and places them in 'file2'. Sort clears any previous version of 'file2' before starting the sort.
The full switch options for sort are as follows:
3:20 pm Thu 20 Jul 1995
|at 2:45 am||at 2:45 tomorrow morning
|sort -r hugefile -o hugesort||sort a huge file in reverse order
|pr -f -2 hugesort | lp||then format it and print it
|Ctrl-D||puts above script into scheduler
Console responses are place in a log file which appears in the user's email file the next morning.
If you maintain a text file called 'calendar' in your home directory in which you enter important events prefixed by their dates, then every midnight UNIX will send you an email message the next morning showing the events for the coming day and the day after.
|cal 7 1995||displays calendar for given month and year.
|sleep 600; lp bigfile||start to print bigfile in one hour's time.
To save on disk space, files which are referred to only occasionally can be compressed. Compressing files before transmitting them over a slow Internet link can also save on transmission time. To compress a file you use the 'compress' command as follows:
compress -v file1
file1: Compression 49.79%-replaced with file1.Z
The response is invoked by the -v switch. If you leave it out you get no message. You usually get a 50% saving with text files, but on some binary files you may not get any saving at all. To get 'file1' back you type:
You can read a compressed file directly without uncompressing it by using 'zcat' as follows:
zcat file1.Z | more
An older program called 'pack' uses a different compression algorithm from 'compress'. Although compress is generally better, 'pack' can work better than 'compress' on some files. It is therefore a good idea to try both to see which one gives the greater amount of compression.
The file command tries to make a guess as to the kind of information a file contains:
file2: [nt]roff, tbl, or eqn input text
file3: ASCII text
file4.Z: compressed file-with 16 bits
It reckons 'file2' contains text which has been coded for input to the text formatter program troff. It reckons 'file4.Z' has been compressed according to a 16-bit compression scheme. 'uncompress' can uncompressed files which were compressed by any known compression scheme.
A Command Line Calculator
|bc||invoke the calculator
|(2+9)*3||enter the expression you want evaluated
|33||bc puts the answer on the next line
|Ctrl-D||to leave the bc calculator.
A Banner Generator
banner "My Ultimate" "Program Listing"
Prints a tacky (in this case, two-line) banner heading in # marks.
© 1998 Robert John Morton