Here’s a real-life example where hexdump may be helpful. If you’re working with binary data, this will be very difficult to understand. For ease, you can quickly turn the binary data into hexadecimal or decimal.
In this guide, check out how to use hexdump command in Linux.
Hexdump in Linux
Hexdump is a simple yet useful program that’s written in C language. That’s why professional C programmers may find its usage easy. However, even if you’re not experienced in C programming, you can still use hexdump for your purpose.
Hexdump comes pre-installed in any Linux distro. In this guide, I’ll be using Ubuntu for demonstration purposes.
Hexdump usage
For demonstrating the usage of hexdump, I’ve created a sample text file dummy.txt.
We’ll be passing this file to hexdump to convert its content into various formats of output.
One-byte octal display
The following hexdump command will print the input data in hexadecimal format. In the output, each line contains 16 space-separated bytes of input data, each having 3 columns and zero-filled, in octal.
One-byte character display
The following hexdump command will display the input data in hexadecimal format. In the output, each line contains 16 space-separated characters of input data, each having 3 columns and space-filled.
Canonical hex + ASCII display
The following hexdump command will display the input data in hexadecimal. In the output, each line contains 16 space-separated hexadecimal bytes, each having 2 columns. The following content will be the same bytes in %_p format enclosed in “|” characters.
Two-byte decimal display
The following hexdump command will display the input data in hexadecimal format. In the output, each line contains 8 space-separated 2 bytes units of input data, each having 5 columns and zero-filled, in unsigned decimal.
Two-byte octal display
The following hexdump command will print the input data in hexadecimal format. In the output, each line contains 8 space-separated 2 bytes of input data, each with 6 columns and zero-filled, in octal.
Two-byte hexadecimal display
The following hexdump command will print the input data in hexadecimal format. In the output, each line contains 8 space-separated 2 bytes of input data, each with 4 columns and zero-filled, in hexadecimal.
Display all input
When using hexdump, it’ll replace the content of repeated lines with a single asterisk. If you want to force hexdump to output all the contents, then use the “-v” flag.
Limit amount of bytes
Hexdump supports the option of deciding a specific number of bytes from a file to hexdump. To specify the amount, use the flag “-s” followed by the byte amount.
Final thought
The examples demonstrated here are the ways you’ll mostly use hexdump. For complete information on hexdump, the man page is one of the best resources.
Hexdump is a powerful tool if you know when and how to use it. However, tools aren’t always the answer when it comes to debugging. Check out how to debug a bash script. If you’re into NodeJS, then check out how to use the NodeJS debugger.
Enjoy!
from Linux Hint https://ift.tt/3kMcPew
0 Comments