Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux's method of displaying file types using the file command

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the method that Linux uses the file command to display file types. It is very detailed and has certain reference value. Friends who are interested must read it!

Linux file command

The file command is useful when you have to find a file type that you have never seen before or that file does not have a file extension.

The syntax of the Linux file command is:

File [option] [file]

Option parameter: you can use the following values

●-b: when listing the identification results, the file name is not displayed.

●-c: displays the instruction execution process in detail to facilitate debugging or analysis of program execution.

●-f: specify name files that have one or more file names in their contents, and have file identify them sequentially in one file name per column.

●-L: directly displays the category of the file that the symbolic link points to.

●-m: specifies the magic number file.

●-v: displays version information.

●-z: try to interpret the contents of the compressed file.

File parameter: indicates a list of files to determine the type (file or directory.), multiple files are separated by spaces, and multiple files can be matched using the Shell wildcard.

How do I display file types using the file command?

The file command classifies files according to a series of tests and determines the file type based on the first successful test.

It is the simplest form to use without any option parameters, where the file command displays the file name and file type:

[root@localhost ~] # file install.loginstall.log: UTF-8 Unicode text [root@localhost ~] # file / etc/group/etc/group: ASCII text

If you want to display only the file type, you can use the-b (--brief) option:

[root@localhost ~] # file-b install.logUTF-8 Unicode text [root@localhost ~] # file-b / etc/groupASCII text

As you can see from the example output above, the install.log and / etc/group files are both text files.

How do I display the file types of multiple files?

We can pass multiple files as parameters to the file command:

[root@localhost ~] # file / bin/bash / opt/card.zip

Note: multiple files need to be separated by spaces

The file command outputs the type of each file on a separate file:

/ bin/bash: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter / lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID [sha1] = 42602c973215ba5b8ab5159c527e72f38e83ee52, stripped/opt/card.zip: Zip archive data, at least v1.0 to extract

The file command also accepts finding file types that display wildcards. For example, to display the type of each .jpg file in the current directory, you can do the following:

[root@localhost] # file * .jpg

Output:

Imgage001.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, progressive, precision 8, 2083x1250, components 3imgage031.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), density 72x72, segment length 16, comment: "Created with GIMP", baseline, precision 8, 1280x1024, components

How do I view the Mime type of a file?

We use the-I (--mime) option to determine the mime type of the file:

[root@localhost ~] # file install.loginstall.log: text/plain; charset=utf-8 [root@localhost ~] # file / var/www/index.html/var/www/index.html: text/html; charset=utf-8 is all the contents of Linux's method of displaying file types using the file command. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report