Zip and Unzip Files Using Tar on Linux (Tutorial)

Zip and Unzip Files Using Tar on Linux (Tutorial)

Sometimes it's hard to remember commands. Bookmark this page or just save this meme for reference.

1. How to ZIP (Compress) Files and Folders

tar czf archive-name.tar.gz folder-name

Breakdown

  • c — create a new archive
  • z — compress using gzip
  • f — specify the filename (must come last before the archive name)

2. How to UNZIP (Extract) Files

tar xzf archive-name.tar.gz

Breakdown

  • x — extract files
  • z — decompress gzip
  • f — specify the filename

3. Extract to a Specific Folder

You can choose where to unpack:

tar xzf backup.tar.gz -C /path/to/destination/

4. View Contents Without Extracting

See what’s inside:

tar tzf backup.tar.gz