cli-power-tools

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Utility Pro

全能CLI工具集

Overview

概述

Masters the command-line environment by turning raw text and unstructured data into actionable insights. Combines Rust-powered search tools (ripgrep, fd, bat), structured data shells (Nushell), JSON manipulation (jq/yq), and modern HTTP clients (xh) for high-performance CLI workflows.
Core philosophy: Replace legacy text-parsing pipelines (grep/awk/sed chains) with purpose-built tools that understand structure. ripgrep understands gitignore rules, fd understands file types, jq understands JSON, and Nushell understands tables.
When to use: Codebase-wide search and analysis, multi-file refactoring, JSON/YAML transformation pipelines, API debugging, directory navigation, log parsing, disk usage auditing, dependency tracing.
When NOT to use: GUI-based tasks, complex application logic (write a script instead), tasks requiring interactive prompts.
精通命令行环境,可将原始文本和非结构化数据转化为可执行的洞察信息。结合Rust驱动的搜索工具(ripgrep、fd、bat)、结构化数据shell(Nushell)、JSON处理工具(jq/yq)以及现代HTTP客户端(xh),打造高性能CLI工作流。
核心理念: 用理解数据结构的专用工具替代传统文本解析流水线(grep/awk/sed链)。ripgrep理解gitignore规则,fd理解文件类型,jq理解JSON,Nushell理解表格。
适用场景: 全代码库搜索与分析、多文件重构、JSON/YAML转换流水线、API调试、目录导航、日志解析、磁盘使用审计、依赖追踪。
不适用场景: 基于GUI的任务、复杂应用逻辑(建议编写脚本替代)、需要交互式提示的任务。

Quick Reference

快速参考

PatternTool / CommandKey Points
Text search
rg "pattern" -g "*.tsx"
10-100x faster than grep, respects
.gitignore
File search
fd -e pdf
or
fd "pattern"
Fast alternative to
find
with smart defaults
Syntax-highlighted read
bat file.ts
Cat with syntax highlighting and git integration
Directory jump
z project-name
Remembers frequently visited directories
Fuzzy search
fzf
or
CTRL-T
/
CTRL-R
Interactive selection for files and history
Tree view
eza --tree --level=2
Metadata-rich ls replacement with tree support
JSON query
jq '.items[] | select(.active)'
Full functional programming for JSON
YAML query
yq '.config.database' file.yml
jq-like syntax for YAML files
HTTP request
xh POST api.example.com/v1/data key=value
Colorized, user-friendly HTTP client
Multi-file refactor
fd -e tsx -x sed -i 's/Old/New/g' {}
Find files then execute transforms
Structured shell
ls | where size > 1mb | sort-by size
Nushell tables instead of text parsing
Log parsing
rg "ERROR" --json | jq 'select(.type == "match") | .data.lines.text'
Combine ripgrep JSON output with jq filters
File preview with search
fzf --preview 'bat --color=always {}'
Browse files with syntax-highlighted preview
Find recently changed
fd --changed-within 1h
Find files modified within a time window
Export count by file
rg -c "pattern" -g "*.ts" | sort -t: -k2 -rn
Count matches per file, sorted by frequency
JSON format conversion
yq -o json config.yml
Convert between YAML, JSON, CSV, and other formats
Advanced regex search
rg -P "(?<=function\s)\w+" --only-matching
PCRE2 for lookahead/lookbehind patterns
Git-aware file listing
eza -la --git --icons
Show file metadata with inline git status
用途工具/命令核心要点
文本搜索
rg "pattern" -g "*.tsx"
比grep快10-100倍,遵循
.gitignore
规则
文件搜索
fd -e pdf
fd "pattern"
替代
find
的快速工具,自带智能默认配置
语法高亮查看文件
bat file.ts
支持语法高亮和Git集成的Cat替代工具
目录跳转
z project-name
记忆常用访问目录
模糊搜索
fzf
CTRL-T
/
CTRL-R
文件与历史记录的交互式选择工具
树形视图展示
eza --tree --level=2
支持树形展示的元数据丰富型ls替代工具
JSON查询
jq '.items[] | select(.active)'
面向JSON的完整函数式编程能力
YAML查询
yq '.config.database' file.yml
类jq语法的YAML处理工具
HTTP请求
xh POST api.example.com/v1/data key=value
带颜色输出、用户友好的HTTP客户端
多文件重构
fd -e tsx -x sed -i 's/Old/New/g' {}
查找文件后执行批量转换操作
结构化shell
ls | where size > 1mb | sort-by size
用Nushell表格替代文本解析
日志解析
rg "ERROR" --json | jq 'select(.type == "match") | .data.lines.text'
将ripgrep的JSON输出与jq过滤器结合使用
带搜索的文件预览
fzf --preview 'bat --color=always {}'
浏览文件时展示语法高亮预览
查找最近修改的文件
fd --changed-within 1h
查找指定时间窗口内修改的文件
按文件导出匹配计数
rg -c "pattern" -g "*.ts" | sort -t: -k2 -rn
统计每个文件的匹配次数并按频率排序
JSON格式转换
yq -o json config.yml
在YAML、JSON、CSV等格式间相互转换
高级正则搜索
rg -P "(?<=function\s)\w+" --only-matching
支持前瞻/后顾模式的PCRE2正则引擎
感知Git的文件列表
eza -la --git --icons
展示文件元数据及内嵌Git状态

