hexdump Command in Linux
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Overview
Hexdump command in Linux is a highly useful utility that converts and displays binary data in hexadecimal format. This can be instrumental when analyzing files at a bit-level, especially when dealing with data encoding, debugging, or network packet analysis.
Syntax of hexdump Command in Linux
The basic syntax of the hexdump command in Linux is as follows:
Where:
- options: These are optional and alter the output format or behavior of the hexdump command.
- file: The file for which you want to generate the hexdump.
Options in hexdump Command in Linux
-
-C: This option displays the output in 'canonical' hex+ASCII display.
For example -
Output:
This command provides the hexadecimal representation of each byte in myfile.txt, along with the corresponding ASCII values.
-
-v: The -v option causes hexdump to display all input data.
For example -
Output:
Unlike the default behavior, the -v option prevents the use of '*' notation to indicate repeated lines.
-
-n length: The -n length option tells hexdump to display 'length' bytes of input.
For example -
Output:
This command will only display the first 10 bytes of myfile.txt.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Example Usages
-
Basic usage of hexdump:
Output:
Explanation: This will output the hexadecimal representation of myfile.txt, grouping input into short words.
-
Using hexdump with -b option for one-byte octal display:
Output:
Explanation: This command outputs the octal values of each byte in myfile.txt.
Tips
-
To read hexdump output more easily, remember that it is grouped into 16-byte sequences by default.
-
The hexdump command in Linux works with pipes and redirections, making it versatile in scripting and data analysis.
Turn Learning into Career Growth
Advanced Use Cases of hexdump Command in Linux
-
Using hexdump with -e option for custom formats:
Output:
Explanation: This command provides a custom formatted hexadecimal dump of myfile.txt with offset in file, sixteen space-separated, two-column, zero-filled, hexadecimal bytes, and a newline.
-
Creating a hexadecimal color code using hexdump:
Output:
Explanation: This command generates a hex color code from a string by reading the first three characters ('H', 'e', 'l'), translating each to its hexadecimal equivalent and then taking the first 6 hex digits.
-
Reading binary file data with hexdump:
Output:
Explanation: This command outputs a 'canonical' hexadecimal plus ASCII dump of a binary file. It is especially useful when dealing with unknown or corrupt file formats.
Conclusion
-
The hexdump command in Linux is a powerful tool for examining binary files or producing human-readable data from binary input.
-
Hexdump provides a range of options to alter the output format, including '-C' for canonical hex+ASCII display, and '-n length' to control the length of output.
-
With advanced usage, hexdump can be customized to display data in different formats and used for tasks like generating hex color codes.




