How to pack and unpack an archive using SSH

Being a Web Developer or IT technician, you will undoubtedly come across the need to move large amounts of files from one machine to another, in a Web Developers case you may be moving projects from a development environment to a live environment or creating/restoring backups of projects. We all know from experience (only a few minutes of experience required) that FTP is extremely slow when it comes to transferring allot of files due to the nature of the protocol having to request and download each file/folder individually. So it becomes increasingly vital to be able to package up a project into one compressed file, download it and then upload that package to another location and unpacking it – this is not only a smarter approach to moving files as you are saving bandwidth, but because it is only one file you are moving between machines it is actually far faster. Below you can find useful copy + paste SSH functions that will make your life a whole lot better.  

Packing up the current directory

All you need to do is navigate to the directory you wish to package up into a tar.gz archive and run the following command, it will package up all files and sub folders in the current directory:

tar -cvzf packed.tar.gz .


Unpacking archive to current directory

All you need to do is upload the tar.gz archive to the folder you wish to unpack the files into, then in SSH navigate to that folder and run the following command:

tar xvfz packed.tar.gz .


Author: Dean Williams

Professional PHP Web Developer with expertise in OpenCart Web Development, WordPress Web Development, Bespoke Systems - also a seasoned Linux Server Administrator.

Leave a Reply

Your email address will not be published. Required fields are marked *