Tips Linux Explorers   All Things Linux Forum   Great Linux Links   Hometown   Email 


Here is a real short one, the command "file".
This command can help to determine the type of file you are viewing. The file command performs 3 tests to check the file type: file system tests, magic number tests, and language tests. By default the magic number test is checked against the /usr/share/misc/file/magic.mgc or /usr/share/misc/file/magic but there are options to let it use another customized file. More about how exactly this command works and even a bit of history about this UNIX command existing since 1973 can be found by typing "man file"

Here are a few examples, you will see the output on the second line:

$ file /etc/lilo.conf
/etc/lilo.conf: ASCII text

Now if we add the -i option we sometimes get some more useful info ( uses another magic file ):

$ file -i /etc/lilo.conf
/etc/lilo.conf: text/plain; charset=us-ascii

Or on another file:

$ file -i /usr/bin/top
/usr/bin/top: application/x-executable, for GNU/Linux 2.2.5, dynamically linked (uses shared libs), stripped

And another:

$ file -i /usr/bin/startkde
/usr/bin/startkde: Bourne shell script text executable

A few alternative options, the -z option looks in compressed files:

$ file -iz /usr/share/man/bg/man1/apropos.1.bz2
/usr/share/man/bg/man1/apropos.1.bz2: text/troff; charset=iso-8859-1 (application/x-bzip2)

The -s option for reading block or special character files:

$ file -s /dev/hda10
/dev/hda10: Linux rev 1.0 ext3 filesystem data (needs journal recovery)

The command "file" is not prefect, it only makes a guess of what the file is you are looking at: text, executable or data ( everything else ) . . . so still can be of good use.


-- Sep 20 2005 ( Revised Dec 10 2005 ) --

Tips Linux Explorers   All Things Linux Forum   Great Linux Links   Hometown   Email