Linux command
file 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Determine file type
file [filename]
Check multiple files
file [file1] [file2] [file3]
Show MIME type
file --mime-type [filename]
Follow symlinks
file -L [symlink]
Read from stdin
cat [file] | file -
说明
file determines file types by examining content rather than extensions. It uses magic number patterns and heuristics from a database to identify formats. The tool recognizes thousands of file types including executables, archives, documents, images, and text encodings. It examines file headers and content patterns rather than trusting filename extensions. file is essential for identifying unknown files and verifying file types in scripts.
参数
- -b, --brief
- Omit filename from output.
- -i, --mime
- Output MIME type and encoding.
- --mime-type
- Output MIME type only.
- -L, --dereference
- Follow symlinks.
- -z, --uncompress
- Look inside compressed files.
- -f _FILE_
- Read filenames from file.
- --help
- Display help information.
FAQ
What is the file command used for?
file determines file types by examining content rather than extensions. It uses magic number patterns and heuristics from a database to identify formats. The tool recognizes thousands of file types including executables, archives, documents, images, and text encodings. It examines file headers and content patterns rather than trusting filename extensions. file is essential for identifying unknown files and verifying file types in scripts.
How do I run a basic file example?
Run `file [filename]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -b, --brief do in file?
Omit filename from output.