Comprehensive Guide to Archiving and Compression Tools: zip, tar, etc.
Table of Contents
- Introduction
- Installing Archiving and Compression Tools
- Using
zip - Using
tar - Using
gzip - Using
bzip2 - Using
xz - Summary of Commands
- Conclusion
Introduction
Archiving and compression are essential skills for efficiently managing files on a Unix-like operating system. Tools such aszip, tar, gzip, bzip2, and xz are commonly used for these purposes. This guide provides detailed instructions on how to install, set up, and use these tools.
Installing Archiving and Compression Tools
Most archiving and compression tools come pre-installed on Unix-like systems. However, if they are not available, you can install them using your package manager.Ubuntu/Debian
CentOS/RHEL
Fedora
Using zip
Creating a Zip Archive
To create a zip archive, use the following command:Extracting a Zip Archive
To extract a zip archive, use:Listing Contents of a Zip Archive
To list the contents of a zip archive without extracting:Adding Files to an Existing Zip Archive
To add files to an existing zip archive:Using tar
Creating a tar Archive
To create a tar archive, use the following command:Extracting a tar Archive
To extract a tar archive, use:Listing Contents of a tar Archive
To list the contents of a tar archive without extracting:Creating a Compressed tar Archive with gzip
To create a tar archive compressed with gzip:Extracting a Compressed tar Archive with gzip
To extract a tar archive compressed with gzip:Using gzip
Compressing a File
To compress a file with gzip:Decompressing a File
To decompress a file with gzip:Keeping the Original File After Compression
To compress a file and keep the original file:Using bzip2
Compressing a File
To compress a file with bzip2:Decompressing a File
To decompress a file with bzip2:Keeping the Original File After Compression
To compress a file and keep the original file:Using xz
Compressing a File
To compress a file with xz:Decompressing a File
To decompress a file with xz:Keeping the Original File After Compression
To compress a file and keep the original file:Summary of Commands
zip Commands
- Create:
zip archive_name.zip file1 file2 - Extract:
unzip archive_name.zip - List:
unzip -l archive_name.zip - Add:
zip archive_name.zip newfile1
tar Commands
- Create:
tar -cvf archive_name.tar file1 file2 - Extract:
tar -xvf archive_name.tar - List:
tar -tvf archive_name.tar - Create gzip:
tar -czvf archive_name.tar.gz file1 file2 - Extract gzip:
tar -xzvf archive_name.tar.gz
gzip Commands
- Compress:
gzip file1 - Decompress:
gunzip file1.gz - Compress and keep original:
gzip -k file1
bzip2 Commands
- Compress:
bzip2 file1 - Decompress:
bunzip2 file1.bz2 - Compress and keep original:
bzip2 -k file1
xz Commands
- Compress:
xz file1 - Decompress:
unxz file1.xz - Compress and keep original:
xz -k file1
