Linux file Command
The Linux file command is used to determine the type of a file.
Using the file command, we can identify the type of the file.
Syntax
file [-bcLvz][-f <name file>][-m <magic number file>...][files or directories...]
Parameters:
-b Do not prepend the filename to the output line.
-c Print detailed output of the command execution process, useful for debugging or analyzing program execution.
-f<name file> Specify a name file containing one or more filenames. The file command will sequentially identify these files, with each filename on a new line.
-L Follow symbolic links and display the file type of the target.
-m<magic number file> Specify the magic number file.
-v Display version information.
-z Attempt to inspect the contents of compressed files.
[files or directories...] A list of files or directories to determine the type of, separated by spaces. Shell wildcard characters 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 <== Do not display the filename
UTF-8 Unicode text
[root@localhost ~]# file -i install.log <== Display MIME type.
install.log: text/plain; charset=utf-8
[root@localhost ~]# file -b -i install.log
text/plain; charset=utf-8
Display file type 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