Skip to content

Archives in Linux

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 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 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: Compresses file1 into a smaller .gz file.
  • 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.

GoalCommand
Send files to a Windows userzip -r data.zip folder/
Backup a Linux folder (Smallest size)tar -cvzf backup.tar.gz folder/
See what’s in a .tar without extractingtar -tf backup.tar
Read a compressed log filezcat system.log.gz
Move a folder to another server`tar -cf - dir1