Linux命令学习总结: file命令
2016-05-17 18:43
246 查看
http://www.cnblogs.com/kerrycode/p/3806618.html
Linux命令学习总结:file命令
命令简介:该命令用来识别文件类型,也可用来辨别一些文件的编码格式。它是通过查看文件的头部信息来获取文件类型,而不是像Windows通过扩展名来确定文件类型的。
执行权限:AllUser
指令所在路径:/usr/bin/file
命令语法:
file[-bchikLnNprsvz][-fnamefile][-Fseparator][-mmagicfiles]file...
命令参数:
下表列出了部分常用的参数。
参数 | 长参数 | 描叙 |
-b | 列出文件辨识结果时,不显示文件名称。 | |
-c | 详细显示指令执行过程,便于排错或分析程序执行的情形 | |
-f | 列出文件中文件名的文件类型 | |
-F | 使用指定分隔符号替换输出文件名后的默认的“:”分隔符。 | |
-i | 输出mime类型的字符串 | |
-L | 查看对应软链接对应文件的文件类型 | |
-z | 尝试去解读压缩文件的内容 | |
--help | 显示命令在线帮助 | |
--version | 显示命令版本信息 |
1:查看file命令的帮助信息
[root@DB-Server~]#file--help
Usage:file[OPTION]...[FILE]...
DeterminefiletypeofFILEs.
-m,--magic-fileLISTuseLISTasacolon-separatedlistofmagic
numberfiles
-z,--uncompresstrytolookinsidecompressedfiles
-b,--briefdonotprependfilenamestooutputlines
-c,--checking-printoutprinttheparsedformofthemagicfile,usein
conjunctionwith-mtodebuganewmagicfile
beforeinstallingit
-f,--files-fromFILEreadthefilenamestobeexaminedfromFILE
-F,--separatorstringusestringasseparatorinsteadof`:'
-i,--mimeoutputmimetypestrings
-k,--keep-goingdon'tstopatthefirstmatch
-L,--dereferencecausessymlinkstobefollowed
-n,--no-bufferdonotbufferoutput
-N,--no-paddonotpadoutput
-p,--preserve-datepreserveaccesstimesonfiles
-r,--rawdon'ttranslateunprintablecharsto\ooo
-s,--special-filestreatspecial(block/chardevices)filesas
ordinaryones
--helpdisplaythishelpandexit
--versionoutputversioninformationandexit
当然你也可以使用manfile获取更加详细的帮助文档信息。
2:查看文件类型
例如,如下所示,Temp.txt文件类型为text,编码为UTF-8Unicode
[root@DB-Server~]#fileTemp.txt
Temp.txt:UTF-8Unicodetext,withverylonglines,withCRLFlineterminators
3:不输出文件名称,只显示文件格式以及编码
通过下面两个命令对时,就可以清晰的了解参数-b的作用。
[root@DB-Server~]#fileTemp.txt
Temp.txt:UTF-8Unicodetext,withverylonglines,withCRLFlineterminators
[root@DB-Server~]#file-bTemp.txt
UTF-8Unicodetext,withverylonglines,withCRLFlineterminators
4:输出mime类型的字符串
[root@DB-Server~]#file-iTemp.txt
Temp.txt:text/plain;charset=utf-8
5:查看文件中的文件名的文件类型
这个参数非常适合shell脚本去查找、判别某种文件类型的数据。
[root@DB-Server~]#cat>test
/root/install.log
itisonlyonetestfile
[2]+Stoppedcat>test
[root@DB-Server~]#file-ftest
/root/install.log:ASCIItext
itisonlyonetestfile:ERROR:cannotopen`itisonlyonetestfile'(Nosuchfileordirectory)
[root@DB-Server~]#
[root@DB-Server~]#
5:使用指定分隔符号替换输出文件名后的默认的“:”分隔符。
感觉这个参数很鸡肋!我搞明白这个参数的作用时,很是纳闷。
6:尝试去解读压缩文件的内容
[root@DB-Server~]#file-zTemp.txt.gz
Temp.txt.gz:UTF-8Unicodetext,withverylonglines,withCRLFlineterminators(gzipcompresseddata,was"Temp.txt",fromUnix,lastmodified:TueJun2400:34:152014)
[root@DB-Server~]#
7:查看软链接对应文件的文件类型
如下所示,创建一个软链接sfile,然后分别用file和带参数的file-L查看
[root@DB-Server~]#ln-sTemp.txt.gzsfile
[root@DB-Server~]#filesfile
sfile:symboliclinkto`Temp.txt.gz'
[root@DB-Server~]#file-Lsfile
sfile:gzipcompresseddata,was"Temp.txt",fromUnix,lastmodified:TueJun2400:34:152014
[root@DB-Server~]#
作者:
出处:
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.
相关文章推荐
- linux初始化init系统:systemd
- 我使用过的Linux命令之file - 检测并显示文件类型
- Linux下进程使用nohup或daemon进入后台CPU利用率100%
- 0048 linux(ubuntu)中Spark的本地模式安装
- linux 常用命令演示
- pthread_create(linux下C语言多线程)
- Linux cat命令
- centos6.7环境半虚拟化软件xen及xm配置工具使用详解
- centos6.7环境半虚拟化软件xen及xm配置工具使用详解
- linux进程后端运行,脱离终端
- Linux那些事儿之我是Sysfs(final)后记
- Linux那些事儿之我是Sysfs(13)举例四:sysfs读入普通文件内容
- Linux那些事儿之我是Sysfs(12)举例三:sysfs读入文件夹内容
- Linux那些事儿之我是Sysfs(11)sysfs 创建普通文件
- Linux中iptables设置详细
- Linux那些事儿之我是Sysfs(10)sysfs 创建目录
- linux学习之路——linux虚拟机的克隆
- Linux那些事儿之我是Sysfs(9)sysfs文件系统模型
- Linux那些事儿之我是Sysfs(8)一起散散步-pathwalk
- Linux常用命令汇总--ln