comp.org.uk

Networking | Programming | Security | Linux | Computer Science | About

Displaying files in Octal

Some files aren’t easily displayed in ASCII. For example, most graphics files, audio files, and so on use non-ASCII characters that look like gibberish. Worse, these characters can do strange things to your display if you try to view such a file with cat or a similar tool. For instance, your font may change, or your console may begin beeping uncontrollably. Nonetheless, you may sometimes want to display such files, particularly if you want to investigate the structure of a data fi le.

In such a case, od (whose name stands for octal dump) can help. It displays a file in an unambiguous format—octal (base 8) numbers by default.

Here's an example

od listing1.2.txt
0000000 032465 026465 031462 033471 072440 066156 071551 062564
0000020 005144 032465 026465 030465 033061 066040 071551 062564
0000040 005144 032465 026465 034467 034462 066040 071551 062564
0000060 005144 032465 026465 034071 030467 072440 066156 071551
0000100 062564 005144 0000104

The first field on each line is an index into the file in octal. For instance, the second line begins at octal 20 (16 in base 10) bytes into the file. The remaining numbers on each line represent the bytes in the file. This type of output can be difficult to interpret unless you’re well versed in octal notation and perhaps in the ASCII code. Although od is nominally a tool for generating octal output, it can generate many other output formats, such as hexadecimal (base 16), decimal (base 10), and even ASCII with escaped control characters.

Consult the man page for od for details on creating these variants.


Published on Sat 08 September 2001 by Lai Yahui in Linux with tag(s): octal