fd - Fast File Finder
User-friendly alternative to find with smart defaults.
Quick Start
Basic search
CODEBLOCK0
Common patterns
CODEBLOCK1
Advanced Usage
Filtering
CODEBLOCK2
Execution
CODEBLOCK3
Regex patterns
CODEBLOCK4
Time-based filtering
CODEBLOCK5
Size filtering
CODEBLOCK6
Output formatting
CODEBLOCK7
Common Use Cases
Find and delete old files:
CODEBLOCK8
Find large files:
CODEBLOCK9
Copy all PDFs to directory:
CODEBLOCK10
Count lines in all Python files:
CODEBLOCK11
Find broken symlinks:
CODEBLOCK12
Search in specific time window:
CODEBLOCK13
Integration with other tools
With ripgrep:
CODEBLOCK14
With fzf (fuzzy finder):
CODEBLOCK15
With bat (cat alternative):
CODEBLOCK16
Performance Tips
- -
fd is typically much faster than INLINECODE2 - Respects
.gitignore by default (disable with -I) - Uses parallel traversal automatically
- Smart case: lowercase = case-insensitive, any uppercase = case-sensitive
Tips
- - Use
-t for type filtering (f=file, d=directory, l=symlink, x=executable) - INLINECODE6 for extension is simpler than INLINECODE7
- INLINECODE8 in
-x commands represents the found path - INLINECODE10 strips the extension
- INLINECODE11 gets basename,
{//} gets directory
Documentation
GitHub: https://github.com/sharkdp/fd
Man page: INLINECODE13
fd - 快速文件查找器
find 的友好替代方案,具有智能默认设置。
快速入门
基本搜索
bash
按名称查找文件
fd pattern
在特定目录中查找
fd pattern /path/to/dir
不区分大小写
fd -i pattern
常见模式
bash
查找所有 Python 文件
fd -e py
查找多种扩展名
fd -e py -e js -e ts
仅查找目录
fd -t d pattern
仅查找文件
fd -t f pattern
查找符号链接
fd -t l
高级用法
过滤
bash
排除模式
fd pattern -E node_modules -E *.min.js
包含隐藏文件
fd -H pattern
包含忽略文件 (.gitignore)
fd -I pattern
搜索所有(隐藏 + 忽略)
fd -H -I pattern
最大深度
fd pattern -d 3
执行
bash
对结果执行命令
fd -e jpg -x convert {} {.}.png
并行执行
fd -e md -x wc -l
与 xargs 配合使用
fd -e log -0 | xargs -0 rm
正则表达式模式
bash
完整正则搜索
fd ^test.*\.js$
匹配完整路径
fd --full-path src/.*/test
通配符模式
fd -g *.{js,ts}
基于时间的过滤
bash
最近一天内修改
fd --changed-within 1d
特定日期之前修改
fd --changed-before 2024-01-01
最近创建
fd --changed-within 1h
大小过滤
bash
大于 10MB 的文件
fd --size +10m
小于 1KB 的文件
fd --size -1k
特定大小范围
fd --size +100k --size -10m
输出格式
bash
绝对路径
fd --absolute-path
列表格式(类似 ls -l)
fd --list-details
空分隔符(用于 xargs)
fd -0 pattern
始终/从不/自动显示颜色
fd --color always pattern
常见用例
查找并删除旧文件:
bash
fd --changed-before 30d -t f -x rm {}
查找大文件:
bash
fd --size +100m --list-details
将所有 PDF 复制到目录:
bash
fd -e pdf -x cp {} /target/dir/
统计所有 Python 文件的行数:
bash
fd -e py -x wc -l | awk {sum+=$1} END {print sum}
查找损坏的符号链接:
bash
fd -t l -x test -e {} \; -print
在特定时间窗口内搜索:
bash
fd --changed-within 2d --changed-before 1d
与其他工具集成
与 ripgrep 配合:
bash
fd -e js | xargs rg pattern
与 fzf(模糊查找器)配合:
bash
vim $(fd -t f | fzf)
与 bat(cat 替代品)配合:
bash
fd -e md | xargs bat
性能提示
- - fd 通常比 find 快得多
- 默认遵守 .gitignore(使用 -I 禁用)
- 自动使用并行遍历
- 智能大小写:小写 = 不区分大小写,任何大写 = 区分大小写
提示
- - 使用 -t 进行类型过滤(f=文件,d=目录,l=符号链接,x=可执行文件)
- -e 用于扩展名比 -g *.ext 更简单
- -x 命令中的 {} 表示找到的路径
- {.} 去除扩展名
- {/} 获取基本名称,{//} 获取目录
文档
GitHub:https://github.com/sharkdp/fd
手册页:man fd