国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

Linux命令學習總結: file命令

2024-06-28 13:25:36
字體:
來源:轉載
供稿:網友
linux命令學習總結: file命令 2014-06-24 17:59 by 瀟湘隱者, ... 閱讀, ... 評論, 收藏, 編輯

命令簡介:

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

執行權限 :All User

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

命令語法:

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

命令參數:

下表列出了部分常用的參數。

參數

長參數

描敘

-b

列出文件辨識結果時,不顯示文件名稱。

-c

詳細顯示指令執行過程,便于排錯或分析程序執行的情形

-f

列出文件中文件名的文件類型

-F

使用指定分隔符號替換輸出文件名后的默認的“:”分隔符。

-i

輸出mime類型的字符串

-L

查看對應軟鏈接對應文件的文件類型

-z

嘗試去解讀壓縮文件的內容

--help

顯示命令在線幫助

--version

顯示命令版本信息

使用示例:

1:查看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:查看文件類型

例如,如下所示,Temp.txt 文件類型為text,編碼為UTF-8 Unicode

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

3:不輸出文件名稱,只顯示文件格式以及編碼

通過下面兩個命令對時,就可以清晰的了解參數-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.txt
UTF-8 Unicode text, with very long lines, with CRLF line terminators

clip_image001

4: 輸出mime類型的字符串

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

5: 查看文件中的文件名的文件類型

這個參數非常適合shell腳本去查找、判別某種文件類型的數據。

[root@DB-Server ~]# cat >test
/root/install.log 
it is only one test file
[2]+  Stopped                 cat > test
[root@DB-Server ~]# file -f  test
/root/install.log:        ASCII text
it is only one test file: ERROR: cannot open `it is only one test file' (No such file or directory)
[root@DB-Server ~]# 
[root@DB-Server ~]# 

clip_image002

5: 使用指定分隔符號替換輸出文件名后的默認的“:”分隔符。

感覺這個參數很雞肋!我搞明白這個參數的作用時,很是納悶。

clip_image003

6:嘗試去解讀壓縮文件的內容

[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 ~]# 

7: 查看軟鏈接對應文件的文件類型

如下所示,創建一個軟鏈接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 ~]# 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临清市| 仁寿县| 门源| 杭锦后旗| 六枝特区| 区。| 上饶县| 霍林郭勒市| 黄石市| 江山市| 渭源县| 宝应县| 怀安县| 定安县| 丹棱县| 铜陵市| 平潭县| 龙井市| 兴化市| 都江堰市| 五家渠市| 金乡县| 友谊县| 新宁县| 河北省| 肇庆市| 文化| 五常市| 永定县| 高州市| 泾川县| 同德县| 赞皇县| 托克逊县| 北川| 江城| 湟中县| 静安区| 象州县| 综艺| 郓城县|