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
- Finds all
*.zipfiles in~/storage/downloads/ - Creates a subfolder for each file using the same name (without
.zip) - Extracts the archive into that subfolder
- Reports errors per file without stopping the batch
- Shows a summary of what was found and processed
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"
# Checks
if [ ! -d "$DOWNLOAD_DIR" ]; then
echo "Error: Downloads folder not found. Did you run 'termux-setup-storage'?"
exit 1
fi
command -v unzip >/dev/null || { echo "Error: unzip missing. Install with: pkg install unzip"; exit 1; }
cd "$DOWNLOAD_DIR" || exit
echo "--- Searching for ZIP archives in $DOWNLOAD_DIR ---"
# Nullglob: prevents literal '*.zip' when no files present
shopt -s nullglob
zips=(*.zip)
if [ ${#zips[@]} -eq 0 ]; then
echo "No ZIP files found."
exit 0
fi
echo "Found: ${#zips[@]} ZIP file(s)."
echo "Starting extraction..."
for zipfile in "${zips[@]}"; do
echo "Processing: $zipfile"
foldername="${zipfile%.zip}"
mkdir -p "$foldername"
unzip -q "$zipfile" -d "$foldername"
if [ $? -eq 0 ]; then
echo " -> Successfully extracted to: $foldername/"
else
echo " -> ERROR extracting $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:
encrypt-folder.shpacks a folder withtarand encrypts it with GPG into a.tar.gz.gpgfiledecrypt-folder.shdecrypts and unpacks that file completely
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:
-
GrapheneOS Handbook:
My ebook "GrapheneOS: Android in the Age of Surveillance" — the complete guide.
https://alien-investor.org/buecher -
Buy Bitcoin in Europe: 21bitcoin
Bitcoin-only app from Europe. Use code ALIENINVESTOR for a permanent 0.2 percentage point fee reduction.
https://alien-investor.org/21bitcoin -
₿ Bitcoin Self-Custody:
Hardware wallet instead of exchange account. I use the BitBox.
https://alien-investor.org/bitbox -
Privacy and Mail: Proton
Email, VPN and cloud without Big Tech dependency.
https://alien-investor.org/proton
Disclosure: Some links are affiliate links. Using them supports my work at no extra cost to you.