Compress and Extract files using SSH

By whgandalf | June 18, 2018

Sometimes we need handy lines to be able to compress or extract files in the command line using different extensions, here are some useful lines to achieve it:

Compress Files

Depending on the file extension and compression technology you have to use a different command line tool. The most commonly used however is the tar.gz format. An example of creating a file with this extension is:

    tar -zcf filename.tar.gz foldername/

You can also create zip files using:

    zip -r filename.zip foldername/

If you prefer tar.bz2 files you will have to use:

    tar -cvjSf filename.tar.bz2 foldername/

what about RAR files ? this is it:

    rar a -r -rr10 /path/to/filename.rar /path/to/file

You like 7zip huh? create files using:

    7z a filename.7z foldername/

Extract Files

To extract a ZIP file, you can use:

    unzip filename.zip

To extract a TAR file, you can use:

    tar -xvf filename.tar

To extract a TAR.GZ file, you can use:

    tar -zxvf filename.tar.gz

To extract a RAR file, you can use:

    unrar x /media/data/homes-backup.rar homes-backup/

To extract a 7zip file, try this:

    7z e filename.7z


Not working? …

These tools will be available after you install the package depending on the operative system you are using, sometimes when you use Linux installers they come with everything ready, but if not you will get an error like this:

    sudo: unzip: command not found

Not to worry, Google how to install the tool and use it as we did above.

comments powered by Disqus