Linux 基础命令 -- file

命令介绍

命令:file 查看文件类型

用法:file [OPTION…] [FILE…] file 选项 文件

命令选项

[root@fp-21 ~]# file --help

  -z, --uncompress           # 尝试查看压缩文件
  -b, --brief                # 不在输出行面前加文件名
  -c, --checking-printout    # 详细显示指令执行过程,便于排错或分析程序执行的情形
  -e, --exclude TEST         # 从要对文件执行的测试列表中排除测试
  -f, --files-from FILE      # 指定文件,判断内容中的文件名的文件类型
  -F, --separator STRING     # 以指定的字符串作为分隔符
  -i, --mime                 #  MIME 类型字符串输出
      --apple                #  Apple 类型输出 
      --mime-type            #  MIME 类型输出
      --mime-encoding        #  MIME 编码输出
  -L, --dereference          # 直接显示符号连接所指向的文件的类别
  -0, --print0               # 用ASCII NUL终止文件名
  -p, --preserve-date        # 保留文件的访问时间
  -r, --raw                  # 不要将无法打印的字符转换为\ooo
  -s, --special-files        # 将特殊(块/字符设备)文件视为普通文件
  -C, --compile              # 编译由-m指定的文件
  -d, --debug                # 打印调试信息
  --help                     # 帮助文档
  -v, --version              # 版本信息

命令实例

# 查看文件类型
[root@fp-21 ~]# file test_file 
test_file: ASCII text
[root@fp-21 ~]# file test_dir
test_dir: directory
[root@fp-21 ~]# file file
file: symbolic link to 'test_file'

# 尝试查看压缩文件
[root@fp-21 ~]# file -z mysql-5.6.45.tar.gz 
mysql-5.6.45.tar.gz: POSIX tar archive (GNU) (gzip compressed data, from Unix, last modified: Mon Jun 10 18:31:21 2019)

# 不在输出行面前加文件名
[root@fp-21 ~]# file 777
777: directory
[root@fp-21 ~]# file -b 777
directory

# 指定文件,判断内容中的文件名的文件类型
[root@fp-21 ~]# mkdir test_dir
[root@fp-21 ~]# echo "test_dir" >> test_file
[root@fp-21 ~]# echo "test_file" >> test_file
[root@fp-21 ~]# file -f test_file
test_dir:  directory
test_file: ASCII text

# 以指定的字符串作为分隔符
[root@fp-21 ~]# file -F " -->" test_file
test_file --> ASCII text

# 以 MIME 类型字符串输出
[root@fp-21 ~]# file -i test_file
test_file: text/plain; charset=us-ascii

link 查看 Linux 基础命令

只有注入思想的博客才是好的博客

发布了33 篇原创文章 · 获赞 145 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/xtlhxl/article/details/104462265