← Back to Control

Unzip Archives with Termux

by Alien Investor

You download a ZIP file on Android. The file manager offers to open it. The extracted files land right in the middle of your Downloads folder, mixed with everything else.

This script takes a different approach: it finds all ZIPs in the Downloads folder, creates a dedicated subfolder for each archive, and extracts into it. One command, all archives, neatly separated.

1. What the Script Does

Original ZIP files are left in place. The script deletes nothing.

2. Setup: unzip and Termux Storage

If not done yet, set up access to device storage first:

termux-setup-storage

Confirm the dialog ("Allow"). Then install unzip:

pkg update && pkg upgrade
pkg install unzip

Create a scripts folder:

mkdir -p ~/Skripte

3. The Script: unzip_downloads.sh

Create the file:

nano ~/Skripte/unzip_downloads.sh

Paste the content:

#!/data/data/com.termux/files/usr/bin/bash

set -o pipefail

DOWNLOAD_DIR="$HOME/storage/downloads"

if [ ! -d "$DOWNLOAD_DIR" ]; then
    echo "Error: Downloads folder not found. Run 'termux-setup-storage'."
    exit 1
fi

command -v unzip >/dev/null || { echo "Error: unzip missing. Run: pkg install unzip"; exit 1; }

cd "$DOWNLOAD_DIR" || exit 1

echo "--- Searching for ZIP archives in $DOWNLOAD_DIR ---"

shopt -s nullglob
zips=(*.zip)

if [ ${#zips[@]} -eq 0 ]; then
    echo "No ZIP files found."
    exit 0
fi

echo "Found: ${#zips[@]} ZIP file(s)."

for zipfile in "${zips[@]}"; do
    echo "Processing: $zipfile"
    foldername="${zipfile%.zip}"
    mkdir -p "$foldername"
    if unzip -q "$zipfile" -d "$foldername"; then
        echo "  -> Extracted to: $foldername/"
    else
        echo "  -> ERROR: $zipfile"
    fi
done

echo "--- Done ---"

(Save in nano: CTRL+O, Enter, then CTRL+X)

Make the script executable:

chmod +x ~/Skripte/unzip_downloads.sh

4. Running the Script

~/Skripte/unzip_downloads.sh

The script scans the Downloads folder and extracts each ZIP into its own subfolder. Example: documents.zip is extracted to documents/.

If the Downloads folder contains no ZIP files, the script reports that and exits cleanly.

5. ZIP vs. Encrypted Archives

This script handles standard ZIP files. The encryption scripts from the same series use a different format:

For .tar.gz.gpg archives: use decrypt-folder.sh. For .zip files: use this script.

One command. All archives. No chaos in the Downloads folder.

More in This Series

Encrypt and decrypt folders directly on your smartphone:
The Mobile Bunker: Encryption on GrapheneOS (Termux Edition)

Strip EXIF metadata from photos before sharing them:
Remove EXIF Data from Photos with Termux

Tools for Real Owners (Ads/Affiliate)

Tools I use myself, for Bitcoin self-custody and digital sovereignty:

Disclosure: Some links are affiliate links. If you use them, I receive a commission.


Power Up (Donate)

Send fuel to the mothership

Thank you for your support.