Question: How do I create an **unmodified** hex dump of a binary file in Linux using bash? The `od` and `hexdump` commands both insert spaces in the dump and this is not ideal.

Is there a way to simply write a long string with all the hex characters, minus spaces or newlines in the output?

Answer: 
```
xxd -p file

```

Or if you want it all on a single line:

```
xxd -p file | tr -d '\n'

```
This code produces a "pure" hex dump string and it **runs faster than the all the
other examples given**.
It has been tested on 1GB files filled with binary zeros, and all linefeeds.
It is not data content dependent and reads 1MB records instead of lines.

```
perl -pe 'BEGIN{$/=\1e6} $_=unpack "H*"'

```

Dozens of timing tests show that for 1GB files, these other methods below are slower.
All tests were run writing output to a file which was then verified by checksum.
Three 1GB input files were tested: all bytes, all binary zeros, and all LFs.

```
hexdump -ve '1/1 "%.2x"'                    #  ~10x  slower
od -v -t x1 -An | tr -d "\n "               #  ~15x  slower
xxd -p | tr -d \\n                          #   ~3x  slower
perl -e 'local \$/; print unpack "H*", <>'  # ~1.5x  slower
- this also slurps the whole file into memory

```

To reverse the process:

```
perl -pe 'BEGIN{$/=\1e6} $_=pack "H*",$_'

```