mac-cleaner

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Mac Cleaner

Mac Cleaner

扫描和清理 macOS 系统垃圾文件,帮助释放磁盘空间。
Scan and clean junk files on macOS systems to help free up disk space.

快速开始

Quick Start

使用以下命令扫描不同类型的垃圾文件:
bash
undefined
Use the following commands to scan different types of junk files:
bash
undefined

扫描系统缓存和临时文件

Scan system cache and temporary files

bash .claude/skills/mac-cleaner/scripts/scan_cache.sh
bash .claude/skills/mac-cleaner/scripts/scan_cache.sh

扫描开发临时文件和构建产物 (node_modules, .next, dist 等)

Scan development temporary files and build artifacts (node_modules, .next, dist, etc.)

bash .claude/skills/mac-cleaner/scripts/scan_dev_files.sh /path/to/scan
bash .claude/skills/mac-cleaner/scripts/scan_dev_files.sh /path/to/scan

扫描重复文件 (需要先安装 fdupes: brew install fdupes)

Scan duplicate files (requires fdupes to be installed first: brew install fdupes)

bash .claude/skills/mac-cleaner/scripts/scan_duplicates.sh /path/to/scan
bash .claude/skills/mac-cleaner/scripts/scan_duplicates.sh /path/to/scan

扫描大文件 (默认 > 100MB)

Scan large files (default > 100MB)

bash .claude/skills/mac-cleaner/scripts/scan_large_files.sh /path/to/scan 100M 20
undefined
bash .claude/skills/mac-cleaner/scripts/scan_large_files.sh /path/to/scan 100M 20
undefined

扫描类型

Scan Types

1. 系统缓存文件

1. System Cache Files

扫描包括:
  • ~/Library/Caches
    - 用户缓存
  • /Library/Caches
    - 系统缓存
  • ~/Library/Logs
    - 用户日志
  • /Library/Logs
    - 系统日志
  • ~/.Trash
    - 回收站
  • /tmp
    - 临时文件
脚本:
scan_cache.sh
使用场景:
  • 系统运行缓慢
  • 应用程序出现异常
  • 定期清理系统
注意事项:
  • 删除系统缓存需要 sudo 权限
  • 删除后首次运行应用可能会变慢(需要重建缓存)
  • 建议先备份重要数据
Scans include:
  • ~/Library/Caches
    - User cache
  • /Library/Caches
    - System cache
  • ~/Library/Logs
    - User logs
  • /Library/Logs
    - System logs
  • ~/.Trash
    - Trash
  • /tmp
    - Temporary files
Script:
scan_cache.sh
Usage Scenarios:
  • Slow system performance
  • Application exceptions
  • Regular system maintenance
Notes:
  • Deleting system cache requires sudo privileges
  • Applications may run slowly the first time after deletion (cache needs to be rebuilt)
  • It is recommended to back up important data first

2. 开发临时文件

2. Development Temporary Files

扫描包括:
  • node_modules
    - Node.js 依赖
  • .next
    - Next.js 构建产物
  • dist
    /
    build
    - 前端构建产物
  • target
    - Java/Scala 编译产物
  • __pycache__
    /
    *.pyc
    - Python 缓存
  • .DS_Store
    - macOS 系统文件
  • *.log
    - 日志文件
脚本:
scan_dev_files.sh
参数:
  • 第一个参数: 扫描目录 (默认当前目录)
  • 第二个参数: 最大深度 (默认 3 层)
使用场景:
  • 开发项目占用大量空间
  • 切换分支前清理构建产物
  • 清理不再使用的项目依赖
示例:
bash
undefined
Scans include:
  • node_modules
    - Node.js dependencies
  • .next
    - Next.js build artifacts
  • dist
    /
    build
    - Frontend build artifacts
  • target
    - Java/Scala compilation artifacts
  • __pycache__
    /
    *.pyc
    - Python cache
  • .DS_Store
    - macOS system files
  • *.log
    - Log files
Script:
scan_dev_files.sh
Parameters:
  • First parameter: Scan directory (default current directory)
  • Second parameter: Maximum depth (default 3 levels)
Usage Scenarios:
  • Development projects taking up too much space
  • Clean up build artifacts before switching branches
  • Clean up unused project dependencies
Examples:
bash
undefined

扫描当前目录

Scan current directory

bash .claude/skills/mac-cleaner/scripts/scan_dev_files.sh
bash .claude/skills/mac-cleaner/scripts/scan_dev_files.sh

扫描指定目录,深度为 2

Scan specified directory with depth 2

bash .claude/skills/mac-cleaner/scripts/scan_dev_files.sh ~/projects 2
undefined
bash .claude/skills/mac-cleaner/scripts/scan_dev_files.sh ~/projects 2
undefined

3. 重复文件

3. Duplicate Files

使用
fdupes
工具查找重复文件。
脚本:
scan_duplicates.sh
前提条件:
bash
brew install fdupes
参数:
  • 第一个参数: 扫描目录 (默认当前目录)
  • 第二个参数: 最小文件大小 (默认 1M)
使用场景:
  • 备份文件重复
  • 下载文件重复
  • 项目资源文件重复
示例:
bash
undefined
Use the
fdupes
tool to find duplicate files.
Script:
scan_duplicates.sh
Prerequisites:
bash
brew install fdupes
Parameters:
  • First parameter: Scan directory (default current directory)
  • Second parameter: Minimum file size (default 1M)
Usage Scenarios:
  • Duplicate backup files
  • Duplicate downloaded files
  • Duplicate project resource files
Examples:
bash
undefined

扫描当前目录中大于 1MB 的重复文件

Scan duplicate files larger than 1MB in current directory

bash .claude/skills/mac-cleaner/scripts/scan_duplicates.sh
bash .claude/skills/mac-cleaner/scripts/scan_duplicates.sh

扫描指定目录中大于 10MB 的重复文件

Scan duplicate files larger than 10MB in specified directory

bash .claude/skills/mac-cleaner/scripts/scan_duplicates.sh ~/Documents 10M

**清理命令**:
```bash
bash .claude/skills/mac-cleaner/scripts/scan_duplicates.sh ~/Documents 10M

**Cleanup Commands**:
```bash

交互式删除 (保留每个重复组的第一个文件)

Interactive deletion (keep the first file in each duplicate group)

fdupes -r -d -N /path/to/scan
undefined
fdupes -r -d -N /path/to/scan
undefined

4. 大文件

4. Large Files

查找占用大量空间的文件。
脚本:
scan_large_files.sh
参数:
  • 第一个参数: 扫描目录 (默认当前目录)
  • 第二个参数: 最小文件大小 (默认 100M)
  • 第三个参数: 显示前 N 个文件 (默认 20)
使用场景:
  • 磁盘空间不足
  • 查找可以删除的大文件
  • 分析磁盘空间占用
示例:
bash
undefined
Locate files that take up a lot of space.
Script:
scan_large_files.sh
Parameters:
  • First parameter: Scan directory (default current directory)
  • Second parameter: Minimum file size (default 100M)
  • Third parameter: Show top N files (default 20)
Usage Scenarios:
  • Insufficient disk space
  • Find large files that can be deleted
  • Analyze disk space usage
Examples:
bash
undefined

查找大于 100MB 的文件,显示前 20 个

Find files larger than 100MB, show top 20

bash .claude/skills/mac-cleaner/scripts/scan_large_files.sh
bash .claude/skills/mac-cleaner/scripts/scan_large_files.sh

查找大于 1GB 的文件,显示前 10 个

Find files larger than 1GB, show top 10

bash .claude/skills/mac-cleaner/scripts/scan_large_files.sh ~/Documents 1G 10
undefined
bash .claude/skills/mac-cleaner/scripts/scan_large_files.sh ~/Documents 1G 10
undefined

清理流程

Cleanup Process

所有扫描脚本都会提供清理命令建议。遵循以下安全流程:
All scan scripts will provide cleanup command recommendations. Follow this safe process:

步骤 1: 扫描

Step 1: Scan

首先使用相应的脚本扫描目标目录,识别垃圾文件。
First use the corresponding script to scan the target directory and identify junk files.

步骤 2: 检查结果

Step 2: Review Results

仔细检查扫描结果,确认要删除的文件:
  • 确认文件确实不再需要
  • 检查是否有重要数据
  • 验证删除不会影响其他程序
Carefully review the scan results and confirm the files to delete:
  • Confirm the files are no longer needed
  • Check for important data
  • Verify deletion will not affect other programs

步骤 3: 备份 (可选)

Step 3: Backup (Optional)

对于重要文件,建议先备份:
bash
undefined
For important files, it is recommended to back up first:
bash
undefined

创建备份

Create backup

cp -r /path/to/important/file ~/backup/
cp -r /path/to/important/file ~/backup/

或使用 tar 打包

Or use tar to package

