The Linux file command

Linux file information FAQ: How can I tell what type of file a file is on a Unix or Linux system?

The Linux file command shows you the type of a file, or multiple files. It's usually used when you're about to look at some type of file you've never seen before. When I first started working with Unix and Linux systems I used it a lot to make sure I wasn't about to open a binary file in the vi editor, amongst other things.

You issue the Linux file command just like other commands, like this:

file /etc/passwd

The output of the file command looks something like this:

/etc/passwd: ASCII English text

This is telling you that this is a plain text file. If you use the file command on a gzip'd file, the output will include text like this:

gzip compressed data

If you issue this command on a directory the output will say "directory", a PDF document will be reported as "PDF document", and if you issue it on a special Linux device file (typically under the /dev directory) it will look like this:

/dev/ttyp0: character special (4/0)

You can also issue the Linux file command on more than one file at a time, so you can do this to issue the file command on all files in the current directory:

file *

or this to look at all files in the /etc directory:

file /etc/*

and like this to look at all files in the /dev directory:

file /dev/*

Linux file command - Summary

I hope these Linux file command examples have been helpful. While the file command isn't used too often, it can keep you out of some sticky situations if you use it before trying to do something with a file you're not familiar with.