• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

xxd command – Expressed in hexadecimal form

by admin

Similar to od, xxd produces a hexadecimal or binary dump of a file in several different formats. It can also do the reverse, converting from its hex dump format back into the original data. For example, here’s a hex dump of binary file /usr/bin/who:

$ xxd /usr/bin/who
0000000: 7f45 4c46 0101 0100 0000 ... 0000 .ELF............
0000010: 0200 0300 0100 0000 a08c ... 0000 ............4...
0000020: 6824 0000 0000 0000 3400 ... 2800 h$......4. ...(.
0000030: 1900 1800 0600 0000 3400 ... 0408 ........4...4...
...

The left column indicates the file offset of the row, the next eight columns contain the data, and the final column displays the printable characters in the row, if any. By default, xxd outputs three columns: file offsets, the data in hex, and the data as text (printable characters only).

Syntax:

# xxd [parameter]

Common parameters

Some of the commonly used parameters:

Command Option Description
-l N Display only the first N bytes. (Default displays the entire file,)
-s N Skip the first N bytes of the file.
-s -N Begin N bytes from the end of the file. (There is also a +N syntax for more advanced skipping through standard input; see the manpage.)
-c N Display N bytes per row. (Default=16)
-g N Group each row of bytes into sequences of N bytes, separated by whitespace, like od -s. (Default=2)
-b Display the output in binary instead of hexadecimal.
-u Display the output in uppercase hexadecimal instead of lowercase.
-p Display the output as a plain hexdump, 60 contiguous bytes per line.
-r The reverse operation: convert from an xxd hex dump back into the original file format. Works with the default hexdump format and, if you add the -p option, the plain hexdump format.
-i Display the output as a C programming language data structure. When reading from a file, it produces an array of unsigned chars containing the data, and an unsigned int containing the array length. When reading from standard input, it produces only a comma-separated list of hex bytes.

xxd Command Examples

1. Use the -a parameter to automatically skip blanks, starting from 0x200, input file:

# xxd -a -s +0x200 geek.txt

2. Use the -a, -c parameters, automatically skip blanks, display 12 bytes per line, starting from 0x200, input file:

# xxd -a -c 12 -s +0x200 geek.txt

3. Use the -a, -c, and -g parameters to automatically skip blanks. Each line displays 12 bytes, one byte per line, and 512 bytes of content. Starting from 0x200, input file:

# xxd -a -c 12 -g 1 -l 512 -s +0x200 geek.txt

Filed Under: Linux

Some more articles you might also be interested in …

  1. make: Nothing to be done for `default’
  2. do-release-upgrade Command Examples in Linux
  3. Honeypot Tutorials – Modes and Working of Honeypot
  4. ark: command not found
  5. mailstat Command Examples in Linux
  6. dracut: command not found
  7. CentOS / RHEL : How to change the UUID of the filesystem
  8. Understanding the /proc/mounts, /etc/mtab and /proc/partitions files
  9. Understanding the /etc/skel directory in Linux
  10. How to send Audit Logs to Remote Rsyslog Server in CentOS/RHEL 6,7

You May Also Like

Primary Sidebar

Recent Posts

  • aws ec2: CLI for AWS EC2 (Command Examples)
  • aws cur – Create, query, and delete AWS usage report definitions (Command Examples)
  • aws configure – Manage configuration for the AWS CLI (Command Examples)
  • aws cognito-idp: Manage Amazon Cognito user pool and its users and groups using the CLI

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright