How to Compress and Extract Files using SSH

If you are using VPS or Dedicated Server in that you like to upload or download the files for backup, it is difficult to download using FTP. So here using SSH you can compress and download the file faster as much you can depend on your internet speed. Using SSH you can compress and extract the files or folders in the server.
If you looking to compress and extract files using remote server? Here you have the solution for that. First, you need to identify the exact archive type by seeing at the file extension. The most of users are use zip type (.zip) and other extensions are tar (.tar), Tar.bz2 (.tar.bz2), Tar+Gunzip (.tar.gz), Bzip (.bz2) and Rar (.rar).
Note: Here every archive type has its own command for compressing or extracting files that all are listed below.
Compress and Extract Zip Files using SSH.
Compress files and Folders in Zip extension
If you like to compress file or folder in zip format use the below command.
1 |
zip -r filename.zip file/folder-name |
Example:
1 |
zip -r backup.zip config.php |
Compress multiple files and Folders in Zip extension
If you like to compress multiple files/folders to a .zip file, use the below command.
1 |
zip -r filename.zip folder1 folder2 folder2 ... |
Example:
1 |
zip -r backup.zip wp-admin wp-content wp-includes ... |
Extract Zip extension files and Folders
If you like to extract file use the following command.
1 |
unzip filename.zip |
Example:
1 |
unzip backup.zip |
Compress and Extract Tar Files using SSH.
Compress files and Folders in Tar extension.
Use the following command to compress the file or folder to a tar file format.
1 |
tar -cvf filename.tar file/folder-name |
Example:
1 |
tar -cvf backup.tar config.php |
Compress multiple files and Folders in Tar extension
If you like to compress multiple files/folders to a .tar file, use the below command.
1 |
tar -cvf filename.tar folder1 folder2 folder2 ... |
Example:
1 |
tar -cvf backup.zip wp-admin wp-content wp-includes ... |
Extract Tar extension files and Folders
If you like to extract file use the following command.
1 |
tar -xvf filename.tar |
Example:
1 |
tar -xvf backup.tar |
Compress and Extract Tar.bz2 Files using SSH.
Compress files and Folders in Tar.bz2 extension.
Use the following command to compress the file or folder to a tar.bz2 file format.
1 |
tar -cvjf filename.tar.bz2 file/folder-name |
Example:
1 |
tar -cvjf backup.tar.bz2 config.php |
Compress multiple files and Folders in Tar.bz2 extension
If you like to compress multiple files/folders to a tar.bz2 file, use the below command.
1 |
tar -cvjf filename.tar.bz2 folder1 folder2 folder3 ... |
Example:
1 |
tar -cvjf backup.tar.bz2 wp-admin wp-content wp-includes ... |
Extract Tar.bz2 extension files and Folders
If you like to extract file use the following command.
1 |
tar -xvf filename.tar |
Example:
1 |
tar -xvjf backup.tar.bz2 |
Compress and Extract Tar.gz Files using SSH.
Compress files and Folders in Tar.gz extension.
Use the following command to compress the file or folder to a tar.gz file format.
1 |
tar -cvzf filename.tar.gz file/folder-name |
Example:
1 |
tar -cvzf backup.tar.gz config.php |
Compress multiple files and Folders in Tar.gz extension
If you like to compress multiple files/folders to a tar.gz file, use the below command.
1 |
tar -cvzf filename.tar.gz folder1 folder2 folder3 ... |
Example:
1 |
tar -cvzf backup.tar.gz wp-admin wp-content wp-includes ... |
Extract Tar.gz extension files and Folders
If you like to extract file use the following command.
1 |
tar -xvzf filename.tar.gz |
Example:
1 |
tar -xvzf backup.tar.gz |
Compress and Extract Bzip Files using SSH.
Compress files and Folders in Bzip extension.
Use the following command to compress the file or folder to a bz2 file format.
1 |
Bzip2 -zk file/folder-name |
Example:
1 |
Bzip2 -zk config.php |
Extract Bzip extension files and Folders
If you like to extract file use the following command.
1 |
bunzip2 filename.bz2 |
Example:
1 |
bunzip2 backup.bz2 |
Mraj
Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts. If you have any questions let me drop an email with the article name to the following email id: [email protected]