Linux file command

The file command is used to determine the type of any file without caring about the file extension. It just uses file command and displays the file type for us. It has other options as well.


file <filename>

Example: file 1.png

codes@w3schools:~/Desktop$ file jdk-8u91-linux-i586.rpm
jdk-8u91-linux-i586.rpm: RPM v3.0 bin i386/x86_64
codes@w3schools:~/Desktop$ file 1.png
1.png: PNG image date, 724 x 463, 8-bit/color RGBA, non-interlaced
codes@w3schools:~/Desktop$ file linux.docx
linux.docx: Microsoft Word 2007+
codes@w3schools:~/Desktop$ file linuxfun.pdf
linuxfun.pdf: PDF document, version 1.4
codes@w3schools:~/Desktop$ file usr
usr: directory

In the above example, as you can see, we have used the file command along with different arguments, and as a result it displays their file types.

Note: For the file command to easily tell us the file type is because of a magic file which contains all the patterns to recognize a file type. The path of magic file is /usr/share/file/magic and you can use the command ‘man 5 magic’ for more information.

Linux File Command Options

Option Function
file -s It is used for special files.
file * It is used to list types of all the files.
file/directory name/* It is used to list types of all the files from a specifically mentioned directory.
file [range]* It will display the list of all the files starting from the alphabet present within the given range in place of [range].


Please follow and like us:
Content Protection by