Compression and Extraction Commands in Linux: Tar, Gzip, Bzip2, Xz, Zip, Unzip

VPTS Team Content has been moderated
Published date:7/5/2025 Update:7/5/2025 Views:174 Reviews: 5.0/5203reviews
VPTS on

On Windows operating systems, users often choose software like WinRAR or 7-Zip to compress and extract data with an intuitive, easy-to-use graphical interface....

On Windows operating systems, users often choose software like WinRAR or 7-Zip to compress and extract data with an intuitive, easy-to-use graphical interface. However, in Linux environments, especially on servers running CentOS, these operations are mostly performed via command line to ensure flexibility and efficiency in system administration.

In the article below,VPTSwill guide you on how to use the most common compression and extraction commands in Linux, such as:tar, gzip, bzip2, xz, zip, andunzip. These are indispensable tools to help you manage data, back up, and transfer files quickly and accurately in a professional server environment.

linux

What is file extraction?

Decompression is the process of opening or recovering data from a previously compressed file.

1. Some Notes Before Use

Some compression tools might not be pre-installed. Use the following command to install them:

Copy
sudo yum install gzip bzip2 xz zip unzip -y

Commonly used parameters intar:

  • c: Create archive file

  • x: Extract

  • v: Show detailed progress

  • f: Specify filename

  • z: Used with gzip

  • j: Used with bzip2

  • J: Used with xz

2. Guide to Compressing and Extracting by Format

Compress and extract with extension.tar

  • File compression command
Copy
tar -cvf archive.tar file1.txt file2.txt
  • Decompression command
Copy
tar -xvf archive.tar

Compress and extract with extension.gz (Gzip)

  • File compression command
Copy
gzip filename
  • Decompression command
Copy
gunzip filename.gz

Compress and extract with extension.bz2 (Bzip2)

  • File compression command
Copy
bzip2 filename
  • Decompression command
Copy
bunzip2 filename.bz2

Compress and extract with extension .xz

  • File compression command
Copy
tar -cJf archive.tar.xz file.txt
  • Decompression command
Copy
tar -xJf archive.tar.xz

Compress and extract with extension.zip

  • File compression command
Copy
zip -r archive.zip folder_or_file
  • Decompression command
Copy
unzip archive.zip

3. Conclusion

Archiving and extracting in Linux becomes simpler once you master the basic commands. These are critical operations in data backup, file transfer, and storage space optimization.

VPTSrecommends bookmarking the command table shared above for quick and efficient use whenever you need to work on Linux systems. With just a few short command lines, you can master professional file management right within your VPS environment!

VPTS – Comprehensive Digital Infrastructure Solutions Provider

VPTS is a digital infrastructure solution provider in Vietnam, serving deployment, operation, and data storage needs for individuals, developers, and enterprises. The service ecosystem includesVietnam VPS, International VPS, VPS Anti DDoS, Hosting cPanel, dedicated server, Rack rental, Proxy IPv4/IPv6, S3 MinIOandCloud Storage.

Besides providing infrastructure resources, VPTS also focuses on assisting customers with deployment, configuration, and practical troubleshooting. Content on the VPTS Blog is drawn from common scenarios in operating VPS, servers, and online systems, helping readers understand root causes and apply clear solutions.

VPTS – Stable infrastructure, flexible solutions, and continuous partnership throughout operations.

VPTS Team Contact Information