How To Use Linux Xxd Command Tutorial For Hex and Binary Operations With Example? – POFTUT

How To Use Linux Xxd Command Tutorial For Hex and Binary Operations With Example?


Linux provides a lot of tools for hexadecimal and binary manipulation. Xxd is one of the most popular tool. Xxd is generally used to create hex dump of the given file or standard input.

Help

We can list help information about xxd command with the -h option.

$ xxd -h
Help
Help

Syntax

We will use following syntax for xxd command.

xxd [options] [infile [outfile]]

Dump to Hexadecimal

A file can be dumped into hexadecimal format just providing the file name. We will dump the file named Makefile in this example.

$ xxd Makefile
Dump to Hexadecimal
Dump to Hexadecimal

Dump From Commands Line or Standard Input

In previous example we have dumped from a file. xxd also supports dumping from standard input or console. We will provide - to specify input as standard input. At the end of the input we will stop input with CTRL+d shortcut.

$ xxd -
Dump From Commands Line or Standard Input
Dump From Commands Line or Standard Input

Set Start Index

While dumping from a file there may be a lot of data those we are not interested. So we simply skip them. xxd provides -s option to skip to the specified index. In this example we will skip first 5 lines and start from 6. line.

$ xxd -s 0x50 Makefile
Set Start Index
Set Start Index

Set End Index

Previous example we have set the start index , we can also set the end index to limit printing data range in a file. We will use -l option with the value. In this example we set end index as 30 .

$ xxd -l 100 Makefile
Set End Index
Set End Index

Set Column Length

xxd uses 16 as the default column length. This value can be changed with the -l option providing length value. In this example we will set column length as 12 .

$ xxd -c 12 Makefile
Set Column Length
Set Column Length

LEARN MORE  Linux Multipurpose Relay Socat Command Tutorial with Examples

1 thought on “How To Use Linux Xxd Command Tutorial For Hex and Binary Operations With Example?”

Leave a Comment