views:

83

answers:

4

First things first, I'm on a Mac ssh'ing into a Linux machine via Terminal.

I would like to view the contents of a file in the current directory, but in binary. Is there a binary mode for any text editors like VI or Nano or the like?

+2  A: 

As a fallback there's always od -xc filename

Jim Garrison
+1  A: 

"hexdump -C yourfile.bin" perhaps, unless you want to edit it of course. Most linux distros have hexdump by default (but obviously not all).

tyranid
I like this idea, but like the other suggestions it only outputs hex. Obviously this is much more compact than binary, but I am dealing with very small files so binary is preferred. Is hex the only way I will be able to view the file?
adam_0
Well how small is the file? Anything over a couple of bytes and you will start to lose your mind using binary anyway. Hex makes much more sense for most things. If you are uncomfortable with hex just locate the bytes in which you are interested and convert them using a hex calculator.
Duck
I need to make sure that my file is compressing correctly and I don't know what it should look like in hex (the size of each unit is 7 bits), so I would have to crunch the numbers by hand.
adam_0
A: 

See Improved Hex editing in the Vim Tips Wiki.

intgr
A: 

vi yourfilename

hit escape

enter ":%!xxd" (minus quotes)

“:%!xxd -r“ will return to normal editing.

Duck