http://www.cnblogs.com/kerrycode/p/3806618.htmlLinux Command Learning Summary: File command
Introduction to Commands:
This command is used to identify file types and to identify the encoding format of some files. It does this by looking at the header information of the file to get the file type, rather than identifying the file type as Windows does by extension.
Execute permissions: All User
Instruction Path:/usr/bin/file
Command syntax:
file [-BCHIKLNNPRSVZ] [-F NameFile] [-F separator] [-M magicfiles] file ...
Command parameters:
The following table lists some of the commonly used parameters.
Parameters |
Long parameters |
Description |
-B |
|
When listing file identification results, the file name is not displayed. |
-C |
|
Detailed instruction execution process to facilitate troubleshooting or analysis of program execution scenarios |
-F |
|
List file types for file names in files |
-F |
|
Replaces the default ":" Delimiter after the output file name with the specified separator symbol. |
-I. |
|
Output MIME-type string |
-L |
|
View file types for corresponding soft link files |
-Z |
|
Try to interpret the contents of a compressed file |
|
--help |
Show Commands online Help |
|
--version |
Display Command version information |
Examples of Use:
1: View the Help information for the file command
[[Email protected] ~] # file--help
Usage:file [OPTION] ... [FILE] ...
Determine file type of FILEs.
-M,--magic-file list use list as a colon-separated list of magic
Number files
-Z,--uncompress try to look inside compressed files
-B,--brief do not prepend filenames to output lines
-C,--checking-printout in
conjunction with-m to debug a new magic file
Before installing it
-F,--files-from FILE read the filenames to is examined from file
-F,--separator string use string as separator instead of ': '
-I,--mime output MIME type strings
-K,--keep-going don ' t stop at the first match
-L,--dereference causes symlinks to be followed
-N,--no-buffer do not buffer output
-N,--no-pad do not pad output
-P,--preserve-date preserve access times on files
-R,--raw don ' t translate unprintable chars to \ooo
-S,--special-files treat Special (Block/char devices) files as
Ordinary ones
--help Display this help and exit
--version output version information and exit
Of course you can also use the man file to get more detailed help document information.
2: View File types
For example, as shown below, the Temp.txt file type is text, encoded as UTF-8 Unicode
[[Email protected] ~]
Temp.txt:utf-8 Unicode text, with very long lines, with CRLF line terminators
3: Do not output file name, only show file format and encoding
With the following two commands, you can clearly understand the role of parameter-B.
[[Email protected] ~]
Temp.txt:utf-8 Unicode text, with very long lines, with CRLF line terminators
[[Email protected] ~] # file-b Temp.txt
UTF-8 Unicode text, with very long lines, with CRLF line terminators
4: Output MIME-type string
[[Email protected] ~]
Temp.txt:text/plain; Charset=utf-8
5: View file types for file names in files
This parameter is ideal for Shell scripting to find and discriminate data for a file type.
[[Email protected] ~] # cat >test
It is only one test file
[2]+ Stopped cat > Test
[[Email protected] ~] # file-f Test
/root/install.log: ASCII text
It is only one test File:ERROR:cannot open ' It was only one test file ' (No such file or directory)
[[Email protected] ~]
5: Replaces the default ":" Delimiter after the output file name with the specified separator symbol.
Feel this parameter is very chicken! I was puzzled when I understood the function of this parameter.
6: Try to interpret the contents of the compressed file
[[Email protected] ~]
"Temp.txt", from Unix, last modified:tue June 24 00:34:15 2014)
7: View the file type of the soft link file
As shown below, create a soft-link sfile, and then view the file with the file-l with the parameter separately
[[Email protected] ~] # ln-s Temp.txt.gz sfile
[[Email protected] ~]
Sfile:symbolic link to ' Temp.txt.gz '
[[Email protected] ~]
"Temp.txt", from Unix, last modified:tue June 24 00:34:15 2014
Xiaoxiang Hidden Source: http://www.cnblogs.com/kerrycode/This article copyright belongs to the author, welcome to reprint, but without the consent of the author must retain this paragraph statement, and in the article page obvious location to the original link.
Linux Command Learning Summary: File command