6.1 Directory and File Management Using the Command Line
6.1.2 Determining file type
The file Command
Command Format:
file filename(s)

There are many types of files found on a UNIX system. The file type can be determined by using the file command. This information can be important when a user is attempting to open or read a file. Determining the file type can help a user decide which program or command to use to open the file. The output from this command will most often be one of the following: Text, Executable or Data.

  • Text - Examples include ASCII or English text, commands text, and executable shell scripts. This type of file can be read using the cat or more commands, which are discussed in this chapter, and can be edited using vi or another text editor.
  • Executable or Binary - Examples include 32-bit executable and extensible linking format (ELF) code files and other dynamically linked executables. This file type indicates that the file is a command or program. The strings command, which is covered next, will print out readable characters in this type of file.
  • Data - Data files are those which are created by an application running on the system. In some cases the type of file is indicated; for example, FrameMaker document. When the application in which this file was created cannot be determined by the file command, the output will simply indicate data file. The only way to read a data file is to determine which application created it and open the file with that application.

Note: For information on other file types, see the man pages.

Figure shows several examples using the file command. The first example is a text file. The second is a data file which must be read by FrameMaker. The third is the cat command which is an executable. In the first two examples, we change to the directory where the file is located first. In the third example, we specify the file using its absolute pathname.

The strings command
The
strings command can be used to print out readable characters in an executable or binary file. The output produced by strings can be interpreted by someone with a programming background. The command is introduced here solely as a method for demonstrating the printable characters of an executable file. The strings command must be used to read an executable file such as /usr/bin/cat. In Figure , the strings command is followed by the file name of the command including the absolute pathname. The strings command also shows the usage syntax of the command in most cases.
Interactive Media Activity (Flash, 95 kB)
  Using the strings command

In this media activity, you are logged in as user2 and your current working directory is: /home/user2/dir2. Refer to the Class File Tree Structure by clicking the 'tree' button located on the Menu Bar and type the commands that would accomplish the requested objectives. 
Note: Be sure to press enter after each one. Click on step 1 to begin.