《linux命令学习总结-flie命令》由会员分享,可在线阅读,更多相关《linux命令学习总结-flie命令(4页珍藏版)》请在金锄头文库上搜索。
1、Linux 命令学习总结: file 命令命令简介:该命令用来识别文件类型,也可用来辨别一些文件的编码格式。它是通过查看文件的头部信息来获取文件类型,而不是像 Windows 通过扩展名来确定文件类型的。执行权限 :All User指令所在路径:/usr/bin/file命令语法:file -bchikLnNprsvz -f namefile -F separator -m magicfiles file .命令参数:下表列出了部分常用的参数。 参数 长参数 描叙-b 列出文件辨识结果时,不显示文件名称。-c 详细显示指令执行过程,便于排错或分析程序执行的情形-f 列出文件中文件名的文件类型-
2、F 使用指定分隔符号替换输出文件名后的默认的“:”分隔符。-i 输出 mime 类型的字符串-L 查看对应软链接对应文件的文件类型-z 尝试去解读压缩文件的内容-help 显示命令在线帮助-version 显示命令版本信息使用示例: 1:查看 file 命令的帮助信息rootDB-Server # file -helpUsage: file OPTION. FILE.Determine file type of FILEs. -m, -magic-file LIST use LIST as a colon-separated list of magicnumber files-z, -unco
3、mpress 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 inconjunction with -m to debug a new magic filebefore installing it-f, -files-from FILE read the filenames to be examined from FILE-F, -sep
4、arator string use string as separator instead of :-i, -mime output mime type strings-k, -keep-going dont stop at the first match-L, -dereference causes symlinks to be followed-n, -no-buffer do not buffer output-N, -no-pad do not pad output-p, -preserve-date preserve access times on files-r, -raw don
5、t translate unprintable chars to ooo-s, -special-files treat special (block/char devices) files asordinary ones-help display this help and exit-version output version information and exit当然你也可以使用 man file 获取更加详细的帮助文档信息。2:查看文件类型例如,如下所示,Temp.txt 文件类型为 text,编码为 UTF-8 UnicoderootDB-Server # file Temp.tx
6、t Temp.txt: UTF-8 Unicode text, with very long lines, with CRLF line terminators3:不输出文件名称,只显示文件格式以及编码通过下面两个命令对时,就可以清晰的了解参数-b 的作用。rootDB-Server # file Temp.txt Temp.txt: UTF-8 Unicode text, with very long lines, with CRLF line terminatorsrootDB-Server # file -b Temp.txtUTF-8 Unicode text, with very l
7、ong lines, with CRLF line terminators4: 输出 mime 类型的字符串rootDB-Server # file -i Temp.txt Temp.txt: text/plain; charset=utf-85: 查看文件中的文件名的文件类型这个参数非常适合 shell 脚本去查找、判别某种文件类型的数据。rootDB-Server # cat test/root/install.log it is only one test file2+ Stopped cat testrootDB-Server # file -f test/root/install.l
8、og: ASCII textit is only one test file: ERROR: cannot open it is only one test file (No such file or directory)rootDB-Server # rootDB-Server # 5: 使用指定分隔符号替换输出文件名后的默认的“:”分隔符。感觉这个参数很鸡肋!我搞明白这个参数的作用时,很是纳闷。6:尝试去解读压缩文件的内容rootDB-Server # file -z Temp.txt.gz Temp.txt.gz: UTF-8 Unicode text, with very long l
9、ines, with CRLF line terminators (gzip compressed data, was Temp.txt, from Unix, last modified: Tue Jun 24 00:34:15 2014)rootDB-Server # 7: 查看软链接对应文件的文件类型如下所示,创建一个软链接 sfile,然后分别用 file 和带参数的 file -L 查看rootDB-Server # ln -s Temp.txt.gz sfilerootDB-Server # file sfile sfile: symbolic link to Temp.txt.gzrootDB-Server # file -L sfile sfile: gzip compressed data, was Temp.txt, from Unix, last modified: Tue Jun 24 00:34:15 2014rootDB-Server #