Linux file command
The Linux file command is used to identify file types.
With the file command, we can identify the type of the file.
Syntax
file [-bcLvz][-f <名称文件>][-m <魔法数字文件>...][文件或目录...]
Options:
- -b When listing identification results, do not display the file name.
- -c Displays the execution process in detail, making it easier to debug or analyze the program execution.
- -f<name file> Specifies a name file. When its content contains one or more file names, let file identify these files in sequence; the format is one file name per line.
- -L Directly displays the type of the file pointed to by a symbolic link.
- -m<magic number file> Specifies the magic number file.
- -v Displays version information.
- -z Attempts 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. Shell wildcards can be used to match multiple files.
Examples
Display file type:
[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: directoryOther Extensions
Linux Command Reference