Search code examples
linuxbashshelldirectoryunzip

How to unzip all files in directory using shell script?


I want to unzipped all the files from the specific directory but dont know how to do it using shell script.

Lgl_Entitiy.txt.zip
Lgl_Entitiy.txt_1.zip
Lgl_Relate.txt.zip
Lgl_Relate.txt_1.zip
Lgl_Name.txt.zip
Lgl_Name.txt_1.zip

Solution

  • Install unzip:

    sudo apt install unzip or yum install unzip

    Use this in the same directory you want to unzip the files:

    unzip ‘*.zip’
    

    If you want to put the uncompressed files in other directory, then use this:

    unzip ‘*.zip’ -d /usr/sampleZip/ExampleDir
    

    To put it into a shell script:

    vim shellscript.sh
    

    Then the script could be something like:

    #!/bin/bash
    
    unzip ‘*.zip’
    

    After saving the script, to execute it:

    ./shellscript.sh