Home » 2014 » October » 24 » HEXDUMP command in Linux to display the file content in decimal, hexadecimal, octal format

10:36 PM
HEXDUMP command in Linux to display the file content in decimal, hexadecimal, octal format

Share on Google+

hexdump - is a Linux utility to dump the file content into ascii, decimal, hexadecimal, octal formats. 

It accepts the input from a file or from standard input and creates a dump in ASCII, octal. hexadecimal or decimal formats.

FORMAT
      [-bcCdovx] [-e format_string] [-f format_file] [-n length] [-s skip] file ...

DESCRIPTION
     The hexdump utility is a filter which displays the specified files, or the standard input, if no files are specified, in a user specified format.


The options are as follows:

 -x          Two-byte hexadecimal display.  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.

shanky@localhost:~> hexdump -x abc.txt
0000000    6261    6463    000a
0000005

Note:-

Here we may notice that the hexdump is showing the file content i.e. "abcd" in two byte hexadecimal format. The utility takes two byte chunk "ab"  and shows as 6261 because hexadecimal value of a and b is 61 and 62 and they are displayed from LSB(least significant bit) to MSB(Most significant byte)

MSB LSB

0x62 (1 byte)

0x61 (1 byte)

   

again the next byte is new line "\n" whose ASCII value is 10 and hexadecimal value is 0x0a which is displayed.

On the next line we have "0000005" which means that 5 bytes have been dumped 4 bytes for "abcd"  and one byte for "\n".

 

 -b          One-byte octal display.  Display the input offset in hexadecimal, followed by sixteen space-separated, three column, zero-filled, bytes of input data, in octal, per line.

shanky@localhost:~> cat abc.txt
abcd

shanky@localhost:~> hexdump -b abc.txt
0000000 141 142 143 144 012
0000005

 

     -c          One-byte character display.  Display the input offset in hexadecimal, followed by sixteen space-separated, three column, space-filled, characters of input data per line.

shanky@localhost:~> hexdump -c abc.txt
0000000   a   b   c   d  \n
0000005

 

     -C          Canonical hex+ASCII display.  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 ``|'' characters.

shanky@localhost:~> hexdump -C abc.txt
00000000  61 62 63 64 0a                                    |abcd.|
00000005

 

     -d          Two-byte decimal display.  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.

shanky@localhost:~> hexdump -d abc.txt
0000000   25185   25699   00010
0000005

 



 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 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.


Examples:

shanky@localhost:~> cat abc.txt
abcd
shanky@localhost:~> hexdump -C abc.txt
00000000  61 62 63 64 0a                                    |abcd.|
00000005
shanky@localhost:~> hexdump -c abc.txt
0000000   a   b   c   d  \n
0000005
shanky@localhost:~> hexdump -b abc.txt
0000000 141 142 143 144 012
0000005
shanky@localhost:~> hexdump -d abc.txt
0000000   25185   25699   00010
0000005
shanky@localhost:~> hexdump -x abc.txt
0000000    6261    6463    000a
0000005

shanky@localhost:~> hexdump abc.txt
0000000 6261 6463 000a
0000005

For each input file, hexdump 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.

 
 

Category: Open System-Linux | Views: 1731 | Added by: shanky | Tags: hexdump command in linux, hexdump, hexdump command in unix, hexdump unix, hexdump command with example, hexdump linux | Rating: 0.0/0

Related blogs


You may also like to see:


[2014-10-26][Open System-Linux]
XMLLINT command in linux : a validating XML parser
[2014-10-06][Open System-Linux]
Time command in Linux to give resource usage
[2014-03-13][Open System-Linux]
crontab: A command in linux to automatically start/repeat a process at certian time and interval
[2014-05-22][Open System-Linux]
Archiving and compression of files in Linux
[2015-08-18][Open System-Linux]
How to open a PDF file or a Postscript file in Linux - Evince Document viewer?

Total comments: 0
ComForm">
avatar