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

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

问题描述

我需要在目录中找到二进制文件。我想用文件做这件事,之后我会用grep检查结果。但我的问题是,我不知道什么是二进制文件。什么会给文件命令的二进制文件,或者我应该检查与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 用于二进制文件。

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.

这不是完全万无一失的,因为它只是在前1000个字符左右,但比这里提出的一些特别方法更好。请参阅 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开关的工作方式如下。首先检查
文件的第一个块,看看它是否包含
非ASCII字符的有效UTF-8。如果这是一个-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.

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

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