侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

一天一个shell命令 linux文本系列-file命令用法

linux  /  管理员 发布于 7年前   186

linux file 命令简介:

该命令用来识别文件类型,也可用来辨别一些文件的编码格式。它是通过查看文件的头部信息来获取文件类型,而不是像Windows通过扩展名来确定文件类型的。

更多介绍可以查看这篇文章:///LINUXjishu/388984.html

file 官方解释:Determine type of FILEs. 判定文件的类型。

小知识:在UNIX/Linux系统中,文件类型并不是由扩展名决定的(Windows是的)。

开篇例子:

1. $file file.txt

输出:file.txt: ASCII English text

注:file.txt是我用file Chelp > file.txt生成的帮助文档

查看―help

复制代码 代码如下:
Usage: file [OPTION...] [FILE...]
 Determine type of FILEs.
--help   display this help and exit
-v, --version   output version information and exit
 -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   print the parsed form of the magic file, use in
conjunction with -m to debug a new magic file before installing it
 -e, --exclude TEST   exclude TEST from the list of test to be performed for file. Valid tests are: ascii, apptype, compress, elf, soft, tar, tokens, troff
 -f, --files-from FILE   read the filenames to be examined from FILE
-F, --separator STRING   use string as separator instead of `:'
-i, --mime  output MIME type strings (--mime-type and
 --mime-encoding)
--apple  output the Apple CREATOR/TYPE
 --mime-type  output the MIME type
--mime-encoding  output the MIME encoding
 -k, --keep-going  don't stop at the first match
 -l, --list  list magic strength
 -L, --dereference  follow symlinks (default)
-h, --no-dereference  don't follow symlinks
 -n, --no-buffer  do not buffer output
 -N, --no-pad  do not pad output
 -0, --print0  terminate filenames with ASCII NUL
-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
 -C, --compile  compile file specified by -m
 -d, --debug  print debugging messages

解读:

1. -z

查看压缩文件内的信息

2. -b, -e, -i, Cr

-b 去掉输出行的前缀命名
-e 从测试列表到被执行文件排除测试。有效的测试包括:ascii, apptype, compress, elf, soft, tar,
-i 打印MIME
-R 不转译无法打印的字符为\ooo

3. magic file

以mgc为扩展名的文件,Microsoft office媒体目录文件

实战实例:

1. $file -z file.zip
查看file.zip包中的文件信息

2. $file Ci file.txt
out:file.txt: text/plain; charset=us-ascii

打印MIME类型
 
$file file.txt
out:file.txt: ASCII English text

3. magic file

我翻译起来实在蹩脚。。 只能猜测查看$which file 看看,没有收获。最终通过$file得到

Usage: file  [-bchikLlNnprsvz0] [--apple] [--mime-encoding] [--mime-type]
       [-e testname] [-F separator] [-f namefile] [-m magicfiles] file ...
 file  -C [-m magicfiles]
 file  [--help]

然后尝试file CC 得到magic.mgc文件。。。 不知有何用,惭愧

Usage: file [OPTION...] [FILE...]
Determine type of FILEs.

      --help                 display this help and exit
  -v, --version              output version information and exit
  -m, --magic-file LIST       以冒号分割的魔法数字清单作为列表
                           
  -z, --uncompress           查看压缩文件内容
  -b, --brief                不前缀文件名到输出行里
  -c, --checking-printout    打印魔法文件的解析格式,安装前,用-m debug一个新的魔法文件
                             
  -e, --exclude TEST         排除测试从测试列表到执行文件。有效的测试:ascii, apptype, compress, elf, soft, tar, tokens, troff
  -f, --files-from FILE      从已查的文档中读取文件名
  -F, --separator STRING     用String作为分隔器 代替 “:”
  -i, --mime                 输出MIME类型的字符串 (--mime-type and
                               --mime-encoding)
         
      --apple                输出苹果类型 CREATOR/TYPE
      --mime-type            打印MIME类型
      --mime-encoding        打印 MIME 编码
  -k, --keep-going           不停留在第一个匹配
  -l, --list                 列出magic深度
  -L, --dereference          跟随符号链接(缺省)
  -h, --no-dereference       不跟随符号链接
  -n, --no-buffer            不缓冲输出
  -N, --no-pad               不打印输出
  -0, --print0               NUL终止文件
  -p, --preserve-date        保持文件上的原访问时间
  -r, --raw                  不转移不可打印的字符到\ooo
  -s, --special-files        把特殊(块/字符 设备)文件作为普通文件对待
  -C, --compile              编译用-m指定的文件
  -d, --debug                打印调试信息

Report bugs to http://bugs.gw.com/


  • 上一条:
    一天一个shell命令 linux文本操作系列-diff命令详解
    下一条:
    一天一个shell命令 linux文本操作系列-touch命令用法
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Linux系统中使用Iptables实现流量转发功能流程步骤(0个评论)
    • vim学习笔记-入门级需要了解的一些快捷键(0个评论)
    • 在centos7系统中实现分区并格式化挂载一块硬盘到/data目录流程步骤(0个评论)
    • 在Linux系统种查看某一个进程所占用的内存命令(0个评论)
    • Linux中grep命令中的10种高级用法浅析(0个评论)
    • 近期文章
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-11
    • 2017-07
    • 2017-10
    • 2017-11
    • 2018-01
    • 2018-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-03
    • 2022-04
    • 2022-08
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-06
    • 2023-07
    • 2023-10
    • 2023-12
    • 2024-01
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客