While most people, even programmers, won't work with bits and bytes on a daily basis, there are ways you can explore files on your Linux system at this level. And xxd is one such utility, a hex dumper.
Here's how you can use the xxd hex dumper utility to print the content of files in hexadecimal format.
What Is A Hex Dumper?
As mentioned above, a hex dumper outputs the contents of a file, or "dumps" it, into hexadecimal numbers. Hexadecimal numbers use 16 characters, with letters A-F representing the numbers 10-15.
Hexadecimal numbers are generally used to represent binary because four bits, or half a byte, can be represented in a hexadecimal digit, It's a more human-friendly way to write out binary numbers without having to deal with long strings of ones and zeros.
You might have used the hexadecimal format when picking out color palettes for your designs, such as in this chart of web-safe colors. The hex values of these colors start with a Pound (#) character.
Dump Your Files in Hex Format Using xxd
While xxd is not a part of a standard Linux system, it is a part of the Vim editor. Since Vim itself is widely installed on many Linux systems, it might as well be the standard. If it's not installed, look for it in your distro's package manager.
To invoke xxd, type:
xxd [FILE]
By default, xxd will print out the line number, the binary contents in hexadecimal, and any human-readable strings in a columnar format. Using xxd on text files is an educational experience if you have an ASCII chart handy, but it can also be surprisingly useful for examining binary files.
Above is a sample from a PNG file that was a screenshot from another article.
Binary files will also have strings embedded in them, which you can find with a text editor. A lot of times, it will be the type of file being examined, but other messages may be left in. Most of the text will be gibberish in a binary but toward the beginning of a file, you might see things like the type of file and the program used to create it.
You Can Examine Files With xxd
With xxd and other hex dump utilities, you can explore all kinds of files on your system. You'd be surprised at what you might find.
If you're brave enough, you can also use a hex editor to make changes to the file. Apart from hex editors, several text editors are available for free on a Linux system.
0 Comments