Step-by-step guide to scan, identify and delete corrupted files on a failing external drive. All commands are safe dry-runs first — nothing is modified until you confirm.
Before you start: If you can copy any data off this drive, do that first. Repair is a last resort. Keep the drive plugged into a power source — not a laptop battery. Close every app that might be accessing the drive.
step 1
Identify the drive
List all block devices and find your external drive by size. Look for /dev/sdX entries.
lsblk
sudo fdisk -l
step 2
Mount the drive (if needed)
Replace sdb1 with your actual partition from step 1.
sudo mkdir -p /mnt/external
sudo mount /dev/sdb1 /mnt/external
mount | grep external
step 3
Scan and delete corrupted files
This one-liner finds files that file can't read and deletes them, writing a log to ~/deleted_files.txt.
for file in $(find /mnt/external -type f 2>/dev/null); do if ! file "$file" >/dev/null 2>&1; then echo "DELETING: $file" >> ~/deleted_files.txt && rm -f "$file"; fi; done
View what was deleted:
cat ~/deleted_files.txt
Detailed scan: For a progress bar version, copy the script from the Advanced tab.
step 4
Repair filesystem
Unmount first, then run a dry-run check (-n). Only after reviewing the output, run the actual repair (-y). Pick the section for your drive's filesystem.
NTFS (Windows):
sudo apt install ntfs-3g
sudo ntfsck -n /dev/sdb1
sudo ntfsck -P --progress /dev/sdb1
ext4 (Linux):
sudo umount /dev/sdb1
sudo fsck -n /dev/sdb1
sudo fsck -y /dev/sdb1
exFAT:
sudo fsck.exfat -n /dev/sdb1
sudo fsck.exfat -y /dev/sdb1
step 5
Verify and remount
sudo mount /dev/sdb1 /mnt/external
ls -lah /mnt/external
cat ~/deleted_files.txt
step 1
Identify the drive
diskutil list
diskutil info /Volumes/YourDriveName
step 2
Scan and delete corrupted files
Replace YourDriveName with your drive's mount name from step 1.
for file in $(find /Volumes/YourDriveName -type f 2>/dev/null); do if ! cat "$file" >/dev/null 2>&1; then echo "DELETING: $file" >> ~/Desktop/deleted_files.txt && rm -f "$file"; fi; done
cat ~/Desktop/deleted_files.txt
step 3
Repair filesystem
NTFS:
brew install ntfs-3g
diskutil unmount /dev/disk2s1
sudo ntfsck -P --progress /dev/disk2s1
exFAT:
diskutil unmount /dev/disk2s1
sudo fsck_exfat -n /dev/disk2s1
sudo fsck_exfat -y /dev/disk2s1
FAT32:
diskutil unmount /dev/disk2s1
sudo fsck_fat -y /dev/disk2s1
step 4
Remount
diskutil mount /Volumes/YourDriveName
cat ~/Desktop/deleted_files.txt
detailed scan
Progress bar scan script
Save as scan_and_delete.sh, make executable, and run. Shows progress percentage and logs every deletion.
#!/bin/bash MOUNT_POINT="/mnt/external" LOG_FILE="$HOME/deleted_files.txt" DELETED_COUNT=0 TOTAL_FILES=$(find "$MOUNT_POINT" -type f 2>/dev/null | wc -l) CURRENT=0 > "$LOG_FILE" echo "Starting scan on $MOUNT_POINT..." echo "Total files to check: $TOTAL_FILES" find "$MOUNT_POINT" -type f 2>/dev/null | while read file; do CURRENT=$((CURRENT + 1)) PERCENT=$((CURRENT * 100 / TOTAL_FILES)) echo -ne "\rProgress: $PERCENT% ($CURRENT/$TOTAL_FILES)" if ! cat "$file" >/dev/null 2>&1; then echo "" echo "CORRUPTED: $file" | tee -a "$LOG_FILE" rm -f "$file" echo "✓ Deleted" | tee -a "$LOG_FILE" fi done echo "" echo "Scan complete. Log: $LOG_FILE"