System file cleanup tool that helps users scan for, identify, and clean up large files and junk files.
Core Features
1. Large File Scan
Scan a specified directory to find large files that take up space (default >10MB).
python3 scripts/find_large_files.py <directory> [options]
Options:
--min-size <MB>- Minimum file size (default: 10)--max-results <N>- Maximum number of results (default: 100)--show <N>- Number of files displayed (default: 20)--export <path>- Export results to JSON
Examples:
# 扫描 home 目录的大文件
python3 scripts/find_large_files.py ~
# 扫描大于 50MB 的文件
python3 scripts/find_large_files.py ~ --min-size 50
# 导出结果
python3 scripts/find_large_files.py ~ --export large_files.json
2. Junk File Scan
Scan for and identify various types of junk files: temporary files, caches, logs, backups, etc.
python3 scripts/find_garbage.py <directory> [options]
Junk file categories:
temp_files- Temporary files (.tmp, .temp, .bak, .swp, .DS_Store)cache_files- Cache files (pycache, *.pyc, .cache)log_files- Log files (*.log)backup_files- Backup files (.backup, .old)build_artifacts- Build artifacts (dist, build, .next, out)editor_temp- Editor temporary files (.swo, .swn)download_temp- Download temporary files (.crdownload, .part)
Options:
--categories <cat1> <cat2>- Specify scan categories (default: all)--show <N>- Number of files displayed per category (default: 10)--export <path>- Export results to JSON--script <path>- Generate a cleanup script
Examples:
# 扫描所有垃圾文件
python3 scripts/find_garbage.py ~
# 只扫描缓存和临时文件
python3 scripts/find_garbage.py ~ --categories cache_files temp_files
# 导出结果
python3 scripts/find_garbage.py ~ --export garbage_scan.json
# 生成清理脚本
python3 scripts/find_garbage.py ~ --script cleanup.sh
3. Interactive Cleanup
Based on scan results, provide an interactive interface that lets users choose which files to clean up.
python3 scripts/clean_interactive.py <scan_result.json> [options]
Options:
--type <garbage|large>- Type of scan results (default: garbage)--dry-run- Dry-run mode, does not actually delete files
Examples:
# 清理垃圾文件
python3 scripts/clean_interactive.py garbage_scan.json
# 清理大文件
python3 scripts/clean_interactive.py large_files.json --type large
# 预演模式(测试)
python3 scripts/clean_interactive.py garbage_scan.json --dry-run
Workflow
Standard workflow: scan → export → cleanup
# 步骤 1: 扫描垃圾文件
python3 scripts/find_garbage.py ~ --export /tmp/garbage_scan.json
# 步骤 2: 交互式清理
python3 scripts/clean_interactive.py /tmp/garbage_scan.json
Quick workflow: direct cleanup (recommended)
For junk files, you can directly generate a cleanup script:
# 生成清理脚本
python3 scripts/find_garbage.py ~ --script cleanup.sh
# 检查脚本(确认要删除的文件)
cat cleanup.sh
# 执行清理
bash cleanup.sh
Large file workflow: analyze → selective cleanup
For large files, interactive cleanup is recommended:
# 扫描大文件
python3 scripts/find_large_files.py ~ --export /tmp/large_files.json
# 交互式选择删除
python3 scripts/clean_interactive.py /tmp/large_files.json --type large
Safety Features
Automatic Exclusion
The following directories and files are automatically excluded to avoid accidental deletion:
- System directories:
/proc,/sys,/dev,/usr,/bin, etc. - Version control:
.git,.svn,.hg - Python environments:
venv,.venv,env
Junk File Classification
Junk files are divided into two categories:
🟢 Safe to delete (automatically marked):
- Temporary files
- Cache files
- Backup files
- Build artifacts
- Editor temporary files
🟡 Requires confirmation (manual check needed):
- Log files (may be used for debugging)
- Download temporary files (may be incomplete)
Dry-run Mode
Use --dry-run to test cleanup operations without actually deleting:
python3 scripts/clean_interactive.py scan.json --dry-run
Usage Recommendations
Regular cleanup
It is recommended to perform file cleanup once a month:
# 每月清理脚本
python3 scripts/find_garbage.py ~ --export /tmp/monthly_scan.json
python3 scripts/clean_interactive.py /tmp/monthly_scan.json
Insufficient disk space
When disk space is insufficient:
# 1. 找出最大的文件
python3 scripts/find_large_files.py ~ --min-size 100 --show 20
# 2. 清理垃圾文件
python3 scripts/find_garbage.py ~ --script cleanup.sh
bash cleanup.sh
Project cleanup
Clean up development project directories:
# 清理构建产物和缓存
python3 scripts/find_garbage.py ~/projects \
--categories build_artifacts cache_files \
--script project_cleanup.sh
Notes
⚠️ Must-read before use:
-
Preview before deleting
- Use
--dry-runto test - Confirm after checking the scan results
- Use
-
Back up important files
- Back up important data before deleting
- Log files may contain important information
-
Permission issues
- Some files may require sudo permissions
- Files without permission will be automatically skipped
-
Irreversible
- Deletion operations cannot be undone
- It is recommended to use the
trashcommand instead of deleting directly
Script description
find_large_files.py
Scan large files and output the file list and total size. System directories and version control directories are automatically excluded.
find_garbage.py
Identify 7 types of junk files, categorize and count them, and mark safe-to-delete status. Can generate an automatic cleanup script.
clean_interactive.py
Interactive cleanup interface, supporting selection by category, batch operations, and dry-run mode. Displays file details and total size.
Example scenarios
Scenario 1: Disk space critical
# 快速找出大文件
python3 scripts/find_large_files.py ~ --min-size 500 --show 10
Scenario 2: Development environment cleanup
# 清理所有构建产物
python3 scripts/find_garbage.py ~/projects \
--categories build_artifacts cache_files \
--export dev_cleanup.json
python3 scripts/clean_interactive.py dev_cleanup.json
Scenario 3: Regular maintenance
# 完整扫描
python3 scripts/find_garbage.py ~ --export monthly_scan.json
python3 scripts/find_large_files.py ~ --export large_files.json
# 分别处理
python3 scripts/clean_interactive.py monthly_scan.json
python3 scripts/clean_interactive.py large_files.json --type large
Troubleshooting
Permission error
# 使用 sudo(谨慎)
sudo python3 scripts/find_large_files.py /
Scan is too slow
# 限制扫描深度(只扫描指定目录)
python3 scripts/find_large_files.py ~/Downloads --max-results 50
JSON export failed
# 确保目录存在
mkdir -p /tmp
python3 scripts/find_garbage.py ~ --export /tmp/scan.json