查看文件类型:file 命令

  • -b:只显示文件格式和编码,不显示文件名
  • -i:显示文件的 MIME 类型字符串
  • -F “sep” :指定输出的分隔符 ```bash [root@iZwz9de6ypp03mqjv3cshhZ]~# file read.sh

    文件名:文件类型和文件格式

    read.sh: Bourne-Again shell script, ASCII text executable

[root@iZwz9de6ypp03mqjv3cshhZ]~# file -b read.sh Bourne-Again shell script, ASCII text executable

[root@iZwz9de6ypp03mqjv3cshhZ]~# file -i read.sh read.sh: text/x-shellscript; charset=us-ascii

[root@iZwz9de6ypp03mqjv3cshhZ]~# file -F “->” read.sh read.sh-> Bourne-Again shell script, ASCII text executable

  1. > MIMEMultipurpose Internet Mail Extension,多用途互联网邮件扩展类型,用来标识和记录文件的打开方式,常见类型有:
  2. > - text/plain:普通文本
  3. > - text/htmlHTML文本
  4. > - application/pdfPDF文档
  5. > - application/mswordWord文档
  6. > - image/pngPNG图片
  7. > - image/jpegJPEG图片
  8. > - application/x-tartar文件
  9. > - application/x-gzipGzip文件
  10. file 查看软链接文件:
  11. - 通过 file 直接查看软链接文件,则查看的就是软链接文件本身的信息
  12. - 如果使用 -L 选项来查看软链接文件,则查看的是软链接指向的目标文件的信息
  13. ```bash
  14. [root@iZwz9de6ypp03mqjv3cshhZ]~# ln -s read.sh read.link.sh #创建符号链接
  15. [root@iZwz9de6ypp03mqjv3cshhZ]~# file read.link.sh
  16. read.link.sh: symbolic link to `read.sh'
  17. [root@iZwz9de6ypp03mqjv3cshhZ]~# file -L read.link.sh
  18. read.link.sh: Bourne-Again shell script, ASCII text executable

如果想要查看多个文件的类型,可以将所有的文件名写入一个文件,使用 file -f 参数进行查看:

  1. [root@iZwz9de6ypp03mqjv3cshhZ]~# cat file.txt
  2. 1.txt
  3. read.sh
  4. read.link.sh
  5. 2.txt
  6. 3.txt #不存在的文件
  7. [root@iZwz9de6ypp03mqjv3cshhZ]~# file -f file.txt
  8. 1.txt: ASCII text
  9. read.sh: Bourne-Again shell script, ASCII text executable
  10. read.link.sh: symbolic link to `read.sh'
  11. 2.txt: ASCII text
  12. 3.txt: cannot open (No such file or directory)