file

确定文件类型.

语法

  file [-bchikLNnprsvz0] [--apple] [--mime-encoding] [--mime-type] [-e testname]
     [-F separator] [-f namefile] [-m magicfiles] file ... 

  file -C [-m magicfiles]

  file [--help]

选项

   -b, --brief     不将文件名前置到输出行(简短模式).
   -C, --compile   编写一个magic.mgc输出文件
   -c, --checking-printout
                   详细显示指令执行过程,便于排错或分析程序执行的情形
   -e, --exclude testname
                   从对其进行的测试列表中
                   排除testname中指定的测试
                   确定文件类型。
   -F, --separator 分隔符
                   使用指定的字符串作为文件名和之间的分隔符
                   返回文件结果。默认为':'。
   -f, --files-from namefile
                   查看这两个文件的名称从namefile(每行一个)进行检查
   -h, --no-dereference
                   选项导致不遵循符号链接(在支持符号链接的系统上)。
                   如果未定义环境变量POSIXLY_CORRECT,则这是缺省值。
   -i, --mime      使文件命令输出mime 类型字符串。
   --mime-type, --mime-encoding
                   与-i类似,但仅打印指定的元素
   -k, --keep-going
                   第一次匹配之后不停止. 随后的匹配将会
                   有字符串 '\012- ' 前置. 
   -L, --dereference
                   选项会导致遵循符号链接,因为名称相同的选项
                   in ls(1)(在支持符号链接的系统上)。
                   如果定义了环境变量POSIXLY_CORRECT,则这是默认值。
   -m, --magic-file magicfiles
                   指定包含魔术的文件和目录的备用列表
   -N, --no-pad    D不填充文件名,以便它们在输出中对齐。
   -n, --no-buffer 在检查每个文件后强制刷新stdout。这只是
                   在检查文件列表时很有用。它旨在被使用
                   想要从管道输出文件类型的程序。
   -p, --preserve-date
                   在支持utime(2)或utimes(2)的系统上,尝试保留
                   分析文件的访问时间,假装文件永远不会读取它们
   -r, --raw       不将不可打印的字符转换为\ooo。通常是文件
                   将不可打印的字符转换为八进制表示。
   -s, --special-files
                   文件还读取作为块或字符特殊文件的参数文件。这对于确定
                   原始磁盘分区(块特殊文件)中的数据的文件系统类型很有用
   -v, --version   打印程序的版本并退出
   -z, --uncompress
                   尝试查看压缩文件
   -0, --print0    在文件名结尾后输出一个空字符'\ 0'
   --help          打印帮助信息并退出

如果文件操作数指定的文件不存在,无法读取,或者无法确定文件操作数指定的文件类型,则不会将其视为影响退出状态的错误。

实例

$ file file.c file /dev/{wd0a,hda}
file.c:   C program text
file:     ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),

    dynamically linked (uses shared libs), stripped 

/dev/wd0a: block special (0/0)
/dev/hda: block special (3/0)

$ file -s /dev/wd0{b,d}
/dev/wd0b: data
/dev/wd0d: x86 boot sector

$ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10}
/dev/hda: x86 boot sector
/dev/hda1: Linux/i386 ext2 filesystem
/dev/hda2: x86 boot sector
/dev/hda3: x86 boot sector, extended partition table
/dev/hda4: Linux/i386 ext2 filesystem
/dev/hda5: Linux/i386 swap file
/dev/hda6: Linux/i386 swap file
/dev/hda7: Linux/i386 swap file
/dev/hda8: Linux/i386 swap file
/dev/hda9: empty
/dev/hda10: empty

$ file -i file.c file /dev/{wd0a,hda}
file.c: text/x-c
file: application/x-executable
/dev/hda: application/x-not-regular-file
/dev/wd0a: application/x-not-regular-file 

file使用了几种有利于速度而不是准确性的算法,因此可能会误导文本文件的内容。

file 命令实例:

