≡ Menu

Linux / UNIX: Determine File Type

How do I determine the file type under UNIX or Linux like operating systems?

You need to use the file command to determine file type. File command tests each argument in an attempt to classify it. There are three sets of tests, performed in this order: filesystem tests, magic number tests, and language tests. The first test that succeeds causes the file type to be printed on screen.

file Command Examples

Type the following command:
$ file /etc/passwd
Sample outputs:

/etc/passwd: ASCII text

Another example:
$ file /home/voffice/letter.doc
Sample outputs:

/home/voffice/letter.doc: Microsoft Office Document

Find out type of the file.c, enter:
$ file file.c
Sample outputs:

file.c:   C program text

You can also use binary file, enter:
$ file $(which ls)
$ file /bin/ls
Sample outputs:

/bin/ls: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.0, dynamically linked (uses shared libs), stripped

Finally, it can also display info about devices:
$ file /dev/sda{1,2,3}

/dev/sda1: block special (8/1)
/dev/sda2: block special (8/2)
/dev/sda3: block special (8/3)
Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 3 comments… add one }
  • sims6785 January 14, 2010, 4:00 am

    thanks a lot :)

  • iris March 2, 2011, 8:16 pm

    This is useful!!

  • Mohit Malik September 19, 2012, 1:03 pm

    very nice demonstration:) brief and accurate

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , , , , , ,