hexdump command in Linux with examples
hexdump command in Linux is used to filter and display the specified files, or standard input in a human readable specified format. For example, if you want to view an executable code of a program, you can use
hexdump to do so.
hd [OPTIONS...] [FILES...]
- -b : One-byte octal display. Display the input offset in hexadecimal, followed by sixteen space-separated, three column, zero-filled, bytes of input data, in octal, per line.
hd -b input.txt
The first column of the output represents the input offset in file.
- -c : One-byte character display. Display the input offset in hexadecimal, followed by sixteen space-separated, three column, space-filled, characters of input data per line.
hd -c input.txt
- -C : Canonical hex+ASCII display. Display the input offset in hexadecimal, followed by sixteen space-separated, two column, hexadecimal bytes, followed by the same sixteen bytes in %_p format enclosed in “|” characters.
hexdump -C input.txt
- -d : Two-byte decimal display. Display the input offset in hexadecimal, followed by eight space-separated, five column, zero-filled, two-byte units of input data, in unsigned decimal, per line.
hd -d input.txt
- -n length : Where length is an integer. Interprets only ‘length’ bytes of output.
hd -n length input.txt
- -o: Two-byte octal display. Display the input offset in hexadecimal, followed by eight space-separated, six column, zero-filled, two byte quantities of input data, in octal, per line.
hd -o input.txt
- -s offset : Skip ‘offset’ bytes from the beginning of the input. By default, offset is interpreted as a decimal number. With a leading 0x or 0X, offset is interpreted as a hexadecimal number, otherwise, with a leading 0, offset is interpreted as an octal number. Appending the character b, k, or m to offset causes it to be interpreted as a multiple of 512, 1024, or 1048576, respectively.
hd -s offset input.txt
As you can see, in the output, first 6 characters, i.e. ‘Hello ‘ are skipped.
- -v : Cause hexdump to display all input data. Without the -v option, any number of groups of output lines, which would be identical to the immediately preceding group of output lines (except for the input offsets), are replaced with a line comprised of a single asterisk.
hd -v input.txt
We will see the use of this option as we display the output using
As you can observe, when we use
hd for the first time, without -v, when similar output appears, it prints out an asterisk (*). But when we pass a
-v flag, we get all the output lines.
- -x : Two-byte hexadecimal display. Display the input offset in hexadecimal, followed by eight, space separated, four column, zero-filled, two-byte quantities of input data, in hexadecimal, per line.
hd -x input.txt
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!