DevToolBox免费
博客

2026 开发者必备 Linux 命令行工具

13 分钟阅读作者 DevToolBox

2026 年每位开发者应掌握的 Linux 命令行工具

经典 UNIX 工具(find、grep、cat、ls)依然有效,但新一代 Rust 驱动的替代品提供了显著更好的性能、合理的默认值和对开发者友好的输出。本指南涵盖 fd、ripgrep、bat、eza、delta、zoxide、fzf、jq 和 HTTPie。

fd 和 ripgrep:增强版查找与搜索

fd 以合理的默认值替代 find(遵守 .gitignore、不区分大小写、彩色输出)。ripgrep 替代 grep,在大型代码库中搜索速度提升 10-100 倍。

# fd: modern find replacement (written in Rust)
# Faster, respects .gitignore, simpler syntax

# Install
brew install fd          # macOS
apt install fd-find      # Ubuntu/Debian (binary is 'fdfind')

# Find files by name (case-insensitive by default)
fd config                # finds files named 'config', 'Config.js', etc.
fd '\.tsx$'              # regex: all .tsx files
fd -e ts -e tsx          # by extension (no dot)
fd -t d src              # type: directory named 'src'
fd -t f -x wc -l        # find files, run 'wc -l' on each (parallel)

# ripgrep (rg): grep replacement -- blazing fast, respects .gitignore
# Install: brew install ripgrep / apt install ripgrep

# Basic search
rg 'useState'                       # search current dir recursively
rg 'TODO|FIXME' --glob '*.ts'       # glob filter
rg -l 'console\.log'               # list file names only
rg -n 'export default' src/         # show line numbers

# Context lines
rg -C 3 'throw new Error'           # 3 lines before and after
rg -A 5 'async function fetchUser'  # 5 lines after match

# Type filtering (rg knows language extensions)
rg --type ts 'interface'            # TypeScript files only
rg --type-add 'web:*.{html,css,js}' --type web 'font-face'

bat 和 eza:更好的 cat 和 ls

bat 为 cat 增加了语法高亮和 git diff 集成。eza 以 git 状态指示器、默认人类可读的文件大小和树形输出替代 ls。

# bat: cat with syntax highlighting, line numbers, git diffs
# Install: brew install bat / apt install bat (binary may be 'batcat')

# Basic usage
bat README.md                       # with syntax highlighting
bat src/index.ts                    # TypeScript highlighted
bat --style=plain file.txt          # no decorations (pipe-safe)
bat --paging=never file.txt         # don't use pager

# Show git changes inline (like 'diff')
bat --diff src/app.ts               # highlight lines changed vs git

# As a colorized pager for man pages
export MANPAGER="sh -c 'col -bx | bat -l man -p'"

# eza: modern ls replacement (was exa, now maintained fork)
# Install: brew install eza / apt install eza

# Basic usage
eza                                 # color-coded by file type
eza -l                              # long listing (like ls -l)
eza -la                             # include hidden files
eza --tree                          # tree view
eza --tree --level=2                # tree, max 2 levels deep
eza -l --git                        # show git status per file
eza --sort=modified                 # sort by modification time
eza -lh --group                     # human sizes, group by owner

# Useful aliases
alias ls='eza --color=auto'
alias ll='eza -l --git'
alias la='eza -la --git'
alias lt='eza --tree --level=2'

delta 和 zoxide:Git 差异与智能导航

delta 通过语法高亮和并排视图改造 git diff 输出。zoxide 学习你最常访问的目录,让你用 1-2 个字母命令跳转过去。

# delta: syntax-highlighting pager for git diffs
# Install: brew install git-delta / cargo install git-delta

# Configure in ~/.gitconfig
[core]
    pager = delta

[interactive]
    diffFilter = delta --color-only

[delta]
    navigate = true      # n/N to jump between diff sections
    light = false        # set to true for light terminal
    side-by-side = true  # show old/new side by side
    line-numbers = true
    syntax-theme = Dracula

# Now all git diff/log/show output is highlighted
git diff HEAD~1
git log -p --follow -- src/utils.ts
git show a1b2c3d

# zoxide: smarter cd that learns your habits
# Install: brew install zoxide / apt install zoxide

# Add to ~/.zshrc or ~/.bashrc:
eval "$(zoxide init zsh)"    # for zsh
eval "$(zoxide init bash)"   # for bash

# Usage -- z learns directories you visit frequently
z project         # jump to most-used directory matching 'project'
z dev tool        # multiple terms: matches paths containing both
zi                # interactive mode: fuzzy search with fzf

# After a few days of normal use:
z dev             # /Users/you/Development/my-project
z dt              # /Users/you/devtoolbox
z log             # /var/log  or wherever you go most often

fzf 和 jq:模糊搜索与 JSON 处理

fzf 为任何命令添加交互式模糊搜索。jq 是 shell 脚本和 API 工作中解析、过滤和转换 JSON 数据的标准工具。

# fzf: command-line fuzzy finder -- connects everything together
# Install: brew install fzf / apt install fzf

# Interactive file picker
vim $(fzf)                          # open any file in vim
code $(fzf --preview 'bat {}')      # open in VS Code with preview

# Shell history search (Ctrl+R replacement)
export FZF_CTRL_R_OPTS="--sort --exact"

# Pipe into fzf for interactive selection
git branch | fzf | xargs git checkout    # interactive branch switcher
docker ps | fzf | awk '{print $1}' | xargs docker stop

# jq: JSON processor for the command line
# Install: brew install jq / apt install jq

# Basic extraction
curl -s https://api.github.com/repos/sharkdp/fd | jq '.stargazers_count'
cat package.json | jq '.dependencies | keys'
cat data.json | jq '.users[] | {name, email}'

