Chapter 11: File Compression and Archiving in WSL Ubuntu

Chapter 11: File Compression and Archiving in WSL Ubuntu

AI Reading

Quick summary of this article

This chapter covers how to compress and archive files in WSL Ubuntu using common Linux tools. You can save disk space and make file transfers easier by combining files into archives with tar, or compressing them individually with gzip and zip. Each tool has simple commands for creating and extracting archives.

  • tar creates and extracts archives, often compressed with gzip (e.g., .tar.gz). Use tar -czvf to create and tar -xzvf to extract.
  • gzip compresses single files, replacing the original with a .gz version. Use gunzip to restore the original file.
  • zip compresses entire folders and files into a .zip archive, and unzip extracts them. The -r option includes subfolders.
  • Compression helps save disk space and is useful for backups or transferring files between systems.

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 files
  • zip / 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.

Leave a Reply

Your email address will not be published. Required fields are marked *