Safe Deletion & Maintenance
Dry-run with -print before -delete — always preview first
# ALWAYS run with -print first to see what would be deleted
find /tmp -name "*.log" -type f -mtime +7 -print
# Only after verifying the list, switch to -delete
# find /tmp -name "*.log" -type f -mtime +7 -delete
Find and delete empty files
# Dry run — list empty files
find ~/atelier/_bibliotheca/domus-captures/docs -type f -empty -print
# Delete empty files
# find ~/atelier/_bibliotheca/domus-captures/docs -type f -empty -delete
Find and delete empty directories
# Dry run — list empty directories (depth-first so nested empties resolve)
find ~/atelier/_bibliotheca/domus-captures/docs -type d -empty -print
# Delete empty directories
# find ~/atelier/_bibliotheca/domus-captures/docs -type d -empty -delete
Delete files older than 30 days — dry-run then execute
# Dry run — list files older than 30 days in /tmp
find /tmp -type f -mtime +30 -print | head -20
# Count what would be deleted
find /tmp -type f -mtime +30 -print | wc -l
# Execute deletion
# find /tmp -type f -mtime +30 -delete
Delete .bak files with confirmation — -ok prompts per file
# Create test fixtures
echo "old backup" > /tmp/test-cleanup.bak
echo "another backup" > /tmp/test-cleanup2.bak
# -ok prompts y/n for each file (safer than -exec rm)
find /tmp -name "*.bak" -type f -ok rm {} \;
Clean pacman cache older than 90 days
# Dry run — list stale cache packages
find /var/cache/pacman/pkg -name "*.pkg.tar.zst" -type f -mtime +90 -print | wc -l
# Preview the oldest 10
find /var/cache/pacman/pkg -name "*.pkg.tar.zst" -type f -mtime +90 \
-exec ls -lh {} + 2>/dev/null | sort -k6,7 | head -10
Remove orphaned .pyc files — bytecode without matching .py
find ~/atelier -type d -name "__pycache__" -print
# Remove __pycache__ directories (dry run)
find ~/atelier -type d -name "__pycache__" -print
# Execute
# find ~/atelier -type d -name "__pycache__" -exec rm -rf {} +
Delete core dumps
# Find core dumps
find /tmp /var/tmp ~ -name "core" -o -name "core.*" -type f 2>/dev/null | head -20
# Check sizes before removing
find /tmp /var/tmp ~ \( -name "core" -o -name "core.*" \) -type f \
-exec ls -lh {} + 2>/dev/null
Clean /tmp files older than 7 days
# Dry run — list with sizes
find /tmp -maxdepth 1 -type f -mtime +7 -exec ls -lh {} + 2>/dev/null
# Count by extension
find /tmp -maxdepth 1 -type f -mtime +7 -print | \
awk -F. '{print ($NF == $0) ? "no-ext" : $NF}' | sort | uniq -c | sort -rn
Find and remove broken symlinks
# -xtype l matches symlinks whose target does not exist
find ~/atelier/_bibliotheca/domus-captures -xtype l -print
# Remove broken symlinks (dry run first!)
# find ~/atelier/_bibliotheca/domus-captures -xtype l -delete