博客
关于我
Linux 文件管理 : file 命令详解
阅读量:245 次
发布时间:2019-03-01

本文共 803 字,大约阅读时间需要 2 分钟。

file命令:探测文件类型

语法

file命令的语法格式为:

file(选项)(参数)

选项说明

  • -b:在列出文件类型时,不显示文件名称。
  • -c:详细显示指令执行过程,便于排查或分析程序执行情况。
  • -f <文件>:指定文件列表,文件内容包含一个或多个文件名称时,file命令会依次检查这些文件。
  • -L:直接显示符号链接所指向的文件类型。
  • -m <魔法数字文件>:指定魔法数字文件。
  • -v:显示file命令的版本信息。
  • -z:尝试解读压缩文件的内容。

参数说明

  • 文件:需要确定类型的文件列表,多个文件之间用空格分隔,也可以使用shell通配符匹配多个文件。

实例

1. 查看文件类型

命令:

file Temp.txt

输出:

Temp.txt: UTF-8 Unicode text

2. 不输出文件名称,只显示文件格式及编码

命令:

file -b Temp.txt

输出:

UTF-8 Unicode text

3. 显示MIME类型的字符串

命令:

file -i Temp.txt

输出:

Temp.txt: text/plain; charset=utf-8

4. 查看文件中的文件名的文件类型

命令:

file -f test

输出:

test: text/plain

5. 使用指定分隔符替换输出文件名的默认":"分隔符

命令:

file --F "--" test

输出:

--: text/plain

6. 尝试去解读压缩文件的内容

命令:

file -z test.gz

输出:

test.gz: gzip compressed data

7. 查看软链接对应文件的文件类型

命令:

file -L file

输出:

file: directory

总结

通过file命令,您可以轻松探测出文件的类型,了解文件的性质。通过合理使用各种选项和参数,您可以获取更详细的信息,满足不同的需求。

转载地址:http://veut.baihongyu.com/

你可能感兴趣的文章
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>