How to Extract or Create Archives via SSH

In most cases, web-based file managers have certain limitations when it comes to file extraction. Or maybe you are using a VPS without any management panels at all, thus extracting archives will require you to connect via SSH and execute a certain command based on the archive type. The most common types of archives are .tar; .tar.gz and .zip, each having its own commands used for extraction or compression.

Extracting archives via SSH

First of all, you will need to navigate to the directory where your archive is located. For example, if your archive is located in public_html/files directory, the following command will do the trick:

cd public_html/files

How to extract .tar.gz

The following command will allow you to extract the contents of a .tar.gz archive:

tar -zxvf ArchiveName.tar.gz

You will see the visual output of all the files being extracted and will be able to execute commands again once the process finishes.


How to extract .tar

This type of compressed file can be extracted with the following command:

tar -xvf ArchiveName.tar

It will display the visual output of the process and will be completed once you are able to type commands again.


How to extract .zip

This command will take care of .zip file decompression:


Once the process ends, commands will become executable again.


Creating archives via SSH

Now that we know how to extract all these archive types, we will also learn how to compress your files into any desired format.

How to create .tar.gz

The below-shown method will allow you to compress selected files into an archive:

tar -zcf NewArchive.tar.gz yourfile1.php yourfile2.php yourfile3.txt

If you intend to compress an entire directory, this will also do the trick:

tar -zcf NewArchive.tar.gz DirectoryName

As a rule of thumb, the archive generation finishes once commands become executable again in your terminal window.


How to create .tar

The syntax for creating .tar archives is very similar:

tar -zcf archive-name.tar.gz filename1.php filename2.php filename3.php

If you want to archive a directory, simply write the directory name instead of listing the files.

tar -zcf archive-name.tar.gz DirectoryName

Once you are able to type in a command again, it means that your archive has been created.


How to create .zip

This type of archive is even easier to create. The syntax is as follows:

zip filename1.php filename2.php filename3.php

Compression of directories uses the same syntax as well:

zip archive-name DirectoryName

The screen will display a progress output and once it finishes it will allow you to write commands again.



Congratulations! By following this simple tutorial you now know how to create and extract .tar.gz; .tar; .zip archives using SSH.

About the author

Gediminas B.

Gediminas is a passionate content writer and SEO geek at Hostinger. He started his journey at customer support and aims to use his gathered knowledge to create the most epic content the world has ever seen. From WordPress to server management, there's no topic he can't cover! He also likes cats.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Exclusive Content

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!

More in SSH
SSH tutorial How Does SSH Work
How does SSH Work