xxd
xxd linux command cheatsheet by Thamizhiniyan C S
Introduction
xxd creates a hex dump of a given file or standard input. It can also convert a hex dump back to its original binary form.
Syntax
xxd -h[elp]
xxd [options] [infile [outfile]]
xxd -r[evert] [options] [infile [outfile]]
Important Flags
-b
will give binary representation instead of hexdump
-E
Change the character encoding in the right hand column from ASCII to EBCDIC (Feel free to leave this flag if you don't know about BCD notation)
-c
int Sets the number of bytes to be represented in one row. (i.e. setting the column size in bytes; Default to 16)
-g
This flag is to set how many bytes/octets should be in a group i.e. separated by a whitespace (default to 2 bytes; Set -g0 if no space is needed).
-i
To output the hexdump in C include format ('0xff' integers)
-l
Specify the length of output(if the string is bigger than the length specified, hex of the rest of the string will not be printed)
-p
Second most used flag; Converts the string passed into plain hexdump style(continuous string of hex bytes)
-r
Most used flag, will revert the hexdump to binary(Interpreted as plain text).
-u
Use uppercase hex letters(default is lower case)
-s
seek at offset (will discuss this in a little brief in examples)
Examples
It will produce a hexdump of the string "hello world foo bar fiz"
Change the character encoding in the right hand column from ASCII to EBCDIC
Will give binary representation instead of hexdump
To output the hexdump in C include format
It will display the hexdump of the first 12 bytes of the input string "hello world foo bar fiz"
Seeking an offset
Seeking at offset from the end of the file
To display a n bytes of hexdump in 3 columns with a group of 3 octets per row from file.txt
Seek at 10th byte(in hex) in file.txt and display only 50 bytes
To read plain hexadecimal dumps
Last updated
Was this helpful?