xxd combines od , dd and more

The commandline "xxd" is available in Linux and Mac OS X (though not on other BSD's I've looked at). The author says

The tools weirdness matches its creators brain. Use entirely at your own risk. Copy files. Trace it. Become a wizard.

It is similar to od, but doesn't try to do word interpretation. If what you want to see is hex bytes, displayed in the same order as they actually appear in your file, xxd is the tool.

You don't need extra flags with xxd to get combined hex and ascii :



$ echo "1234" | xxd
0000000: 3132 3334 0a                             1234.
 

Notice that "od -x" interprets and rearranges the bytes in word order:

$ echo "1234" | od -x
0000000      3231    3433    000a 
0000005
 

Some might think it weird, but really it's incredibly useful. Basically, it combines od and dd, which is an excellent marriage by itself. It also can reverse a hex dump. For example, take a text file "t".

$ cat t
An ordinary text file.
$ xxd t > t.hex
$ cat t.hex
0000000: 416e 206f 7264 696e 6172 7920 7465 7874  An ordinary text
0000010: 2066 696c 652e 0a                         file..
$ xxd -r t.hex
An ordinary text file.
 

Unlike od, xxd doesn't automatically use "*" to indicate repeated blocks, and even if requested (with -a) it will only do this for nul (hex 0) bytes.

Like dd, xxd can skip past bytes, and it can also patch files directly:

$ echo "0000000: 4120 7061 7463 6865 6420 2020" | xxd -r - t
$ cat t
A patched   text file.
$ echo "0000010: 2066 6f6f 6c2e" | xxd -r - t
$ cat t
A patched   text fool.
 

This makes xxd extemely useful in unattended scripting as well as at the command line.

If you have xxd, you can use it with "vi": use :%!xxd to change to hex and :%!xxd -r to go back to text.



Got something to add? Send me email.





(OLDER) <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> xxd combines od , dd and more

1 comment



Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Anthony Lawrence







Tue Apr 28 09:53:33 2009: 6272   Jasan

gravatar
xxd is part of VIM, so it is pretty portable...



------------------------
Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us