查看文件类型: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
> MIME:Multipurpose Internet Mail Extension,多用途互联网邮件扩展类型,用来标识和记录文件的打开方式,常见类型有:
> - text/plain:普通文本
> - text/html:HTML文本
> - application/pdf:PDF文档
> - application/msword:Word文档
> - image/png:PNG图片
> - image/jpeg:JPEG图片
> - application/x-tar:tar文件
> - application/x-gzip:Gzip文件
file 查看软链接文件:
- 通过 file 直接查看软链接文件,则查看的就是软链接文件本身的信息
- 如果使用 -L 选项来查看软链接文件,则查看的是软链接指向的目标文件的信息
```bash
[root@iZwz9de6ypp03mqjv3cshhZ]~# ln -s read.sh read.link.sh #创建符号链接
[root@iZwz9de6ypp03mqjv3cshhZ]~# file read.link.sh
read.link.sh: symbolic link to `read.sh'
[root@iZwz9de6ypp03mqjv3cshhZ]~# file -L read.link.sh
read.link.sh: Bourne-Again shell script, ASCII text executable
如果想要查看多个文件的类型,可以将所有的文件名写入一个文件,使用 file -f 参数进行查看:
[root@iZwz9de6ypp03mqjv3cshhZ]~# cat file.txt
1.txt
read.sh
read.link.sh
2.txt
3.txt #不存在的文件
[root@iZwz9de6ypp03mqjv3cshhZ]~# file -f file.txt
1.txt: ASCII text
read.sh: Bourne-Again shell script, ASCII text executable
read.link.sh: symbolic link to `read.sh'
2.txt: ASCII text
3.txt: cannot open (No such file or directory)