Linux -- file 命令

博客主要介绍了Linux系统中file命令的相关知识。该命令可接受文件参数,通过执行测试确定文件类型。还列举了file命令的多个参数及实例,如查看文件和目录类型、以MIME格式显示信息等,同时给出了不同选项的格式对比。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1.file命令含义

    file命令用于接受一个文件作为参数并执行某些测试,以确定正确的文件类型

  2.file命令参数以及实例

    (1)file命令查看文件类型

$ file /etc/irbrc 
/etc/irbrc: Ruby script text, ASCII text

    (2) file命令查看目录类型

1 $ file learn/Linux/
2 learn/Linux/: directory

   (3)使用-i选项,可以以MIME类型的格式显示文件类型的信息

1 $ file -i /etc/irbrc 
2 /etc/irbrc: regular file

    (4) -N 选项 --输出的队列可以以在文件名之后无空白填充的形式显示,格式对比如下

 1  file -N *
 2 1.sh: UTF-8 Unicode text
 3 2.3.5.sh: UTF-8 Unicode text
 4 2.3.6.sh: UTF-8 Unicode text
 5 2.4.2.sh: ASCII text
 6 Desktop: directory
 7 Documents: directory
 8 Downloads: directory
 9 IdeaProjects: directory
10 Library: directory
11 Movies: directory
12 Music: directory
13 Pictures: directory

      (5)-n 选项 --和-N选项一样,就是在显示的格式上稍微有点区别

 1 $ file -n *
 2 1.sh:                UTF-8 Unicode text
 3 2.3.5.sh:            UTF-8 Unicode text
 4 2.3.6.sh:            UTF-8 Unicode text
 5 2.4.2.sh:            ASCII text
 6 Desktop:             directory
 7 Documents:           directory
 8 Downloads:           directory
 9 IdeaProjects:        directory
10 Library:             directory
11 Movies:              directory
12 Music:               directory

   (6) 类似与-n 和-N选项的显示文件的类型,还有一种方法,不需要任何的参数,如下

 1 $ file -n *
 2 1.sh:                UTF-8 Unicode text
 3 2.3.5.sh:            UTF-8 Unicode text
 4 2.3.6.sh:            UTF-8 Unicode text
 5 2.4.2.sh:            ASCII text
 6 Desktop:             directory
 7 Documents:           directory
 8 Downloads:           directory
 9 IdeaProjects:        directory
10 Library:             directory
11 Movies:              directory
12 Music:               directory

 

 

 

 

  

转载于:https://www.cnblogs.com/start-wang/p/10816468.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值