file

Used to detect the type of a given file

Supplementary instructions

file command is used to detect the type of a given file. The file command's check of files is divided into three processes: file system, magic number check, and language check.

grammar

file(option)(parameter)

Options

-b: When listing the identification results, do not display the file name;
-c: Display the instruction execution process in detail to facilitate troubleshooting or analysis of program execution;
-f <name file>: specifies a name 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<magic number file>: specifies the magic number file;
-v: Display version information;
-z: Try to decipher the contents of the compressed file.

Parameters

File: To determine the type of file list, use spaces to separate multiple files. You can use shell wildcards to match multiple files.

Example

Show file types

[root@localhost ~]# file install.log
install.log: UTF-8 Unicode text

[root@localhost ~]# file -b install.log <== Do not display the file name
UTF-8 Unicode text

[root@localhost ~]# file -i install.log <== Display MIME categories.
install.log: text/plain; charset=utf-8

[root@localhost ~]# file -b -i install.log
text/plain; charset=utf-8

Show file types of symbolic links

[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