Go to the previous, next section.

Summarizing files

These commands generate just a few numbers representing entire contents of files.

wc: Print byte, word, and line counts

wc counts the number of bytes, whitespace-separated words, and newlines in each given file, or standard input if none are given or for a file of `-'. Synopsis:

wc [option]... [file]...

wc prints one line of counts for each file, and if the file was given as an argument, it prints the filename following the counts. If more than one file is given, wc prints a final line containing the cumulative counts, with the filename `total'. The counts are printed in this order: lines, words, bytes.

By default, wc prints all three counts. Options can specify that only certain counts be printed. Options do not undo others previously given, so

wc --bytes --words

prints both the byte counts and the word counts.

The program accepts the following options. Also see section Common options.

`-c'
`--bytes'
`--chars'
@opindex -c @opindex --bytes @opindex --chars Print only the byte counts.

`-w'
`--words'
@opindex -w @opindex --words Print only the word counts.

`-l'
`--lines'
@opindex -l @opindex --lines Print only the newline counts.

sum: Print checksum and block counts

sum computes a 16-bit checksum for each given file, or standard input if none are given or for a file of `-'. Synopsis:

sum [option]... [file]...

sum prints the checksum for each file followed by the number of blocks in the file (rounded up). If more than one file is given, filenames are also printed (by default). (With the `--sysv' option, corresponding file name are printed when there is at least one file argument.)

By default, GNU sum computes checksums using an algorithm compatible with BSD sum and prints file sizes in units of 1024-byte blocks.

The program accepts the following options. Also see section Common options.

`-r'
@opindex -r Use the default (BSD compatible) algorithm. This option is included for compatibility with the System V sum. Unless `-s' was also given, it has no effect.

`-s'
`--sysv'
@opindex -s @opindex --sysv Compute checksums using an algorithm compatible with System V sum's default, and print file sizes in units of 512-byte blocks.

sum is provided for compatibility; the cksum program (see next section) is preferable in new applications.

cksum: Print CRC checksum and byte counts

cksum computes a cyclic redundancy check (CRC) checksum for each given file, or standard input if none are given or for a file of `-'. Synopsis:

Synopsis:

cksum [option]... [file]...

cksum prints the CRC for each file along with the number of bytes in the file, and the filename unless no arguments were given.

cksum is typically used to ensure that files have been transferred by unreliable means (e.g., netnews) have not been corrupted, by comparing the cksum output for the received files with the cksum output for the original files (usually given in the distribution).

The CRC algorithm is specified by the POSIX.2 standard. It is not compatible with the BSD or System V sum programs; it is more robust.

Go to the previous, next section.