-->
Previous | Table of Contents | Next |
Table 16.1 explains the arguments for the file command.
Argument | Description |
---|---|
-c | Prints out the parsed form of the magic file (/usr/lib/magic), which is a number in the first part of a binary file that identifies the file type. This is usually used with -m to debug a new magic file before installing it. |
-z | Looks inside a compressed file and tries to figure out the file type. |
-L | Causes symbolic links to be followed. |
-f namefile | Tells file that the list of files to identify is found in namefile, which is a text file. This is useful when many files must be identified. |
-m magicfile | Specifies an alternative file of magic numbers to use for determining file types. The default file is /usr/lib/magic. |
filelist | Lists space-delimited files whose type you want to know. |
Ordinary files are what you spend most of your time manipulating. Ordinary files can contain text, C language source code, shell scripts (programs interpreted by one of the Linux shells), binary executable programs, and data of various types. As far as Linux is concerned, a file is a file. The only difference that Linux knows is files marked as executable. Executable files can be executed directlyprovided, of course, that the file contains something to execute and that its in your search path. Basically, the search path is a list of path names youve specified that Linux searches to find an executable file.
See Understanding Shells, p. 339
Executable files are binary filesthat is, files that execute machine code and shell scripts. The Linux file command discussed in the preceding section looks at the data in a file and makes a reasonable guess as to whats inside. If you type file *, for example, you might see something similar to this:
INSTALL: symbolic link to /var/adm ghostvw.txt: ascii text linux: symbolic link to /usr/src/linux mbox: mail text mterm.txt: English text seyon.txt: English text xcalc.txt: English text xclock.txt: English text xeyes.txt: English text xgrap.txt: English text xlock.txt: English text xspread.txt: English text xtris.txt: empty
All the files named in the first column are ordinary files that contain different kinds of data. All the files are located within the directory where the file command was executed.
Directories are files that contain the names of files and subdirectories, as well as pointers to those files and subdirectories. Directory files are the only place that Linux stores names of files. When you list the contents of a directory with the ls command, all youre doing is listing the contents of the directory file. You never touch the files themselves.
When you rename a file with the mv command and that file is in the current directory, all youre doing is changing the entry in the directory file. If you move a file from one directory to another, all youre doing is moving the description of the file from one directory file to anotherprovided, of course, that the new directory is on the same physical disk or partition. If not, Linux physically copies each byte of the program to the other disk.
Every file in a Linux system is assigned a unique number called an inode. The inode is stored in a table called the inode table, which is allocated when the disk is formatted. Every physical disk or partition has its own inode table. An inode contains all the information about a file, including the address of the data on the disk and the file type. File types include such things as ordinary files, directories, and special files.
The Linux file system assigns inode number 1 to the root directory. This gives Linux the address on disk of the root directory file. The root directory file contains a list of file and directory names and their respective inode numbers. Linux can find any file in the system by looking up a chain of directories, beginning with the root directory. The contents of the root directory file might look like this:
1 . 1 .. 45 etc 230 dev 420 home 123 .profile
Notice that the files. (dot) and .. (double dot) are shown in the directory. Because this is the root directory,. and its parent directory, .., are identical. The contents of the /home directory file would be different and might look something like this:
420 . 1 .. 643 fred
Notice that the inode of the current directory (.) matches the inode for /home found in the root directory file, and the inode for the parent directory (..) is the same as that of the root directory.
Linux navigates its file system by chaining up and down the directory file system. If you want to move a file to a directory on another physical disk, Linux detects this by reading the inode table. In such a case, the file is physically moved to the new disk and assigned a new inode on that disk before being deleted from its original location.
As with the mv command, when you delete a file with the rm command, you never touch the file itself. Instead, Linux marks that inode as free and returns it to the pool of available inodes. The files entry in the directory is erased.
See Moving and Renaming Files, p. 323
Ordinary links arent really files at all; theyre actually directory entries that point to the same inode. The inode table keeps track of how many links there are to a file, and only when the last directory reference is deleted is the inode finally released back to the free pool. Obviously, ordinary links cant cross device boundaries because all the directory references point to the same inode.
To create a link you use the ln command, which has the following form:
ln [options] source destination
For example to create a link between a file named mainfile.txt and a file named tempfile.txt, you would enter the following command:
ln mainfile.txt tempfile.txt
Previous | Table of Contents | Next |