You have been using commands like cat and more with text files. How do you know which file is a text file, which contains binary data, or which is a C program? The UNIX file command is used to determine the type of file. See the following examples.
$ file /etc/profile /etc/profile: ascii text $
$ file /etc /etc: directory $
$ file /bin/ls /bin/ls: PA-RISC1.1 shared executable $
$ file /lib/libc.1 /lib/libc.1: PA-RISC1.1 shared library -not stripped $
$ file abc abc: commands text $
Similarly, the file command is able to detect a number of other file types. The file command uses the /etc/magic file to determine different file types by finding a magic string inside the file. A detailed discussion on magic numbers is out of the scope of this book, but you can see man pages for /etc/magic for further information on magic numbers. The file command is very useful in situations where you want to determine the type of file before performing an operation on it. It is quite possible that your display would be garbled if you were to use the cat command on a binary file.
Study BreakCopying and Moving Files Using Wildcards and Finding the Type of a File
|
Top |