Tool Overview

工具概览

CategoryModern ToolReplacesKey Advantage
Text searchripgrep (
rg
)
grep, ag, git grepSpeed,
.gitignore
awareness, Unicode
File searchfdfindSmart defaults, regex, parallelism
File viewerbatcat, lessSyntax highlighting, git diff markers
Directory jumpzoxide (
z
)
cd, autojumpFrecency-based ranking, fzf fallback
Fuzzy finderfzfmanual pipingUniversal selector for any list
File listingezals, treeTree view, git status, icons
JSON processingjqawk, python onelinersTyped, functional JSON transforms
YAML processingyqsed on YAMLjq-compatible syntax for YAML
HTTP clientxhcurl, httpieHTTPie syntax, Rust speed, single binary
Structured shellNushellbash + awk/sedTyped tables, native format conversion
分类现代工具替代工具核心优势
文本搜索ripgrep (
rg
)
grep, ag, git grep速度快、支持
.gitignore
、兼容Unicode
文件搜索fdfind智能默认配置、支持正则、并行处理
文件查看器batcat, less语法高亮、Git差异标记
目录跳转工具zoxide (
z
)
cd, autojump基于访问频率排序、支持fzf降级使用
模糊查找器fzf手动管道操作适用于任意列表的通用选择器
文件列表工具ezals, tree树形视图、Git状态显示、图标支持
JSON处理工具jqawk, Python单行脚本类型化、函数式JSON转换
YAML处理工具yq处理YAML的sed工具兼容jq语法的YAML处理工具
HTTP客户端xhcurl, httpieHTTPie语法、Rust级速度、单二进制文件
结构化shellNushellbash + awk/sed类型化表格、原生格式转换

Common Mistakes

常见误区

MistakeCorrect Pattern
Using
grep
instead of
ripgrep
for codebase search
Use
rg
which is 10-100x faster and respects
.gitignore
by default
Piping
ls
output into
grep
for file filtering
Use
fd
for file discovery, or
eza -D
/
eza --ignore-glob
for listing
Writing complex
awk
scripts for structured data
Use Nushell or
jq
which natively understand JSON, CSV, and YAML
Running
rm -rf
in scripts without a dry-run step
Always add a verification or dry-run step before destructive operations
Using capturing groups in regex when not neededPrefer non-capturing groups
(?:...)
for better performance in large-scale scans
Searching
node_modules
or
.git
directories
Use
rg
which skips these by default, or configure exclusions explicitly
Forgetting
select(.type == "match")
on
rg --json
ripgrep JSON emits begin, match, context, end, and summary message types
Using
curl
with verbose flag syntax
Use
xh
which provides colorized output and HTTPie-compatible request-item syntax
Parsing text output between tools with
cut
/
tr
Use Nushell pipelines that preserve structured data through every stage
Anchoring regex with
.*
at the start
Anchor with
^
when possible; unanchored
.*
causes expensive backtracking
错误做法正确方式
使用
grep
而非ripgrep进行代码库搜索
使用
rg
,它比grep快10-100倍且默认遵循
.gitignore
规则
ls
输出通过管道传给
grep
进行文件过滤
使用
fd
进行文件发现,或使用
eza -D
/
eza --ignore-glob
进行列表展示
为结构化数据编写复杂
awk
脚本
使用Nushell或
jq
,它们原生支持JSON、CSV和YAML格式解析
在脚本中直接运行
rm -rf
而不进行预演
执行破坏性操作前务必添加验证或预演步骤
不必要时在正则中使用捕获组优先使用非捕获组
(?:...)
,提升大规模扫描的性能
搜索
node_modules
.git
目录
使用默认跳过这些目录的
rg
,或显式配置排除规则
使用
rg --json
时忘记添加
select(.type == "match")
ripgrep的JSON输出包含begin、match、context、end和summary等多种消息类型
使用带冗长参数语法的
curl
使用
xh
,它提供彩色输出且兼容HTTPie的请求项语法
使用
cut
/
tr
在工具间解析文本输出
使用Nushell管道,在整个流程中保留结构化数据
在正则开头使用
.*
作为锚点
尽可能使用
^
作为锚点;未锚定的
.*
会导致昂贵的回溯操作

