Guide to Unix/Commands/File Analysing
file displays the file type. To get the mimetype, use the -i option.
$ file Unix.txt Unix.txt: ASCII text
$ file -i Unix.txt Unix.txt: text/plain; charset=us-ascii
wc tells you the number of lines, words and characters in a file.
$ wc hello.txt 2 6 29 hello.txt
$ wc -l hello.txt 2 hello.txt
$ wc -w hello.txt 6 hello.txt
$ wc -c hello.txt 29 hello.txt
cksum gives you the CRC checksum of some files.
Checksums can be used to protect against accidental modifications to files: if the checksum has not changed, then the file is probably undamaged. The default CRC checksum is not cryptographic.
Cryptographic checksums are those checksums which protect against both accidental modifications and malicious modifications. Use these to verify that there is no trojan inserted into your file. The "md5" algorithm is beginning to show weaknesses against attacks, so "sha1" is preferred.
$ cksum /etc/passwd 3052342160 2119 /etc/passwd
Some "cksum" implementations provide other algorithms, such as "md5" and "sha1":
$ cksum -a sha1 /etc/passwd SHA1 (/etc/passwd) = 816d937ca4cdb4dee92d5002610fae63b639d224
Some "cksum" implementations let you take checksums of strings specified as arguments:
$ cksum -s 'Guide to UNIX' 2195826759 13 Guide to UNIX $ cksum -a sha1 -s 'Guide to UNIX' SHA1 ("Guide to UNIX") = 0e9c1779e61c7fdb473d2e55eb878a82c37eecea
- cksum, opengroup.org
- sum man page, man.cat-v.org
- cksum, freebsd.org
- 6.3 cksum in GNU Coreutils manual, gnu.org
Outputs lines matching a regular expression, not matching it, and similar, depending on options and the regular expression used. See Grep Wikibook.