# Filtering and transformation
cat users.json | jq '[.[] | select(.active == true)] | length'
cat logs.json  | jq '.[] | select(.level == "error") | .message'

# Build new structure
cat data.json | jq '{ total: length, names: [.[].name] }'

# Compact output (single line)
cat pretty.json | jq -c .           # minified JSON output

HTTPie 和 xh:对开发者友好的 HTTP 客户端

HTTPie 和 xh 提供直观的 HTTP 请求语法,具有自动 JSON 格式化、会话管理和清晰的输出——在开发工作中替代 curl。

# HTTPie / xh: human-friendly HTTP clients
# HTTPie: pip install httpie  |  brew install httpie
# xh (Rust, faster): brew install xh / cargo install xh

# GET request
http GET https://api.example.com/users
xh GET https://api.example.com/users         # same, xh syntax

# POST JSON (auto-detected from key=value syntax)
http POST https://api.example.com/users \
  name="Alice" \
  email="alice@example.com" \
  role=admin

# With headers and auth
http GET https://api.example.com/profile \
  Authorization:"Bearer $TOKEN" \
  Accept:application/json

# Form data
http --form POST https://example.com/upload file@/path/to/file.txt

# Download file
http --download https://example.com/file.zip

# Save session (cookies, headers) between requests
http --session=./session.json POST https://api.example.com/login \
  username=admin password=secret

http --session=./session.json GET https://api.example.com/dashboard

Shell 别名与生产力函数

好的别名和 shell 函数可以减少重复输入。本节涵盖安全别名、git 快捷键和通用辅助函数,如 mkcd 和 extract。

# Productivity shell aliases and functions
# Add to ~/.zshrc or ~/.bashrc

# Navigation
alias ..='cd ..'
alias ...='cd ../..'

# Safety nets
alias rm='rm -i'            # confirm before delete
alias cp='cp -i'            # confirm before overwrite
alias mv='mv -i'

# One-line process management
alias psg='ps aux | grep -v grep | grep -i'
alias ports='ss -tlnp'      # listening ports (Linux)
alias myip='curl -s ifconfig.me'

# Git shortcuts
alias gs='git status -sb'
alias ga='git add -p'       # interactive staging
alias gl='git log --oneline --graph --decorate -20'

# Modern replacements (if installed)
command -v fd  > /dev/null && alias find='fd'
command -v rg  > /dev/null && alias grep='rg'
command -v bat > /dev/null && alias cat='bat --paging=never'
command -v eza > /dev/null && alias ls='eza'

# Useful functions
mkcd() { mkdir -p "$1" && cd "$1"; }          # mkdir + cd
extract() {                                    # universal archive extractor
  case "$1" in
    *.tar.gz)  tar xzf "$1"  ;;
    *.tar.bz2) tar xjf "$1"  ;;
    *.zip)     unzip "$1"    ;;
    *.gz)      gunzip "$1"   ;;
    *.7z)      7z x "$1"     ;;
    *) echo "Unknown format: $1" ;;
  esac
}

经典工具 vs 现代工具对比

ClassicModernLanguageKey Improvements
findfdRustRespects .gitignore, case-insensitive by default, regex support
grepripgrep (rg)Rust10-100x faster, parallel search, respects .gitignore
catbatRustSyntax highlighting, line numbers, git diff integration
lsezaRustColors, git status, icons, tree view, human sizes default
diff / git diffdeltaRustSyntax highlighting, side-by-side, line numbers, themes
cdzoxide (z)RustFrecency-based jump, interactive with fzf (zi)
Ctrl+R historyfzfGoFuzzy search, composable with any command, preview pane
python -m json.tooljqCFilter, transform, query — full DSL for JSON
curlhttpie / xhPython/RustHuman-readable output, auto JSON, session management

常见问题

这些工具在 macOS 上能用吗?

能。所有列出的工具都是跨平台的。通过 Homebrew 安装:brew install fd ripgrep bat eza git-delta zoxide fzf jq httpie。Linux 上使用包管理器(apt、dnf、pacman)或 cargo install 安装 Rust 工具。

将 grep 别名为 rg 安全吗?

交互使用时可以。但在脚本中需谨慎——ripgrep 的参数兼容性略有不同。更安全的做法是在脚本中显式使用 rg,只在交互式 shell 会话中设置别名。

fzf 和 zoxide 有何区别?

它们解决不同的问题。zoxide 从 cd 历史中学习,让你用 z 关键字跳转到常用目录。fzf 是与任何命令输出集成的通用模糊查找器。两者互补:zi 在 zoxide 内部使用 fzf 进行交互式选择。

脚本中应该用 HTTPie 还是 curl?

自动化和脚本中,curl 更具移植性(随处预装)且选项更多。HTTPie/xh 更适合交互式开发和 API 测试。在你能控制环境的脚本中可使用 xh,因为它是单一二进制文件。

相关工具

𝕏 Twitterin LinkedIn
这篇文章有帮助吗?

保持更新

获取每周开发技巧和新工具通知。

无垃圾邮件,随时退订。

试试这些相关工具

{ }JSON FormatterCron Expression Parser.*Regex Tester

相关文章

开发者必备 Linux 命令速查表

面向开发者的全面 Linux 命令参考。文件管理、文本处理、网络、权限、进程管理和效率命令一行搞定,附示例。

Linux 命令速查表:50 个必备命令

掌握 50 个按类别组织的 Linux 必备命令:文件管理、文本处理、网络、进程管理和系统管理,附可复制示例。

Git 命令速查表:开发者必备命令大全

完整的 Git 命令速查表:涵盖配置、分支、合并、变基、暂存和高级工作流程。