Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a zip file using shell script?

I want to create a zip files based on the directory. But I need to make zip file from Result directory.

#!/bin/bash zip -r /home/admin/download.zip /home/admin/1/2/3/Results 
like image 318
javasundaram Avatar asked Oct 30 '14 06:10

javasundaram


People also ask

How do I zip a file in shell script?

The easiest way to zip a folder on Linux is to use the “zip” command with the “-r” option and specify the file of your archive as well as the folders to be added to your zip file. You can also specify multiple folders if you want to have multiple directories compressed in your zip file.


1 Answers

From your question, I understand that you want to zip the files in the "Results" directory without considering the directory "Results" itself when trying to zip.

If so, then use the below commands

#!/bin/bash cd /home/admin/1/2/3/Results zip -r /home/admin/download.zip ./* 

After this, the zip file would be created in the required location. Zip file is with only the files from the result directory, without the "Result" directory itself.

like image 97
Santosh A Avatar answered Oct 01 '22 14:10

Santosh A