Tutorials

How to zip or unzip files and folders using command line on Ubuntu server

Introduction

Sometimes you might need to upload or download a folder or file to/from your server and the folder / file can be of any size. It can take a lot of time to upload a folder or file to the server. Also it is a lot faster to move one large compressed file rather than multiple number of small files. Also the FTP clients like FileZilla do not allow unzipping or zipping of files, but you can still do it via ssh(secure shell).

How to zip and unzip the files via Command line

Steps to zip the file or folder

Step 1 : Login to the server :

ssh username@ your_server_ip
Example : ssh alex@11.11.11.152

Step 2 : Install zip(incase you do not have). To install the zip, type the following command

apt-get install zip

Step 3 : Now to zip the folder or file enter the following command

zip -r example.zip originalfolder
Here example.zip will be the zipped file while “originalfolder” is the folder which you want to zip

This command will make the .zip file in the same folder where “original_folder” is present. But you can change the destination of the target folder where zip file will be created. To change the destination folder of .zip file while creating it just prepend the address where you want to create the .zip file

zip -r folder/add/here/example.zip original_folder

Note : Use -r in the command for the folder having more than one file or folder and do not use -r for single file. Use following command for single file

zip singlefile.zip original_file

Steps to unzip the .zip file

Step 1 : Login to the server via terminal

Step 2 : Install unzip(incase you do not have). To Install the unzip, type the following command

sudo apt-get install unzip

Step 3 : Navigate to the directory where .zip file, which you want to unzip, is present

Step 4 : Now type the following command to unzip the file

unzip default.zip
where default is the filename which you wish to unzip


Copyright © 2018 WPOven