How to extract files and create archives via SSH

BillEssley

Well-known member
Registered
Joined
Feb 19, 2013
Messages
358
Points
28
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:
Older Threads
Newer Threads
Replies
8
Views
5,516
Replies
14
Views
3,758
Replies
6
Views
5,845
Replies
1
Views
2,408
Replies
0
Views
1,628
Latest Threads
Replies
1
Views
19
Replies
0
Views
171
Replies
1
Views
37
Replies
2
Views
80
Recommended Threads
Replies
6
Views
1,954
wcq
Replies
14
Views
7,523

Latest postsNew threads

Latest Hosting OffersNew Reviews

Sponsors

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