tar -czf backup_$(date +%Y%m%d).tar.gz /path/to/file
undefined
tar -czf backup_$(date +%Y%m%d).tar.gz /path/to/file
undefined

步骤 4: 删除

Step 4: Delete

使用脚本提供的清理命令,或手动删除:
bash
undefined
Use the cleanup commands provided by the script, or delete manually:
bash
undefined

删除单个文件/目录

Delete single file/directory

rm -rf /path/to/file
rm -rf /path/to/file

删除多个文件

Delete multiple files

rm -rf file1 file2 file3
rm -rf file1 file2 file3

使用 find 批量删除

Use find to delete in batches

find . -name "node_modules" -type d -prune -exec rm -rf {} +
undefined
find . -name "node_modules" -type d -prune -exec rm -rf {} +
undefined

最佳实践

Best Practices

开发项目清理

Development Project Cleanup

对于开发项目,建议使用
.gitignore
防止提交临时文件:
gitignore
node_modules/
.next/
dist/
build/
__pycache__/
*.pyc
.DS_Store
*.log
清理项目前,可以使用:
bash
undefined
For development projects, it is recommended to use
.gitignore
to prevent committing temporary files:
gitignore
node_modules/
.next/
dist/
build/
__pycache__/
*.pyc
.DS_Store
*.log
Before cleaning up the project, you can use:
bash
undefined

保存依赖列表

Save dependency list

npm list > dependencies.txt
npm list > dependencies.txt

删除 node_modules

Delete node_modules

rm -rf node_modules
rm -rf node_modules

需要时恢复

Restore when needed

npm install
undefined
npm install
undefined

定期清理

Regular Cleanup

建议定期(每月或每季度)运行清理:
  1. 清空回收站
  2. 清理浏览器缓存
  3. 删除开发构建产物
  4. 查找并删除重复文件
It is recommended to run cleanup regularly (monthly or quarterly):
  1. Empty Trash
  2. Clear browser cache
  3. Delete development build artifacts
  4. Find and delete duplicate files

系统缓存清理

System Cache Cleanup

系统缓存清理需谨慎:
  • 只删除已知安全的缓存
  • 避免删除正在使用的缓存
  • 删除后可能需要重启应用
System cache cleanup requires caution:
  • Only delete known safe caches
  • Avoid deleting caches that are in use
  • Applications may need to be restarted after deletion

安全警告

Safety Warnings

⚠️ 重要提示:
  • 删除操作不可逆,请仔细确认
  • 系统文件和缓存删除需要 sudo 权限,需格外谨慎
  • 删除前建议备份重要数据
  • 不确定文件用途时,请先查询或咨询
  • 某些缓存删除后首次运行应用会变慢
⚠️ Important Notes:
  • Deletion operations are irreversible, please confirm carefully
  • Deleting system files and caches requires sudo privileges, extra caution is needed
  • It is recommended to back up important data before deletion
  • If you are unsure about the purpose of a file, please query or consult first
  • Some applications may run slowly the first time after cache deletion

故障排除

Troubleshooting

fdupes 未安装

fdupes Not Installed

如果使用重复文件扫描时提示 fdupes 未安装:
bash
brew install fdupes
If you get a prompt that fdupes is not installed when using duplicate file scanning:
bash
brew install fdupes

权限不足

Insufficient Permissions

某些系统目录需要 sudo 权限:
bash
sudo bash .claude/skills/mac-cleaner/scripts/scan_cache.sh
Some system directories require sudo privileges:
bash
sudo bash .claude/skills/mac-cleaner/scripts/scan_cache.sh

扫描速度慢

Slow Scanning

对于大型目录:
  • 限制扫描深度
  • 增加最小文件大小限制
  • 分目录扫描
For large directories:
  • Limit scan depth
  • Increase minimum file size limit
  • Scan directories separately

资源

Resources

scripts/

scripts/

  • scan_cache.sh
    - 扫描系统缓存和临时文件
  • scan_dev_files.sh
    - 扫描开发临时文件和构建产物
  • scan_duplicates.sh
    - 扫描重复文件
  • scan_large_files.sh
    - 扫描大文件
  • generate_cleanup_commands.sh
    - 生成带确认的安全删除脚本
  • scan_cache.sh
    - Scan system cache and temporary files
  • scan_dev_files.sh
    - Scan development temporary files and build artifacts
  • scan_duplicates.sh
    - Scan duplicate files
  • scan_large_files.sh
    - Scan large files
  • generate_cleanup_commands.sh
    - Generate safe deletion scripts with confirmation