您的位置:首页 >Linux系统之file命令的基本使用
发布于2026-08-13 阅读(0)
扫一扫,手机访问
[root@jeven ~]# file --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
Report bugs to http://bugs.gw.com/file(选项)(参数)-b:仅显示文件类型,不显示文件名;
-i:显示MIME类型;
-z:对压缩文件也进行检测。
-c:详细显示指令执行过程,便于排错或分析程序执行的情形;
-f<名称文件>:指定名称文件,其内容有一个或多个文件名称时,让file依序辨识这些文件,格式为每列一个文件名称;
-L:直接显示符号链接所指向的文件类别;
-m<魔法数字文件>:指定魔法数字文件;
-v:显示版本信息;
-s: 查询(块/字符设备)文件信息文件:要确定类型的文件列表,多个文件之间使用空格分开,可以使用shell通配符匹配多个文件。man file
在 Linux 里,常见的文件类型主要有这些:
[root@jeven ~]# file -v
file-5.11
magic file from /etc/magic:/usr/share/misc/magic[root@jeven ~]# file test.txt
test.txt: ASCII text[root@jeven ~]# file -b test.txt
ASCII text[root@jeven ~]# file -i test.txt
test.txt: text/plain; charset=us-ascii[root@server-01 ~]# ls -l /var/mail
lrwxrwxrwx. 1 root root 10 Jul 11 2019 /var/mail -> spool/mail查询/var/mail文件类型[root@server-01 ~]# file /var/mail
/var/mail: symbolic link to `spool/mail'显示符号链接所指向的文件类型[root@server-01 ~]# file -L /var/mail
/var/mail: directory[root@jeven tmp]# file *
clr-debug-pipe-8952-724-in: fifo (named pipe)
clr-debug-pipe-8952-724-out: fifo (named pipe)
clr-debug-pipe-8970-1925-in: fifo (named pipe)
clr-debug-pipe-8970-1925-out: fifo (named pipe)
dotnet-diagnostic-8952-724-socket: socket
dotnet-diagnostic-8970-1925-socket: socket
passwd: ASCII text
start-015d97ac.sh: ASCII text, with no line terminators
start-109f1a86.sh: ASCII text, with no line terminators
start-26c0fb80.sh: ASCII text, with no line terminators
start-4203b95e.sh: ASCII text, with no line terminators
start-92889412.sh: ASCII text, with no line terminators
start-ddceaaa1.sh: ASCII text, with no line terminators
systemd-private-08fc6e47aa874539ac4d70bc789f5282-bolt.service-mnASgU: directory
systemd-private-08fc6e47aa874539ac4d70bc789f5282-colord.service-HplXU8: directory
systemd-private-08fc6e47aa874539ac4d70bc789f5282-cups.service-xyIPUs: directory
systemd-private-08fc6e47aa874539ac4d70bc789f5282-rtkit-daemon.service-bw5Sug: directory
systemd-private-b900215aacec4b86a1e8d464980a5c54-bolt.service-VNJiad: directory
systemd-private-b900215aacec4b86a1e8d464980a5c54-colord.service-ZUXvYP: directory
systemd-private-b900215aacec4b86a1e8d464980a5c54-cups.service-RlD3bV: directory
systemd-private-b900215aacec4b86a1e8d464980a5c54-rtkit-daemon.service-zH4Tz7: directory
vmware-root_8951-3886978998: directory
vmware-root_8974-2832928238: directory
vmware-root_8984-2865826809: directory
vmware-root_8989-3852833186: directory
vmware-root_8994-2857503325: directory[root@jeven boot]# find /etc/httpd -type f -name "*.conf" -exec file {} ;
/etc/httpd/conf/httpd.conf: ASCII text
/etc/httpd/conf.d/autoindex.conf: ASCII text
/etc/httpd/conf.d/userdir.conf: ASCII text
/etc/httpd/conf.d/welcome.conf: ASCII text
/etc/httpd/conf.modules.d/00-base.conf: ASCII text
/etc/httpd/conf.modules.d/00-da v.conf: ASCII text
/etc/httpd/conf.modules.d/00-lua.conf: ASCII text
/etc/httpd/conf.modules.d/00-mpm.conf: ASCII text
/etc/httpd/conf.modules.d/00-proxy.conf: ASCII text
/etc/httpd/conf.modules.d/00-systemd.conf: ASCII text
/etc/httpd/conf.modules.d/01-cgi.conf: ASCII text[root@server-01 ~]# file -s /dev/vda*
/dev/vda: x86 boot sector; partition 1: ID=0x83, active, starthead 32, startsector 2048, 104854207 sectors, code offset 0x63
/dev/vda1: Linux rev 1.0 ext4 filesystem data, UUID=1114fe9e-2309-4580-b183-d778e6d97397 (needs journal recovery) (extents) (large files) (huge files)
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
正版软件
正版软件
正版软件
正版软件
正版软件
1
2
3
4
5
6
7
8
9