Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
The bzip2
command in Linux is a utility used to compress files using the Burrows-Wheeler block sorting text compression algorithm and Huffman coding. In this tutorial, we will discuss how to use the bzip2
command effectively, along with various options and examples.
Basic usage of the bzip2
command:
To compress a file using the bzip2
algorithm, use the bzip2
command followed by the name of the file you want to compress:
bzip2 file.txt
This command will compress the file.txt
and create a compressed file named file.txt.bz2
. The original file.txt
will be deleted after successful compression.
Keeping the original file:
If you want to keep the original file after compression, use the -k
or --keep
option:
bzip2 -k file.txt
This command will compress file.txt
into a file named file.txt.bz2
and retain the original file.txt
file.
Adjusting the compression level:
The bzip2
command allows you to adjust the compression level using an option in the form of -N
, where N is a number from 1 (fastest but least compression) to 9 (slowest but maximum compression). The default compression level is 9.
For example, to compress a file using the fastest compression level, you would run:
bzip2 -1 file.txt
Compressing multiple files:
You can compress multiple files simultaneously by providing multiple input file names:
bzip2 file1.txt file2.txt file3.txt
This command will compress file1.txt
, file2.txt
, and file3.txt
, creating compressed files named file1.txt.bz2
, file2.txt.bz2
, and file3.txt.bz2
, respectively. The original files will be deleted.
Verbose mode:
If you want to display additional information during the compression process, use the -v
or --verbose
option:
bzip2 -v file.txt
This command will compress file.txt
and display information such as the compression ratio and progress.
By following this tutorial, you should now have a good understanding of how to use the bzip2
command in Linux to compress files. With various options and the ability to handle multiple files, the bzip2
command is a powerful tool for managing compressed files in Linux. To decompress files compressed with the bzip2
algorithm, you can use the bunzip2
command or the bzip2
command with the -d
or --decompress
option.
How to use bzip2
command in Linux:
bzip2
command.bzip2 file
Compressing files with bzip2
in Linux:
bzip2
to compress a file and create a .bz2 archive.bzip2 file
Creating .bz2 archives with bzip2
:
bzip2
.bzip2 -c file > file.bz2
Recursive compression with bzip2
in Linux:
find /path/to/directory -type f -exec bzip2 {} \;
Checking compression ratio with bzip2
:
bzip2 -l file.bz2
Setting compression options in bzip2
:
bzip2 -9 file # Maximum compression
Compressing directories with bzip2
:
bzip2
.tar cjf archive.tar.bz2 directory
Comparing bzip2
and gzip
compression in Linux:
bzip2
and gzip
.bzip2 file gzip file