How can I do recursive unzip from terminal? [duplicate]

Inside a zip I have one more zip file

I want a command to extract all at once.


Solution 1:

My suggestion is to create a custom command by adding the following function in your .bashrc:

# Recursive UNZIP 
# - covers only the firs level of the recursion; 
# - works only with one input file
unzipr () {
    # Get the users input
    TARGET_ZIP_FILE="${1}"

    # Get the list of sub archive zip files
    ZIP_LIST="$(unzip -l "$TARGET_ZIP_FILE" | awk 'NR > 1 && $NF ~ /zip/ { print $NF }')"

    # Output the list of sub archive zip files
    if [ ! -z "${ZIP_LIST}" ]; then
        echo 'List of Sub Archives:'
        for ZIP in $ZIP_LIST; do echo -e " - $ZIP"; done; echo
    else
        echo "Sub Archives Not Found."
    fi

    # Extract and unzip the files
    for ZIP in $ZIP_LIST; do
        # Ask the user for his/her preferences
        echo -n "Do you want to extract and unzip \"$ZIP\" [Y|n]: "
        read preference

        # Extract the file according to the users preferences
        if [ -z "${preference}" ] || [[ "${preference}" =~ ^(y|Y).* ]]; then
            unzip "$TARGET_ZIP_FILE" "$ZIP"
            unzip "$ZIP"
            rm "$ZIP"
            echo
        fi
    done
}

Add these lines to the bottom of ~/.bashrc, then do source ~/.bashrc and you will have a command called unzipr. Here is how it works:

enter image description here