hd(C)


hd -- display files in hexadecimal format

Syntax

hd [ -format ] [ -D ] [ -s offset ] [ -n count ] [ file ] ...

Description

The hd command displays the contents of files in hexadecimal, octal, decimal, and character formats. The format flags specify how the file contents are to be displayed. The default format is to print addresses (file offsets) in hexadecimal and bytes (file data) in hexadecimal and character form.

If no file argument is given, hd reads the standard input.

hd prints offset addresses and file data according to output format modifiers. The following format flags specify that offset addresses are to be formatted and how file data is to be interpreted:


a
file offset address; this appears once on each line of output that refers to a new offset into the file (addresses are output as hexadecimal if a is not specified, or if no format modifier is specified)

b
file data to be interpreted one byte at a time (output as hexadecimal, decimal, and octal if no format modifier is specified)

c
file data to be interpreted one character at a time (if no format modifier is specified, output as the printable or C escaped characters where possible; otherwise as the hexadecimal, decimal, or octal value)

l
file data to be interpreted one long word (4 bytes) at a time (output as hexadecimal, decimal, and octal if no format modifier is specified)

w
file data to be interpreted one short word (2 bytes) at a time (output as hexadecimal, decimal, and octal if no format modifier is specified)
The following output format modifiers are available:

d
Output data in decimal.

o
Output data in octal.

x
Output data in hexadecimal.
The following flags interpret the file as characters:

A
Outputs all printable characters without change, and all others as a period ``.''. The characters are output to the right of the other specified formats (bx is assumed by default).

t
Outputs each line of a text file preceded by its offset address. Normally, lines should be terminated by a \n character; but long lines will be broken up. Control characters in the range 0x00 to 0x1f are printed as ``^@'' to ``^_''. Bytes with the high bit set are preceded by a tilde ``~'' and printed as if the high bit were not set. The special characters ``^'', ``~'' and ``\'' are preceded by a backslash ``\'' to escape their special meaning. As special cases, these two values are represented numerically as ``\177'' and ``\377''. This flag cancels all other output format specifiers except that applied to the offset address.
The default format is -abxA.

hd accepts the following options:


-D
Omits filtering of duplicate lines in hd output, shortening execution time significantly.

-s offset
Specifies the beginning offset in the file where printing is to begin. If no file argument is given, or if a seek fails because the input is a pipe, offset bytes are read from the input and discarded. Otherwise, a seek error will terminate processing of the current file.

The offset may be given as a decimal, hexadecimal (preceded by 0x), or octal (preceded by a 0) number. It is normally interpreted as a number of bytes unless it is followed by one of the following multipliers:


b
physical blocks (512 bytes)

k
logical blocks (1024 bytes)

l
long words (4 bytes)

w
short words (2 bytes)
Since specifying a hexadecimal offset in physical blocks would result in an ambiguous trailing ``b'', you must separate the offset and multiplier using an asterisk ``*''. (You may need to precede the asterisk by a backslash ``\'' to prevent it from being interpreted by the shell.)

-n count
Specifies the number of bytes to process. count has the same format as offset for the -s option.

Exit values

hd can return the following exit values:

0
No error.

1
An error occurred.

2
Incorrect usage.

Examples

Read characters from the standard input and write their hexadecimal and character forms to the standard output. You can terminate the input by typing two EOF characters (usually <Ctrl>D) immediately following a newline character. Otherwise, you can limit the number of characters to be processed using the -n option. hd writes to the standard output when it receives a newline character and it has more than 16 characters to output, or when it exits:

hd -abxA

Examine a file foo and print it as hexadecimal byte, short word, and long word values:

hd -abwlx foo

Output the byte and long word values from foo in octal and decimal form but output offset addresses in hexadecimal. Read the file from the standard input and write the output to foo.dump:

hd -blod < foo > foo.dump

See also

adb(CP), cat(C), od(C)

Standards conformance

hd is not part of any currently supported standard; it is an extension of AT&T System V provided by the Santa Cruz Operation.
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005