Linux file Command
The Linux file command is used to identify file types.
With the file command, we can identify the type of a file.
Syntax
file [-bcLvz][-f <名称文件>][-m <魔法数字文件>...][文件或目录...]
Parameters:
- -b Do not display file names when listing identification results.
- -c Display the command execution process in detail, making it easier to troubleshoot or analyze program execution.
- -f
Specify a name file. When it contains one or more file names, let file identify these files in order, with one file name per line. - -L Directly display the type of the file pointed to by a symbolic link.
- -m
Specify a magic number file. - -v Display version information.
- -z Attempt to interpret the contents of compressed files.
- [file-or-directory...] A list of files whose types are to be determined; separate multiple files with spaces, and shell wildcards can be used to match multiple files.
Example
Display file types:
[root@localhost ~]# file install.log
install.log: UTF-8 Unicode text
[root@localhost ~]# file -b install.log <== 不显示文件名称
UTF-8 Unicode text
[root@localhost ~]# file -i install.log <== 显示MIME类别。
install.log: text/plain; charset=utf-8
[root@localhost ~]# file -b -i install.log
text/plain; charset=utf-8
Display the file type of a symbolic link
[root@localhost ~]# ls -l /var/mail
lrwxrwxrwx 1 root root 10 08-13 00:11 /var/mail -> spool/mail
[root@localhost ~]# file /var/mail
/var/mail: symbolic link to `spool/mail'
[root@localhost ~]# file -L /var/mail
/var/mail: directory
[root@localhost ~]# file /var/spool/mail
/var/spool/mail: directory
[root@localhost ~]# file -L /var/spool/mail
/var/spool/mail: directory
Linux Command Reference