<code id='qzspx'><strong id='qzspx'></strong></code>
    <i id='qzspx'><div id='qzspx'><ins id='qzspx'></ins></div></i>
  1. <dl id='qzspx'></dl>

    <i id='qzspx'></i>
    <acronym id='qzspx'><em id='qzspx'></em><td id='qzspx'><div id='qzspx'></div></td></acronym><address id='qzspx'><big id='qzspx'><big id='qzspx'></big><legend id='qzspx'></legend></big></address>

      <ins id='qzspx'></ins>
      1. <tr id='qzspx'><strong id='qzspx'></strong><small id='qzspx'></small><button id='qzspx'></button><li id='qzspx'><noscript id='qzspx'><big id='qzspx'></big><dt id='qzspx'></dt></noscript></li></tr><ol id='qzspx'><table id='qzspx'><blockquote id='qzspx'><tbody id='qzspx'></tbody></blockquote></table></ol><u id='qzspx'></u><kbd id='qzspx'><kbd id='qzspx'></kbd></kbd>

          <span id='qzspx'></span>
          <fieldset id='qzspx'></fieldset>

          Linux系统中file命令的使用详解

          • 时间:
          • 浏览:32
          • 来源:124软件资讯网

              下令简介:

              该下令用来识别文件类型  ,也可用来分辨一些文件的编码花样  。它是通过检察文件的头部信息来获取文件类型 ,而不是像Windows通过扩展名来确定文件类型的  。

              执行权限 :All User

              指令所在路径:/usr/bin/file

              下令语法:

              代码如下:

              file [ -bchikLnNprsvz ] [ -f namefile ] [ -F separator ] [ -m magicfiles ] file ...

              下令参数:

              下表列出了部门常用的参数  。

              使用示例:

              代码如下:

              [root@DB-Server ~]# file --help

              Usage: file [OPTION]... [FILE]...

              Determine file type of FILEs.

              -m, --magic-file LIST use LIST as a colon-separated list of magic number files

              -z, --uncompress 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 in conjunction with -m to debug a new magic file before installing it

              -f, --files-from FILE read the filenames to be examined from FILE

              -F, --separator string use string as separator instead of `:'

              -i, --mime output mime type strings

              -k, --keep-going don't 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't translate unprintable chars to \ooo

              -s, --special-files treat special (block/char devices) files as ordinary ones

              --help display this help and exit

              --version output version information and exit

              固然你也可以使用 man file 获取越发详细的资助文档信息  。

              2:不输出文件名称  ,只显示文件花样以及编码

              通过下面两个下令对时 ,就可以清晰的相识参数-b的作用  。

              代码如下:

              [root@DB-Server ~]# file Temp.txt Temp.txt: UTF-8 Unicode text, with very long lines, with CRLF line terminators[root@DB-Server ~]# file -b Temp.txtUTF-8 Unicode text, with very long lines, with CRLF line terminators

              3: 输出mime类型的字符

              代码如下:

              [root@DB-Server ~]# file -i Temp.txt Temp.txt: text/plain; charset=utf-8

              4: 检察文件中的文件名的文件类型

              这个参数很是适合shell剧本去查找、判别某种文件类型的数据 。

              你可以像下面这样使用 file 下令确定文件的类型 。下面的截图显示了用 file 下令确定差别文件类型的例子  。

              代码如下:

              tecmint@tecmint ~/Linux-Tricks $ dir

              BACKUP master.zip

              crossroads-stable.tar.gz num.txt

              EDWARD-MAYA-2011-2012-NEW-REMIX.mp3 reggea.xspf

              Linux-Security-Optimization-Book.gif tmp-link

              tecmint@tecmint ~/Linux-Tricks $ file BACKUP/

              BACKUP/: directory

              tecmint@tecmint ~/Linux-Tricks $ file master.zip

              master.zip: Zip archive data, at least v1.0 to extract

              tecmint@tecmint ~/Linux-Tricks $ file crossroads-stable.tar.gz

              crossroads-stable.tar.gz: gzip compressed data, from Unix, last modified: Tue Apr 5 15:15:20 2011

              tecmint@tecmint ~/Linux-Tricks $ file Linux-Security-Optimization-Book.gif

              Linux-Security-Optimization-Book.gif: GIF image data, version 89a, 200 x 259

              tecmint@tecmint ~/Linux-Tricks $ file EDWARD-MAYA-2011-2012-NEW-REMIX.mp3

              EDWARD-MAYA-2011-2012-NEW-REMIX.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 192 kbps, 44.1 kHz, JntStereo

              tecmint@tecmint ~/Linux-Tricks $ file /dev/sda1

              /dev/sda1: block special

              tecmint@tecmint ~/Linux-Tricks $ file /dev/tty1

              /dev/tty1: character special

              5:实验去解读压缩文件的内容

              代码如下:

              [root@DB-Server ~]# file -z Temp.txt.gz Temp.txt.gz: UTF-8 Unicode text, with very long lines, with CRLF line terminators (gzip compressed data, was "Temp.txt", from Unix, last modified: Tue Jun 24 00:34:15 2014)[root@DB-Server ~]#

              6: 检察软链接对应文件的文件类型

              如下所示  ,建立一个软链接sfile ,然后划分用file 和带参数的file -L检察

              代码如下:

              [root@DB-Server ~]# ln -s Temp.txt.gz sfile[root@DB-Server ~]# file sfile sfile: symbolic link to `Temp.txt.gz'[root@DB-Server ~]# file -L sfile sfile: gzip compressed data, was "Temp.txt", from Unix, last modified: Tue Jun 24 00:34:15 2014[root@DB-Server ~]#