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

How to fix the footer at the bottom of the page (multiple methods)

As a front-end Web engineer, you must have encoun...

How to add fields and comments to a table in sql

1. Add fields: alter table table name ADD field n...

Implementation of HTML command line interface

HTML Part Copy code The code is as follows: <!D...

Example of disabling browser cache configuration in Vue project

When releasing a project, you will often encounte...

Detailed explanation of Vue's hash jump principle

Table of contents The difference between hash and...

MySQL series multi-table join query 92 and 99 syntax examples detailed tutorial

Table of contents 1. Cartesian product phenomenon...

Detailed explanation of three ways to import CSS files

There are three ways to introduce CSS: inline sty...

How to decompress multiple files using the unzip command in Linux

Solution to the problem that there is no unzip co...

Example of how to install kong gateway in docker

1. Create a Docker network docker network create ...

Vue template configuration and webstorm code format specification settings

Table of contents 1. Compiler code format specifi...

Installation and daemon configuration of Redis on Windows and Linux

# Installation daemon configuration for Redis on ...

Vue encapsulation component tool $attrs, $listeners usage

Table of contents Preface $attrs example: $listen...

SMS verification code login function based on antd pro (process analysis)

Table of contents summary Overall process front e...

Zabbix3.4 method to monitor mongodb database status

Mongodb has a db.serverStatus() command, which ca...

Install and build a server environment of PHP+Apache+MySQL on CentOS

Yum (full name Yellow dog Updater, Modified) is a...