关于 file-operations
面向 Claude 的文件检查技能,可在不修改文件的情况下查看元数据、内容和模式。适合需要比较文件或统计代码指标的开发者。
主要功能
- 01查看文件大小和元数据
- 02统计行数及代码元素
- 03分析内容并搜索模式
- 04查找文件并比较大小
适用场景
- 01查看文件元数据和行数
- 02比较多个源文件的大小
- 03统计函数、类、导入项或 TODO
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ mhattingpete/ claude-skills-marketplace --skill file-operations安装后在 Claude Code 中输入/file-operations确认已加载。
详细介绍
文件操作
使用 Claude 的原生工具分析文件并获取元数据,不修改文件。
适用场景
- “分析 [file]”
- “获取 [file] 的文件信息”
- “[file] 有多少行”
- “比较 [file1] 和 [file2]”
- “文件统计”
核心操作
文件大小和元数据
stat -f "%z bytes, modified %Sm" [file_path] # Single file
ls -lh [directory] # Multiple files
du -h [file_path] # Human-readable size
行数统计
wc -l [file_path] # Single file
wc -l [file1] [file2] # Multiple files
find [dir] -name "*.py" | xargs wc -l # Directory total
内容分析
使用 Read 分析结构,然后统计函数、类和导入项。
模式搜索
Grep(pattern="^def ", output_mode="count", path="src/") # Count functions
Grep(pattern="TODO|FIXME", output_mode="content", -n=true) # Find TODOs
Grep(pattern="^import ", output_mode="count") # Count imports
查找文件
Glob(pattern="**/*.py")
工作流示例
全面分析文件
- 获取大小/修改时间:
stat -f "%z bytes, modified %Sm" file.py - 统计行数:
wc -l file.py - 读取文件:
Read(file_path="file.py") - 统计函数:
Grep(pattern="^def ", output_mode="count") - 统计类:
Grep(pattern="^class ", output_mode="count")
比较文件大小
- 查找文件:
Glob(pattern="src/**/*.py") - 获取大小:
ls -lh src/**/*.py - 总大小:
du -sh src/*.py
代码质量指标
- 总行数:
find . -name "*.py" | xargs wc -l - 测试文件:
find . -name "test_*.py" | wc -l - TODO 项:
Grep(pattern="TODO|FIXME|HACK", output_mode="count")
查找最大文件
find . -type f -not -path "./node_modules/*" -exec du -h {} + | sort -rh | head -20
最佳实践
- 无破坏性:使用 Read/stat/wc,绝不修改文件
- 高效:完整读取小文件,使用 Grep 搜索大文件
- 结合上下文:与项目平均值比较,并提出优化建议
集成
可与以下工具配合使用:
- code-auditor:全面分析
- code-transfer:识别大型文件后使用
- codebase-documenter:了解文件用途
评论
支持 Markdown