核心工具
核心工具 是 GNU/Linux 系统基本、基础的工具。本文提供对它们不完整的概览、链接文档并描述有用的替代品。本文的范围包括,但不限于 GNU coreutils。大多数核心工具都是传统的 Unix 工具,它们中的许多已由 POSIX 标准化,但已进一步发展,从而提供更多功能。
大多数命令行界面的文档都在 man page 中,来自 GNU 项目 的工具的文档主要在 Info manual 中,一些 shell 为内置命令提供了 help
命令。另外,大多数命令在使用 --help
标志运行时会显示自身的使用说明。
基础[编辑 | 编辑源代码]
下表列出了一些 Arch Linux 用户应当熟悉的重要的工具。另请参见 intro(1)。
防止数据损失[编辑 | 编辑源代码]
rm
、mv
、cp
和 shell 重定向无需确认即可删除或覆盖文件。rm
、mv
和 cp
都支持 -i
标志以在删除/覆盖前提醒用户。一些用户喜欢通过 alias 默认启用 -i
。依赖这些 shell 选项可能很危险,因为你会习惯于它们,从而在你使用没有它们的系统或用户时导致潜在的数据损失。防止数据损失的最好办法是创建备份。
非关键[编辑 | 编辑源代码]
此表格列出了常常很有用的核心工具。
包 | 工具 | 描述 | 文档 | 替代品 |
---|---|---|---|---|
shell 内置 | ||||
alias | 定义或显示别名 | alias(1p) | ||
type | 打印命令的类型 | type(1p) | command(1p), whereis(1), which(1) | |
time | 记录命令执行时间 | time(1p) | ||
GNU coreutils包 | tee | 读取 stdin,写入 stdout 和文件 | tee(1), info | pee(1) |
mktemp | 创建临时文件或目录 | mktemp(1), info | ||
mknod | create named pipe or device node | mknod(1), mkfifo(1), info | ||
truncate | shrink or extend the size of a file | truncate(1), info | fallocate(1) | |
basenc | encoding input and output it | basenc(1), base64(1), info | ||
cut | 打印选中的行 | cut(1), info | colrm(1), hck包, choose包 | |
tr | 转换或删除字符 | tr(1), info | uconv(1) | |
od | 以 8 进制或其他格式转储文件 | od(1), info | hexdump(1), vim's xxd(1) | |
sort | 给行排序 | sort(1), info | ||
uniq | 报告或忽略重复的行 | uniq(1), info | anewer包, runiqAUR, huniq-gitAUR | |
comm | 逐行比对两个有序的文件 | comm(1), info | zetAUR | |
head | 输出文件的前一部分 | head(1), info | ||
join | join lines of two inputs on a common field | join(1), info | combine(1) zetAUR | |
md5sum | calculate cryptography hash functions of inputs and output | sha256sum(1), sha512sum(1), info | shasum(1), hashdeep(1), rhash(1) | |
tail | output the last part of files, or follow files | tail(1), info | ||
wc | 输出换行、单词和字节数 | wc(1), info | ||
GNU binutils包 | strings | 打印二进制文件中可打印的字符 | strings(1), info | stringsextAUR |
util-linux包 | column | columnate file, optionally pretty-printing in table with grid | column(1) | paste(1), csviewAUR |
GNU findutils包 | xargs | combine or template arguments from stdin to invoke external command | xargs(1) | parallel(1) (parallel_alternatives(7)) |
GNU glibc包 | iconv | 转换字符编码 | iconv(1) | recode包, uconv(1) |
GNU sharutils包 | uudecode | encode file into email friendly text | uuencode(1), uudecode(1), info | uudeview(1) |
file包 | file | 猜测文件类型 | file(1) |
moreutils包 包提供了 GNU coreutils 中没有的有用的工具,例如 sponge(1)。
替代品[编辑 | 编辑源代码]
Alternative core utilities are provided by the following packages:
- BusyBox — Utilities for rescue and embedded systems.
- Toybox — An all-in-one Linux command line.
- uutils — Cross-platform Rust rewrite of the GNU coreutils.
- Heirloom Toolchest — Traditional implementations of standard Unix utilities.
- 9base — A port of various original Plan9 tools to unix.
- sbase — A suckless variant of the *nix core utilities.
- ubase — An extension of the sbase utilities.
cat 替代品[编辑 | 编辑源代码]
- bat — 支持语法高亮和 Git 集成的 cat 克隆。
cd 替代品[编辑 | 编辑源代码]
- zoxide — A smart cd command that learns your habits, allowing you to navigate anywhere in just a few keystrokes.
- autojump — A faster way to navigate your filesystem from the command line.
See also Bash#Auto "cd" when entering just a path and Zsh#Remembering recent directories.
cp 替代品[编辑 | 编辑源代码]
Using rsync#As cp/mv alternative allows you to resume a failed transfer, to show the transfer status, to skip already existing files and to make sure of the destination files integrity using checksums.
ls 替代品[编辑 | 编辑源代码]
- broot — A new way to see and navigate directory trees.
- clifm — A file manager that can list files like ls(1) would (plus icons and RGB colors support).
- exa — Another ls replacement with color support, tree view, git integration and other features.
- lsd — Modern ls with a lot of pretty colors and awesome icons.
find 替代品[编辑 | 编辑源代码]
- fd — Simple, fast and user-friendly alternative to find. Ignores hidden and
.gitignore
'd files by default.
- fuzzy-find — Fuzzy completion for finding files.
- mlocate — Merging locate/updatedb implementation.
- plocate — A much faster locate.
For graphical file searchers, see List of applications/Utilities#File searching.
diff 替代品[编辑 | 编辑源代码]
While diffutils包 does not provide a word-wise diff, several other programs do:
- git diff can do a word diff with
--color-words
, using--no-index
it can also be used for files outside of Git working trees. - cwdiff — A GNU wdiff wrapper that colorizes the output.
- git-delta — A syntax-highlighting pager for git, diff, and grep output.
- dwdiff — A word diff front-end for the diff program; supports colors.
- icdiff — A colorized diff tool written in Python. "Improved color diff" is meant to supplement normal diff use.
- wdiff — A wordwise implementation of GNU diff; does not support colors.
See also List of applications/Utilities#Comparison, diff, merge.
grep 替代品[编辑 | 编辑源代码]
- mgrep — 多行 grep。
- pdfgrep — 在 PDF 文件中搜索文本的工具。
- ripgrep-all — Search in plain text and also in PDFs, E-Books, Office documents, zip, tar.gz.
- agrep — 近似搜索。
代码搜索工具[编辑 | 编辑源代码]
以下 3 个工具旨在在代码搜索方面替代 grep。它们默认执行递归搜索、跳过二进制文件并遵守 .gitignore
。
- ack — 基于 Perl 的 grep 替代品,为搜索大量异构的源码树而生。
- ripgrep (rg) — 结合了 ag 的易用性和 grep 的速度。
- The Silver Searcher (ag) — 类似 Ack 的代码搜索工具,不过更快。
- ugrep (ug) — Ultrafast grep with interactive user interface, fuzzy search, boolean queries, hexdumps and more.
交互式过滤器[编辑 | 编辑源代码]
- fzf — General-purpose command-line fuzzy finder, powered by find by default.
- fzy — A fast, simple fuzzy text selector with an advanced scoring algorithm.
- peco — Simplistic interactive filtering tool.
- percol — Adds flavor of interactive filtering to the traditional pipe concept of the UNIX shell.
- skim — Fuzzy finder written in Rust, similar to fzf.
dd alternatives[编辑 | 编辑源代码]
Alternative dd implementations[编辑 | 编辑源代码]
This subsection lists dd implementations whose interface and default behaviour is mostly compliant with the POSIX specification of dd(1p).
- ddpt — A portable rewrite of sg_dd(8) by the SCSI subsystem maintainer of the Linux kernel, with optional but very specialised hardware I/O (SCSI command sets) support, plus many other features.
- sdd — A dd implementation portable across UNIX environments by Joerg Schilling, that can checksum the copied data and retry reading bad blocks.
Spin-offs of GNU dd[编辑 | 编辑源代码]
The GNU implementation of dd found in coreutils包 also conforms to POSIX. This subsection lists its forks.
- dcfldd — feature-enhanced fork of GNU dd for forensics and security scenarios, includes on-the-fly hashing capability, flexible wipes, write verification, output to multiple targets at the same time, split and piped output.
- dc3dd — Another patched version of GNU dd from the United States Department of Defense Cyber Crime Center (DC3), with similar goals and features to dcfldd.
Modernised dd analogues[编辑 | 编辑源代码]
This subsection lists dd alternatives that do not conform to POSIX (in terms of the JCL-resembling command-line syntax and default behaviour).
- dd_rescue — A feature-packed, modernised dd analogue that is suitable for daily scripting, disk cloning, and data recovery.
- rw — Minimal and portable dd analogue with conventional command-line flags.
- https://sortix.org/rw/ || rwAUR
buffer spin-offs[编辑 | 编辑源代码]
This subsection lists forks of bufferAUR, a general-purpose I/O buffering utility similar to dd but has a dynamic-sized buffer. It supports blockwise I/O and can be used when dumping from/to an LTO-tape to avoid shoe shining.
- mbuffer — Continuation of the buffer utility with threading and other features.
df alternatives[编辑 | 编辑源代码]
- duf — A disk usage/free utility.
du alternatives[编辑 | 编辑源代码]
- dust — A more intuitive version of du, in rust.
- ncdu — Simple ncurses disk usage analyzer.
- gdu — Disk usage analyzer with console interface, written in Go.
See also List of applications/Utilities#Disk usage display.
参阅[编辑 | 编辑源代码]
- GNU Coreutils 文档
- GNU Coreutils FAQ
- Coreutils Gotchas: GNU coreutils maintainer's notes about some confusing behaviour in coreutils components
- POSIX 工具