fd-file-finding について
fd-file-findingは、fdでファイルを名前、パス、属性から探すための開発者向けスキルです。無視設定を考慮した検索、各種フィルタリング、該当ファイルへのコマンド実行を扱います。
主な機能
- 01名前、拡張子、パターンで検索
- 02種類、深さ、パスで絞り込み
- 03隠しファイルや無視対象を含める
- 04サイズと更新時刻で絞り込み
- 05結果ごとまたは一括でコマンド実行
活用シーン
- 01設定ファイルやテストファイルの特定
- 02最近変更されたファイルや大容量ファイルの検索
- 03該当ファイルを整形・検索コマンドへ渡す
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ laurigates/ claude-plugins --skill fd-file-findingインストール後、Claude Code で/fd-file-findingを入力して読み込まれたか確認します。
詳細
fd によるファイル検索
スマートなデフォルト設定と強力な絞り込み機能を備えた、高速で使いやすい find の代替ツールとして fd を使うための専門知識です。
このスキルを使うタイミング
| 次のような場合はこのスキルを使います… | 次のような場合は代わりに rg-code-search を使います… |
|---|---|
| 名前、拡張子、パスパターンでファイルを検索する | ファイルの内容からテキストや正規表現を検索する |
mtime(--changed-within)やサイズ(--size)で絞り込む | ファイルタイプ(-t py、-t js)で一致結果を絞り込む |
-x / -X での実行に渡すファイルを特定する | 多数のファイルを対象にパターンを使ってソースコードを監査する |
| 次のような場合はこのスキルを使います… | 次のような場合は代わりに jq-json-processing を使います… |
|---|---|
| ディスク上の JSON、YAML、その他のファイルを見つける | それらのファイルの内容をクエリまたは変換する |
| 後続の一括処理に使うファイルリストを作成する | フィールドを抽出したり、配列を絞り込んだり、JSON の構造を変更したりする |
主な特徴
fd の利点
- 並列実行が高速(Rust で記述)
- デフォルトでカラー表示
.gitignoreを自動的に尊重- 大文字と小文字を区別しないスマート検索
findよりシンプルな構文- 正規表現に対応
基本的な使い方
シンプルなファイル検索
# Find all files named config
fd config
# Find files with extension
fd -e rs # All Rust files
fd -e md # All Markdown files
fd -e js -e ts # JavaScript and TypeScript
# Case-sensitive search
fd -s Config # Only exact case match
パターンマッチング
# Regex patterns
fd '^test_.*\.py$' # Python test files
fd '\.config$' # Files ending in .config
fd '^[A-Z]' # Files starting with uppercase
# Glob patterns
fd '*.lua' # All Lua files
fd 'test-*.js' # test-*.js files
高度な絞り込み
タイプによる絞り込み
# Search only files
fd -t f pattern # Files only
fd -t d pattern # Directories only
fd -t l pattern # Symlinks only
fd -t x pattern # Executable files
# Multiple types
fd -t f -t l pattern # Files and symlinks
深さの制御
# Limit search depth
fd -d 1 pattern # Only current directory
fd -d 3 pattern # Max 3 levels deep
fd --max-depth 2 pattern # Alternative syntax
# Minimum depth
fd --min-depth 2 pattern # Skip current directory
隠しファイルと無視対象のファイル
# Include hidden files
fd -H pattern # Include hidden files (starting with .)
# Include ignored files
fd -I pattern # Include .gitignore'd files
fd -u pattern # Unrestricted: hidden + ignored
# Show all files
fd -H -I pattern # Show everything
サイズによる絞り込み
# File size filters
fd --size +10m # Files larger than 10 MB
fd --size -1k # Files smaller than 1 KB
fd --size +100k --size -10m # Between 100 KB and 10 MB
更新日時
# Files modified recently
fd --changed-within 1d # Last 24 hours
fd --changed-within 2w # Last 2 weeks
fd --changed-within 3m # Last 3 months
# Files modified before
fd --changed-before 1y # Older than 1 year
実行と処理
コマンドの実行
# Execute command for each result
fd -e jpg -x convert {} {.}.png # Convert all JPG to PNG
# Parallel execution
fd -e rs -x rustfmt # Format all Rust files
# Execute with multiple results
fd -e md -X wc -l # Word count on all Markdown files
出力形式
# Custom output format using placeholders
fd -e tf --format '{//}' # Parent directory of each file
fd -e rs --format '{/}' # Filename without directory
fd -e md --format '{.}' # Path without extension
# Placeholders:
# {} - Full path (default)
# {/} - Basename (filename only)
# {//} - Parent directory
# {.} - Path without extension
# {/.} - Basename without extension
他のツールとの連携
# Prefer fd's native execution over xargs when possible:
fd -e log -x rm # Delete all log files (native)
fd -e rs -X wc -l # Count lines in Rust files (batch)
# Use with rg for powerful search
fd -e py -x rg "import numpy" {} # Find numpy imports in Python files
# Open files in editor
fd -e md -X nvim # Open all Markdown in Neovim (batch)
# When xargs IS useful: complex pipelines or non-fd inputs
cat filelist.txt | xargs rg "TODO" # Process file from external list
よく使われるパターン
開発ワークフロー
# Find test files
fd -e test.js -e spec.js # JavaScript tests
fd '^test_.*\.py$' # Python tests
fd '_test\.go$' # Go tests
# Find configuration files
fd -g '*.config.js' # Config files
fd -g '.env*' # Environment files
fd -g '*rc' -H # RC files (include hidden)
# Find source files
fd -e rs -e toml -t f # Rust project files
fd -e py --exclude __pycache__ # Python excluding cache
fd -e ts -e tsx src/ # TypeScript in src/
クリーンアップ操作
# Find and remove
fd -e pyc -x rm # Remove Python bytecode
fd node_modules -t d -x rm -rf # Remove node_modules
fd -g '*.log' --changed-before 30d -X rm # Remove old logs
# Find large files
fd --size +100m -t f # Files over 100 MB
fd --size +1g -t f -x du -h # Size of files over 1 GB
パスに基づく検索
# Search in specific directories
fd pattern src/ # Only in src/
fd pattern src/ tests/ # Multiple directories
# Exclude paths
fd -e rs -E target/ # Exclude target directory
fd -e js -E node_modules -E dist # Exclude multiple paths
# Full path matching
fd -p src/components/.*\.tsx$ # Match full path
特定のファイルを含むディレクトリを検索
# Find all directories with Terraform configs
fd -t f 'main\.tf$' --format '{//}'
# Find all directories with package.json
fd -t f '^package\.json$' --format '{//}'
# Find Go module directories
fd -t f '^go\.mod$' --format '{//}'
# Find Python project roots (with pyproject.toml)
fd -t f '^pyproject\.toml$' --format '{//}'
# Find Cargo.toml directories (Rust projects)
fd -t f '^Cargo\.toml$' --format '{//}'
注意: xargs にパイプで渡す代わりに --format '{//}' を使ってください。こちらのほうが高速でシンプルです。
ベストプラクティス
fd を使う場面
- 名前やパターンでファイルを検索する
- gitignore を考慮して検索する
- ディレクトリを高速に走査する
- タイプを指定して検索する
- 時間に基づいてファイルを検索する
代わりに find を使う場面
- 複雑なブール論理を使う
- POSIX 互換性が必要
- 高度な権限チェックを行う
- 標準以外のファイル属性を扱う
パフォーマンスのヒント
- 順序が重要な場合は
-j 1を使い、順次検索する --max-depthと組み合わせて範囲を制限する-t fを使ってディレクトリの処理を省く- リポジトリ内の検索を高速化するために gitignore を活用する
rg との連携
# Prefer native execution over xargs
fd -e py -x rg "class.*Test" {} # Find test classes in Python
fd -e rs -x rg "TODO" {} # Find TODOs in Rust files
fd -e md -x rg "# " {} # Find headers in Markdown
fd の組み込み実行機能を使う
# fd can execute directly — no need for xargs
fd -t f 'main\.tf$' --format '{//}' # Find dirs containing main.tf
fd -e log -x rm # Delete all .log files
クイックリファレンス
主なオプション
| オプション | 用途 | 例 |
|---|---|---|
-e EXT | 拡張子で絞り込む | fd -e rs |
-t TYPE | タイプで絞り込む(f/d/l/x) | fd -t d |
-d DEPTH | 検索の最大深度 | fd -d 3 |
-H | 隠しファイルを含める | fd -H .env |
-I | 無視対象のファイルを含める | fd -I build |
-u | 制限なし(無視設定なし) | fd -u pattern |
-E PATH | パスを除外する | fd -E node_modules |
-x CMD | コマンドを実行する | fd -e log -x rm |
-X CMD | 一括実行する | fd -e md -X cat |
-s | 大文字と小文字を区別する | fd -s Config |
-g GLOB | Glob パターン | fd -g '*.json' |
--format FMT | カスタム出力形式 | fd -e tf --format '{//}' |
時間の単位
s= 秒m= 分h= 時間d= 日w= 週y= 年
サイズの単位
b= バイトk= キロバイトm= メガバイトg= ギガバイトt= テラバイト
よく使われるコマンドパターン
# Find recently modified source files
fd -e rs --changed-within 1d
# Find large files in current directory
fd -d 1 -t f --size +10m
# Find executable scripts
fd -t x -e sh
# Find config files including hidden
fd -H -g '*config*'
# Find and count lines
fd -e py -X wc -l
# Find files excluding build artifacts
fd -e js -E dist -E node_modules -E build
# Find all Terraform/IaC project directories
fd -t f 'main\.tf$' --format '{//}'
# Find all Node.js project roots
fd -t f '^package\.json$' --format '{//}'
これにより、開発ワークフローで高速かつ直感的にファイルを検索する際に、fd が最適なツールとなります。
コメント
Markdown 対応