Eamorr Eamorr - 1 year ago 106
Linux Question

Convert string to hexadecimal on command line

I'm trying to convert "Hello" to

48 65 6c 6c 6f
in hexadecimal as efficiently as possible using the command line.

I've tried looking at
and google, but I can't get anywhere.

Any help greatly appreciated.

Many thanks in advance,

echo -n "Hello" | od -A n -t x1


  • The echo program will provide the string to the next command.
  • The -n flag tells echo to not generate a new line at the end of the "Hello".
  • The od program is the "octal dump" program. (We will be provide a flag to tell it to dump it in hexadecimal instead of octal.)
  • The -A n flag is short for --address-radix=n, with n being short for "none". Without this part, the command would output an ugly numerical address prefix on the left side. This is useful for large dumps, but for a short string it is unnecessary.
  • The -t x1 flag is short for --format=x1, with the x being short for "hexidecimal" and the 1 meaning 1 byte.