hd

display files in decimal, hex, octal, or ASCII (UNIX)

Syntax:


hd [-A format] [-n count] [-s skip] 

   [-t format[fmt_string]] [-v] [file...]

Options:

-A format
Display the file offset field in the specified format. Valid formats are:
format Display
x (hex, 7 digits)
o (octal, 10 digits)
d (decimal, 9 digits)
n (none)
-n count
Display only count bytes of input.
-s skip
Ignore the first skip bytes of data.
-t format[fmt_string]
Use this output/display format.
-v
Be verbose. Display all input.
file
The pathname of an input file. If no files are specified, the standard input is used. If a file is a dash character (-), hd reads from the standard input at that point in the sequence.

Examples:

Display the 2nd to 11th sectors of the floppy disk /dev/fd0:


    hd -s 1b -n 10b /dev/fd0 | more

Description:

You use the hd utility to output data in decimal, hex, octal, or ASCII. The name "hd" (hex dump) is derived from the default output format.

The hd utility processes input in 16-byte units that are formatted into a line. In the default output format:

For example, if you issue the following command:


    echo "abcdefghijklmnopqrstuvwxyz01234" | hd

you should see the following output:


0000000: 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 abcdefghijklmnop

0000010: 71 72 73 74 75 76 77 78 79 7a 30 31 32 33 34 0a qrstuvwxyz01234.

The -v option (verbose) inhibits hd's default behavior of folding multiple identical lines into a single line that contains an asterisk (*). When -v is specified, all data is displayed.

To exclude part of the input, you use the -n and -s options. You can specify the arguments to these options in hex (using a 0x prefix) or octal (using a 0 prefix).

The arguments to -n and -s also let you specify three different units:

To specify:Add this suffix:
blocks (512 bytes)b
kilobytes (1024 bytes)k
megabytes (1048576 bytes)m

To specify the output format, you use the -t option. The format argument — which can be specified in decimal, hex, or octal — instructs hd as to which format to use for presenting the output. The format argument can be one of the following:

format:Display as:
o[1|2|4] octal, 1-, 2-, or 4-byte objects (default is 2)
x[1|2|4] hex 1-, 2-, or 4-byte objects (default is 2)
X[1|2|4] hex 1-, 2-, or 4-bytes objects, with characters (default is 1)
d[1|2|4] decimal 1-, 2-, or 4-byte objects (default is 2)
c characters

The input, processed in 16-byte units formatted into a line, is displayed according to the option ([1|2|4]) you choose:

To display input as:Choose:
sixteen 1-byte objects1
eight 2-byte objects2
four 4-byte values per line4

The X (uppercase) format instructs hd to redisplay the input block at the end of line in a special character format. The special character format displays printable characters "as is" and nonprintable characters as a single dot (.). If you don't specify the -t option, the default output format is the same as using the option -t X.

The c format displays printable characters as themselves. With the exception of the following characters, all other characters are displayed as 2-digit hex values.

ASCII mnemonic:Value:Representation:
NUL00\0
alert07\a
backspace08\b
tab09\t
newline0a\n
vertical tab0b\v
formfeed0c\f
carriage return0d\r

Exit status:

0
All input files were processed successfully.
>0
An error occurred.

See also: