Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

hd - hex dump

&pagelevel(4)&pagelevel

hd prints the contents of files in hexadecimal, octal or decimal notation or as character strings. It can also display the position of characters within a string.


Syntax


hd[ -format]...[ -A][ -t][ -s offset[*][wlbk]][ -n count[*][wlbk]][ file]...

If no format, offset, and count is specified:

The output is identical to that of hd -abx -A, i.e. addresses and bytes are shown in hexadecimal. In addition, all bytes that represent printable characters are shown as such, and non-printing characters are represented by a dot. Addresses are displayed at the beginning of each line, followed by the hexadecimal representation of the bytes in the next few columns and the actual characters (with dots if required) on the right.

Addresses are calculated relative to the start of the file. If no file is specified, the standard input is read; otherwise, the contents of all specified files are listed.

-format

Format that determines how individual byte blocks are to be interpreted and output (see “Format description”).

-A

(ASCII)

All printable characters appear unaltered; non-printing characters are represented by a dot. The characters are shown in the column to the right of the first output format.

-t

(text) If this option is set, hd will ignore all format options that do not affect addresses. Each text line is printed with the address shown at the start of the line. Long lines are folded (split). The notation for control characters (values 0x00 to 0x1f) is a caret followed by the corresponding character (^@ to ^_). Bytes with the high order bit set are shown with a preceding tilde (~), but without the high order bit itself. The caret, tilde and backslash characters are preceded by a backslash in the output. Some special cases are represented by numeric values, e.g. a 7-bit DELETE (127) character as \177, and an 8-bit DELETE (255) as \377, respectively.

-s offset[*][wlbk]

Relative address at which printing of the file is to begin. If you do not specify a file or if you supply the input via a pipeline, a corresponding number of bytes will be skipped. hd will abort processing of the current file if you give it an invalid address.

The relative address consists of a number, which can be specified in decimal, hexadecimal (preceded by 0x) or octal (preceded by 0), and optionally a flag indicating a unit size directly after the number.

The possible flags are:


w 2-byte units (i.e. one word)
l 4-byte units (i.e. one long word)
b 512-byte units (i.e. half of one Kbyte)
k 1024-byte units (i.e. one Kbyte)


You can mark the difference between a hexadecimal number that includes the digit b and the b flag by putting an asterisk (*) between the hexadecimal number and the b flag.

The following examples show how the offset can be specified:
-s 111 (111 bytes), -s 124l (496 bytes), -s 0xa*b (5120 bytes), -s 011k (9216 bytes).

-s offset[*][wlbk] not specified:
The output begins at the start of the file.

-n count[*][wlbk]

Number of bytes to be dumped. The count is specified in the same format as the offset, i.e. in decimal, hexadecimal or octal, followed by an optional w, l, b or k flag (see the -s option).

file

Name of the file to be dumped by hd. More than one file may be named.

file not specified:
hd reads input lines from standard input.

Format description

A format consists of the following components:

  • the byte block option (a, b, c, l or w) and

  • the method by which a byte block is to be interpreted in the output, i.e.: hexadecimal (x), decimal (d) or octal (o).

All specified interpretation methods are applied to all specified byte blocks in a format. Format options can be combined and repeated to display addresses, characters, words, etc. in various ways. For example, you could combine -ax -bx into -abx, or specify -cxdo to show all characters in hexadecimal, decimal, and octal.


Byte block options

a

(address)
Format option for addresses.
Addresses are only interpreted by one method, i.e. in hexadecimal, octal, or decimal. The address is always shown at the start of each line to be displayed, or in the first line of an output block if multiple lines are required for the formats.

b(byte)
Format option for byte.

c

(character)
Format option for characters.
All printing characters are displayed. C-language escape sequences are output as defined in the language; all other characters are shown in octal, hexadecimal or decimal, depending on the interpretation method.

l(long word)
Format option for 4 bytes.

w

(word)
Format option for 2 bytes.


Interpretation methods

x(hexadecimal)
hd interprets addresses or byte blocks as hexadecimal numbers.
d(decimal)
hd interprets addresses or byte blocks as decimal numbers.

o

(octal)
hd interprets addresses or byte blocks as octal numbers.


Without an interpretation method, but with a byte block option:

The format is interpreted as -xdo.

With no byte block option except for addresses:

hd uses -bx in addition to the specified address format.

Without a byte block option, but with an interpretation method:

The format is interpreted as -acbwl.

-format not specified:

hd acts as if hd -abx -A were specified.

See also

od