bash 如何从bash查看二进制文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1765311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 18:42:29  来源:igfitidea点击:

How to view files in binary from bash?

bashshellbinary

提问by adam_0

I would like to view the contents of a file in the current directory, but in binary from the command line. How can I achieve this?

我想查看当前目录中文件的内容,但是从命令行查看二进制文件。我怎样才能做到这一点?

回答by Emilio Bool

xxddoes both binary and hexadecimal.

xxd二进制和十六进制都可以。

bin:

斌:

xxd -b file

hex:

十六进制:

xxd file

回答by tyranid

hexdump -C yourfile.bin

unless you want to edit it of course. Most linux distros have hexdumpby default (but obviously not all).

除非你当然想编辑它。大多数 linux 发行版hexdump默认都有(但显然不是全部)。

回答by Duck

vi your_filename

hit esc

esc

Type :%!xxdto view the hex strings, the n :%!xxd -rto return to normal editing.

键入:%!xxd查看十六进制字符串,在n:%!xxd -r恢复到正常的编辑。

回答by Jim Garrison

As a fallback there's always od -xc filename

作为后备,总是有 od -xc filename

回答by Raju

If you want to open binary files (in CentOS 7):

如果你想打开二进制文件(在 CentOS 7 中):

strings <binary_filename>

回答by siddiq

sudo apt-get install bless

sudo apt-get install bless

Bless is GUI tool which can view, edit, seach and a lot more. Its very light weight.

Bless 是一个 GUI 工具,可以查看、编辑、搜索等等。它的重量很轻。

回答by Aalex Gabi

$ echo -n 'Hello world!' | hd
00000000  48 65 6c 6c 6f 20 77 6f  72 6c 64 21              |Hello world!|
0000000c

回答by dividebyzero

You can open emacs (in terminal mode, using emacs -nwfor instance), and then use Hexl mode: M-x hexl-mode.

您可以打开 emacs(在终端模式下,emacs -nw例如使用),然后使用 Hexl 模式:M-x hexl-mode

https://www.gnu.org/software/emacs/manual/html_node/emacs/Editing-Binary-Files.html

https://www.gnu.org/software/emacs/manual/html_node/emacs/Editing-Binary-Files.html

回答by craken

You can use hexdump binary file

您可以使用 hexdump 二进制文件

sudo apt-get install hexdump

hexdump -C yourfile.bin