昨日推薦:天天學一個 Linux 命令(22):pwdcentos
file 命令用於查看指定文件的類型。centos7
在Linux系統中,一切皆文件。這裏就不得不提一下Linux系統中的文件類型:spa
普通文件 #屬性信息表示爲 - 目錄文件 #屬性信息表示爲 d 連接文件 #屬性信息表示爲 l 套接字文件 #屬性信息表示爲 s 字符設備文件 #屬性信息表示爲 b 塊設備文件 #屬性信息表示爲 c 管道文件 #屬性信息表示爲 p
文件的屬性信息在以前的文章: 天天學一個 Linux 命令(17):chmod 中有介紹,文件類型信息通常都是位於文件權限信息之首的位置。3d
[root@centos7 testdir]# ll total 0 lrwxrwxrwx 1 root root 11 Jan 15 22:50 cp -> /usr/bin/cp drwxr-xr-x 2 root root 62 Jan 2 09:15 dir -rw-r--r-- 1 root root 0 Jan 2 09:03 test2.txt -rw-r--r-- 1 root root 0 Jan 2 08:57 test2.txt~
file [選項] [文件名或目錄名]
-b:#列出結果,但不顯示文件名稱 -c:#詳細顯示指令執行過程 -L:#顯示連接文件的源文件類型 -m<魔法數字文件>:#指定魔法數字文件 -v:#打印出版本信息 -z:#查看壓縮文件的內容
#查看文件類型 [root@centos7 testdir]# file cp cp: symbolic link to `/usr/bin/cp` [root@centos7 testdir]# file dir dir: directory [root@centos7 testdir]# file test2.txt test2.txt: empty [root@centos7 testdir]# file test2.txt~ test2.txt~: empty #直接顯示結果,不顯示文件名 [root@centos7 testdir]# file -b dir directory #解讀壓縮文件的內容 [root@centos7 ~]# file -z httpd-2.4.46.tar.gz httpd-2.4.46.tar.gz: POSIX tar archive (GNU) (gzip compressed data, was "httpd-2.4.46.tar", from Unix, last modified: Sat Aug 1 10:12:01 2020, max compression)