The Linux file command is used to query file types.
Linux file command Function Description
Use the file command to query the file type of a specified file to know whether a file is a binary executable, a shell script file, or some other format. file command can identify file types such as directory, shell script, English text, binary executable, C source file, text file, and DOS executable file.
Linux file command Syntax
file [option] [filename]
The meaning of each option in the command is shown in the table.
Option | Description |
---|---|
-v |
Displays version information after standard output and exits |
-z |
Probe the compressed file type |
-L |
Allow symbolic links |
-b |
The file name is not displayed when the identification results are listed |
-c |
Detailed display of command execution process, easy to troubleshoot or analyze the program execution situation |
-i |
Display MIME type |
-f <Name file> |
Read the list of file names to analyze from the file |
Linux file command Examples
View the file types of all files in the /home/deepinout directory
file /home/deepinout/*
Output:
File names are not displayed when viewing the /root/anaconda-ks.cfg file type.
[root@rhel ~]# file -b /root/anaconda-ks.cfg
ASCII English text
Display the MIME type of the /root/anaconda-ks.cfg file.
[root@rhel ~]# file -i /root/anaconda-ks.cfg
/root/anaconda-ks.cfg: text/plain; charset=us-ascii
Display file type
[root@localhost ~]# file install.log
install.log: UTF-8 Unicode text
[root@localhost ~]# file -b install.log <== Do not display file names
UTF-8 Unicode text
[root@localhost ~]# file -i install.log <== Displays the MIME category.
install.log: text/plain; charset=utf-8
[root@localhost ~]# file -b -i install.log
text/plain; charset=utf-8
Display file types for 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