How to create a zip file using shell script?
72,014
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.
Related videos on Youtube
Author by
javasundaram
Updated on December 06, 2020Comments
-
javasundaram over 3 years
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
-
Fazlin over 9 yearsWhat is the problem/error you are facing? Please be elaborate when you ask question.
-
javasundaram over 9 years@user1984289 i like this structure download.zip | _ files (result directory files) but now download.zip | _home | _admin | _1 | _2 | _3 |_files (Result directories)
-
Ed Heal over 9 years@javasundaram - your comment makes no sense
-
javasundaram over 9 years@EdHeal i like this format man download.zip->file(Result directory) but now, download.zip->home/admin/1/2/3/file(Result directory)
-
-
Santosh A over 9 years@javasundaram Welcome
-
javasundaram over 9 years@Santhosh A i'm trying to implement same code in project it's not working.
-
Santosh A over 9 years@javasundaram I tried it myself on a folder, it is working. Check for any other possible issues
-
javasundaram over 9 years@Santhosh i tried this one cd $MCELL_GENERATION_BASE_DIR/$uniqueid/$scenario_name/BWSIM/ >> $DBG_FILE 2>&1 cp $SCRIPTS_EXE_BASE_DIR/$version/$SIM_EXE $MCELL_GENERATION_BASE_DIR/$uniqueid/$scenario_name/BWSIM/ cp $SCRIPTS_EXE_BASE_DIR/$version/$WRAP_EXE $MCELL_GENERATION_BASE_DIR/$uniqueid/$scenario_name/BWSIM/ cd $MCELL_GENERATION_BASE_DIR/$uniqueid/$scenario_name/BWSIM/Results/ zip -r $MCELL_GENERATION_BASE_DIR/$uniqueid/$scenario_name/BWSIM/dnldtopology.zip ./*
-
Santosh A over 9 yearsTry with only these two commands cd $MCELL_GENERATION_BASE_DIR/$uniqueid/$scenario_name/BWSIM/Results/ zip -r $MCELL_GENERATION_BASE_DIR/$uniqueid/$scenario_name/BWSIM/dnldtopology.zip ./*
-
javasundaram over 9 years@Santhosh A i need result directory files only make zip but it take outside result directory
-
Santosh A over 9 yearsLet us continue this discussion in chat.