Linux and Unix file command

Quick links

About file
Syntax
Examples
Related commands
Linux and Unix main page

About file

Tells you if the object you are looking at is a file or if it is a directory.

Syntax

file [-c] [-h] [-m mfile] [-f ffile] names

-cCheck the magic file for format errors. For reasons of efficiency, this validation is normally not carried out.
-hDo not follow symbolic links.
-m mfileUse mfile as an alternate magic file.
-f ffileffile contains a list of the files to be examined.
namesSpecifies the directories of files that you want the information about.

Examples

file *

Below is an example of what may appear when running file with a wildcard for all files.

shutdown.htm: HTML document text
si.htm: HTML document text
side0.gif: GIF image data, version 89a, 107 x 18
robots.txt: ASCII text, with CRLF line terminators
routehlp.htm: HTML document text
rss: setgid directory

file *.txt

Below is an example of what may appear when running the above example; running the file command listing any file ending with .txt.

form.txt: news or mail text
friend.txt: news or mail text
ihave.txt: news or mail text
index.txt: ASCII Java program text, with very long lines, with CRLF line terminators
jargon.txt: news or mail text
news.txt: Non-ISO extended-ASCII C program text, with very long lines, with CRLF line terminators
newsdata.txt: Non-ISO extended-ASCII English text, with very long lines, with CRLF line terminators
qad.txt: news or mail text
refrence.txt: news or mail text
robots.txt: ASCII text, with CRLF line terminators
stopwords.txt: ASCII English text, with CRLF line terminators
yhelp.txt: news or mail text

Related commands

ls
wc