Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ GNU text utilities - 6. Summarizing files

Media Vault

Software Library

Restoration Projects

Artifacts Sought

GNU text utilities - 6. Summarizing files

Go to the first, previous, next, last section, table of contents.


6. Summarizing files

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

6.1 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 file name following the counts. If more than one file is given, wc prints a final line containing the cumulative counts, with the file name `total'. The counts are printed in this order: newlines, 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 2. Common options.

`-c'
`--bytes'
`--chars'
Print only the byte counts.
`-w'
`--words'
Print only the word counts.
`-l'
`--lines'
Print only the newline counts.

6.2 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, file names 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 2. Common options.

`-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'
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.

6.3 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:

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

cksum prints the CRC checksum 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 (typically 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 algorithms (see the previous section); it is more robust.

The only options are `--help' and `--version'. See section 2. Common options.

6.4 md5sum: Print or check message-digests

md5sum computes a 128-bit checksum (or fingerprint or message-digest for each given file, or standard input if none are given or for a file of `-'. It can also check if the checksum has changed. Synopsis:

md5sum [option]... [file]...

For each file, `md5sum' outputs the MD5 checksum, a flag indicating a binary or text input file, and the filename.

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

`-b'
`--binary'
Treat input files as binary. This makes no difference on Unix systems, but other systems have different internal and external character representations, notably to mark end-of-line.
`-c'
`--check=file'
file is taken as the output of a former run of `md5sum': each line consists of an MD5 checksum, a binary/text flag, and a filename. The file will be opened (with each possible relative path) and the its message-digest computed. If this computed message digest is not the same as that given in the line, the file will be marked as failed.
`-s'
`--string=string'
Compute the message digest for string, instead of for a file. The result is the same as for a file with contains exactly string.
`-t'
`--text'
Treat all input files as text files. This is the reverse of `--binary'.
`-v'
`--verbose'
Print progress information.


Go to the first, previous, next, last section, table of contents.

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026