Section 4.13. Looking at Raw File Contents: od


[Page 148]

4.13. Looking at Raw File Contents: od

The octal dump utility, od, allows you to see the contents of a nontext file in a variety of formats. Figure 4-29 describes how it works.

Figure 4-29. Description of the od command.

Utility: od -abcdfhilox fileName [offset[.][b]]

od displays the contents of fileName in a form specified by one of several options:

OPTION

MEANING

-a

Interpret bytes as characters, and print as ASCII names (i.e., 0 = null).

-b

Interpret bytes as unsigned octal.

-c

Interpret bytes as characters, and print in C notation (i.e., 0 = \0).

-d

Interpret two-byte pairs as unsigned decimal.

-f

Interpret four-byte pairs as floating point.

-h

Interpret two-byte pairs as unsigned hex.

-i

Interpret two-byte pairs as signed decimal.

-l

Interpret four-byte pairs as signed decimal.

-o

Interpret two-byte pairs as unsigned octal.

-s[n]

Look for strings of minimum length n (default 3), terminated by null characters.

-x

Interpret two-byte pairs as hex.


By default, the contents are displayed as a series of octal numbers. offset specifies where the listing should begin. If the offset ends in b, then it is interpreted as a number of blocks; otherwise, it is interpreted as an octal number. To specify a hex number, precede it by x. To specify a decimal number, end it with a period.



[Page 149]

In the following example, I displayed the contents of the "/bin/od" executable as octal numbers, and then as characters:

$ od /usr/bin/od        ...dump the "/bin/od" file in octal. 0000000 042577 043114 000401 000001 000000 000000 000000 000000 0000020 000002 000003 000001 000000 107020 004004 000064 000000 0000040 101244 000000 000000 000000 000064 000040 000010 000050 0000060 000031 000030 000006 000000 000064 000000 100064 004004 0000100 100064 004004 000400 000000 000400 000000 000005 000000 0000120 000004 000000 000003 000000 000464 000000 100464 004004 0000140 100464 004004 000023 000000 000023 000000 000004 000000 ... $ od -c /usr/bin/od     ...dump "/bin/od" as characters. 0000000 177   E   L   F 001 001 001  \0  \0  \0  \0  \0  \0   \0  \0  \0 0000020 002  \0 003  \0 001  \0  \0  \0 020 216 004  \b  4   \0  \0  \0 0000040 304 202  \0  \0  \0  \0  \0  \0   4  \0      \0  \b   \0  (  \0 0000060 031  \0 030  \0 006  \0  \0  \0   4  \0  \0  \0   4 200 004  \b 0000100   4 200 004  \b  \0 001  \0  \0  \0 001  \0  \0 005  \0  \0   \0 0000120 004  \0  \0  \0 003  \0  \0  \0   4 001  \0  \0   4 201 004   \b 0000140   4 201 004  \b 023  \0  \0  \0 023  \0  \0  \0 004  \0  \0   \0 ... $ _ 


You may search for strings of a minimum length by using the -s option. Any series of characters followed by an ASCII null is considered to be a string.

$ od -s7 /usr/bin/od   ...search for strings 7 chars or more. 0000464 /lib/ld-linux.so.2 0003121 libc.so.6 0003142 putc_unlocked 0003160 getopt_long 0003174 __fpending 0003225 setvbuf 0003235 mbrtowc 0003263 strtoumax 0003312 iswprint ... $ _ 





Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net