How to unzip a ZIP File in Terminal Using SSH
3 mins read

How to unzip a ZIP File in Terminal Using SSH

Description :

Restoring a backup from a ZIP file – like the ones generated by our downloadable backup feature – can sometimes be a lengthy process.

If you unzip a ZIP file locally on your computer before uploading the backup with SFTP, you’ll likely run into a bottleneck because SFTP can only transfer a limited number of files concurrently.

There is a faster method that can reduce the backup restore time significantly.

Instead of unzipping a ZIP file locally and uploading the unzipped folder, it’s often faster to upload a ZIP file to the server before unzipping it.

In this post, we can see how to unzip a file uploaded to a server using SSH.

Step 1 – Log In to Your Server with SSH

First step is to log in to your server with SSH

When logging in to your server with SSH, there are two authentication methods – password and public key authentication. The password authentication method uses a plain text password.

Public key authentication is widely regarded as a more secure alternative to password authentication.

The public key authentication method requires you to generate a key pair – public key and private key.

The public key is uploaded to the server, while the private key is stored locally on your computer. During the SSH login process, the cryptographic link between the two keys is verified to authenticate the user.

ssh username@ip-address -p port

Step 2 – Install the Unzip Package (Optional)

In some Linux distributions, the unzip package is not installed by default.

If you are managing a server that does not have the unzip package installed, you can use the following command to install it – note that sudo level permissions are required.

Ubuntu and Debian

sudo apt install unzip

CentOS and Fedora

sudo yum install unzip

Step 3 – Unzip the ZIP File Using Terminal

The next step is to navigate to the ZIP file and unzip it.

To navigate to the correct folder, we can use the cd command, as shown below.

cd directory

We uploaded the backup.zip file to the ~/private directory, so we’ll use the command below.

cd ~/private

Notice how our Terminal prompt shows the ~/private directory now.

We can use the ls command to list the files and folders in the current directory.

There are two ways to unzip a ZIP file. You can either unzip it to the current directory or a different directory.

To unzip the file to the current directory, use the command below.

unzip your-file.zip

To unzip the file to a different directory, use this command instead.

unzip your-file.zip -d directory

For the backup.zip file, we want to unzip it to our ~/public folder, which can be done with the command below.

unzip backup.zip -d ~/public

After running the unzip command, you should see a series of lines that start with “inflating”. This indicates that the unzip process was started successfully.

After the unzip process is finished, navigate to the destination directory with the cd command, and list out the files with the ls command to verify the unzipped files are in the right place.

If you would like to remove the original ZIP file after unzipping it, you can use the rm command like this.

rm /path/to/your-file.zip

In general, if you are dealing with a ZIP file that is over 50 MB in size, unzipping it on the server instead of locally on your computer will usually be faster. But there’s more to unzipping ZIP files as using SSH and Terminal is useful for a number of use cases beyond restoring backups.

Leave a Reply

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