Use of Linux file command

Use of Linux file command

1. Command Introduction

The file command is used to identify the file type. The file check is divided into three steps: file system check, magic number check and language check. It can also be used to identify the encoding format of some files. It obtains the file type by looking at the file header information, rather than determining the file type by the extension like Windows does.

2. Command format

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

3. Option Description

-b, --brief: Simple mode, does not display file names;
-C, --compile: Generate magic.mgc file. Use with option -m -c, --checking-printout: Print out the analysis results of the magic file -e, --exclude [testname]: Exclude checking of files of the specified type. The values ​​of testname are apptype, ascii, encoding, tokens, cdf, compress, elf, soft, tar
-F, --separator [separator]: Replace the default ":" separator after the output file name with the specified separator -f, --files-from [namefile]: Read the files to be tested from the file namefile, one per line -i, --mime: Output a string of mime type instead of a readable string, for example, output "text/plain; charset=us-ascii" instead of "ASCII text"
--mime-type, --mime-encoding: Like -i, but only print the specified elements;
-k, --keep-going: Do not stop at the first match, keep checking -l, --list: Print information about the strength of each magic pattern
-L, --dereference: Check the file type of the file corresponding to the soft link -m, --magic-file [magicfiles]: Specify the magic file. Magic files refer to files with special contents, such as C files, which will have the word #include; the first few bytes of tar files will have special rules. The magic file inspection rule is to determine the type of a file based on these special formats. These rules are stored in $HOME/.magic.mgc
-N, --no-pad: Don't pad filenames so that they align in the output
-n, --no-buffer: Force flushing of standard output stdout. This option is only effective when checking multiple files. You can also use this option when getting file types through a pipeline -p, --preserve-date: preserve the access time of the file to be detected, even if the file command does not change the access time of the file to be detected
-r, --raw: Do not convert non-printable characters to octal form \ooo. Normally, file will do the conversion. -s, --special-files: Normally, the file command only supports the detection of ordinary files, just like stat(2). Use this option to allow the file command to support special files, such as raw disk partitions, etc. -v, --version: Display version information -z, --uncompress: Try to interpret the contents of the compressed file -0, --print0: Output a null character '\0' after the file name
--help: Display help information

4. Common Examples

(1) Check the file type.

[root@TENCENT64 ~]# file Changelog 
Changelog: ASCII text

(2) The file name is not output, only the file format and encoding are displayed.

[root@TENCENT64 ~]# file -b Changelog 
ASCII text

(3) Output the MIME type string.

[root@TENCENT64 ~]# file -i Changelog 
Changelog: text/plain; charset=us-ascii

(4) Check the file type of the file corresponding to the soft link.

[root@TENCENT64 ~]# ll Changelog*
-rw-r--r-- 1 root root 1598 Nov 6 22:39 Changelog
lrwxrwxrwx 1 root root 9 Nov 6 23:07 Changelog.ln -> Changelog

# Look at the soft link type [root@TENCENT64 ~]# file Changelog.ln
Changelog.ln: symbolic link to `Changelog'

# View the file type of the soft link corresponding file [root@TENCENT64 ~]# file -L Changelog.ln
Changelog.ln: ASCII text

The above is the detailed content of the use of Linux file command. For more information about Linux file command, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed tutorial on how to delete Linux users using userdel command
  • Use of Linux date command
  • How to run Linux commands in the background
  • Use of Linux telnet command
  • Use of Linux ls command
  • Use of Linux read command
  • Use of Linux usermod command
  • Use of Linux ln command
  • Usage of Linux userdel command

<<:  Various correct postures for using environment variables in Webpack

>>:  Mysql accidental deletion of data solution and kill statement principle

Recommend

js implements mouse in and out card switching content

This article shares the specific code of js to re...

Summary of Spring Boot Docker packaging tools

Table of contents Spring Boot Docker spring-boot-...

Simple use of Vue vee-validate plug-in

Table of contents 1. Installation 2. Import 3. De...

How to create a table in mysql and add field comments

Directly post code and examples #Write comments w...

Detailed steps for installing and using vmware esxi6.5

Table of contents Introduction Architecture Advan...

Detailed explanation of Linux text processing tools

1. Count the number of users whose default shell ...

JavaScript DOMContentLoaded event case study

DOMContentLoaded Event Literally, it fires after ...

JavaScript implements large file upload processing

Many times when we process file uploads, such as ...

Are you still Select *?

There are many reasons why an application is as s...

Example of building a Jenkins service with Docker

Pull the image root@EricZhou-MateBookProX: docker...

Vue implements form validation function

This article mainly describes how to implement fo...

Detailed tutorial on installing mysql 5.7.26 on centOS7.4

MariaDB is installed by default in CentOS, which ...

Use vue2+elementui for hover prompts

Vue2+elementui's hover prompts are divided in...

uniapp dynamic modification of element node style detailed explanation

Table of contents 1. Modify by binding the style ...