溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

file命令如何在inux中使用

發(fā)布時間:2021-04-01 16:49:16 來源:億速云 閱讀:177 作者:Leah 欄目:開發(fā)技術(shù)

file命令如何在inux中使用?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。

linux file 命令簡介:

該命令用來識別文件類型,也可用來辨別一些文件的編碼格式。它是通過查看文件的頭部信息來獲取文件類型,而不是像Windows通過擴(kuò)展名來確定文件類型的。

更多介紹可以查看這篇文章:http://www.kemok4.com/LINUXjishu/388984.html

file 官方解釋:Determine type of FILEs. 判定文件的類型。

小知識:在UNIX/Linux系統(tǒng)中,文件類型并不是由擴(kuò)展名決定的(Windows是的)。

開篇例子:

1. $file file.txt

輸出:file.txt: ASCII English text

注:file.txt是我用file –help > file.txt生成的幫助文檔

查看—help

代碼如下:


Usage: file [OPTION...] [FILE...]
 Determine type of FILEs.
--help   display this help and exit
-v, --version   output version information and exit
 -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
 -e, --exclude TEST   exclude TEST from the list of test to be performed for file. Valid tests are: ascii, apptype, compress, elf, soft, tar, tokens, troff
 -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 (--mime-type and
 --mime-encoding)
--apple  output the Apple CREATOR/TYPE
 --mime-type  output the MIME type
--mime-encoding  output the MIME encoding
 -k, --keep-going  don't stop at the first match
 -l, --list  list magic strength
 -L, --dereference  follow symlinks (default)
-h, --no-dereference  don't follow symlinks
 -n, --no-buffer  do not buffer output
 -N, --no-pad  do not pad output
 -0, --print0  terminate filenames with ASCII NUL
-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
 -C, --compile  compile file specified by -m
 -d, --debug  print debugging messages

解讀:

1. -z

查看壓縮文件內(nèi)的信息

2. -b, -e, -i, –r

-b 去掉輸出行的前綴命名
-e 從測試列表到被執(zhí)行文件排除測試。有效的測試包括:ascii, apptype, compress, elf, soft, tar,
-i 打印MIME
-R 不轉(zhuǎn)譯無法打印的字符為\ooo

3. magic file

以mgc為擴(kuò)展名的文件,Microsoft office媒體目錄文件

實(shí)戰(zhàn)實(shí)例:

1. $file -z file.zip
查看file.zip包中的文件信息

2. $file –i file.txt
out:file.txt: text/plain; charset=us-ascii

打印MIME類型
 
$file file.txt
out:file.txt: ASCII English text

3. magic file

我翻譯起來實(shí)在蹩腳。。 只能猜測查看$which file 看看,沒有收獲。最終通過$file得到

Usage: file  [-bchikLlNnprsvz0] [--apple] [--mime-encoding] [--mime-type]
       [-e testname] [-F separator] [-f namefile] [-m magicfiles] file ...
 file  -C [-m magicfiles]
 file  [--help]

然后嘗試file –C 得到magic.mgc文件。。。 不知有何用,慚愧

Usage: file [OPTION...] [FILE...]
Determine type of FILEs.

      --help                 display this help and exit
  -v, --version              output version information and exit
  -m, --magic-file LIST       以冒號分割的魔法數(shù)字清單作為列表
                           
  -z, --uncompress           查看壓縮文件內(nèi)容
  -b, --brief                不前綴文件名到輸出行里
  -c, --checking-printout    打印魔法文件的解析格式,安裝前,用-m debug一個新的魔法文件
                             
  -e, --exclude TEST         排除測試從測試列表到執(zhí)行文件。有效的測試:ascii, apptype, compress, elf, soft, tar, tokens, troff
  -f, --files-from FILE      從已查的文檔中讀取文件名
  -F, --separator STRING     用String作為分隔器 代替 “:”
  -i, --mime                 輸出MIME類型的字符串 (--mime-type and
                               --mime-encoding)
         
      --apple                輸出蘋果類型 CREATOR/TYPE
      --mime-type            打印MIME類型
      --mime-encoding        打印 MIME 編碼
  -k, --keep-going           不停留在第一個匹配
  -l, --list                 列出magic深度
  -L, --dereference          跟隨符號鏈接(缺?。?br/>  -h, --no-dereference       不跟隨符號鏈接
  -n, --no-buffer            不緩沖輸出
  -N, --no-pad               不打印輸出
  -0, --print0               NUL終止文件
  -p, --preserve-date        保持文件上的原訪問時間
  -r, --raw                  不轉(zhuǎn)移不可打印的字符到\ooo
  -s, --special-files        把特殊(塊/字符 設(shè)備)文件作為普通文件對待
  -C, --compile              編譯用-m指定的文件
  -d, --debug                打印調(diào)試信息

看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進(jìn)一步的了解或閱讀更多相關(guān)文章,請關(guān)注億速云行業(yè)資訊頻道,感謝您對億速云的支持。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI