如何在目录中查找二进制文件? [英] How to find binary files in a directory?

查看:521
本文介绍了如何在目录中查找二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在目录中找到二进制文件.我想使用文件执行此操作,然后我将使用grep检查结果.但是我的问题是我不知道什么是二进制文件.会给二进制文件的file命令什么?我应该用grep检查什么?

I need to find the binary files in a directory. I want to do this with file, and after that I will check the results with grep. But my problem is that I have no idea what is a binary file. What will give the file command for binary files or what should I check with grep?

推荐答案

仅需提及 Perl -T测试文本文件,以及与之相反的-B测试二进制文件. /p>

Just have to mention Perl's -T test for text files, and its opposite -B for binary files.

$ find . -type f | perl -lne 'print if -B'

将打印出它看到的所有二进制文件.如果需要相反的操作,请使用-T:文本文件.

will print out any binary files it sees. Use -T if you want the opposite: text files.

它并不是完全安全的,因为它只能显示前1,000个字符左右,但比这里建议的某些临时方法要好.有关完整的摘要,请参见 man perlfunc .这是一个摘要:

It's not totally foolproof as it only looks in the first 1,000 characters or so, but it's better than some of the ad-hoc methods suggested here. See man perlfunc for the whole rundown. Here is a summary:

-T"和"-B"开关的工作方式如下.第一块左右 检查该文件以查看它是否为有效的UTF-8,其中包括 非ASCII字符.如果是,那么它是一个"-T"文件.否则一样 检查文件的一部分是否有奇怪的字符,例如奇怪的字符 高位设置的控制代码或字符.如果超过一个 第三个字符很奇怪,它是一个"-B"文件;否则就是 一个"-T"文件.此外,在检查的文件中任何包含零字节的文件 部分被视为二进制文件.

The "-T" and "-B" switches work as follows. The first block or so of the file is examined to see if it is valid UTF-8 that includes non-ASCII characters. If, so it's a "-T" file. Otherwise, that same portion of the file is examined for odd characters such as strange control codes or characters with the high bit set. If more than a third of the characters are strange, it's a "-B" file; otherwise it's a "-T" file. Also, any file containing a zero byte in the examined portion is considered a binary file.

这篇关于如何在目录中查找二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