只需提及Perl-T对文本文件的测试,以及-B二进制文件的相反测试.
$ find . -type f | perl -lne 'print if -B'
Run Code Online (Sandbox Code Playgroud)
将打印出它看到的任何二进制文件.-T如果您想要相反的方法,请使用:文本文件.
它并非完全万无一失,因为它只能看到前1000个字符左右,但它比这里建议的一些特殊方法更好.请参阅man perlfunc了解整个破坏.以下是摘要:
"-T"和"-B"开关的工作原理如下.检查文件的第一个块左右,看它是否是包含非ASCII字符的有效UTF-8.如果,那么这是一个"-T"文件.否则,检查文件的相同部分是否有奇数字符,例如奇怪的控制代码或高位设置的字符.如果超过三分之一的字符是奇怪的,那么它是一个"-B"文件; 否则它是一个"-T"文件.此外,在被检查部分中包含零字节的任何文件都被视为二进制文件.
这将查找所有非基于文本的二进制文件和空文件。
仅解决方案grep(根据Mehrdad的评论):
grep -r -I -L .
Run Code Online (Sandbox Code Playgroud)
除find和以外,不需要任何其他工具grep:
find . -type f -exec grep -IL . "{}" \;
Run Code Online (Sandbox Code Playgroud)
-I 告诉grep假定二进制文件不匹配
-L 仅打印不匹配的文件
. 匹配其他任何东西
查找所有非空二进制文件:
find . -type f ! -size 0 -exec grep -IL . "{}" \;
Run Code Online (Sandbox Code Playgroud)
Bre*_*tão -4
您可以使用基本上您想要的find参数。-executable
手册页说:
-executable
Matches files which are executable and directories which are searchable (in a file name resolution sense). This takes into account access control lists and other permissions artefacts which the -perm test ignores. This test makes use of the access(2) system call, and so can be fooled by NFS servers which do UID mapping (or root-squashing), since many systems implement access(2) in the client's kernel and so cannot make use of the UID mapping information held on the server. Because this test is based only on the result of the access(2) system call, there is no guarantee that a file for which this test succeeds can actually be executed.
Run Code Online (Sandbox Code Playgroud)
这是您想要的结果:
# find /bin -executable -type f | grep 'dmesg'
/bin/dmesg
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21042 次 |
| 最近记录: |