Linux "file" Command Line Options and Examples
determine file type

This manual page documents version 5.32 of the file command. file tests each argument in an attempt to classify it.


Usage:

file [-bcdEhiklLNnprsvzZ0] [--apple] [--extension] [--mime-encoding] [--mime-type] [-e testname] [-F separator] [-f namefile]
[-m magicfiles] [-P name=value] file ...
file -C [-m magicfiles]
file [--help]






Command Line Options:

--apple
Causes the file command to output the file type and creator code as used by older MacOS versions. The code consists of eightletters, the first describing the file type, the latter the creator.
file --apple ...
-b
Do not prepend filenames to output lines (brief mode).
file -b ...
-C
Write a magic.mgc output file that contains a pre-parsed version of the magic file or directory.
file -C ...
-c
Cause a checking printout of the parsed form of the magic file. This is usually used in conjunction with the -m flag to debuga new magic file before installing it.
file -c ...
-d
Prints internal debugging information to stderr.
file -d ...
-e
Exclude the test named in testname from the list of tests made to determine the file type. Valid test names are:apptype EMX application type (only on EMX).ascii Various types of text files (this test will try to guess the text encoding, irrespective of the setting of the‘encoding’ option).encoding Different text encodings for soft magic tests.tokens Ignored for backwards compatibility.cdf Prints details of Compound Document Files.compress Checks for, and looks inside, compressed files.elf Prints ELF file details, provided soft magic tests are enabled and the elf magic is found.soft Consults magic files.tar Examines tar files.text A synonym for ‘ascii’.
file -e ...
--extension
Print a slash-separated list of valid extensions for the file type found.
file --extension ...
-F
Use the specified string as the separator between the filename and the file result returned. Defaults to ‘:’.
file -F ...
-f
Read the names of the files to be examined from namefile (one per line) before the argument list. Either namefile or at leastone filename argument must be present; to test the standard input, use ‘-’ as a filename argument. Please note that namefileis unwrapped and the enclosed filenames are processed when this option is encountered and before any further options processingis done. This allows one to process multiple lists of files with different command line arguments on the same file invocation.Thus if you want to set the delimiter, you need to do it before you specify the list of files, like: “-F @ -f namefile”,instead of: “-f namefile -F @”.
file -f ...
-h
option causes symlinks not to be followed (on systems that support symbolic links). This is the default if the environmentvariable POSIXLY_CORRECT is not defined.
file -h ...
-i
Causes the file command to output mime type strings rather than the more traditional human readable ones. Thus it may say‘text/plain; charset=us-ascii’ rather than “ASCII text”.
file -i ...
--mime-type
Like -i, but print only the specified element(s).
file --mime-type ...
-k
Don't stop at the first match, keep going. Subsequent matches will be have the string ‘\012- ’ prepended. (If you want a new‐line, see the -r option.) The magic pattern with the highest strength (see the -l option) comes first.
file -k ...
-l
Shows a list of patterns and their strength sorted descending by magic(4) strength which is used for the matching (see also the
file -l ...
-L
option causes symlinks to be followed, as the like-named option in ls(1) (on systems that support symbolic links). This is thedefault if the environment variable POSIXLY_CORRECT is defined.
file -L ...
-m
Specify an alternate list of files and directories containing magic. This can be a single item, or a colon-separated list. Ifa compiled magic file is found alongside a file or directory, it will be used instead.
file -m ...
-N
Don't pad filenames so that they align in the output.
file -N ...
-n
Force stdout to be flushed after checking each file. This is only useful if checking a list of files. It is intended to beused by programs that want filetype output from a pipe.
file -n ...
-p
On systems that support utime(3) or utimes(2), attempt to preserve the access time of files analyzed, to pretend that filenever read them.
file -p ...
-P
Set various parameter limits.Name Default Explanationindir 15 recursion limit for indirect magicname 30 use count limit for name/use magicelf_notes 256 max ELF notes processedelf_phnum 128 max ELF program sections processedelf_shnum 32768 max ELF sections processedregex 8192 length limit for regex searchesbytes 1048576 max number of bytes to read from file
file -P ...
-r
Don't translate unprintable characters to \ooo. Normally file translates unprintable characters to their octal representation.
file -r ...
-s
Normally, file only attempts to read and determine the type of argument files which stat(2) reports are ordinary files. Thisprevents problems, because reading special files may have peculiar consequences. Specifying the -s option causes file to alsoread argument files which are block or character special files. This is useful for determining the filesystem types of thedata in raw disk partitions, which are block special files. This option also causes file to disregard the file size asreported by stat(2) since on some systems it reports a zero size for raw disk partitions.
file -s ...
-v
Print the version of the program and exit.
file -v ...
-z
Try to look inside compressed files.
file -z ...
-Z
Try to look inside compressed files, but report information about the contents only not the compression.
file -Z ...
-0
Output a null character ‘\0’ after the end of the filename. Nice to cut(1) the output. This does not affect the separator,which is still printed.If this option is repeated more than once, then file prints just the filename followed by a NUL followed by the description (orERROR: text) followed by a second NUL for each entry.
file -0 ...
--help
FILES/usr/share/misc/magic.mgc Default compiled list of magic./usr/share/misc/magic Directory containing default magic files.ENVIRONMENTThe environment variable MAGIC can be used to set the default magic file name. If that variable is set, then file will not attempt toopen $HOME/.magic. file adds “.mgc” to the value of this variable as appropriate. However, file has to exist in order for file.mimeto be considered. The environment variable POSIXLY_CORRECT controls (on systems that support symbolic links), whether file willattempt to follow symlinks or not. If set, then file follows symlink, otherwise it does not. This is also controlled by the -L and -hoptions.
file --help ...