Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

file - linux command line to display file information

Date: 2007-05-06 00:00:00 -0400

To display the type of a file, and the info about the type you can use the command line file, this command shows you the type of file no matter the extension it may have. So it is really useful to know the type of file, and to know which tool you need to work with that file.

Usage file [option] file-list

Option

-f file
When specified, the file command takes the list of file from the file specified after the -f parameter, you need to enter one name per line in that text file
-i
Displays MIME file information, in MIME format
-L
Shows the info of the files being symbolic linked and the link itself
-z
Classify the files contained by a compressed file

file can recognize more than 5.000 file types but it is not always accurate or exact.

Example

Try this,

vi file.tar.gz

Write this inside

Some text

And save the file now use file to discover the type of file it is.

file file.tar.gz

This is the output.

[user@ggarron Desktop]$ file hola.tar.gz hola.tar.gz: HTML document text

As you can see, it is not guided by the file extension but for the content itself.

If you liked this article please share it.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.