The Linux Newbie Guide  ⇒    Fundamentals     Advanced     Supplement   Command Index   ENG⇒中
All rights reserved, please indicate the source when citing
  

Identifying File Types with "file" Command





In the Linux world, there's a handy tool called file for identifying file types. It can tell you about various known file types, such as text files, executable files, compressed files, files with special permissions, and a wide array of other types. It doesn't rely on file extensions but instead analyzes the actual file data to make educated guesses about its format, encoding, and purpose. The file command is particularly useful when dealing with files lacking recognizable file extensions or when you want to verify a file's type.

When you execute the file command followed by the path to a file, it provides you with information about the file's type, including its format, encoding, and other relevant details.

Example:
$ file smiley.jpg ←Check what type of file "smiley.jpg" is
smiley.jpg: JPEG image data, JFIF standard 1.01 ←JPEG image file
$ file /etc/passwd ←Check what type of file "/etc/passwd" is
/etc/passwd: ASCII text ←ASCII text file

The file command is a valuable tool for identifying unknown files or verifying file types. It's often used in scripts, as part of file processing pipelines, and in manual file inspections. It's important to note that while file is quite accurate, it's still making an educated guess based on the file's contents, so there may be cases where its determination isn't entirely accurate.

For more examples and usage details, please refer to the provided link.