一天一個(gè)shell命令 linux文本系列-file命令用法
linux file 命令簡(jiǎn)介:
該命令用來(lái)識(shí)別文件類(lèi)型,也可用來(lái)辨別一些文件的編碼格式。它是通過(guò)查看文件的頭部信息來(lái)獲取文件類(lèi)型,而不是像Windows通過(guò)擴(kuò)展名來(lái)確定文件類(lèi)型的。
更多介紹可以查看這篇文章:http://chabaoo.cn/LINUXjishu/388984.html
file 官方解釋?zhuān)篋etermine type of FILEs. 判定文件的類(lèi)型。
小知識(shí):在UNIX/Linux系統(tǒng)中,文件類(lèi)型并不是由擴(kuò)展名決定的(Windows是的)。
開(kāi)篇例子:
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 從測(cè)試列表到被執(zhí)行文件排除測(cè)試。有效的測(cè)試包括:ascii, apptype, compress, elf, soft, tar,
-i 打印MIME
-R 不轉(zhuǎn)譯無(wú)法打印的字符為\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類(lèi)型
$file file.txt
out:file.txt: ASCII English text
3. magic file
我翻譯起來(lái)實(shí)在蹩腳。。 只能猜測(cè)查看$which file 看看,沒(méi)有收獲。最終通過(guò)$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 以冒號(hào)分割的魔法數(shù)字清單作為列表
-z, --uncompress 查看壓縮文件內(nèi)容
-b, --brief 不前綴文件名到輸出行里
-c, --checking-printout 打印魔法文件的解析格式,安裝前,用-m debug一個(gè)新的魔法文件
-e, --exclude TEST 排除測(cè)試從測(cè)試列表到執(zhí)行文件。有效的測(cè)試:ascii, apptype, compress, elf, soft, tar, tokens, troff
-f, --files-from FILE 從已查的文檔中讀取文件名
-F, --separator STRING 用String作為分隔器 代替 “:”
-i, --mime 輸出MIME類(lèi)型的字符串 (--mime-type and
--mime-encoding)
--apple 輸出蘋(píng)果類(lèi)型 CREATOR/TYPE
--mime-type 打印MIME類(lèi)型
--mime-encoding 打印 MIME 編碼
-k, --keep-going 不停留在第一個(gè)匹配
-l, --list 列出magic深度
-L, --dereference 跟隨符號(hào)鏈接(缺?。?br />
-h, --no-dereference 不跟隨符號(hào)鏈接
-n, --no-buffer 不緩沖輸出
-N, --no-pad 不打印輸出
-0, --print0 NUL終止文件
-p, --preserve-date 保持文件上的原訪(fǎng)問(wèn)時(shí)間
-r, --raw 不轉(zhuǎn)移不可打印的字符到\ooo
-s, --special-files 把特殊(塊/字符 設(shè)備)文件作為普通文件對(duì)待
-C, --compile 編譯用-m指定的文件
-d, --debug 打印調(diào)試信息
Report bugs to http://bugs.gw.com/
- linux中無(wú)make命令的問(wèn)題(make: *** 沒(méi)有指明目標(biāo)并且找不到 makefile及make命令安裝方法)
- Linux 中makefile的命令包定義及使用
- Linux執(zhí)行可執(zhí)行文件提示No such file or directory的解決方法
- Linux下環(huán)境變量配置方法小結(jié)(.bash_profile和.bashrc的區(qū)別)
- Linux中文件描述符fd與文件指針FILE*互相轉(zhuǎn)換實(shí)例解析
- Linux makefile 和shell文件相互調(diào)用實(shí)例詳解
- Linux file命令的使用
相關(guān)文章
win下調(diào)用putty執(zhí)行命令腳本分享
這篇文章主要介紹了win下調(diào)用putty執(zhí)行命令腳本,可以利用這個(gè)實(shí)現(xiàn)一些自動(dòng)化的工作,需要的朋友可以參考下2014-03-03shell腳本中/bin/bash的作用引號(hào)與括號(hào)的使用小結(jié)
shell腳本通常第一句是#!/bin/bash,在很多情況中,如果沒(méi)有設(shè)置好這一行,那么該程序很可能無(wú)法執(zhí)行,#!/bin/bash是指此腳本使用/bin/bash來(lái)解釋執(zhí)行,本文給大家介紹shell腳本中/bin/bash的作用,引號(hào)與括號(hào)的使用,感興趣的朋友一起看看吧2023-12-12Rsync 秒殺一切備份工具,你能手動(dòng)屏蔽某些目錄嗎?
這篇文章主要介紹了Rsync 秒殺一切備份工具,你能手動(dòng)屏蔽某些目錄嗎?本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12shell腳本自動(dòng)修復(fù)mysql損壞的表
這篇文章主要介紹了shell腳本如何自動(dòng)修復(fù)mysql損壞的表,需要的朋友可以參考下2015-10-10shell腳本操作mysql數(shù)據(jù)庫(kù)刪除重復(fù)的數(shù)據(jù)
今天小編就為大家分享一篇關(guān)于shell腳本操作mysql數(shù)據(jù)庫(kù)刪除重復(fù)的數(shù)據(jù),小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-03-03