A main source of data on a Linux system is a file. Linux data also moves in streams. A pipe, for instance, routes an ordered stream of data from one process to another. That data might never touch a file.
At the lowest level, Linux data is a series of bits — 1s and 0s. When you’re debugging a problem or simply trying to understand how something works (or more likely, why something doesn’t work), it can help to know exactly what’s in that data, bit-by-bit. The od utility can show you. There are also techniques to compare binary data. Get your shovel ready; let’s dig in. (The October 2004 “Powers Tool” column Performing Data Surgery” has some related information.)
Introducing od
The od utility dumps the contents of a file or a data stream (from od’s standard input) to standard output, in a more-readable format. od stands for “octal dump,” but od can also interpret data as ASCII characters and backslashed escapes (its -c option), signed decimal (-d option), hexadecimal (-x), and more. By default, od dumps all of the data. The GNU option -N count dumps only the first count bytes of input.
As a first example, let’s create a file with 100 NUL (zero) bytes. Reading the Linux device /dev/zero returns as many NUL bytes as you want. The obscure dd utility is good at reading an exact number of bytes. We’ll read a block of 100 bytes from /dev/zero and write it to…
Please log in to view this content.
Not Yet a Member?
Register with LinuxMagazine.com and get free access to the entire archive, including: