Linuxstar
Published on

file command-identify file type

Jonas

Jonas

2 min read
The file command is used to identify the file type, and can also be used to identify the encoding format of some files. It obtains the file type by looking at the header information of the file, instead of determining the file type by extension like Windows. Syntax: file [parameter] [file]
Command parameters
-b When listing recognition results, do not display the file name (brief mode)
-c Instruction execution process is shown in detail, or to facilitate debugging scenario analysis program execution is often used in conjunction with -m, to debug it before installing magic file
-f Specify the name of the file, when the content has one or more file names, let file identify these files in order, the format is one file name per column
-L Directly display the file category pointed to by the symbolic link
-m Specify magic number file
-v Display version information
-z Try to interpret the contents of the compressed file
-i Show MIME category

Example:

Display file type:
[root@linuxstar ~]# file install.log install.log: UTF-8 Unicode text
Display file type, not file name:
[root@linuxstar ~]# file -b install.log UTF-8 Unicode text
Display the file type, display the MIME category, not the file name:
[root@linuxstar ~]# file -b -i install.log text/plain; charset=utf-8
Display the file type of the symbolic link:
[root@linuxstar ~]# ls -l /var/mail lrwxrwxrwx 1 root root 10 08-13 00:11 /var/mail -> spool/mail
[root@linuxstar ~]# file /var/mail /var/mail : symbolic link to `spool/mail'
Display the file category pointed to by the symbolic link:
[root@linuxstar ~]# file -L /var/mail /var/mail: directory