We are on a mission to rediscover and preserve old memories by searching forgotten hard drives, USB devices, and folders for lost photos.
This repository provides a Bash script that automatically scans your external storage devices, extracts images, and organizes them by year and month based on metadata.
β
Scans external drives & USB devices for old photos
β
Detects images (.jpg
, .png
, .gif
, .tiff
, .bmp
)
β
Sorts images by year & month based on file metadata
β
Creates a log file for tracking scanned files
- The script searches all mounted drives for image files.
- It copies them into a central backup folder sorted by year and month.
- A log file keeps track of all extracted images.
Save the following script as scrape_photos.sh
, make it executable, and run it.
#!/bin/bash
# Scrape-together-old-photos - Find and recover old photos from external storage
# Author: TimInTech | Version: 1.0
# Description: This script scans connected hard drives & USB devices for old photos and copies them to a central "Recovered" folder.
### π STEP 1: Define Directories ###
BACKUP_DIR="$HOME/Recovered"
LOG_FILE="$BACKUP_DIR/scrape_log.txt"
# Create backup folder if it doesn't exist
mkdir -p "$BACKUP_DIR"
### π STEP 2: Find All External Drives ###
echo "[INFO] Searching for connected hard drives & USB devices..." | tee -a "$LOG_FILE"
MOUNT_POINTS=$(lsblk -o MOUNTPOINT,TYPE | grep part | awk '{print $1}')
if [ -z "$MOUNT_POINTS" ]; then
echo "[WARNING] No external drives found!" | tee -a "$LOG_FILE"
exit 1
fi
### πΌοΈ STEP 3: Search for Photos & Copy Them ###
echo "[INFO] Scanning the following drives: $MOUNT_POINTS" | tee -a "$LOG_FILE"
for DRIVE in $MOUNT_POINTS; do
echo "[INFO] Scanning $DRIVE for image files..." | tee -a "$LOG_FILE"
find "$DRIVE" -type f \( -iname "*.jpg" -o -iname "*.png" -o -iname "*.gif" -o -iname "*.tiff" -o -iname "*.bmp" \) | while read -r FILE; do
# Extract metadata (year and month)
YEAR=$(stat -c %y "$FILE" | cut -d'-' -f1)
MONTH=$(stat -c %y "$FILE" | cut -d'-' -f2)
# Create target folder
TARGET_DIR="$BACKUP_DIR/$YEAR/$MONTH"
mkdir -p "$TARGET_DIR"
# Copy file
cp -n "$FILE" "$TARGET_DIR"
echo "[OK] Saved: $FILE β $TARGET_DIR" | tee -a "$LOG_FILE"
done
done
echo "[DONE] All images have been saved to: $BACKUP_DIR" | tee -a "$LOG_FILE"
git clone https://github.com/TimInTech/Scrape-together-old-photos.git
cd Scrape-together-old-photos
chmod +x scrape_photos.sh
./scrape_photos.sh
- π Images are stored in:
~/Recovered/Year/Month/
- π Log file:
scrape_log.txt
Check the scan log to see which files were processed:
cat ~/Recovered/scrape_log.txt
If you want to remove duplicate images, use fdupes
:
sudo apt install fdupes
fdupes -rd ~/Recovered
lsblk | grep -i usb
rm -rf ~/Recovered
πΉ Found an issue? Report it! πΉ Want to improve the script? Submit a Pull Request!