Polecenia Linuksa

How to Use hexdump Command in Linux?

How to Use hexdump Command in Linux?
Hexdump is a powerful tool in Linux systems that are mostly used by developers and app debuggers. It can convert input files and data into a pleasant and readable format.

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.

$ cat 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.

$ hexdump -b

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.

$ hexdump -c

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.

$ hexdump -C

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.

$ hexdump -d

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.

$ hexdump -o

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.

$ hexdump -x

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.

$ cat dummy.txt

$ hexdump -b dummy.txt

$ hexdump -v -b

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.

$ hexdump -s 2 -c

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.

$ man hexdump

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!

Gry Jak stworzyć grę na Linuksie
Jak stworzyć grę na Linuksie
Dziesięć lat temu niewielu użytkowników Linuksa przewidywało, że ich ulubiony system operacyjny pewnego dnia stanie się popularną platformą do gier dl...
Gry Open Source Ports of Commercial Game Engines
Open Source Ports of Commercial Game Engines
Free, open source and cross-platform game engine recreations can be used to play old as well as some of the fairly recent game titles. This article wi...
Gry Najlepsze gry wiersza poleceń dla systemu Linux
Najlepsze gry wiersza poleceń dla systemu Linux
Wiersz poleceń jest nie tylko twoim największym sprzymierzeńcem podczas korzystania z Linuksa - może być również źródłem rozrywki, ponieważ możesz go ...