hexdump – Display a File in Hexadecimal Format

The hexdump command is a Linux utility that is used to display the contents of a file in hexadecimal format. It is mainly used to view the binary contents of a file in a human-readable format. The command can be used to display the contents of any file, including binary files, executable files, and text files.

Overview

The syntax for the hexdump command is as follows:

hexdump [OPTIONS] FILE

Where OPTIONS are the various flags that can be used with the command and FILE is the name of the file that you want to display in hexadecimal format.

Here is an example of how to use the hexdump command to display the contents of a file named example.txt in hexadecimal format:

hexdump example.txt

This will display the contents of the example.txt file in hexadecimal format on the terminal.

Specific Use Cases

  • To view the contents of a binary file in a human-readable format.
  • To check the contents of a file for any unusual characters or patterns.
  • To debug an executable file by examining its contents in hexadecimal format.

Options

Here are the available options that can be used with the hexdump command:

Option Description
-C Displays the output in ASCII characters as well as hexadecimal.
-c Displays the output in ASCII characters only.
-n Specifies the number of bytes to be displayed.
-s Specifies the starting offset from where the contents of the file should be displayed.
-v Displays all input data, including any null bytes.
-x Displays the output in hexadecimal format only.

Troubleshooting Tips

  • If the hexdump command is not working as expected, make sure that you have specified the correct file name and path.
  • If the output is too long, try using the -n option to limit the number of bytes displayed.
  • If you are having trouble understanding the output, try using the -C option to display the output in both hexadecimal and ASCII characters.

Notes

  • The hexdump command is often used in conjunction with other commands such as grep, sed, and awk to manipulate and analyze binary files.
  • The xxd command is another Linux utility that can be used to display the contents of a file in hexadecimal format.