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.

Share:
72,014

Related videos on Youtube

javasundaram
Author by

javasundaram

Updated on December 06, 2020

Comments

  • javasundaram
    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
      Fazlin over 9 years
      What is the problem/error you are facing? Please be elaborate when you ask question.
    • javasundaram
      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
      Ed Heal over 9 years
      @javasundaram - your comment makes no sense
    • javasundaram
      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
    Santosh A over 9 years
    @javasundaram Welcome
  • javasundaram
    javasundaram over 9 years
    @Santhosh A i'm trying to implement same code in project it's not working.
  • Santosh A
    Santosh A over 9 years
    @javasundaram I tried it myself on a folder, it is working. Check for any other possible issues
  • javasundaram
    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/Re‌​sults/ zip -r $MCELL_GENERATION_BASE_DIR/$uniqueid/$scenario_name/BWSIM/dn‌​ldtopology.zip ./*
  • Santosh A
    Santosh A over 9 years
    Try with only these two commands cd $MCELL_GENERATION_BASE_DIR/$uniqueid/$scenario_name/BWSIM/Re‌​sults/ zip -r $MCELL_GENERATION_BASE_DIR/$uniqueid/$scenario_name/BWSIM/dn‌​ldtopology.zip ./*
  • javasundaram
    javasundaram over 9 years
    @Santhosh A i need result directory files only make zip but it take outside result directory
  • Santosh A
    Santosh A over 9 years