如何区分在linux下的文本文件二进制 [英] How to tell binary from text files in linux

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

问题描述

而linux 文件命令会在识别文件类型了很好的工作,并给出了非常精细的效果。在差异工具,能够从文本文件告诉二进制文件,产生不同的结果。

The linux file command does a very good job in recognising file types and gives very fine-grained results. The diff tool is able to tell binary files from text files, producing a different output.

有没有办法告诉二进制文件格式的文本文件?我想要的是一个是/否的答案给定文件是否是二进制的。因为这是很难界定的二进制,比方说,我想知道,如果差异将试图基于文本的比较。

Is there a way to tell binary files form text files? All I want is a yes/no answer whether a given file is binary. Because it's difficult to define binary, let's say I want to know if diff will attempt a text-based comparison.

要澄清一个问题:我不在乎,如果它是ASCII文本或XML,只要它的文本。另外,我不希望MP3和JPEG文件的区分,因为它们都是二进制的。

To clarify the question: I do not care if it's ASCII text or XML as long as it's text. Also, I do not want to differentiate between MP3 and JPEG files, as they're all binary.

推荐答案

手册指定

差异确定文件是否是文本
  或二进制通过检查前几
  字节的文件中;的确切数目
  字节是依赖于系统,但它是
  通常几千。如果每个
  在该文件的该部分字节是
  非空,差异将认为该文件
  是文本;否则认为
  文件为二进制。

diff determines whether a file is text or binary by checking the first few bytes in the file; the exact number of bytes is system dependent, but it is typically several thousand. If every byte in that part of the file is non-null, diff considers the file to be text; otherwise it considers the file to be binary.

这篇关于如何区分在linux下的文本文件二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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