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
echo "hello world foo bar fiz" | xxd
It will produce a hexdump of the string "hello world foo bar fiz"
echo "hello world foo bar fiz" | xxd -E
Change the character encoding in the right hand column from ASCII to EBCDIC
echo "hello world foo bar fiz" | xxd -b
Will give binary representation instead of hexdump
echo "hello world foo bar fiz" | xxd -i
To output the hexdump in C include format
echo "hello world foo bar fiz" | xxd -l 12
It will display the hexdump of the first 12 bytes of the input string "hello world foo bar fiz"
xxd -s 0x10 xxd.txt
Seeking an offset
xxd -s -16 xxd.txt
Seeking at offset from the end of the file
xxd -c 3 -g 3 file.txt
To display a n bytes of hexdump in 3 columns with a group of 3 octets per row from file.txt
xxd -s 0xa -l 50 -b file.txt
Seek at 10th byte(in hex) in file.txt and display only 50 bytes
xxd -r -p file.txt
To read plain hexadecimal dumps
Last updated
Was this helpful?