Previous Table of Contents Next


Module 97
od

DESCRIPTION

The external od command provides a way to view the contents of a file byte-by-byte or word-by-word. A byte is eight bits and a word is two bytes (16 bits). The format of each byte or word can be octal, decimal, hexadecimal, or ASCII. You can use od to display a file that has special character sequences, such as control characters or extended ASCII characters.


NOTE:  
The od command displays bytes and words of information. These display formats are not dependent upon the computer hardware.



COMMAND FORMAT

Following is the general format of the od command.

     od [ -bcDdFfOoSsXx ] [ file ] [ [+]offset[.][b] ]

BSD (Berkeley)
od [ -a[pP]bcdfhilovx ] [ -w[n] ] [ -s[n] ] [ file ] \
[ [+]offset[.][bx] [ [+]label[.][bx] ] ]

Options

The following list describes the options and their arguments that may be used to control how od functions.

-b Displays each byte in octal format. For example, a file (pups) containing the word PUPPIES is displayed as
od -b pups
000000 120 125 120 120 111 105 123 012
The first set of zeros is the address of the first byte displayed on the current line. The 120 is the octal representation for P.
-c Displays each byte in its ASCII character format. Nonprinting characters have the following special representations.
Notation Meaning ASCII Label
\0 Null NUL
\b Backspace BS
\f Formfeed FF
\n New-line NL
\r Carriage Return CR
\t Tab HT
\ooo Octal Representation of character
All nonprintable characters that do not have a special symbol are represented using their octal representation.
-D Displays each word in unsigned decimal format.
-d Displays each long word in unsigned decimal format. For example,
od -d pups
000000 080085 080080 073069 083010
-O Displays each long word in octal format.
-o Displays each word in octal format. This is the default if you do not specify any options.
-S Displays each long word in signed decimal.
-s Displays each word as signed decimal.
-v Verbose. Displays all data. By default duplicate lines are replaced with an asterisk (*) in column 1.
-X Displays each long word in hexadecimal.
-x Displays each word as hexadecimal.
[+]offset[.][b] The + sign must be used if no file is specified. The offset is the number of bytes to skip before displaying information. By default the offset is interpreted as octal. The . (period) option changes the meaning of the offset to be decimal instead of octal. The b option changes the offset to be calculated in blocks (512 bytes) instead of bytes. Dumping continues until the end-of-file is reached.

BSD (Berkeley)
-a[pP] Displays bytes as ASCII names. If p is specified, bytes with even parity are underlined. If P is specified, bytes with odd parity are underlined.
-b Same as System V
-d Same as System V
-f Displays long words as floating point.
-h Displays words as unsigned hexadecimal.
-i Displays words as signed decimal.
-l Displays words as signed decimal.
-o Same as System V
-v Same as System V
-x Displays words as hexadecimal.
-s[n] Display strings of ASCII graphic characters, null terminated. The minimum string length is set to n, the default for n is 3.
-w[n] Display n input bytes on one line of output. If -w is not used the default is 16 bytes. If -w is specified without n the width is set to 32 bytes.
[+]offset[.][b][x] The same as SV with the addition of x. If x or 0x is specified, the offset is calculated in hexadecimal.
[+]label[.][b][x] Same as the offset option except it is intended for use with core images to indicate the real memory address.

Arguments

The following describes the argument that may be passed to the od command.

file The name of the input file to be displayed in od format.
If no file is specified od reads from the standard input. Thus you can use od to read input from a pipe or straight off your keyboard. If you use it from your keyboard, no output is displayed until you press Return or Ctrl-D.

RELATED COMMANDS

The cat command with the -v option performs a similar function provided by the od -c command.

APPLICATIONS

The od command can be used to view the contents of a file containing special nonprinting characters. You may find it useful to look at binary files such as compiled C programs containing machine code or data files containing data in binary format. Typically, it is used more by programmers than general users but it is one of those commands worth knowing about when you need it.

TYPICAL OPERATION

In this activity you use the od command to view the contents of a TERMINFO entry. Begin at the shell prompt.

1.  Type od file1 and press Return to display the contents of the file file1.
2.  Now type od -cx file1 and press Return to display the contents of the file in ASCII and hexadecimal format.

System V Only
3.  Type od -cx /usr/lib/terminfo/v/vt100 | pg and press Return. The od command reformats the contents of the vt100 terminfo entry into ASCII and hexadecimal representation. Two lines of output are generated for each ten bytes read.
4.  Press Return at the : prompt of pg to continue stepping through the output of od. Notice the definition of the vt100 terminal is defined in this file.
5.  Turn to Module 79 (SV), Module 81 (BSD) to continue the learning sequence.


Previous Table of Contents Next