Linux file command - query file types

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:

Linux file command

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
Like(0)

Related

Linux Login Logout Command
Linux login commandLinux logout commandLinux nologin commandLinux exit commandLinux sulogin commandLinux rlogin commandLinux poweroff commandLinux ctrlaltdel CommandLinux shutdown commandLinux halt commandLinux reboot commandLinux init commandLinux runlevel commandLinux telinit command
Linux File Management Command
Linux cat commandLinux tac commandLinux nl commandLinux more commandLinux less commandLinux head commandLinux tail commandLinux rev commandLinux fold commandLinux fmt commandLinux expand commandLinux pr commandLinux sort commandLinux uniq commandLinux cut commandLinux comm commandLinux diff commandLinux join commandLinux diff3 commandLinux cmp commandLinux colrm commandLinux paste commandLinux mkdir commandLinux tr commandLinux split commandLinux csplit commandLinux tee commandLinux unexpand commandLinux patch commandLinux awk commandLinux sed commandLinux od commandLinux pwd commandLinux cd commandLinux ls commandLinux dir commandLinux dirs commandLinux touch commandLinux rmdir commandLinux cp commandLinux mv commandLinux rm commandLinux install commandLinux tmpwatch commandLinux file commandLinux du commandLinux wc commandLinux tree commandLinux cksum commandLinux md5sum commandLinux sum commandLinux dirname commandLinux mkfifo Command
Cron Expressions
Cron Expression to Run Every Day at 12 PMUnderstanding Vue Cron ExpressionsUnderstanding JS Cron ExpressionsA Comprehensive Guide to Cron Expressions for Scheduled TasksUnderstanding Linux Cron ExpressionsUnderstanding Quartz Cron ExpressionsCron ExpressionCron Time ExpressionCron Expression ParsingCron Expression: Executing a Task Every SecondCron Expression for Every Minute ExecutionCron Expression to Execute Every 10 MinutesCron Expression: Executing Every HourCron Expression to Execute Once a YearCron Expression: How to Schedule a Task to Run Daily at Midnight?