Don’t miss the New Year’s Sale deals!
search
In this article

SSH compression: how to zip and unzip via SSH

SSH compression: how to zip and unzip via SSH

In this article, we are going to show you how to zip and unzip via SSH. You will learn about the compression and extraction methods on your server for better archive management.

Download ultimate SSH commands cheat sheet

Zip and Unzip via SSH: Everything You Need to Know

Compressing and extracting files is not only common on desktop computers. You may need to do the same things on your VPS. Zipping and unzipping files make it easy for you to download and move data around.

To perform these actions,  you need to run a specific command through the SSH (Secure Shell) protocol on your server.

This process requires you to use an SSH client — like PuTTY (Windows) or terminal shell (macOS & Linux) — to access your server. If Hostinger is your VPS provider, you can get the login credential in the Servers tab of the hPanel. You don’t know how to establish the connection? Our SSH tutorial can help you.

Without further delay, let’s learn how to zip and unzip a file in Linux via SSH.

How to Compress and Extract Different Archive Formats

We will cover the compression and extraction method of popular archive formats, including .tar.gz, .tar, .zip, and .rar.

.tar.gz Files

  1. You can use the command below to compress several files into a .tar.gz archive:
    tar -czvf archive-name.tar.gz your-file.text your-file.php your-file.html

    If you intend to compress an entire directory, use the following method.Don’t forget to replace “archive-name” and “your-file” with your actual file names and directories. Also, you are not limited to file formats that are used in this example.

    tar -czvf archive-name.tar.gz /Directory-Name
  2. To extract a .tar.gz archive, enter:
    tar -zxvf archive-name.tar.gz

.tar Files

  1. The syntax for creating .tar archives is as follows:
    tar -zcf archive-name.tar your-file.php your-file.php your-file.html

    Enter the following line to move the whole directory to a .tar file:

    tar -zcf archive-name.tar.gz /directory-name
  2. You can extract the previous archive by typing this command:
    tar -xvf archive-name.tar

.zip Files

  1. For .zip files, we’ll be using the zip command instead of tar. Here’s how you create an archive in this format:
    zip archive-name.zip your-file.php your-file.php your-file.php

    In order to compress a directory, use this syntax:

    zip -r filename.zip foldername/
  2. This command is used for .zip file decompression:
    unzip archive-name.zip

.rar Files

  1. The command for RAR compression is rar, as shown below:
    rar a archive-name.rar your-file.txt your-file.php your-file.html

    To put an entire folder into one .rar archive, you should use this syntax.

    rar a archive-name.rar /directory-name
  2. This is how you extract the .rar archive.
    unrar x archive-name.rar

After you decompress any archive format, the script will output a list of all the extracted files, like this:

The result after you unzip via SSH
Hostinger web hosting banner

Conclusion

Congratulations! Now you know how to zip and unzip through SSH for easier file management.

There are many archive formats available, and you can choose the ones that suit you best. Keep in mind that .tar and .tar.gz formats use a similar command (tar) while .zip and .rar archives have their own (zip and rar respectively).

Therefore, make sure that you enter the appropriate line for the desired file format.

Let us know in the comments if you have any questions!

Author
The author

Domantas G.

Domantas leads the content and SEO teams forward with fresh ideas and out of the box approaches. Armed with extensive SEO and marketing knowledge, he aims to spread the word of Hostinger to every corner of the world. During his free time, Domantas likes to hone his web development skills and travel to exotic places.

What our customers say

Comments

Author
Ashutosh Pandey

September 12 2020

How can I compress over 40 GB data on server?

Author
Pablo

October 04 2021

How does one unzip a file larger than 256MB if they are on a shared hosting - single plan? It seems like there is no option because SSH is out of the question since we aren't even allowed to use that and Import Website feature is only limited to 256 MB and can only unzip to the public_html location (I can always move it in FTP client later anyway).

Author
Pablo

October 04 2021

Never mind, I can use the file manager for that job. I guess that should work then. I still wonder why SSH cannot be offered to those with a shared single plan unless it's just meant as a way to differentiate between the low cost plans with higher tier plans.

Leave a reply

Please fill the required fields.Please accept the privacy checkbox.Please fill the required fields and accept the privacy checkbox.

Thank you! Your comment has been successfully submitted. It will be approved within the next 24 hours.