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 that determines how individual byte blocks are to be interpreted and output (see “Format description”).
(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.
(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.
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:
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
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).
Name of the file to be dumped by hd. More than one file may be named. file not specified: |
Format description
A format consists of the following components:
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
Interpretation methods
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 |