# # xxd combines od , dd and more
APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

xxd combines od , dd and more

I've removed advertising from most of this site and will eventually clean up the few pages where it remains.

While not terribly expensive to maintain, this does cost me something. If I don't get enough donations to cover that expense, I will be shutting the site down in early 2020.

If you found something useful today, please consider a small donation.



Some material is very old and may be incorrect today

© May 2006 Anthony Lawrence
May 2006

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.


If you found something useful today, please consider a small donation.



Got something to add? Send me email.





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

Printer Friendly Version

->
-> xxd combines od , dd and more

1 comment


Inexpensive and informative Apple related e-books:

Take Control of Upgrading to El Capitan

Take Control of Numbers

Take control of Apple TV, Second Edition

iOS 8: A Take Control Crash Course

El Capitan: A Take Control Crash Course





More Articles by © Anthony Lawrence







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

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



------------------------


Printer Friendly Version

Have you tried Searching this site?

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


Printer Friendly Version





Getting information off the Internet is like taking a drink from a fire hydrant. (Mitchell Kapor)




Linux posts

Troubleshooting posts


This post tagged:

Linux

Shell

Unix



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode