Command to Display Bzip2 File Header Information Ubuntu
This article explains how to inspect header information for bzip2 compressed files on the Ubuntu operating system. Unlike gzip, bzip2 does not store metadata such as original filenames or timestamps within its header. You will learn the specific commands used to verify file integrity, view block size settings, and examine raw header bytes directly from the terminal.
Using the File Command
The most direct way to read the header signature and basic
configuration of a bzip2 file is the file command. This
utility reads the magic numbers at the beginning of the file to identify
its type and compression settings.
Run the following command in your terminal:
file filename.bz2The output will confirm the file type and display the block size used
during compression, such as
bzip2 compressed data, block size = 900k. This information
is derived directly from the file header.
Using Bzip2 Verbose Test
To view detailed structural information about the compressed blocks within the file, use the bzip2 utility in verbose test mode. This does not decompress the file but reads through the header and block structures to verify integrity.
Execute this command:
bzip2 -tvv filename.bz2The -t flag tests integrity, while the -vv
flags enable verbose output. The terminal will display details for each
block, including start and end positions, bytes used, and CRC checks.
This provides the deepest level of internal header information available
without third-party tools.
Viewing Raw Header Bytes
For low-level inspection of the header bytes, you can use
hexdump. The bzip2 format starts with the magic characters
BZ. This method is useful for scripting or forensic
analysis.
Run the following command to see the first few lines of hex data:
hexdump -C filename.bz2 | headThe first line of output will show the ASCII representation of the
header, confirming the BZ signature followed by the
compression version. This confirms the file header is intact at the
binary level.