Linux basics-file command and magic file

Source: Internet
Author: User

// This article is based on CentOS6.3 distribution

The file command is used to verify the file type and print it to the terminal. The file command checks the file types in the following order:

  1. Check the file types supported by the file system.
  2. Verify the magic file rule.
  3. Checks the language and Character Set of the file content.
Check the file types supported by the file system. Ls-lThe file type indicated by the first character in:
  • -(Regular): regular files (including text files (ASCII), executable files (excutable), and other binary files (data ))
  • D (directory): directory
  • L (link): Soft links (excluding hard connections, hard links are displayed as regular files.
  • Block buffered special: Random storage of device files, such as hard disks, CDs, and other storage devices
  • C (character unbuffered special): continuously input device files, such as mouse and keyboard
  • S (socket): socket file, which is most often seen in the/var/run directory
  • P (pipe): A pipe file (first-in-first-out). It aims to solve the problem of simultaneous access to a file by multiple programs.
Test the magic file rule. What does magic file mean? Magic file refers to files with special file formats, such as C files, which have the word "# include". The first few bytes of the tar file have special rules. The magic file rule determines the type of a file based on these special formats. These rules are saved in $ HOME /. magic. mgc, $ HOME /. magic,/etc/magic. mgc,/etc/magic/usr/share/misc/magic. mgc,/usr/share/misc/magic. * The/magic file is a text file, while the */magic. mgc file is a binary file compiled by */magic. Use this file if */magic. mgc exists in the same directory; otherwise, use */magic. The priority of these configurations is $ HOME/. magic *>/etc/magic *>/usr/share/misc/magic *. */Each line in the magic file content format file specifies a rule to test the file type. This rule is specified by four fields:
  • Offset: Specify the bytes starting from the file.
  • Type: the data type to be tested, that is, the Data type starting from the offset byte. For specific data types, parameter magic (5) is supported ). Common data types include
    Byte: the value of a byte.
    Short: the value of two bytes.
    Long: the value of four bytes.
    String: string.
  • Test: test value. Used to check whether the type under offset is the test value. It is represented by a value or character in C language.
  • Message: displays the information of the test result.
If type is a value type, you can add & value next to it, indicating that the operation is performed first with the test value and then the comparison is performed. If type is a string type, it can be followed by/[Bbc] *./B indicates that spaces are ignored, and/c indicates that uppercase and lowercase letters are ignored. If the value of test is numeric, you can add =, <,>, &, ^ ,~, They indicate equal, less than, greater than, and operation, difference or operation, and reverse operation respectively. If the value of test is of the string type, you can add =, <,> before it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.