Display files in decimal, hex, octal, or ASCII (UNIX)
Syntax:
hd [-8] [-A format] [-n count] [-s skip]
[-t format[fmt_string]] [-v] [file...]
Options:
-
-8
- Use 8-bit ASCII characters (default 7).
-
-A
format
- Display the file offset field in the specified format. Valid formats are:
-
d — decimal, 9 digits
-
n — none (omit this field)
-
o — octal, 10 digits
-
x — hexadecimal, 7 digits.
-
-n
count
- Display only count bytes of input.
You can add a trailing character to specify units of
blocks (b), kilobytes (k), or megabytes
(m).
-
-s
skip
- Ignore the first skip bytes of data.
You can add a trailing character to specify units of
blocks (b), kilobytes (k), or megabytes
(m).
-
-t
format[fmt_string]
- Use this output/display format; see
"
Output formats,"
below.
The default format is x1.
-
-v
- Be verbose.
If you don't specify the -v option, hd folds
multiple identical lines into a single line that contains an asterisk
(*).
-
file
- The pathname of an input file.
If you don't specify any files, hd reads from standard input.
If a file is a hyphen
(-), hd reads from the standard input at
that point in the sequence.
Description:
The hd utility displays 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:
- the file offset field is displayed in hex, 7 digits
- a space separates the file offset field from the data
- the data is displayed as 16 space-separated bytes in hex
- the same data is also displayed in ASCII, if printable;
unprintable data appears as dots.
For example:
$ echo "abcdefghijklmnopqrstuvwxyz01234" | hd
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.
To exclude part of the input, 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 default units for these options are bytes, but
you can specify different units as follows:
| To specify: |
Add this suffix: |
| Blocks (512 bytes) |
b
|
| Kilobytes (1024 bytes) |
k
|
| Megabytes (1048576 bytes) |
m
|
Output formats
To specify the output format, use the -t option. The
format argument — which you can specify in decimal, hex,
or octal — tells hd which format to use
for presenting the output:
-
a
- Named characters.
Display printable characters as themselves,
and nonprintable characters as a single dot (.).
-
c
- Characters.
Display printable characters as themselves; display all other characters
as 2-digit hex values, except for the following:
| ASCII mnemonic |
Value |
Representation |
|
NUL
|
00 |
\0 |
| <alert> |
07 |
\a |
| <backspace> |
08 |
\b |
| <tab> |
09 |
\t |
| <newline> |
0a |
\n |
| <vertical tab> |
0b |
\v |
| <formfeed> |
0c |
\f |
| <carriage return> |
0d |
\r |
-
d[1|2|4|C|S|I|L]
- Decimal, in objects the size of an int by default.
-
f[4|8|F|D|L]
- Floating point, in objects the size of an float by default.
-
o[1|2|4|C|S|I|L]
- Octal, in objects the size of an int by default.
-
u[1|2|4|C|S|I|L]
- Unsigned decimal, in objects the size of an int by default.
-
x[1|2|4|C|S|I|L]
- Hexadecimal, in objects the size of an int by default.
The input, processed in 16-byte units formatted into a line, is displayed
according to the size you choose:
| To display input as: |
Choose: |
| Sixteen 1-byte objects |
1
|
| Eight 2-byte objects |
2
|
| Four 4-byte values per line |
4
|
| Two 8-byte values per line |
8
|
|
char
|
C
|
|
double
|
D
|
|
float
|
F
|
|
int
|
I
|
|
long or long double (depending
on the format)
|
L
|
|
short
|
S
|
Examples:
Display the second to eleventh sectors of the hard disk,
/dev/hd0:
hd -s 1b -n 10b /dev/hd0
Exit status:
- 0
- All input files were processed successfully.
- >0
- An error occurred.