资源描述:
《Linux命令学习总结file命令》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Linux命令学习总结:file命令命令简介:该命令用来识别文件类型,也可用来辨别一些文件的编码格式。它是通过查看文件的头部信息来获取文件类型,而不是像Windows通过扩展名来确定文件类型的。执行权限:AllUser指令所在路径:/usr/bin/file命令语法:file[-bchikLnNprsvz][-fnamefile][-Fseparator][-mmagicfiles]file...命令参数:下表列出了部分常用的参数。参数长参数描叙-b列出文件辨识结果时,不显示文件名称。-c详细显示指令执行过程,便于排错或分析程序执行的情形-f列出文件中文件名的文件
2、类型-F使用指定分隔符号替换输出文件名后的默认的“:”分隔符。-i输出mime类型的字符串-L查看对应软链接对应文件的文件类型-z尝试去解读压缩文件的内容--help显示命令在线帮助--version显示命令版本信息 使用示例:1:查看file命令的帮助信息[root@DB-Server~]#file--helpUsage:file[OPTION]...[FILE]...DeterminefiletypeofFILEs. -m,--magic-fileLISTuseLISTasacolon-separatedlistofmagicnumberfiles-z,--u
3、ncompresstrytolookinsidecompressedfiles-b,--briefdonotprependfilenamestooutputlines-c,--checking-printoutprinttheparsedformofthemagicfile,useinconjunctionwith-mtodebuganewmagicfilebeforeinstallingit-f,--files-fromFILEreadthefilenamestobeexaminedfromFILE-F,--separatorstringusestringass
4、eparatorinsteadof`:'-i,--mimeoutputmimetypestrings-k,--keep-goingdon'tstopatthefirstmatch-L,--dereferencecausessymlinkstobefollowed-n,--no-bufferdonotbufferoutput-N,--no-paddonotpadoutput-p,--preserve-datepreserveaccesstimesonfiles-r,--rawdon'ttranslateunprintablecharstoooo-s,--speci
5、al-filestreatspecial(block/chardevices)filesasordinaryones--helpdisplaythishelpandexit--versionoutputversioninformationandexit当然你也可以使用manfile获取更加详细的帮助文档信息。2:查看文件类型例如,如下所示,Temp.txt文件类型为text,编码为UTF-8Unicode[root@DB-Server~]#fileTemp.txt Temp.txt:UTF-8Unicodetext,withverylonglines,withCR
6、LFlineterminators 3:不输出文件名称,只显示文件格式以及编码通过下面两个命令对时,就可以清晰的了解参数-b的作用。[root@DB-Server~]#fileTemp.txtTemp.txt:UTF-8Unicodetext,withverylonglines,withCRLFlineterminators[root@DB-Server~]#file-bTemp.txtUTF-8Unicodetext,withverylonglines,withCRLFlineterminators 4:输出mime类型的字符串[root@DB-Server~]
7、#file-iTemp.txtTemp.txt:text/plain;charset=utf-8 5:查看文件中的文件名的文件类型这个参数非常适合shell脚本去查找、判别某种文件类型的数据。[root@DB-Server~]#cat>test/root/install.logitisonlyonetestfile [2]+Stoppedcat>test[root@DB-Server~]#file-ftest/root/install.log:ASCIItextitisonlyonetestfile:ERROR:cannotopen`itisonlyonetest
8、file'