Unix / Linux: Create Binary File from Hex Dump

Objective: Create or convert a text hex dump input file to a binary file on Unix / Linux.

To convert a hex dump to a binary file, we will need to use the xxd utility. Let’s look at an example.

The above is a hex dump of the string that we passed to the echo command. Now, let’s pipe that hex dump output to a file.

Now, the hex dump is in the file called “input.hex“. To convert the the hex dump to binary, we run xxd using the following syntax.

We have created a file called "output.bin", which is the binary output file based on the input hex dump file, "input.hex". To verify that the binary output is the same as our original input, we can run hexdump on it again.

As you can see, the hex dump contents are the same. If you would like xxd to read from stdin (standard input) instead of a input file, replace the input file parameter with ‘-‘ character. The example below shows xxd reading input from stdin.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }