Monday, September 3, 2007

determine file type

determine file type

An entry on how to determine file type.

This linux command file determine file types classification in three different ways namely filesystem tests, magic number tests, and language tests. The first test that succeeds causes the file type to be printed.

Determining file types are usually being used inside bash or perl script before any file read/write operation takes place. By doing so, any file validation algorithm can be performed first before any file or write access can be granted or continued.

Simple Usage
~~~~~~~~~~~~

# file /dev/sda1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/dev/sda1: block special (8/1)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# file F7.ISO
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.iso: ISO 9660 CD-ROM filesystem data UDF filesystem data (unknown version, id 'NSR0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# file textfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
textfile.txt: ASCII English text
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# file /dev/cdrom0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/dev/cdrom: symbolic link to `scd0'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy