How To Compress And Extract Files Via SSH

When running a blog in a VPS, Dedicated Server or Cloud Server, you will need to upload and/or download something for installation or backup.

And it will make the upload or download process more fast that if you compress the files or folders first and extract them when the process is completed.

So, how to compress and extract files in a remote server? You can log in your server via SSH and check out the following command lines:

I. How to compress files or folders via SSH

For different compressed formats, you need to use different command lines:

1. Zip

To compress a file or folder to a zip file:

zip -r file.zip file

2. Bz2

To compress a file (ONLY) to a bz2 file:

Bzip2 -zk file

3. Gz

To compress a file (ONLY) to a gz file:

gzip -c file > file.gz

By the way, you need to change the above "file" to the file name with extension (if any) you want to compress, while you can replace the following "xxx" with any keywords:

4. Tar

To compress one file or folder to a tar file:

tar -cvf xxx.tar file

To compress multiple files and/or folders to a tar file:

tar -cvf xxx.tar file1 file2 folder1 folder2 ...

5. Tar.bz2

To compress one file or folder to a tar.bz2 file:

tar -cvjf xxx.tar.bz2 file

To compress multiple files and/or folders to a tar.bz2 file:

tar -cvjf xxx.tar.bz2 file1 file2 folder1 folder2 ...

6. Tar.gz

To compress one file or folder to a tar.gz file:

tar -cvzf xxx.tar.gz file

To compress multiple files and/or folders to a tar.gz file:

tar -cvzf xxx.tar.gz file1 file2 folder1 folder2 ...

II. How to extract file via SSH

To extract a file will be easier, since you don't need to worry about folders:

1. Zip

To extract a zip file:

unzip file.zip

2. Bz2

To extract a bz2 file:

bunzip2 file.bz2

3. Gz

To extract a gz file:

gzip -d file.gz

4. Tar

To extract a tar file:

tar -xvf file.tar

5. Tar.bz2

To extract a tar.bz2 file:

tar -xvjf file.tar.bz2

6. Tar.gz

To extract a tar.gz file:

tar -xvzf file.tar.gz

By the way, you need to replace the above "file"s of the compressed files with the real file names.

Bonus:

Besides remote servers, the above command lines are also available for a Mac OS computer with the Terminal application.

This entry was posted in Other Free Nuts and tagged , . Bookmark the permalink. Both comments and trackbacks are currently closed.

2 Comments

  1. twimagic
    Posted December 4, 2012 at 12:25 am | Permalink

    I use http://2zip.org It extracts 7z, bar, bz2, bzip2, gz, gzip, jar, rar, tar, tbz, tgz, war, xz, z, zar, zip

  2. ianxzone
    Posted April 4, 2014 at 6:17 pm | Permalink

    thx brother :) helpfull :)