Introduction to xxd
Xxd makes a hex dump of a standard input or given file. Also, it can transform a hex dump into its real binary form. It permits the binary data transmission in the 'mail-safe' ASCII representation. However, it has the benefit of decoding into a standard output like uudecode(1) and uuencode(1). It can be used to implement binary file patching.
The xxd command shows a file as its ASCII representation and hexadecimal values and permits edits to that on Unix-like operating systems. Xxd was integrated in 1990 by Juergen Weigert.
The xxd program brings a standard input or file and results in a hex dump that utilizes only EBCDIC and ASCII characters. This final hex dump can easily be emailed and established at the destination. Also, it can take a formatted hex dump and transform it into binary form, permitting binary files to be patched and edited as text.
Below is the basic xxd command syntax.
Note: If a parameter is added with a lengthy option name, like -autoskip, a similar parameter can be described with the related short option, like -a.
The xxd command behaves as if -c16 (16 octs/row) were mentioned if display switches are not specified.
The xxd command contains the below return codes:
The below examples represent a few ways that the xxd command can be used.
Printing the initial 20 bytes of a file
The above commands will read the contents of file1, bring the initial 20 bytes, and then print those as a hex dump. The 1st command shows the length in decimal, the 2nd command shows the length in hexadecimal, and the 3rd command shows the length in octal.
Printing the last 20 bytes of a file
The above commands will read the contents of file1, jump to the file's end, seek backwards 20 bytes, and print through then forward as a hex dump. The 1st command shows the length in decimal, the 2nd command shows the length in hexadecimal, and the 3rd command shows the length in octal.
Printing the initial 5 file bytes as bits
The above commands will read the contents of file1, brings the initial 5 bytes, and then print those as binary dumps.