Home > Text Processing & Search > xxd

xxd: Dump binary data in binary format

`xxd` is a utility that dumps the content of files or standard input in hexadecimal or binary format. In particular, the `-b` option allows for detailed analysis of data as binary bit sequences, making it useful for understanding the internal structure of files or for debugging.

Overview

`xxd` generates a hexadecimal or binary representation of given data. The `-b` option displays each byte as an 8-bit binary sequence, making it an essential tool for low-level data analysis. It is primarily used when analyzing binary files, network packets, memory dumps, and more.

Key Features

  • Displays binary data as binary bit sequences
  • Processes files or standard input
  • Can convert dumped content back to binary
  • Useful for data analysis and debugging

Key Options

The `xxd` command allows control over the output format through various options. The `-b` option, in particular, enables binary output, and can be combined with other options for more granular analysis.

Output Format and Control

Generated command:

Try combining the commands.

Description:

`xxd` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

`xxd -b` can be used to analyze binary data in various situations. Learn the basic usage through the following examples.

Dump a string in binary format

echo "Hello" | xxd -b

Takes the string 'Hello' as standard input and outputs it in binary format.

Dump a portion of a file in binary format (first 16 bytes)

head -c 16 /bin/ls | xxd -b

Dumps the first 16 bytes of the `/bin/ls` file in binary format.

Dump in binary format with 4 bytes per line

echo "Linux Command" | xxd -b -c 4

Outputs the string 'Linux Command' in binary format, with 4 bytes per line.

Convert binary dump back to a string

echo "01001000 01100101 01101100 01101100 01101111" | xxd -r -b

Reverts a binary string to its original string using `xxd -r -b`.

Dump in binary format from a specific offset in a file

echo "0123456789ABCDEF" | xxd -b -s 4

Starts dumping the string '0123456789ABCDEF' in binary format from the 4th byte.

Tips & Precautions

Here are some tips and precautions for effectively using `xxd -b`.

Usage Tips

  • You can analyze data in real-time by piping the output of other commands to `xxd -b`.
  • You can use `grep` to find specific binary patterns (e.g., `xxd -b file | grep '01001000'`).
  • It is useful to combine the `-s` (offset) and `-l` (length) options when analyzing the header or specific sections of binary files.

Precautions

The output of `xxd -b` can be very long, so it is recommended to use it with pagination tools like `head`, `tail`, or `less`. Running `xxd -b` directly on large files can slow down your terminal or consume significant system resources.


Related commands

These are commands that are functionally similar or are commonly used together.



Same category commands