🐧
Linux

Compressing and Extracting Tar and Gzip Files

πŸ“… 19 October 2026 ✏️ 19 October 2026 ⏱ 5 min leestijd

Learn how to use tar and gzip to compress and extract files via SSH, including commands, examples, and common mistakes.

A tar.gz file is a folder or collection of files that has first been bundled (tar) and then compressed (gzip). On a Linux server, such as with web hosting using LiteSpeed, this is the standard way to move files efficiently, create backups, or keep a website export small. With a few simple commands via SSH, you can compress and extract any archive within seconds.

What is the difference between tar and gzip

Tar stands for “tape archive” and bundles multiple files and folders into one file, without compressing them. Gzip then compresses that bundled file, making it significantly smaller. The combination results in a .tar.gz file, also known as a “tarball”. You can also use tar on its own without compression, but for website files, database dumps, and backups, the compressed variant is almost always the better choice because you can upload and download faster.

FilesTar bundleGzip compresses.tar.gzarchive

Compressing files with tar and gzip

Log in via SSH to your server and go to the folder you want to archive. Use the following command to create a tar.gz file of an entire folder:

tar -czvf archivename.tar.gz /path/to/folder

The options used mean:

  • c – create, creates a new archive
  • z – uses gzip compression
  • v – verbose, shows which files are being processed
  • f – indicates that the next argument is the file name

If you only want to compress a few specific files instead of an entire folder, list them separately:

tar -czvf archive.tar.gz file1.txt file2.txt

πŸ’‘ Tip: Always exclude large log files or temporary cache files with the option --exclude="*.log", so your archive stays more compact and organized.

Extracting archives

To extract a tar.gz file again, use almost the same command, but with the option x (extract) instead of c:

tar -xzvf archivename.tar.gz

By default, this command extracts the archive into the current folder. If you want to extract it to a different location, add the option -C followed by the target path:

tar -xzvf archivename.tar.gz -C /path/to/targetfolder

If you only have a gzip file without tar, such as a .gz file from, for example, a database dump, simply use gunzip file.sql.gz to extract it.

1

Connect via SSH

Log in to your server with an SSH client and navigate to the correct folder.

2

Create the archive

Use tar -czvf to compress the desired files or folder.

3

Check the contents

Use tar -tzvf archive.tar.gz to view which files are in it, without extracting them.

4

Extract where needed

Use tar -xzvf to restore the archive to the desired location.

Common mistakes and solutions

A common mistake is mixing up the order of options, such as tar -cvzf instead of tar -czvf. In practice, the order of the individual letters usually works fine as long as f comes last, since the file name follows after it. Another pitfall is having too little disk space when extracting a large archive, causing the process to stop halfway. Check the available space beforehand with df -h.

It also happens that people accidentally include the full path in the archive, causing a whole series of folders to be created upon extraction. Therefore, first use cd to go to the correct folder before running the tar command, so that only relative paths end up in the archive. If you encounter file permission issues after extracting, you can restore them with chmod and chown. In Plesk, as used with Tandata web hosting, you can also extract archives via the browser-based file manager without using SSH.

If you get stuck managing files on your server or are unsure about the correct permissions and folder structure, check the other articles in the knowledge base for more explanation. If you’re considering switching to another provider with NVMe storage and 24/7 support, check out switching to Tandata.

Frequently asked questions

What is the difference between .tar and .tar.gz?

A .tar file is only bundled, without compression. A .tar.gz file is additionally compressed with gzip, making it much smaller in file size.

Can I extract a tar.gz file without SSH?

Yes, in Plesk you can upload and extract archives via the file manager with just a few clicks, without needing any command-line knowledge.

Why does extracting a large archive take a long time?

This depends on the number of files, the compression ratio, and the server load. Many small files often take longer than one large file of the same total size.

Can I add a password to a tar.gz file?

Tar and gzip themselves do not support password protection. Use additional tools such as gpg to encrypt the archive after compressing it.

Does tar also work with symbolic links?

Yes, by default tar includes the link itself. If you want to include the content the link points to, use the -h option when creating the archive.

Conclusion

With tar and gzip, you can quickly and reliably compress and archive files via SSH or the Plesk file manager. Remember -czvf for compressing and -xzvf for extracting, make sure there’s enough disk space, and navigate to the correct folder first to avoid messy archives.

View web hosting β†’

Was dit artikel nuttig?