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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
xxd does both binary and hexadecimal
bin:
xxd -b file
hex:
xxd file
回答2:
hexdump -C yourfile.bin
unless you want to edit it of course. Most linux distros have hexdump
by default (but obviously not all).
回答3:
vi your_filename
hit esc
Type :%!xxd
to view the hex strings, the n :%!xxd -r
to return to normal editing.
回答4:
As a fallback there's always od -xc filename
回答5:
sudo apt-get install bless
Bless is GUI tool which can view, edit, seach and a lot more. Its very light weight.
回答6:
See Improved Hex editing in the Vim Tips Wiki.
回答7:
If you want to open binary files (in CentOS 7):
strings <binary_filename>
回答8:
$ echo -n 'Hello world!' | hd
00000000 48 65 6c 6c 6f 20 77 6f 72 6c 64 21 |Hello world!|
0000000c
回答9:
You can use hexdump binary file
sudo apt-get install hexdump
hexdump -C yourfile.bin
回答10:
You can open emacs (in terminal mode, using emacs -nw
for instance), and then use Hexl mode: M-x hexl-mode
.
https://www.gnu.org/software/emacs/manual/html_node/emacs/Editing-Binary-Files.html