hexdump command in Linux with examples

21 May, 2019
The hd or 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.
Syntax:
hd [OPTIONS...] [FILES...]
Options:
-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.Syntax:hd -b input.txtThe first column of the output represents the input offset in file.
Syntax:
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.Syntax:hd -c input.txt
Syntax:
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.Syntax:hexdump -C input.txt
Syntax:
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.Syntax:hd -d input.txt
Syntax:
hd -d input.txt
-n length : Where length is an integer. Interprets only ‘length’ bytes of output.Syntax:hd -n length input.txt
Syntax:
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.Syntax:hd -o input.txt
Syntax:
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.Syntax:hd -s offset input.txtAs you can see, in the output, first 6 characters, i.e. ‘Hello ‘ are skipped.
Syntax:
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.Syntax:hd -v input.txtWe will see the use of this option as we display the output using -c flag.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.
Syntax:
hd -v input.txt
We will see the use of this option as we display the output using -c flag.
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.Syntax:hd -x input.txt
Syntax:
hd -x input.txt
linux-command
Linux-file-commands
Picked
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
tar command in Linux with examples
curl command in Linux with Examples
Tail command in Linux with examples
Conditional Statements | Shell Script
Docker - COPY Instruction
scp command in Linux with Examples
UDP Server-Client implementation in C
echo command in Linux with Examples
Cat command in Linux with examples
touch command in Linux with Examples