hexdump - Linux Command - Unix Command

The 'hexdump' utility displays a file in a specific format

The hexdump Linux utility displays the specified files—or the standard input, if no files are specified—in a user-specified format.

Synopsis

hexdump output

The command takes the following structure:

hexdump [-bcCdovx ] -words [-e format_string ] -words [-f format_file ] -words [-n length ] -words [-sskip ] file ...  

Command Options

The command accepts several switches that modify its behavior:

  • -b: Display the input offset in hexadecimal, followed by sixteen space-separated, three column, zero-filled, bytes of input data, in octal, per line.
  • -c: Display the input offset in hexadecimal, followed by sixteen space-separated, three column, space-filled, characters of input data per line.
  • -C: Display the input offset in hexadecimal, followed by sixteen space-separated, two column, hexadecimal bytes, followed by the same sixteen bytes in %_p format enclosed in pipes.
  • -d: Display the input offset in hexadecimal, followed by eight space-separated, five column, zero-filled, two-byte units of input data, in unsigned decimal, per line.
  • -e format_string: Specify a format string to be used for displaying data.
  • -f format_file: Specify a file that contains one or more newline separated format strings. Empty lines and lines whose first non-blank character is a hash mark are ignored.
  • -n length: Interpret only length bytes of input.
  • -o: Display the input offset in hexadecimal, followed by eight space-separated, six column, zero-filled, two-byte quantities of input data, in octal, per line.
  • -s offset: Skip offset bytes from the beginning of the input. By default, offset is interpreted as a decimal number. With a leading 0x or 0X offset is interpreted as a hexadecimal number, otherwise, with a leading 0 offset is interpreted as an octal number. Appending the character b k or m to offset causes it to be interpreted as a multiple of 5121024, or 1048576, respectively.
  • -v: The -v option causes hexdump to display all input data. Without the -v option, any number of groups of output lines, which would be identical to the immediately preceding group of output lines (except for the input offsets), are replaced with a line comprised of a single asterisk.
  • -x: Display the input offset in hexadecimal, followed by eight, space separated, four column, zero-filled, two-byte quantities of input data, in hexadecimal, per line.

For each input file, sequentially copies the input to standard output, transforming the data according to the format strings specified by the -e and -f options, in the order that they were specified.  

Formats

A format string contains any number of format units, separated by whitespace. A format unit contains up to three items: an iteration count, a byte count, and a format.

The iteration count is an optional positive integer, which defaults to one. Each format is applied to iteration count times. The byte count is an optional positive integer. If specified it defines the number of bytes to be interpreted by each iteration of the format.

If an iteration count or a byte count is specified, a single slash must be placed after the iteration count and before the byte count to disambiguate them. Any whitespace before or after the slash is ignored.

The format is required and must be surrounded by double-quote marks. It is interpreted as an fprintf-style format string, with the following exceptions:

  • An asterisk may not be used as a field width or precision.
  • A byte count or field precision is required for each s conversion character—unlike the fprintf default, which prints the entire string if the precision is unspecified.
  • The conversion characters h, l, n, p, and q are not supported.
  • The single-character escape sequences described in the C standard are supported:
    • <null>: \0
    • <alert character>: \a
    • <backspace>: \b
    • <form-feed>: \f
    • <newline>: \n
    • <carriage return>: \r
    • <tab>: \t
    • <vertical tab>: \v

Hexdump also supports additional conversion strings. Consult the manpage for hexdump for specific usage notes.