Linux provides a lot of tools for hexadecimal and binary manipulation. Xxd is one of the most popular tool. Xxd is generally used to create hex dump of the given file or standard input.
$ xxd -h
xxd [options] [infile [outfile]]
Dump to Hexadecimal
A file can be dumped into hexadecimal format just providing the file name. We will dump the file named
Makefile in this example.
$ xxd Makefile
Dump From Commands Line or Standard Input
In previous example we have dumped from a file. xxd also supports dumping from standard input or console. We will provide
- to specify input as standard input. At the end of the input we will stop input with
$ xxd -
Set Start Index
While dumping from a file there may be a lot of data those we are not interested. So we simply skiip them. xxd provides
-s option to skip to the specified index. In this example we will skip first 5 lines and start from 6. line.
$ xxd -s 0x50 Makefile
Set End Index
Previous example we have set the start index , we can also set the end index to limit printing data range in a file. We will use
-l option with the value. In this example we set end index as
$ xxd -l 100 Makefile
Set Column Length
xxd uses 16 as the default column length. This value can be changed with the
-l option providing length value. In this example we will set column length as 12 .
$ xxd -c 12 Makefile