Installation

安装方法

All tools are available via common package managers. Most are single statically linked binaries.
ToolmacOS (Homebrew)Linux (apt/cargo)
ripgrep
brew install ripgrep
apt install ripgrep
or
cargo install ripgrep
fd
brew install fd
apt install fd-find
or
cargo install fd-find
bat
brew install bat
apt install bat
or
cargo install bat
zoxide
brew install zoxide
cargo install zoxide
fzf
brew install fzf
apt install fzf
eza
brew install eza
cargo install eza
jq
brew install jq
apt install jq
yq
brew install yq
snap install yq
or
go install
xh
brew install xh
cargo install xh
Nushell
brew install nushell
cargo install nu
Shell integration (add to shell config after installing):
ToolShell Integration Required
zoxide
eval "$(zoxide init zsh)"
(or bash/fish equivalent)
fzfSource keybinding and completion scripts from fzf install
所有工具均可通过常用包管理器获取,多数为单静态链接二进制文件。
工具macOS(Homebrew)Linux(apt/cargo)
ripgrep
brew install ripgrep
apt install ripgrep
cargo install ripgrep
fd
brew install fd
apt install fd-find
cargo install fd-find
bat
brew install bat
apt install bat
cargo install bat
zoxide
brew install zoxide
cargo install zoxide
fzf
brew install fzf
apt install fzf
eza
brew install eza
cargo install eza
jq
brew install jq
apt install jq
yq
brew install yq
snap install yq
go install
xh
brew install xh
cargo install xh
Nushell
brew install nushell
cargo install nu
Shell集成(安装后添加到Shell配置文件):
工具所需Shell集成配置
zoxide
eval "$(zoxide init zsh)"
(或bash/fish对应命令)
fzf从fzf安装目录导入快捷键和补全脚本

Delegation

任务委派建议

  • Large-scale codebase search and analysis: Use
    Explore
    agent to run ripgrep queries, trace dependencies, and map code patterns
  • Multi-file refactoring workflows: Use
    Task
    agent to coordinate fd, sed, and verification steps across an entire project
  • Pipeline architecture for data transformation: Use
    Plan
    agent to design structured pipelines combining jq, Nushell, and API tools
  • 大规模代码库搜索与分析:使用
    Explore
    agent运行ripgrep查询、追踪依赖并映射代码模式
  • 多文件重构工作流:使用
    Task
    agent协调fd、sed和验证步骤,完成全项目范围的操作
  • 数据转换流水线架构设计:使用
    Plan
    agent设计结合jq、Nushell和API工具的结构化流水线

References

参考资料

  • Modern Unix Toolbox -- ripgrep, fd, bat, zoxide, fzf, eza, terminal setup
  • Advanced Regex and jq -- named captures, lookahead/lookbehind, jq filters, integrated pipelines
  • Nushell Structured Data -- table paradigm, API interaction, scripting, Unix interop
  • Modern Unix Toolbox -- ripgrep、fd、bat、zoxide、fzf、eza、终端配置
  • Advanced Regex and jq -- 命名捕获组、前瞻/后顾模式、jq过滤器、集成流水线
  • Nushell Structured Data -- 表格范式、API交互、脚本编写、Unix互操作性