linux命令:file /proc/*/fd/* 2>/dev/null | grep Flash | cut -f1 -d: -d: -f1 cut | Flash grep | 2>/dev/null /proc/*/fd/* file file /proc/*/fd/* 2>/dev/null | grep Flash | cut -f1 -d:rootopen.com
linux命令:file /proc/*/fd/* 2>/dev/null | grep Flash | cut -f1 -d: -d: -f1 cut | Flash grep | 2>/dev/null /proc/*/fd/* file file /proc/*/fd/* 2>/dev/null | grep Flash | cut -f1 -d:rootopen.com
2018-12-02 21:44:04

linux命令:file !$ !$ file file !$rootopen.com
linux命令:file !$ !$ file file !$rootopen.com
2018-05-20 06:07:48

linux命令:file =top =top file file =toprootopen.com
linux命令:file =top =top file file =toprootopen.com
2018-05-06 19:42:48

linux命令:file -i * | grep 'text/plain' | wc -l -l wc | 'text/plain' grep | * -i file file -i * | grep 'text/plain' | wc -lrootopen.com
linux命令:file -i * | grep 'text/plain' | wc -l -l wc | 'text/plain' grep | * -i file file -i * | grep 'text/plain' | wc -lrootopen.com
2018-01-20 15:30:48

linux命令:file -i * | grep -c 'text/plain' 'text/plain' -c grep | * -i file file -i * | grep -c 'text/plain'rootopen.com
linux命令:file -i * | grep -c 'text/plain' 'text/plain' -c grep | * -i file file -i * | grep -c 'text/plain'rootopen.com
2018-05-31 14:02:48

linux命令:file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i x86_64 |nl |tail -1 |cut -f1 -f3 && file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -v x86_64 |nl |tail -1 |cut -f1 -f3 -f3 -f1 |cut -1 |tail |nl x86_64 -v |grep /System/Library/Extensions/*.kext/Contents/MacOS/* file && -f3 -f1 |cut -1 |tail |nl x86_64 -i |grep /System/Library/Extensions/*.kext/Contents/MacOS/* file file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i x86_64 |nl |tail -1 |cut -f1 -f3 && file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -v x86_64 |nl |tail -1 |cut -f1 -f3rootopen.com
linux命令:file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i x86_64 |nl |tail -1 |cut -f1 -f3 && file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -v x86_64 |nl |tail -1 |cut -f1 -f3 -f3 -f1 |cut -1 |tail |nl x86_64 -v |grep /System/Library/Extensions/*.kext/Contents/MacOS/* file && -f3 -f1 |cut -1 |tail |nl x86_64 -i |grep /System/Library/Extensions/*.kext/Contents/MacOS/* file file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i x86_64 |nl |tail -1 |cut -f1 -f3 && file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -v x86_64 |nl |tail -1 |cut -f1 -f3rootopen.com
2018-05-25 21:38:48

linux命令:file -i <textfile> <textfile> -i file file -i <textfile>rootopen.com
linux命令:file -i <textfile> <textfile> -i file file -i <textfile>rootopen.com
2018-01-02 03:57:48

linux命令:file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i x86_64 |nl | tail -1 | cut -f1 -f3; file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i "mach-o object i386" |nl | tail -1 | cut -f1 -f3 -f3 -f1 cut | -1 tail | |nl i386" object "mach-o -i |grep /System/Library/Extensions/*.kext/Contents/MacOS/* file -f3; -f1 cut | -1 tail | |nl x86_64 -i |grep /System/Library/Extensions/*.kext/Contents/MacOS/* file file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i x86_64 |nl | tail -1 | cut -f1 -f3; file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i "mach-o object i386" |nl | tail -1 | cut -f1 -f3rootopen.com
linux命令:file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i x86_64 |nl | tail -1 | cut -f1 -f3; file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i "mach-o object i386" |nl | tail -1 | cut -f1 -f3 -f3 -f1 cut | -1 tail | |nl i386" object "mach-o -i |grep /System/Library/Extensions/*.kext/Contents/MacOS/* file -f3; -f1 cut | -1 tail | |nl x86_64 -i |grep /System/Library/Extensions/*.kext/Contents/MacOS/* file file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i x86_64 |nl | tail -1 | cut -f1 -f3; file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i "mach-o object i386" |nl | tail -1 | cut -f1 -f3rootopen.com
2018-01-17 19:28:48

linux命令:file='path to file'; tar -cf - "$file" | pv -s $(du -sb "$file" | awk '{print $1}') | gzip -c | ssh -c blowfish user@host tar -zxf - -C /opt/games /opt/games -C - -zxf tar user@host blowfish -c ssh | -c gzip | $1}') '{print awk | "$file" -sb $(du -s pv | "$file" - -cf tar file'; to file='path file='path to file'; tar -cf - "$file" | pv -s $(du -sb "$file" | awk '{print $1}') | gzip -c | ssh -c blowfish user@host tar -zxf - -C /opt/gamesrootopen.com
linux命令:file='path to file'; tar -cf - "$file" | pv -s $(du -sb "$file" | awk '{print $1}') | gzip -c | ssh -c blowfish user@host tar -zxf - -C /opt/games /opt/games -C - -zxf tar user@host blowfish -c ssh | -c gzip | $1}') '{print awk | "$file" -sb $(du -s pv | "$file" - -cf tar file'; to file='path file='path to file'; tar -cf - "$file" | pv -s $(du -sb "$file" | awk '{print $1}') | gzip -c | ssh -c blowfish user@host tar -zxf - -C /opt/gamesrootopen.com
2018-02-15 12:13:48

linux命令:file /usr/bin/* | grep ELF | cut -d":" -f1 -f1 -d":" cut | ELF grep | /usr/bin/* file file /usr/bin/* | grep ELF | cut -d":" -f1rootopen.com
linux命令:file /usr/bin/* | grep ELF | cut -d":" -f1 -f1 -d":" cut | ELF grep | /usr/bin/* file file /usr/bin/* | grep ELF | cut -d":" -f1rootopen.com
2018-03-26 12:18:48

linux命令:file -L <library> | grep -q '64-bit' && echo 'library is 64 bit' || echo 'library is 32 bit' bit' 32 is 'library echo || bit' 64 is 'library echo && '64-bit' -q grep | <library> -L file file -L <library> | grep -q '64-bit' && echo 'library is 64 bit' || echo 'library is 32 bit'rootopen.com
linux命令:file -L <library> | grep -q '64-bit' && echo 'library is 64 bit' || echo 'library is 32 bit' bit' 32 is 'library echo || bit' 64 is 'library echo && '64-bit' -q grep | <library> -L file file -L <library> | grep -q '64-bit' && echo 'library is 64 bit' || echo 'library is 32 bit'rootopen.com
2018-03-15 02:54:48

linux命令:files=(/usr/share/cowsay/cows/*);cowsay -f `printf "%s\n" "${files[RANDOM % ${#files}]}"` "`fortune`" "`fortune`" ${#files}]}"` % "${files[RANDOM "%s\n" `printf -f files=(/usr/share/cowsay/cows/*);cowsay files=(/usr/share/cowsay/cows/*);cowsay -f `printf "%s\n" "${files[RANDOM % ${#files}]}"` "`fortune`"rootopen.com
linux命令:files=(/usr/share/cowsay/cows/*);cowsay -f `printf "%s\n" "${files[RANDOM % ${#files}]}"` "`fortune`" "`fortune`" ${#files}]}"` % "${files[RANDOM "%s\n" `printf -f files=(/usr/share/cowsay/cows/*);cowsay files=(/usr/share/cowsay/cows/*);cowsay -f `printf "%s\n" "${files[RANDOM % ${#files}]}"` "`fortune`"rootopen.com
2017-12-28 21:33:48

linux命令:file=ftp://ftp.gimp.org/pub/gimp/v2.6/gimp-2.6.10.tar.bz2; ssh server "wget $file -O -" > $PWD/${file##*/} $PWD/${file##*/} > -" -O $file "wget server ssh file=ftp://ftp.gimp.org/pub/gimp/v2.6/gimp-2.6.10.tar.bz2; file=ftp://ftp.gimp.org/pub/gimp/v2.6/gimp-2.6.10.tar.bz2; ssh server "wget $file -O -" > $PWD/${file##*/}rootopen.com
linux命令:file=ftp://ftp.gimp.org/pub/gimp/v2.6/gimp-2.6.10.tar.bz2; ssh server "wget $file -O -" > $PWD/${file##*/} $PWD/${file##*/} > -" -O $file "wget server ssh file=ftp://ftp.gimp.org/pub/gimp/v2.6/gimp-2.6.10.tar.bz2; file=ftp://ftp.gimp.org/pub/gimp/v2.6/gimp-2.6.10.tar.bz2; ssh server "wget $file -O -" > $PWD/${file##*/}rootopen.com
2018-03-19 03:32:48

linux命令:file /music/dir/* | grep -v 44.1 | sed 's/:.*//g' | grep .mp3 | { while IFS= read; do filebak="\"$REPLY.original\""; file="\"$REPLY\""; mv $file $filebak; sox -t mp3 $filebak $file rate 44k; done; }; }; done; 44k; rate $file $filebak mp3 -t sox $filebak; $file mv file="\"$REPLY\""; filebak="\"$REPLY.original\""; do read; IFS= while { | .mp3 grep | 's/:.*//g' sed | 44.1 -v grep | /music/dir/* file file /music/dir/* | grep -v 44.1 | sed 's/:.*//g' | grep .mp3 | { while IFS= read; do filebak="\"$REPLY.original\""; file="\"$REPLY\""; mv $file $filebak; sox -t mp3 $filebak $file rate 44k; done; };rootopen.com
linux命令:file /music/dir/* | grep -v 44.1 | sed 's/:.*//g' | grep .mp3 | { while IFS= read; do filebak="\"$REPLY.original\""; file="\"$REPLY\""; mv $file $filebak; sox -t mp3 $filebak $file rate 44k; done; }; }; done; 44k; rate $file $filebak mp3 -t sox $filebak; $file mv file="\"$REPLY\""; filebak="\"$REPLY.original\""; do read; IFS= while { | .mp3 grep | 's/:.*//g' sed | 44.1 -v grep | /music/dir/* file file /music/dir/* | grep -v 44.1 | sed 's/:.*//g' | grep .mp3 | { while IFS= read; do filebak="\"$REPLY.original\""; file="\"$REPLY\""; mv $file $filebak; sox -t mp3 $filebak $file rate 44k; done; };rootopen.com
2018-02-08 10:26:48

linux命令:file=orig.ps; for i in $(seq `grep "Pages:" $file | sed 's/%%Pages: //g'`); do psselect $i $file $i\_$file; done done $i\_$file; $file $i psselect do //g'`); 's/%%Pages: sed | $file "Pages:" `grep $(seq in i for file=orig.ps; file=orig.ps; for i in $(seq `grep "Pages:" $file | sed 's/%%Pages: //g'`); do psselect $i $file $i\_$file; donerootopen.com
linux命令:file=orig.ps; for i in $(seq `grep "Pages:" $file | sed 's/%%Pages: //g'`); do psselect $i $file $i\_$file; done done $i\_$file; $file $i psselect do //g'`); 's/%%Pages: sed | $file "Pages:" `grep $(seq in i for file=orig.ps; file=orig.ps; for i in $(seq `grep "Pages:" $file | sed 's/%%Pages: //g'`); do psselect $i $file $i\_$file; donerootopen.com
2018-02-15 00:08:48

linux命令:file /bin/* | msort -j -l -n-1 -n2 2> /dev/null /dev/null 2> -n2 -n-1 -l -j msort | /bin/* file file /bin/* | msort -j -l -n-1 -n2 2> /dev/nullrootopen.com
linux命令:file /bin/* | msort -j -l -n-1 -n2 2> /dev/null /dev/null 2> -n2 -n-1 -l -j msort | /bin/* file file /bin/* | msort -j -l -n-1 -n2 2> /dev/nullrootopen.com
2018-03-08 10:04:48

linux命令:file -s /dev/sd* /dev/sd* -s file file -s /dev/sd*rootopen.com
linux命令:file -s /dev/sd* /dev/sd* -s file file -s /dev/sd*rootopen.com
2018-01-06 17:59:48

linux命令:files -type f | xargs -n100 | while read l; do mkdir $((++f)); cp $l $f; done done $f; $l cp $((++f)); mkdir do l; read while | -n100 xargs | f -type files files -type f | xargs -n100 | while read l; do mkdir $((++f)); cp $l $f; donerootopen.com
linux命令:files -type f | xargs -n100 | while read l; do mkdir $((++f)); cp $l $f; done done $f; $l cp $((++f)); mkdir do l; read while | -n100 xargs | f -type files files -type f | xargs -n100 | while read l; do mkdir $((++f)); cp $l $f; donerootopen.com
2018-02-17 21:35:48

linux命令:files=$(find /dir/file -name *.txt -exec grep -l a {} \;) && perl -p -i -e 's/old/new/g;' $files $files 's/old/new/g;' -e -i -p perl && \;) {} a -l grep -exec *.txt -name /dir/file files=$(find files=$(find /dir/file -name *.txt -exec grep -l a {} \;) && perl -p -i -e 's/old/new/g;' $filesrootopen.com
linux命令:files=$(find /dir/file -name *.txt -exec grep -l a {} \;) && perl -p -i -e 's/old/new/g;' $files $files 's/old/new/g;' -e -i -p perl && \;) {} a -l grep -exec *.txt -name /dir/file files=$(find files=$(find /dir/file -name *.txt -exec grep -l a {} \;) && perl -p -i -e 's/old/new/g;' $filesrootopen.com
2018-02-12 00:19:48

linux命令:fileName() { echo "$1" | grep -o "[^/]*$"; } } "[^/]*$"; -o grep | "$1" echo { fileName() fileName() { echo "$1" | grep -o "[^/]*$"; }rootopen.com
linux命令:fileName() { echo "$1" | grep -o "[^/]*$"; } } "[^/]*$"; -o grep | "$1" echo { fileName() fileName() { echo "$1" | grep -o "[^/]*$"; }rootopen.com
2018-02-14 00:41:48

linux命令:fileName(){ echo ${1##*/}; } } ${1##*/}; echo fileName(){ fileName(){ echo ${1##*/}; }rootopen.com
linux命令:fileName(){ echo ${1##*/}; } } ${1##*/}; echo fileName(){ fileName(){ echo ${1##*/}; }rootopen.com
2018-04-30 05:53:48

linux命令:filext () { echo ${1##*.}; } } ${1##*.}; echo { () filext filext () { echo ${1##*.}; }rootopen.com
linux命令:filext () { echo ${1##*.}; } } ${1##*.}; echo { () filext filext () { echo ${1##*.}; }rootopen.com
2018-03-25 04:36:48

linux命令:file <filename> <filename> file file <filename>rootopen.com
linux命令:file <filename> <filename> file file <filename>rootopen.com
2018-06-04 21:14:48

linux命令:file=<filename>;vim ${file} -e -s -c 'runtime! syntax/syntax.vim' -c 'runtime! syntax/2html.vim' -c "w ${file}.html" -c 'q!' -c 'q!' > /dev/null /dev/null > 'q!' -c 'q!' -c ${file}.html" "w -c syntax/2html.vim' 'runtime! -c syntax/syntax.vim' 'runtime! -c -s -e ${file} file=<filename>;vim file=<filename>;vim ${file} -e -s -c 'runtime! syntax/syntax.vim' -c 'runtime! syntax/2html.vim' -c "w ${file}.html" -c 'q!' -c 'q!' > /dev/nullrootopen.com
linux命令:file=<filename>;vim ${file} -e -s -c 'runtime! syntax/syntax.vim' -c 'runtime! syntax/2html.vim' -c "w ${file}.html" -c 'q!' -c 'q!' > /dev/null /dev/null > 'q!' -c 'q!' -c ${file}.html" "w -c syntax/2html.vim' 'runtime! -c syntax/syntax.vim' 'runtime! -c -s -e ${file} file=<filename>;vim file=<filename>;vim ${file} -e -s -c 'runtime! syntax/syntax.vim' -c 'runtime! syntax/2html.vim' -c "w ${file}.html" -c 'q!' -c 'q!' > /dev/nullrootopen.com
2018-01-09 16:55:48

linux命令:file -sL /dev/sda7 /dev/sda7 -sL file file -sL /dev/sda7rootopen.com
linux命令:file -sL /dev/sda7 /dev/sda7 -sL file file -sL /dev/sda7rootopen.com
2018-01-09 19:44:48

linux命令:file -i `find . -name '*.jpg' -print` | grep "application/msword" "application/msword" grep | -print` '*.jpg' -name . `find -i file file -i `find . -name '*.jpg' -print` | grep "application/msword"rootopen.com
linux命令:file -i `find . -name '*.jpg' -print` | grep "application/msword" "application/msword" grep | -print` '*.jpg' -name . `find -i file file -i `find . -name '*.jpg' -print` | grep "application/msword"rootopen.com
2018-03-23 07:07:48

linux命令:fileinfo() { RPMQF=$(rpm -qf $1); RPMQL=$(rpm -ql $RPMQF);echo "man page:";whatis $(basename $1); echo "Services:"; echo -e "$RPMQL\n"|grep -P "\.service";echo "Config files:";rpm -qc $RPMQF;echo "Provided by:" $RPMQF; } } $RPMQF; by:" "Provided $RPMQF;echo -qc files:";rpm "Config "\.service";echo -P "$RPMQL\n"|grep -e echo "Services:"; echo $1); $(basename page:";whatis "man $RPMQF);echo -ql RPMQL=$(rpm $1); -qf RPMQF=$(rpm { fileinfo() fileinfo() { RPMQF=$(rpm -qf $1); RPMQL=$(rpm -ql $RPMQF);echo "man page:";whatis $(basename $1); echo "Services:"; echo -e "$RPMQL\n"|grep -P "\.service";echo "Config files:";rpm -qc $RPMQF;echo "Provided by:" $RPMQF; }rootopen.com
linux命令:fileinfo() { RPMQF=$(rpm -qf $1); RPMQL=$(rpm -ql $RPMQF);echo "man page:";whatis $(basename $1); echo "Services:"; echo -e "$RPMQL\n"|grep -P "\.service";echo "Config files:";rpm -qc $RPMQF;echo "Provided by:" $RPMQF; } } $RPMQF; by:" "Provided $RPMQF;echo -qc files:";rpm "Config "\.service";echo -P "$RPMQL\n"|grep -e echo "Services:"; echo $1); $(basename page:";whatis "man $RPMQF);echo -ql RPMQL=$(rpm $1); -qf RPMQF=$(rpm { fileinfo() fileinfo() { RPMQF=$(rpm -qf $1); RPMQL=$(rpm -ql $RPMQF);echo "man page:";whatis $(basename $1); echo "Services:"; echo -e "$RPMQL\n"|grep -P "\.service";echo "Config files:";rpm -qc $RPMQF;echo "Provided by:" $RPMQF; }rootopen.com
2018-03-09 06:19:48

Linux的Bash命令行(A-Z排序)