Archives in Linux
Zip and Unzip (Windows-Compatible)
Section titled “Zip and Unzip (Windows-Compatible)”Standard tools for creating .zip archives. Use these when you need to send files to someone on Windows or macOS.
zip -rp archive.zip folder/: Compresses a folder and all its contents (recursive) while preserving permissions (p).unzip archive.zip: Extracts everything into your current location.
TAR (The “Tape Archive”)
Section titled “TAR (The “Tape Archive”)”tar is the standard for Linux. It “bundles” many files into one single .tar file. It doesn’t compress by default unless you tell it to.
tar -cvf file.tar /path: Create (c) a file, Verbose (v) to see progress, and specify the Filename (f).tar -xvf file.tar: Extract (x) the contents.tar -tf file.tar: Table of contents (t) — see what’s inside without extracting.tar -cvzf file.tar.gz /path: Create and compress using Gzip (z) at the same time. This is the most common “daily life” command.
GZIP (The Compressor)
Section titled “GZIP (The Compressor)”Gzip is used to make a single file smaller.
Note: Gzip by itself doesn’t “bundle” multiple files; it just shrinks them.
gzip -c file1 > file.gz: Compressesfile1into a smaller.gzfile.gunzip file.gz: Decompresses it back to the original.zcat file.gz: Lets you read the text inside a compressed file without unzipping it first.zgrep "error" file.gz: Searches for text inside a compressed file instantly.
Daily Life Usage
Section titled “Daily Life Usage”| Goal | Command |
|---|---|
| Send files to a Windows user | zip -r data.zip folder/ |
| Backup a Linux folder (Smallest size) | tar -cvzf backup.tar.gz folder/ |
| See what’s in a .tar without extracting | tar -tf backup.tar |
| Read a compressed log file | zcat system.log.gz |
| Move a folder to another server | `tar -cf - dir1 |