disk-hygiene
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDisk Hygiene
磁盘维护
Audit disk usage, clean developer caches, find forgotten large files, and triage Downloads on macOS.
审计磁盘占用情况、清理开发者缓存、查找被遗忘的大文件,以及整理macOS上的下载文件夹。
When to Use This Skill
何时使用此技能
Use this skill when:
- User asks about disk space, storage, or cleanup
- System is running low on free space
- User wants to find old/forgotten large files
- User wants to clean developer caches (brew, uv, pip, npm, cargo)
- User wants to triage their Downloads folder
- User asks about disk analysis tools (dust, dua, gdu, ncdu)
当出现以下情况时使用此技能:
- 用户询问磁盘空间、存储或清理相关问题
- 系统可用空间不足
- 用户想要查找旧的/被遗忘的大文件
- 用户想要清理开发者缓存(brew、uv、pip、npm、cargo)
- 用户想要整理其下载文件夹
- 用户询问磁盘分析工具(dust、dua、gdu、ncdu)
TodoWrite Task Templates
TodoWrite任务模板
Template A - Full Disk Audit
模板A - 完整磁盘审计
1. Run disk overview (df -h / and major directories)
2. Audit developer caches (uv, brew, pip, npm, cargo, rustup, Docker)
3. Scan for forgotten large files (>50MB, not accessed in 180+ days)
4. Present findings with AskUserQuestion for cleanup choices
5. Execute selected cleanups
6. Report space reclaimed1. Run disk overview (df -h / and major directories)
2. Audit developer caches (uv, brew, pip, npm, cargo, rustup, Docker)
3. Scan for forgotten large files (>50MB, not accessed in 180+ days)
4. Present findings with AskUserQuestion for cleanup choices
5. Execute selected cleanups
6. Report space reclaimedTemplate B - Cache Cleanup Only
模板B - 仅缓存清理
1. Measure current cache sizes
2. Run safe cache cleanups (brew, uv, pip, npm)
3. Report space reclaimed1. Measure current cache sizes
2. Run safe cache cleanups (brew, uv, pip, npm)
3. Report space reclaimedTemplate C - Downloads Triage
模板C - 下载文件夹整理
1. List Downloads contents with dates and sizes
2. Categorize into groups (media, dev artifacts, personal docs, misc)
3. Present AskUserQuestion multi-select for deletion/move
4. Execute selected actions1. List Downloads contents with dates and sizes
2. Categorize into groups (media, dev artifacts, personal docs, misc)
3. Present AskUserQuestion multi-select for deletion/move
4. Execute selected actionsTemplate D - Forgotten File Hunt
模板D - 遗忘文件查找
1. Scan home directory for large files not accessed in 180+ days
2. Group by location and type (media, ISOs, dev artifacts, documents)
3. Present findings sorted by size
4. Offer cleanup options via AskUserQuestion1. Scan home directory for large files not accessed in 180+ days
2. Group by location and type (media, ISOs, dev artifacts, documents)
3. Present findings sorted by size
4. Offer cleanup options via AskUserQuestionPhase 1 - Disk Overview
第一阶段 - 磁盘概况
Get the lay of the land before diving into specifics.
bash
/usr/bin/env bash << 'OVERVIEW_EOF'
echo "=== Disk Overview ==="
df -h /
echo ""
echo "=== Major Directories ==="
du -sh ~/Library/Caches ~/Library/Logs ~/Library/Application\ Support \
~/.Trash ~/Downloads ~/Documents ~/Desktop ~/Movies ~/Music ~/Pictures \
2>/dev/null | sort -rh
echo ""
echo "=== Developer Tool Caches ==="
du -sh ~/.docker ~/.npm ~/.cargo ~/.rustup ~/.local ~/.cache \
~/.conda ~/.pyenv ~/.local/share/mise 2>/dev/null | sort -rh
OVERVIEW_EOF在深入细节之前先了解整体情况。
bash
/usr/bin/env bash << 'OVERVIEW_EOF'
echo "=== Disk Overview ==="
df -h /
echo ""
echo "=== Major Directories ==="
du -sh ~/Library/Caches ~/Library/Logs ~/Library/Application\ Support \
~/.Trash ~/Downloads ~/Documents ~/Desktop ~/Movies ~/Music ~/Pictures \
2>/dev/null | sort -rh
echo ""
echo "=== Developer Tool Caches ==="
du -sh ~/.docker ~/.npm ~/.cargo ~/.rustup ~/.local ~/.cache \
~/.conda ~/.pyenv ~/.local/share/mise 2>/dev/null | sort -rh
OVERVIEW_EOFPhase 2 - Cache Audit & Cleanup
第二阶段 - 缓存审计与清理
Cache Size Reference
缓存大小参考
| Cache | Location | Typical Size | Clean Command |
|---|---|---|---|
| uv | | 5-15 GB | |
| Homebrew | | 3-10 GB | |
| pip | | 0.5-2 GB | |
| npm | | 0.5-2 GB | |
| cargo | | 1-5 GB | |
| rustup | | 2-8 GB | |
| Docker | Docker.app | 5-30 GB | |
| Playwright | | 0.5-2 GB | |
| sccache | | 1-3 GB | |
| huggingface | | 1-10 GB | |
| 缓存名称 | 位置 | 典型大小 | 清理命令 |
|---|---|---|---|
| uv | | 5-15 GB | |
| Homebrew | | 3-10 GB | |
| pip | | 0.5-2 GB | |
| npm | | 0.5-2 GB | |
| cargo | | 1-5 GB | |
| rustup | | 2-8 GB | |
| Docker | Docker.app | 5-30 GB | |
| Playwright | | 0.5-2 GB | |
| sccache | | 1-3 GB | |
| huggingface | | 1-10 GB | |
Safe Cleanup Commands (Always Re-downloadable)
安全清理命令(可重新下载,无风险)
bash
/usr/bin/env bash << 'CACHE_CLEAN_EOF'
set -euo pipefail
echo "=== Measuring current cache sizes ==="
echo "uv: $(du -sh ~/Library/Caches/uv/ 2>/dev/null | cut -f1 || echo 'N/A')"
echo "Homebrew: $(du -sh ~/Library/Caches/Homebrew/ 2>/dev/null | cut -f1 || echo 'N/A')"
echo "pip: $(du -sh ~/Library/Caches/pip/ 2>/dev/null | cut -f1 || echo 'N/A')"
echo "npm: $(du -sh ~/.npm/_cacache/ 2>/dev/null | cut -f1 || echo 'N/A')"
echo ""
echo "=== Cleaning ==="
brew cleanup --prune=all 2>&1 | tail -3
uv cache clean --force 2>&1
pip cache purge 2>&1
npm cache clean --force 2>&1
CACHE_CLEAN_EOFbash
/usr/bin/env bash << 'CACHE_CLEAN_EOF'
set -euo pipefail
echo "=== Measuring current cache sizes ==="
echo "uv: $(du -sh ~/Library/Caches/uv/ 2>/dev/null | cut -f1 || echo 'N/A')"
echo "Homebrew: $(du -sh ~/Library/Caches/Homebrew/ 2>/dev/null | cut -f1 || echo 'N/A')"
echo "pip: $(du -sh ~/Library/Caches/pip/ 2>/dev/null | cut -f1 || echo 'N/A')"
echo "npm: $(du -sh ~/.npm/_cacache/ 2>/dev/null | cut -f1 || echo 'N/A')"
echo ""
echo "=== Cleaning ==="
brew cleanup --prune=all 2>&1 | tail -3
uv cache clean --force 2>&1
pip cache purge 2>&1
npm cache clean --force 2>&1
CACHE_CLEAN_EOFTroubleshooting Cache Cleanup
缓存清理故障排除
| Issue | Cause | Solution |
|---|---|---|
| Another uv process running | Use |
| Linked but not latest | Safe to ignore, or |
| System pip vs user pip | Use |
| Docker not running | Docker Desktop not started | Start Docker.app first, or skip |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 有其他uv进程在运行 | 使用 |
| 已链接但不是最新版本 | 可忽略,或执行 |
| 系统pip与用户pip冲突 | 使用 |
| Docker未运行 | Docker Desktop未启动 | 先启动Docker.app,或跳过此步骤 |
Phase 3 - Forgotten File Detection
第三阶段 - 过期文件检测
Find large files that have not been accessed in 180+ days.
bash
/usr/bin/env bash << 'STALE_EOF'
echo "=== Large forgotten files (>50MB, untouched 180+ days) ==="
echo ""查找180天以上未访问的大文件。
bash
/usr/bin/env bash << 'STALE_EOF'
echo "=== Large forgotten files (>50MB, untouched 180+ days) ==="
echo ""Scan home directory (excluding Library, node_modules, .git, hidden dirs)
Scan home directory (excluding Library, node_modules, .git, hidden dirs)
find "$HOME" -maxdepth 4
-not -path '/.'
-not -path '/Library/'
-not -path '/node_modules/'
-not -path '/.git/'
-type f -atime +180 -size +50M 2>/dev/null |
while read -r f; do mod_date=$(stat -f '%Sm' -t '%Y-%m-%d' "$f" 2>/dev/null) size=$(du -sh "$f" 2>/dev/null | cut -f1) echo "${mod_date} ${size} ${f}" done | sort
-not -path '/.'
-not -path '/Library/'
-not -path '/node_modules/'
-not -path '/.git/'
-type f -atime +180 -size +50M 2>/dev/null |
while read -r f; do mod_date=$(stat -f '%Sm' -t '%Y-%m-%d' "$f" 2>/dev/null) size=$(du -sh "$f" 2>/dev/null | cut -f1) echo "${mod_date} ${size} ${f}" done | sort
echo ""
echo "=== Documents & Desktop (>10MB, untouched 180+ days) ==="
find "$HOME/Documents" "$HOME/Desktop"
-type f -atime +180 -size +10M 2>/dev/null |
while read -r f; do mod_date=$(stat -f '%Sm' -t '%Y-%m-%d' "$f" 2>/dev/null) size=$(du -sh "$f" 2>/dev/null | cut -f1) echo "${mod_date} ${size} ${f}" done | sort STALE_EOF
-type f -atime +180 -size +10M 2>/dev/null |
while read -r f; do mod_date=$(stat -f '%Sm' -t '%Y-%m-%d' "$f" 2>/dev/null) size=$(du -sh "$f" 2>/dev/null | cut -f1) echo "${mod_date} ${size} ${f}" done | sort STALE_EOF
undefinedfind "$HOME" -maxdepth 4
-not -path '/.'
-not -path '/Library/'
-not -path '/node_modules/'
-not -path '/.git/'
-type f -atime +180 -size +50M 2>/dev/null |
while read -r f; do mod_date=$(stat -f '%Sm' -t '%Y-%m-%d' "$f" 2>/dev/null) size=$(du -sh "$f" 2>/dev/null | cut -f1) echo "${mod_date} ${size} ${f}" done | sort
-not -path '/.'
-not -path '/Library/'
-not -path '/node_modules/'
-not -path '/.git/'
-type f -atime +180 -size +50M 2>/dev/null |
while read -r f; do mod_date=$(stat -f '%Sm' -t '%Y-%m-%d' "$f" 2>/dev/null) size=$(du -sh "$f" 2>/dev/null | cut -f1) echo "${mod_date} ${size} ${f}" done | sort
echo ""
echo "=== Documents & Desktop (>10MB, untouched 180+ days) ==="
find "$HOME/Documents" "$HOME/Desktop"
-type f -atime +180 -size +10M 2>/dev/null |
while read -r f; do mod_date=$(stat -f '%Sm' -t '%Y-%m-%d' "$f" 2>/dev/null) size=$(du -sh "$f" 2>/dev/null | cut -f1) echo "${mod_date} ${size} ${f}" done | sort STALE_EOF
-type f -atime +180 -size +10M 2>/dev/null |
while read -r f; do mod_date=$(stat -f '%Sm' -t '%Y-%m-%d' "$f" 2>/dev/null) size=$(du -sh "$f" 2>/dev/null | cut -f1) echo "${mod_date} ${size} ${f}" done | sort STALE_EOF
undefinedCommon Forgotten File Types
常见被遗忘的文件类型
| Type | Typical Location | Example |
|---|---|---|
| Windows/Linux ISOs | Documents, Downloads | |
| CapCut/iMovie exports | Movies/ | Large |
| Phone video transfers | Pictures/, DCIM/ | |
| Old Zoom recordings | Documents/ | |
| Orphaned downloads | Documents/ | |
| Screen recordings | Documents/, Desktop/ | Capto/QuickTime |
| 文件类型 | 典型位置 | 示例 |
|---|---|---|
| Windows/Linux镜像文件 | 文档、下载文件夹 | 虚拟机设置的 |
| CapCut/iMovie导出文件 | 电影文件夹/ | 大型 |
| 手机视频传输文件 | 图片文件夹/, DCIM/ | iPhone的 |
| 旧Zoom录制文件 | 文档文件夹/ | 会议的 |
| 孤立下载文件 | 文档文件夹/ | |
| 屏幕录制文件 | 文档文件夹/, 桌面/ | Capto/QuickTime的 |
Phase 4 - Downloads Triage
第四阶段 - 下载文件夹整理
Use AskUserQuestion with multi-select to let the user choose what to clean.
使用AskUserQuestion的多选功能让用户选择要清理的内容。
Workflow
工作流程
- List all files in with dates and sizes
~/Downloads - Categorize into logical groups
- Present AskUserQuestion with categories as multi-select options
- Offer personal/sensitive PDFs separately (keep, move to Documents, or delete)
- Execute selected actions
- 列出 中的所有文件及其日期和大小
~/Downloads - 将文件分类为逻辑组
- 以分类为多选选项呈现AskUserQuestion
- 单独处理个人/敏感PDF文件(保留、移动到文档文件夹或删除)
- 执行用户选择的操作
Categorization Pattern
分类脚本
bash
/usr/bin/env bash << 'DL_LIST_EOF'
echo "=== Downloads by date and size ==="
find "$HOME/Downloads" -maxdepth 1 \( -type f -o -type d \) ! -path "$HOME/Downloads" | \
while read -r f; do
mod_date=$(stat -f '%Sm' -t '%Y-%m-%d' "$f" 2>/dev/null)
size=$(du -sh "$f" 2>/dev/null | cut -f1)
echo "${mod_date} ${size} $(basename "$f")"
done | sort
DL_LIST_EOFbash
/usr/bin/env bash << 'DL_LIST_EOF'
echo "=== Downloads by date and size ==="
find "$HOME/Downloads" -maxdepth 1 \( -type f -o -type d \) ! -path "$HOME/Downloads" | \
while read -r f; do
mod_date=$(stat -f '%Sm' -t '%Y-%m-%d' "$f" 2>/dev/null)
size=$(du -sh "$f" 2>/dev/null | cut -f1)
echo "${mod_date} ${size} $(basename "$f")"
done | sort
DL_LIST_EOFAskUserQuestion Template
AskUserQuestion模板
When presenting Downloads cleanup options, use this pattern:
- Question 1 (multiSelect: true) - "Which items in ~/Downloads do you want to delete?"
- Group by type: movie files (with total size), old PDFs/docs, dev artifacts, app exports
- Question 2 (multiSelect: false) - "What about personal/sensitive PDFs?"
- Options: Keep all, Move to Documents, Delete (already have copies)
- Question 3 (multiSelect: false) - "Ongoing cleanup tool preference?"
- Options: dust + dua-cli, Hazel automation, custom launchd script
呈现下载文件夹清理选项时,使用以下模式:
- 问题1(multiSelect: true)- "你想要删除~/Downloads中的哪些项目?"
- 按类型分组:视频文件(显示总大小)、旧PDF/文档、开发者产物、应用导出文件
- 问题2(multiSelect: false)- "个人/敏感PDF文件如何处理?"
- 选项:全部保留、移动到文档文件夹、删除(已备份)
- 问题3(multiSelect: false)- "长期清理工具偏好?"
- 选项:dust + dua-cli、Hazel自动化、自定义launchd脚本
Disk Analysis Tools Reference
磁盘分析工具参考
Comparison (Benchmarked on ~632GB home directory, Apple Silicon)
对比测试(基于约632GB的用户目录,Apple Silicon芯片)
| Tool | Wall Time | CPU Usage | Interactive Delete | Install |
|---|---|---|---|---|
| dust | 20.4s | 637% (parallel) | No (view only) | |
| gdu-go | 28.8s | 845% (very parallel) | Yes (TUI) | |
| dua-cli | 37.1s | 237% (moderate) | Yes (staged safe delete) | |
| ncdu | 96.6s | 43% (single-thread) | Yes (TUI) | |
| 工具 | 耗时 | CPU占用 | 交互式删除 | 安装方式 |
|---|---|---|---|---|
| dust | 20.4秒 | 637%(并行) | 不支持(仅查看) | |
| gdu-go | 28.8秒 | 845%(高度并行) | 支持(TUI) | |
| dua-cli | 37.1秒 | 237%(中等并行) | 支持(安全分步删除) | |
| ncdu | 96.6秒 | 43%(单线程) | 支持(TUI) | |
Recommended Combo
推荐组合
- for quick "where is my space going?" - fastest scanner, tree output
dust - or
dua ifor interactive exploration with deletiongdu-go
- 用于快速查看"空间都去哪了?" - 最快的扫描工具,树形输出
dust - 或
dua i用于带删除功能的交互式探索gdu-go
Quick Usage
快速使用指南
bash
undefinedbash
undefineddust - instant tree overview
dust - 即时树形概览
dust -d 2 ~ # depth 2
dust -r ~/Library # reverse sort (smallest first)
dust -d 2 ~ # 深度为2
dust -r ~/Library # 反向排序(从小到大)
dua - interactive TUI with safe deletion
dua - 带安全删除的交互式TUI
dua i ~ # navigate, mark, delete with confirmation
dua i ~ # 导航、标记、确认后删除
gdu-go - ncdu-like TUI, fast on SSDs
gdu-go - 类似ncdu的TUI,在SSD上速度快
gdu-go ~ # full TUI with delete support
gdu-go -n ~ # non-interactive (for scripting/benchmarks)
undefinedgdu-go ~ # 完整TUI,支持删除
gdu-go -n ~ # 非交互式(用于脚本/基准测试)
undefinedInstall All Tools
安装所有工具
bash
brew install dust dua-cli gduNote: gdu installs as to avoid conflict with coreutils.
gdu-gobash
brew install dust dua-cli gdu注意:gdu安装后命令为,避免与coreutils冲突。
gdu-goQuick Wins Summary
快速清理效果汇总
Ordered by typical space reclaimed (highest first):
| Action | Typical Savings | Risk | Command |
|---|---|---|---|
| 5-15 GB | None (re-downloads) | |
| 3-10 GB | None (re-downloads) | |
| Delete movie files in Downloads | 2-10 GB | Check first | Manual after AskUserQuestion |
| 0.5-2 GB | None (re-downloads) | |
| 0.5-2 GB | None (re-downloads) | |
| Prune old rustup toolchains | 2-5 GB | Keep current | |
| Docker system prune | 5-30 GB | Removes stopped containers | |
| Empty Trash | Variable | Irreversible | |
按典型回收空间从高到低排序:
| 操作 | 典型回收空间 | 风险 | 命令 |
|---|---|---|---|
| 5-15 GB | 无(可重新下载) | |
| 3-10 GB | 无(可重新下载) | |
| 删除下载文件夹中的视频文件 | 2-10 GB | 需先确认 | 通过AskUserQuestion手动操作 |
| 0.5-2 GB | 无(可重新下载) | |
| 0.5-2 GB | 无(可重新下载) | |
| 清理旧rustup工具链 | 2-5 GB | 保留当前版本 | |
| Docker系统清理 | 5-30 GB | 会移除已停止的容器 | |
| 清空废纸篓 | 空间可变 | 不可逆 | |
Post-Change Checklist
修改后检查清单
After modifying this skill:
- Cache commands tested on macOS (Apple Silicon)
- Benchmark data still current (re-run if tools updated)
- AskUserQuestion patterns match current tool API
- All bash blocks use wrapper
/usr/bin/env bash << 'EOF' - No hardcoded user paths (use )
$HOME - Append changes to evolution-log.md
修改此技能后需完成:
- 缓存命令已在macOS(Apple Silicon)上测试
- 基准数据仍有效(若工具更新需重新运行测试)
- AskUserQuestion模式符合当前工具API
- 所有bash块使用包裹
/usr/bin/env bash << 'EOF' - 无硬编码用户路径(使用)
$HOME - 将修改记录添加到evolution-log.md
Troubleshooting
故障排除
| Issue | Cause | Solution |
|---|---|---|
| Lock held by running uv | Use |
| Already clean or formulae linked | Run |
| System Integrity Protection | Add |
| Installed as | Use |
| Counting method differs | Normal - |
| Stale file scan is slow | Deep directory tree | Limit |
| Docker not accessible | Desktop app not running | Start Docker.app or skip Docker cleanup |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 有运行中的uv进程锁定 | 使用 |
| 已清理干净或包已链接 | 运行 |
| 系统完整性保护限制 | 添加 |
| 安装后命令为 | 使用 |
| 计数方式不同 | 正常现象 - |
| 过期文件扫描缓慢 | 目录树过深 | 限制 |
| Docker无法访问 | 桌面应用未运行 | 启动Docker.app或跳过Docker清理步骤 |