Convert binary data to hexadecimal in a shell script

davka picture davka · Jun 9, 2011 · Viewed 85.9k times · Source

I want to convert binary data to hexadecimal, just that, no fancy formatting and all. hexdump seems too clever, and it "overformats" for me. I want to take x bytes from the /dev/random and pass them on as hexadecimal.

Preferably I'd like to use only standard Linux tools, so that I don't need to install it on every machine (there are many).

Answer

unutbu picture unutbu · Jun 9, 2011

Perhaps use xxd:

% xxd -l 16 -p /dev/random
193f6c54814f0576bc27d51ab39081dc