file-search

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

File Search

文件搜索

Modern file and content search.
现代化的文件与内容搜索。

fd - Find Files

fd - 查找文件

bash
undefined
bash
undefined

Find by name

按名称查找

fd config # Files containing "config" fd -e py # Python files
fd config # 名称包含"config"的文件 fd -e py # Python文件

By type

按类型查找

fd -t f config # Files only fd -t d src # Directories only
fd -t f config # 仅查找文件 fd -t d src # 仅查找目录

Exclude

排除指定内容

fd -E node_modules # Exclude directory fd -E "*.min.js" # Exclude pattern
fd -E node_modules # 排除node_modules目录 fd -E "*.min.js" # 排除匹配该模式的文件

Execute command

执行命令

fd -e py -x wc -l # Line count per file
undefined
fd -e py -x wc -l # 统计每个文件的行数
undefined

rg - Search Content

rg - 内容搜索

bash
undefined
bash
undefined

Simple search

简单搜索

rg "TODO" # Find TODO rg -i "error" # Case-insensitive
rg "TODO" # 查找包含TODO的内容 rg -i "error" # 不区分大小写搜索error

By file type

按文件类型搜索

rg -t py "import" # Python files only rg -t js -t ts "async" # JS and TS
rg -t py "import" # 仅在Python文件中搜索import rg -t js -t ts "async" # 在JS和TS文件中搜索async

Context

显示上下文

rg -C 3 "function" # 3 lines before/after
rg -C 3 "function" # 显示匹配内容前后3行

Output modes

输出模式

rg -l "TODO" # File names only rg -c "TODO" # Count per file
undefined
rg -l "TODO" # 仅输出包含匹配内容的文件名 rg -c "TODO" # 按文件统计匹配次数
undefined

fzf - Interactive Selection

fzf - 交互式选择

bash
undefined
bash
undefined

Find and select

查找并选择

fd | fzf
fd | fzf

With preview

带预览功能

fd | fzf --preview 'bat --color=always {}'
fd | fzf --preview 'bat --color=always {}'

Multi-select

多选模式

fd -e ts | fzf -m | xargs code
undefined
fd -e ts | fzf -m | xargs code
undefined

Combined Patterns

组合用法

bash
undefined
bash
undefined

Find files, search content

查找文件后搜索内容

fd -e py -x rg "async def" {}
fd -e py -x rg "async def" {}

Search, select, open

搜索、选择并打开文件

rg -l "pattern" | fzf --preview 'rg -C 3 "pattern" {}' | xargs vim
undefined
rg -l "pattern" | fzf --preview 'rg -C 3 "pattern" {}' | xargs vim
undefined

Quick Reference

快速参考

TaskCommand
Find TS files
fd -e ts
Find in src
fd -e ts src/
Search pattern
rg "pattern"
Search in type
rg -t py "import"
Files with match
rg -l "pattern"
Count matches
rg -c "pattern"
Interactive
fd | fzf
With preview
fd | fzf --preview 'bat {}'
任务命令
查找TS文件
fd -e ts
在src目录中查找TS文件
fd -e ts src/
搜索指定模式
rg "pattern"
按类型搜索
rg -t py "import"
查看包含匹配内容的文件
rg -l "pattern"
统计匹配次数
rg -c "pattern"
交互式选择
fd | fzf
带预览的交互式选择
fd | fzf --preview 'bat {}'

Performance Tips

性能优化技巧

TipWhy
Both respect
.gitignore
Auto-skip node_modules, dist
Use
-t
over
-g
Type flags are faster
Narrow the path
rg pattern src/
faster
Use
-F
for literals
Avoids regex overhead
技巧原因
均支持
.gitignore
自动跳过node_modules、dist等目录
使用
-t
而非
-g
类型标记的执行速度更快
缩小搜索路径
rg pattern src/
的搜索速度更快
对字面量使用
-F
避免正则表达式的性能开销

Additional Resources

额外资源

For detailed patterns, load:
  • ./references/advanced-workflows.md
    - Git integration, shell functions, power workflows
如需了解详细用法,请查看:
  • ./references/advanced-workflows.md
    - Git集成、Shell函数、高级工作流