Skip to content

hexdump Linux command

The Linux hexdump command is used to display files in hexadecimal format. It allows users to analyze the binary data of files, giving them insights into the structure and content of the files. This command is essential for developers and system administrators who need to work with binary data. By using the various options available with hexdump, users can customize the output format to suit their needs. Overall, hexdump is a powerful tool for examining and understanding the binary data of files on a Linux system.

hexdump Syntax:

Terminal window
hexdump [options] [file]

Options:

OptionDescription
-CDisplay output in ASCII, hexadecimal, and decimal format
-cDisplay output in ASCII characters
-nLimit number of bytes to dump
-sSkip a specific number of bytes before starting to dump
-vDisplay all input data
-xDisplay output in hexadecimal format
-bDisplay output in octal format
-dDisplay output in decimal format
-eFormat with specified C printf-style format control string, e.g., “%08x “

Parameters:

ParameterDescription
fileSpecified file to dump

hexdump bash Examples:

Display hex and ASCII representation of a file

Terminal window
hexdump -C file.txt

Displays the hexadecimal and ASCII representation of the contents of the file.txt.

Display only the hexadecimal data without the ASCII representation

Terminal window
hexdump -e '"%08_ax " 4/4 "%08x " "\n"' file.bin

Displays only the hexadecimal data without the corresponding ASCII representation for the contents of file.bin.

Display file contents as 2-byte (16-bit) units

Terminal window
hexdump -e '2/1 "%04x " "\n"' file.data

Displays the contents of file.data as 2-byte (16-bit) units in hexadecimal format.

Display the content of a file in octal format

Terminal window
hexdump -v -e '16/1 "%03o " "\n"' file.txt

Displays the content of file.txt in octal format with each byte represented by 3 octal digits.

Display a specific number of bytes from a file in hexadecimal format

Terminal window
hexdump -n 16 -e '8/4 "%08x " "\n"' file.dat

Displays the first 16 bytes from file.dat in hexadecimal format with each line containing 8 bytes.

Display the content of a file in little-endian format

Terminal window
hexdump -e '4/4 "%08x " "\n"' -e '4/4 "%08x " "\n"' -e '4/4 "%08x " "\n"' -e '4/1 " \n"' -e '4/4 "%08x " "\n"' -e '4/4 "%08x " "\n"' -e '4/4 "%08x " "\n"' -e '4/1 " \n"' file.bin

Displays the content of file.bin in little-endian format by visually reversing the byte order within each 4-byte unit.

How can I display the contents of a file in hexadecimal format using hexdump?

To display the contents of a file in hexadecimal format with hexdump, you can use the following command:

Terminal window
hexdump -C file.txt

Can I display the output of hexdump in a specified format in Linux?

To display the output of hexdump in a specified format, you can use the following command with the desired format option:

Terminal window
hexdump -e '1/1 "%02x " "\n"' file.txt

How do I display ASCII representation alongside hexadecimal output using hexdump?

To display the ASCII representation alongside the hexadecimal output using hexdump, you can use the following command:

Terminal window
hexdump -C file.txt

Is it possible to skip a certain number of bytes while using hexdump in Linux?

Yes, you can skip a certain number of bytes while using hexdump in Linux by specifying the starting position with the skip option. Here is an example command:

Terminal window
hexdump -s 10 file.txt

How can I reverse the bytes order for output using hexdump in Linux?

To reverse the bytes order for the output using hexdump in Linux, you can use the following command:

Terminal window
hexdump -s 10 -e '1/1 "%x"' file.txt

Can I display the offsets in a different format with hexdump in Linux?

Yes, you can display the offsets in a different format by specifying the desired format option. Here is an example command:

Terminal window
hexdump -e '1/1 "%06_ax "' file.txt

How do I display the contents of a file in octal format using hexdump?

To display the contents of a file in octal format with hexdump, you can use the following command:

Terminal window
hexdump -e '/1 "%03o "' file.txt

Is it possible to display the character counts alongside the hexadecimal output in hexdump?

Yes, you can display the character counts alongside the hexadecimal output by using the following command:

Terminal window
hexdump -C file.txt
## Applications of the hexdump command
- Viewing the hexadecimal representation of a file
- Converting binary data to a human-readable format
- Analyzing file contents at the byte level
- Verifying data integrity
- Debugging and examining file structures