How to extract files and create archives via SSH

BillEssley

Well-known member
Joined
Feb 19, 2013
Messages
288
Best answers
2
Ratings
25
Points
28
#1
In some cases, the file managers in your web hosting control panel have certain limitations in extracting files. Or maybe you are using VPS without a management tool. Therefore, the best way to decompress is to use a connection over SSH to execute commands related to packaging and decompression. Common compressed files will be in .tar format; .tar.gz and .zip, each command will have its own command to extract or compress the file.

How to extract files using SSH
First, you will need to move to the directory where the existing package is located. For example, if the archive file is located in the public_html/your_folder, the following command will move you to this directory:

Code:
cd public_html/your_folder
Extract the .tar.gz file
The following command will help you extract the content of a .tar.gz file:

Code:
tar -zxvf ArchiveName.tar.gz
How to extract the .tar file
The following command will help you extract a .tar file:

Code:
tar -xvf ArchiveName.tar
How to extract .zip
This command will help you extract the .zip file:

Code:
unzip ArchiveName.zip
Create archive files via SSH
Now that you know how to extract archive files, we will continue to learn how to compress multiple files into one desired format.

How to create a .tar.gz file
The following command will help you to compile several compressed files into a .tar.gz file:

Code:
tar -zcf NewArchive.tar.gz yourfile1.php yourfile2.php yourfile3.txt
If you want to compress a directory, use the following command:

Code:
tar -zcf NewArchive.tar.gz DirectoryName
How to create a .tar file
The .tar file structure is similar to the following:

Code:
tar -zcf archive-filename.txt
If you want to create a folder archive, just type the name of the directory instead of listing the whole file:

Code:
tar -zcf archive-name.tar.gz DirectoryName
How to create a .zip file
This file type is also easier to create, the command structure as follows:

Code:
zip archive-name.zip filename1.php filename2.php filename3.php
Compress directories use the same syntax as such:

Code:
zip archive-name -r DirectoryName
Summary
By following simple instructions above, you already knew how to extract files and create a .tar.gz archive file; .tar; .zip using SSH.

Good luck!
 
Last edited:

BillEssley

Well-known member
Joined
Feb 19, 2013
Messages
288
Best answers
2
Ratings
25
Points
28
#4
For the last command with zip, it will not work without -r before the folder name (it will just zip an empty folder).
Bash:
 zip archive-name -r directory
You are right on this, I will update my post with latest zip command.

Great post, thanks for sharing. :)
You are welcome!
I also look forward to reading your great posts.
 
Newer Threads
Replies
8
Views
433
Replies
14
Views
517
Replies
6
Views
593
Replies
1
Views
161
Replies
0
Views
156
Latest Threads
Recommended Threads

Latest postsNew threads

Latest Hosting OffersNew Reviews

Sponsors

Latest Blog ArticlesMost Viewed Threads

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top