网淘吧来吧,欢迎您!

Fd Find技能使用说明

2026-03-29 新闻来源:网淘吧 围观:21
电脑广告
手机广告

fd - 快速文件查找器

用户友好的替代方案,用于find命令并具有智能默认设置。

快速开始

基本搜索

# Find files by name
fd pattern

# Find in specific directory
fd pattern /path/to/dir

# Case-insensitive
fd -i pattern

常见模式

# Find all Python files
fd -e py

# Find multiple extensions
fd -e py -e js -e ts

# Find directories only
fd -t d pattern

# Find files only
fd -t f pattern

# Find symlinks
fd -t l

高级用法

过滤

# Exclude patterns
fd pattern -E "node_modules" -E "*.min.js"

# Include hidden files
fd -H pattern

# Include ignored files (.gitignore)
fd -I pattern

# Search all (hidden + ignored)
fd -H -I pattern

# Maximum depth
fd pattern -d 3

执行

# Execute command on results
fd -e jpg -x convert {} {.}.png

# Parallel execution
fd -e md -x wc -l

# Use with xargs
fd -e log -0 | xargs -0 rm

正则表达式模式

# Full regex search
fd '^test.*\.js$'

# Match full path
fd --full-path 'src/.*/test'

# Glob pattern
fd -g "*.{js,ts}"

基于时间的过滤

# Modified within last day
fd --changed-within 1d

# Modified before specific date
fd --changed-before 2024-01-01

# Created recently
fd --changed-within 1h

基于大小的过滤

# Files larger than 10MB
fd --size +10m

# Files smaller than 1KB
fd --size -1k

# Specific size range
fd --size +100k --size -10m

输出格式化

# Absolute paths
fd --absolute-path

# List format (like ls -l)
fd --list-details

# Null separator (for xargs)
fd -0 pattern

# Color always/never/auto
fd --color always pattern

常见用例

查找并删除旧文件:

Fd Find

fd --changed-before 30d -t f -x rm {}

查找大文件:

fd --size +100m --list-details

将所有PDF复制到目录:

fd -e pdf -x cp {} /target/dir/

统计所有Python文件的行数:

fd -e py -x wc -l | awk '{sum+=$1} END {print sum}'

查找损坏的符号链接:

fd -t l -x test -e {} \; -print

在特定时间窗口内搜索:

fd --changed-within 2d --changed-before 1d

与其他工具集成

与ripgrep配合使用:

fd -e js | xargs rg "pattern"

与fzf(模糊查找器)配合使用:

vim $(fd -t f | fzf)

使用 bat(cat 的替代品):

fd -e md | xargs bat

性能提示

  • fd通常比find
  • 快得多默认情况下尊重.gitignore(可使用-I
  • 禁用)
  • 自动使用并行遍历

智能大小写:全小写 = 不区分大小写,包含大写 = 区分大小写

  • 技巧使用-t
  • 进行类型筛选(f=文件,d=目录,l=符号链接,x=可执行文件)-e按扩展名筛选比
  • -g "*.扩展名"更简单{}
  • -x命令中代表找到的路径
  • {/}获取基本名称,{//}获取目录

文档

GitHub:https://github.com/sharkdp/fd手册页:man fd

免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏
文章底部电脑广告
手机广告位-内容正文底部

相关文章

您是本站第326253名访客 今日有220篇新文章/评论