Doing a Reverse Hex Dump
If you work with the command line you've most likely used hexdump or od to dump binary files, but what do you do if you have a hex dump of something and you want to create the binary version of the data? Assuming your needs aren't too complex, the answer may be xxd. You can use xxd to dump binary files just like hexdump and od, but you can also use it to do the reverse: turn a hex dump back into binary.
If you run xxd with just a file name it dumps the data in a fairly standard hex dump format:
# xxd bdata 0000000: 0001 0203 0405 ......Now if you pipe the output back to xxd with the -r option and redirect that to a new file, you can convert the hex dump back to binary:
# xxd bdata | xxd -r >bdata2 # cmp bdata bdata2 # xxd bdata2 0000000: 0001 0203 0405 ......Note that when doing reverse conversions with xxd, the data needs to look like a hex dump: there needs to be an offset and the data needs to be formatted correctly. So, for example, this works:
# echo 01: 01 02 03 04 | xxd -r >outputbut this does not because the data is not formatted correctly:
# echo 01: 1 2 3 4 | xxd -r >output
As a more concrete example, I recently had a need to create a Motorola S-Record file containing a MAC Address. First thing I needed was a way to create a binary file with the MAC Address so that I could use objcopy to convert it to an S-Record file. A bit of pondering produced no good ideas. Linux and its brethren have a lot of command line utilities for manipulating text but not many for manipulating binary data. Of course, I could have written a C program to create the binary file or to create the S-Record file itself, but that seemed a bit much considering I was only talking about 6 bytes of data.
After a fair bit of searching the net I came across xxd. In OpenSuSE xxd is part of the vim-base package. I'm not sure if that's where it is in all distros, since it doesn't seem to have any relationship to vim.
The script takes a MAC Address and outputs S-Record data:
# sh macid.sh 00:11:22:33:44:55 S00D0000333737382D322E746D703B S1090000001122334455F7 S9030000FCOptionally, you can specify an address for re-basing the S-Record file and an output file name:
# sh macid.sh --address 0xffff0000 --output ma 00:11:22:33:44:55 # cat ma S00D0000333733302D322E746D7047 S30BFFFF0000001122334455F7 S705FFFF0000FCSee the entire script is here
Mitch Frazier is an Associate Editor for Linux Journal.
Practical Task Scheduling Deployment
July 20, 2016 12:00 pm CDT
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.Register Now!
- SUSE LLC's SUSE Manager
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- My +1 Sword of Productivity
- Managing Linux Using Puppet
- Non-Linux FOSS: Caffeine!
- Doing for User Space What We Did for Kernel Space
- SuperTuxKart 0.9.2 Released
- Google's SwiftShader Released
- Parsing an RSS News Feed with a Bash Script
- Rogue Wave Software's Zend Server
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide