Linux常用命令——file 命令详解
命令介绍: file 命令在Linux系统中用于确定文件的类型。它通过检查文件的内容,而不仅仅是文件的扩展名来识别文件类型。
基本语法:
file [选项] 文件...
常用选项和参数:
- -b, --brief: 只输出文件类型信息,而不显示文件名。
- 示例:
file -b example.txt
输出:
ASCII text
- -i, --mime: 输出文件的 MIME 类型。
- 示例:
file -i example.jpg
输出:
example.jpg: image/jpeg
- -f, --files-from FILE: 从指定的文件中读取文件列表,并对每个文件执行 file 命令。
- 示例:
file -f filelist.txt
假设 filelist.txt 包含以下内容:
example.txt
example.jpg
输出:
example.txt: ASCII text
example.jpg: JPEG image data, JFIF standard 1.01
- -L, --dereference: 如果参数是符号链接,直接跟随符号链接指向的文件。
- 示例:
file -L symlink
- -s, --special-files: 检查和报告块特殊文件和字符特殊文件的类型。
- 示例:
file -s /dev/sda1
- -z, --uncompress: 尝试解压缩压缩文件,并分析其内容。
- 示例:
file -z archive.tar.gz
输出:
archive.tar.gz: gzip compressed data, was "archive.tar", last modified: Mon Apr 6 13:45:26 2020, from Unix
更多命令请参考 Linux命令大全 专栏。