比如说一个目录下使用find检索文件,不检索二进制文件,或者只检索某一类型的文件,该使用什么命令?
find -type 可以指定文件的类型;比如查找当前文件夹下的所有以a打头的目录(目录也是文件)
find -type d -name "a*"
find支持的文件检索类型可以区分普通文件和符号链接、目录等,但是二进制文件和文本文件无法直接通过find的类型区分出来;
file命令可以检查文件具体类型(二进制或文本):
$file redis-cli # 二进制文件
redis-cli: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped
$file redis.pid # 文本文件
redis.pid: ASCII text
可以用以下命令组合来实现查找本地目录下的所有二进制文件:
ls -lrt | awk '{print $9}'|xargs file|grep ELF| awk '{print $1}'|tr -d ':'
而文本文件可以这样查找:
ls -lrt | awk '{print $9}'|xargs file|grep ASCII| awk '{print $1}'|tr -d ':'
可以到这里查看find更多的常见用法:
http://linuxtools-rst.readthedocs.org/zh_CN/latest/base/03_text_proces...
附:通过man find可以查看到find支持的文件检索类型:
-type c
File is of type c:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link; this is never true if the -L option or the -follow option is in effect, unless the
symbolic link is broken. If you want to search for symbolic links when -L is in effect, use
-xtype.
s socket
D door (Solaris)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。