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 Command Learning Manual-file

2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

File [- beLvz] [- f] [- m...] [file or directory.] Function

Identify the file type.

Check the file type $file file.c file / dev/hda for example

After the input, the output is as follows:

File.c: C program textfile: ELF 32-bit LSB executable, Intel 80386, version 1 dynamic linked, not stripped/dev/hda: block special check file type, do not output file name $file-b test/

After the input, the output is as follows:

Directory checks the file type, file name and result separated by "," $file-F, example/

After the input, the output is as follows:

Example, directory

Other split characters can be specified here.

Check the inside of the block file and get the file system information $file-s / dev/hda {, 1, 2, 4, 5, 6, 7, 8, 9, 10}

After the input, the output is as follows:

/ dev/hda: x86 boot sector/dev/hda1: Linux/i386 ext2 filesystem/dev/hda2: x86 boot sector/dev/hda3: x86 boot sector, extended partition table/dev/hda4: Linux/i386 ext2 filesystem/dev/hda5: Linux/i386 swap file/dev/hda6: Linux/i386 swap file/dev/hda7: Linux/i386 swap file/dev/hda8: Linux/i386 swap file/dev/hda9: empty/dev/hda10: empty

Here, if you don't have permission, you can't execute it.

Description

This man page describes the use of the version 3.27 file command. The File command attempts to check each parameter to determine the type of file. There are three groups of checks, in the following order: file system check, magic number check, and language check.

If the file system check is successful, the file type is output. The output type generally contains one of the following words: text (only ASCII characters in the file, which can be read with ASCII terminal to ensure the reliability of the content), executable (the file holds the compiled results of the program, some UNIX kernels or other kernels can understand such files), or data represents all other types of files (data is usually binary or non-printable). Some commonly used file formats (such as core files, tar packages), although they also contain binary data, do not fall into this category. You can modify if you want to modify / usr/share/magic or the program itself to deal with these keywords. When a file is of type text, it is considered readable. Don't do it like you did in a Berkeley environment-change shell commands text to shell script.

The file system check is based on the analysis of the results of the stat (2) system call. The program will analyze whether the file is empty or whether it is a special file. All file types that can be used on existing systems (such as socket files, dynamically linked files, named pipe files (FIFOs), etc.) can be checked as long as they are defined in the system header file sys/stat.h.

Magic number check is used to check whether there is special fixed format data in the file. Examples of specifications such as the binary executable (compiled program) a.out, the file format is defined in the a.out.h file in the standard-include= directory, or in exec.h. These files have a 'magic number' stored in a special location near the beginning of the file, which tells the UNIX operating system that the file is a binary executable file and other types contained in it. The concept of magic numbers has been extended to data files. Any file that has an immutable identifier associated with the file type in a fixed location can be represented in this way. The information in these files can be read from the magic number file / usr/share/magic.

If the file is an ASCII file, file will try to check its language. The language check looks for special strings in the first few blocks of the file (see names.h). Br indicates that this file is probably a troff (1) input file, while the keyword struct indicates that this file is a C program. Language checks are not as reliable as the first two groups, so they are executed at the end. It is also used to check some mixed files (such as tar (1) archive files) and determine whether the file is of ascii text type or data type.

Option

-b: do not output the file name (brief mode).-c: print the parsing result of the magic number file when checking. Often used with-m to debug the magic number file before installing it.-f: the named file reads the file name to be checked from the named file in front of the parameter table (one file per line). To have a named file, or at least one file name parameter; if you want to check standard input, use-as the file parameter.-m list: specify a list of files that contain magic numbers. It can be a single file or multiple files separated by colons.-n: force the standard output to be refreshed every time a file is checked. Valid only when checking a set of files. This option is generally used when exporting file types to pipes.-v: print the program version and exit.-z: try to view the internal information of the compressed file.-L: (on systems that support symbolic links) the option displays the original file of the symbolic link file, just like the like-named option of the ls (1) command.-s: generally File is just trying to check the types of files in the file list that stat (2) reports as normal. Since reading special files may lead to unknowable consequences, this can prevent problems. The file command will also read block special files and character special files in the file list when using the-s option. Generally used to obtain the file system type from the original disk partition, this file is a block special file. This option also causes the file command to ignore the file size reported by stat (2), because on some systems the size of the original disk partition is reported as 0. 0. Other information files about magic numbers

/ usr/share/magic-default list of magic numbers

ENVIRONMENT

The environment variable MAGIC is used to set the default magic number file.

See

Magic (4)-the format of the magic number file.

Strings (1), od (1), hexdump (1)-check non-textfile tools.

Consistency of standards

This procedure (general Linux? ) is more powerful than System V's FILE command, and can distinguish almost all fuzzy languages. Most of them are compatible with System V's FILE= commands. This version instinctively recognizes more = magic, but it will also produce different output in some cases (although more accurate).

The significant difference between this version and System V is that this version treats spaces as delimiters, so you cannot include spaces in the format string. For example, in an existing magic number file

> 10 string language impress (imPRESS data)

To change to

> 10 string language\ impress (imPRESS data)

In addition, backslash symbols in format strings should also be avoided. For example, in an existing magic number file

0 string\ begindata Andrew Toolkit document

To change to

0 string\\ begindata Andrew Toolkit document

SunOS releases 3.2 and later include the file (1) command developed from System V, but have been extended. This version is not much different from Sun's file command. It includes extensions to the `& 'operator, such as

> 16 long&0x7fffffff > 0 not strippedMAGIC DIRECTORY

Magic number file entries are mainly collected from USENET, and many people have contributed to it. Christos Zoulas (mentioned below) will collect additional information and fix magic file entries. The merge table of magic file items will be released on a regular basis.

The order of magic number file items is very important. Magic items may be placed in different order on different systems. If the old file command uses a magic number file, please rename the old magic number file (e.g. / usr/share/magic.orig) for later comparison.

Other reference materials

Http://fanqiang.chinaunix.net/a1/b1/20020108/08100041.html

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