The file command is used to detect the type of a given file. The file command can be used to check the file system, magic magic number, and language.

Command syntax

File [option][parameter]

Command options

  • -b: The file name is not displayed when the identification results are listed.
  • -c: displays the command execution process in detail, facilitating troubleshooting or analyzing the program execution.
  • -f< name file > : specifies the name file. If the content has one or more file names, let file identify these files in order, in the format of one file name per column.
  • -l: directly displays the file type pointed to by the symbolic link.
  • -m< magic number file > : specifies the magic number file.
  • -v: displays the version information.
  • -z: Attempts to interpret the contents of the compressed file.

The command parameter

Files: To determine a list of files of type, multiple files are separated by Spaces, and multiple files can be matched using shell wildcards.

Display file type

> file outfile.txt outfile.txt: ASCII text > file -b outfile. TXT <== No file name is displayed ASCII text > file -i outfile. TXT <== MIME categories are displayed. outfile.txt: text/plain; charset=us-ascii > file -i -b outfile.txt text/plain; charset=us-asciiCopy the code

Some common types include:

  • text/plain: Plain text.
  • text/html: HTML text.
  • application/pdf: PDF document.
  • application/msword: Word document.
  • image/png: PNG image.
  • mage/jpeg: JPEG image.
  • application/x-tar: TAR file.
  • application/x-gzip: GZIP file.

Displays the file type of the symbolic link

> file system-release
system-release: symbolic link to `centos-release'

> file -L /tmp/
/tmp/: sticky directory
Copy the code

Unscramble the contents of the compressed file

> file-z python-3.6.4.tgz python-3.6.4.tgz: POSIX tar archive (GNU) (gzip compressed data, from Unix, last modified: Tue Dec 19 13:36:13 2017, max compression)Copy the code

Interpret executable programs

> file /usr/bin/ls /usr/bin/ls: ELF 64-bit LSB Executable, X86-64, Version 1 (SYSV), DYNAMICALLY Linked (Uses Shared Libs), for GNU/Linux 2.6.32, BuildID [sha1] = aaf05615b6c91d3cbb076af81aeff531c5d7dfd9, stripped > file - I/usr/bin/ls < = = shows the MIME type/usr/bin/ls: application/x-executable; charset=binaryCopy the code

Original link :rumenz.com/rumenbiji/l… Wechat official account: entry station