Javatpoint Logo
Javatpoint Logo

Xxd Linux

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.

Syntax

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.

  • Display the command version and help
  • Establish hex dump
  • Transform a hex dump into binary

Xxd options

The xxd command behaves as if -c16 (16 octs/row) were mentioned if display switches are not specified.

Option Description
-autoskip, a Toggle autoskip: One '*' substitutes null-lines.
-bits, b Instead of hex dump, switch to binary digits. This option can write octal as eight digits "0"s and "1"s rather than a common hex dump. All lines are followed by an EBCDIC or ASCII representation and preceded by a hexadecimal line number. The -i, -p, and -r command line options don't work using this mode.
-cols cols, c cols Format octets/lines. Default 16. Max 256. No max for -ps. 0 results in a single output line with -ps.
-capitalize, C Capitalize variable titles in C contain file style, with -i.
-EBCDIC, E Modify the character encoding from ASCII-EBCDIC in the right column. It doesn't modify the hexadecimal representation.
-e In little-endian byte sequence, it considers byte groups as words. It only uses on the hex dump while leaving the EBCDIC or ASCII representation unchanged.
-groupsize bytes, g bytes Isolate the output of all bytes using whitespace.
-help, h Display a summary of commands and then exit. Hex dumping is not implemented.
-include, i Result in C contains the file style. A fully static array definition is specified unless the xxd command reads through stdin.
-len len, I len Stop after specifying octets.
o offset Add to the specified file position.
-plain, -postscript, -ps, p Result in continuous postscript style of hex dump. Also called plain hex dump style.
-revert, r Convert hex dump to binary.
seek offset Revert with <offset> included into file positions detected in hex dump when applied after -r.
u Lowercase is the default. Apply uppercase hex letters.
-version, v Display version string.

Exit status

The xxd command contains the below return codes:

0 No errors
-1 Doesn't support the operation
1 Error during parsing options
2 Errors with input file
3 Errors with the output file
4,5 Seek position is unavailable

Examples

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.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA