2.6 File Types

   

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.

A Text File

 $  file /etc/profile  /etc/profile:  ascii text $ 

A Directory

 $  file /etc  /etc:      directory $ 

An Executable File

 $  file /bin/ls  /bin/ls:    PA-RISC1.1 shared executable $ 

A Shared Library

 $  file /lib/libc.1  /lib/libc.1:  PA-RISC1.1 shared library -not stripped $ 

A Shell Script

 $  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 Break

Copying and Moving Files Using Wildcards and Finding the Type of a File

General syntax of the cp and mv commands is that you specify the source file name first and then the destination file name. Create a directory with the name impfiles in your home directory. Copy the /etc/ hosts file into this directory. Also copy all files starting with " m " from the /etc directory to this directory. Now move the hosts file from the impfiles directory to the /tmp directory. Using range characters [a,e,i,o,u] , list all files in the /usr directory that start with any vowel.

You can find out the type of a file by using the file command. Try to find a shared executable file on the system by applying this command to different files.


   
Top


HP Certified
HP Certified: HP-UX System Administration
ISBN: 0130183741
EAN: 2147483647
Year: 2000
Pages: 390
Authors: Rafeeq Rehman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net