SoFunction
Updated on 2025-03-10

One shell command a day linux text series - file command usage

Introduction to linux file command:

This command is used to identify file types and can also be used to identify the encoding format of some files. It gets the file type by looking at the header information of the file, not like Windows determines the file type through extensions.

For more information, please check out this article:https:///LINUXjishu/

file Official explanation: Determine type of FILEs. Determine the type of file.

Tips: In UNIX/Linux systems, file types are not determined by extensions (Windows is true).

Opening example:

1. $file

Output:: ASCII English text

Note: It is the help document I generated with file –help >

View—help

Copy the codeThe code is as follows:

Usage: file [OPTION...] [FILE...]
 Determine type of FILEs.
--help   display this help and exit
-v, --version   output version information and exit
 -m, --magic-file  LIST  use LIST as a colon-separated list of magic
 number files
-z, --uncompress   try to look inside compressed files
-b, --brief    do not prepend filenames to output lines
 -c, --checking-printout   print the parsed form of the magic file, use in
conjunction with -m to debug a new magic file before installing it
 -e, --exclude TEST   exclude TEST from the list of test to be performed for file. Valid tests are: ascii, apptype, compress, elf, soft, tar, tokens, troff
 -f, --files-from FILE   read the filenames to be examined from FILE
-F, --separator STRING   use string as separator instead of `:'
-i, --mime  output MIME type strings (--mime-type and
 --mime-encoding)
--apple  output the Apple CREATOR/TYPE
 --mime-type  output the MIME type
--mime-encoding  output the MIME encoding
 -k, --keep-going  don't stop at the first match
 -l, --list  list magic strength
 -L, --dereference  follow symlinks (default)
-h, --no-dereference  don't follow symlinks
 -n, --no-buffer  do not buffer output
 -N, --no-pad  do not pad output
 -0, --print0  terminate filenames with ASCII NUL
-p, --preserve-date  preserve access times on files
-r, --raw  don't translate unprintable chars to \ooo
-s, --special-files  treat special (block/char devices) files as ordinary ones
 -C, --compile  compile file specified by -m
 -d, --debug  print debugging messages

Interpretation:

1. -z

View information in the compressed file

2. -b, -e, -i, –r

-b Remove the prefix naming of the output line
-e Exclude tests from test list to executed file. Effective tests include: ascii, apptype, compress, elf, soft, tar,
-i Print MIME
-R Characters that cannot be printed without translation are \ooo

3. magic file

File with mgc as the extension, Microsoft office media directory file

Practical examples:

1. $file -z
View file information in the package

2. $file –i
out:: text/plain; charset=us-ascii

Print MIME type
 
$file
out:: ASCII English text

3. magic file

I translate it really badly. . I can only guess to check $which file and see, but I have no gains. Finally get it through $file

Usage: file  [-bchikLlNnprsvz0] [--apple] [--mime-encoding] [--mime-type]
       [-e testname] [-F separator] [-f namefile] [-m magicfiles] file ...
 file  -C [-m magicfiles]
 file  [--help]

Then try file -C to get the file. . . I don't know what it is, I'm ashamed

Usage: file [OPTION...] [FILE...]
Determine type of FILEs.

      --help                 display this help and exit
  -v, --version              output version information and exit
-m, --magic-file LIST        List of magic numbers divided by colons
                           
-z, --uncompress
-b, --brief                                                            �
-c, --checking-printout    Print the parsing format of the magic file. Before installing, use -m to debug a new magic file
                             
-e, --exclude TEST                                                                                                                                                                                                                                                            Effective tests: ascii, apptype, compress, elf, soft, tar, tokens, troff
-f, --files-from FILE      Read file name from the searched document
-F, --separator STRING      Use String as a separator instead of “:”
-i, --mime                                                                                                                            �
                               --mime-encoding)
         
--apple
--mime-type
--mime-encoding         Print MIME encoding
-k, --keep-going
-l, --list
-L, --dereference          Follow the symbolic link (default)
-h, --no-dereference
-n, --no-buffer
-N, --no-pad                                                           �
-0, --print0                                                                                                                            �
-p, --preserve-date                                                          �
-r, --raw
-s, --special-files       Treat special (block/character device) files as normal files
-C, --compile                                                            �
-d, --debug

Report bugs to /