Chapter 11: File Compression and Archiving in WSL Ubuntu
Managing large files and directories efficiently often requires compression and archiving. Linux offers powerful tools like tar, gzip, zip, and unzip for these tasks.
In this chapter, you’ll learn how to compress, extract, and archive files in WSL Ubuntu for storage, transfer, or backup.
📦 The tar Command
📌 Create a Compressed Archive (.tar.gz)
tar -czvf archive-name.tar.gz folder-name/
-c– Create archive-z– Compress with gzip-v– Verbose (show progress)-f– Specify filename
📌 Extract a Compressed Archive
tar -xzvf archive-name.tar.gz
-x– Extract files-z– gzip compression-v– Verbose-f– File name
📌 Create an Uncompressed Archive (.tar)
tar -cvf archive-name.tar folder-name/
🗜️ Using gzip and gunzip
📌 Compress a Single File
gzip filename.txt
Creates filename.txt.gz and removes the original file.
📌 Decompress a File
gunzip filename.txt.gz
📂 Using zip and unzip
📌 Create a Zip Archive
zip -r archive-name.zip folder-name/
-r– Recursive (include subfolders)
📌 Extract a Zip Archive
unzip archive-name.zip
🧪 Practice Exercises
# Create a compressed tar.gz archive
tar -czvf project.tar.gz project/
# Extract it
tar -xzvf project.tar.gz
# Compress a file with gzip
gzip notes.txt
# Decompress it
gunzip notes.txt.gz
# Create a zip archive
zip -r project.zip project/
# Extract a zip file
unzip project.zip
✅ Summary
tar– Create and extract archives (.tar, .tar.gz)gzip / gunzip– Compress/decompress single fileszip / unzip– Compress directories and files into zip format- Use compression to save disk space and facilitate backups or file transfers
▶️ Coming Up Next
Chapter 12 – User and Permission Management in WSL Ubuntu
Learn how to create users, manage groups, and set file permissions for security in Linux.
