Core utilities (简体中文) - ArchWiki

Jump to content

本文或本节需要翻译。要贡献翻译，请访问简体中文翻译团队。

附注： 请完成翻译。（在 Talk:Core utilities (简体中文)# 中讨论）

相关文章

- Command-line shell
- Users and groups (简体中文)
- systemd (简体中文)
- pacman (简体中文)
- General recommendations (简体中文)

核心工具 是 GNU/Linux 系统基本、基础的工具。本文提供对它们不完整的概览、链接文档并描述有用的替代品。本文的范围包括，但不限于 GNU coreutils。大多数核心工具都是传统的 Unix 工具，它们中的许多已由 POSIX 标准化，但已进一步发展，从而提供更多功能。

大多数命令行界面的文档都在 man page 中，来自 GNU Project 的工具的文档主要在 Info manual 中，一些 shell 为内置命令提供了 `help` 命令。另外，大多数命令在使用 `--help` 标志运行时会显示自身的使用说明。

## 基础

下表列出了一些 Arch Linux 用户应当熟悉的重要的工具。另请参见 intro(1)。

包 | 工具 | 描述 | 文档 | 替代品
--- | --- | --- | --- | ---
shell 内置 | cd | 变更目录 | cd(1p) | #cd alternatives[损坏的链接：无效的章节]
GNU coreutils | ls | 列出目录 | ls(1), info | tree, #ls alternatives[损坏的链接：无效的章节]
cat | 将文件拼接到 stdout | cat(1), info | tac(1), bat
mkdir | 创建目录 | mkdir(1), info
rmdir | 删除空目录 | rmdir(1), info
rm | 删除文件或目录 | rm(1), info | shred
cp | 复制文件或目录 | cp(1), info | #cp alternatives[损坏的链接：无效的章节]
mv | 移动文件或目录 | mv(1), info
ln | 创建硬链接或符号链接 | ln(1), info
chown | 改变文件所有者和组 | chown(1), info | chgrp(1)
chmod | 改变文件权限 | chmod(1), info
dd | 转换并复制文件 | dd(1), info
df | 报告文件系统磁盘空间使用情况 | df(1), info
GNU tar | tar | tar 归档程序 | tar(1), info | archivers
GNU less | less | 终端分页程序 | less(1) | terminal pagers
GNU findutils | find | 搜索文件或目录 | find(1), info, GregsWiki | #find alternatives[损坏的链接：无效的章节]
GNU diffutils | diff | 逐行比对文件 | diff(1), info | #diff alternatives[损坏的链接：无效的章节]
GNU grep | grep | 打印匹配模式的行 | grep(1), info | #grep alternatives[损坏的链接：无效的章节]
GNU sed | sed | 流编辑器 | sed(1), info, one-liners
GNU gawk | awk | 模式扫描和处理语言 | gawk(1), info | nawk, mawkAUR
util-linux | dmesg | print or control the kernel ring buffer | dmesg(1) | systemd journal
lsblk | 列出块设备 | lsblk(8)
mount | 挂载文件系统 | mount(8)
umount | 卸载文件系统 | umount(8)
su | 替换用户 | su(1) | sudo, opendoas
kill | 中止进程 | kill(1) | pkill(1), killall(1)
procps-ng | pgrep | 根据名称或属性查找进程 | pgrep(1) | pidof(1)
ps | 显示进程信息 | ps(1) | top(1), htop
free | 显示已用和可用的内存 | free(1)

### 防止数据损失

`rm`、`mv`、`cp` 和 shell 重定向无需确认即可删除或覆盖文件。`rm`、`mv` 和 `cp` 都支持 `-i` 标志以在删除/覆盖前提醒用户。一些用户喜欢通过 alias 默认启用 `-i`。依赖这些 shell 选项可能很危险，因为你会习惯于它们，从而在你使用没有它们的系统或用户时导致潜在的数据损失。防止数据损失的最好办法是创建备份。

## 非关键

此表格列出了常常很有用的核心工具。

包 | 工具 | 描述 | 文档 | 替代品
--- | --- | --- | --- | ---
shell 内置 | alias | 定义或显示别名 | alias(1p)
type | 打印命令的类型 | type(1p) | which(1)
time | 给命令计时 | time(1p)
GNU coreutils | tee | 读取 stdin，写入 stdout 和文件 | tee(1), info
mktemp | 创建临时文件或目录 | mktemp(1), info
cut | 打印选中的行 | cut(1), info
tr | 转换或删除字符 | tr(1), info
od | 以 8 进制或其他格式转储文件 | od(1), info | hexdump(1), vim 的 xxd(1)
sort | 给行排序 | sort(1), info
uniq | 报告或省略重复的行 | uniq(1), info
comm | 逐行比对两个有序的文件 | comm(1), info
head | 输出文件的前一部分 | head(1), info
tail | output the last part of files, or follow files | tail(1), info
wc | 输出换行、单词和字节数 | wc(1), info
GNU binutils | strings | 打印二进制文件中可打印的字符 | strings(1), info | stringsextAUR
GNU glibc | iconv | 转换字符编码 | iconv(1) | recode
file | file | 猜测文件类型 | file(1)

moreutils 包提供了 GNU coreutils 中没有的有用的工具，例如 sponge(1)。

## 替代品

BusyBox、the Heirloom Toolchest、9base、sbase-gitAUR 和 ubase-gitAUR 提供核心工具的替代品。

### cat 替代品

- bat — 支持语法高亮和 Git 集成的 cat 克隆。

  https://github.com/sharkdp/bat || bat

### cd 替代品

- zoxide — A smart cd command that learns your habits, allowing you to navigate anywhere in just a few keystrokes.

  https://github.com/ajeetdsouza/zoxide || zoxide

### 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.

  https://github.com/Canop/broot || broot

- clifm — A file manager that can list files like ls(1) would (plus icons and RGB colors support).

  https://github.com/leo-arch/clifm/wiki/Advanced#files-lister-ls-mode || clifmAUR

- exa — Another ls replacement with color support, tree view, git integration and other features.

  https://github.com/ogham/exa || exa

- lsd — Modern ls with a lot of pretty colors and awesome icons.

  https://github.com/Peltoche/lsd || lsd

### find 替代品

- fd — Simple, fast and user-friendly alternative to find. Ignores hidden and `.gitignore`'d files by default.

  https://github.com/sharkdp/fd || fd

- fuzzy-find — Fuzzy completion for finding files.

  https://github.com/silentbicycle/ff || ff-gitAUR[损坏的链接：package not found]

- mlocate — Merging locate/updatedb implementation.

  https://pagure.io/mlocate || mlocate

- plocate — A much faster locate.

  https://plocate.sesse.net/ || plocate

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.

  https://github.com/junghans/cwdiff || cwdiffAUR

- git-delta — A syntax-highlighting pager for git, diff, and grep output.

  https://dandavison.github.io/delta/ || git-delta

- dwdiff — A word diff front-end for the diff program; supports colors.

  https://os.ghalkes.nl/dwdiff.html || dwdiff

- icdiff — A colorized diff tool written in Python. "Improved color diff" is meant to supplement normal diff use.

  https://github.com/jeffkaufman/icdiff || icdiffAUR

- wdiff — A wordwise implementation of GNU diff; does not support colors.

  https://www.gnu.org/software/wdiff/ || wdiff

另请参阅 List of applications/Utilities#Comparison, diff, merge。

### grep 替代品

- mgrep — 多行 grep。

  https://sourceforge.net/projects/multiline-grep/ || mgrepAUR

- pdfgrep — 在 PDF 文件中搜索文本的工具。

  https://pdfgrep.org/ || pdfgrep

- ripgrep-all — Search in plain text and also in PDFs, E-Books, Office documents, zip, tar.gz.

  https://github.com/phiresky/ripgrep-all || ripgrep-all

#### 代码搜索工具

一下 3 个工具旨在在代码搜索方面替代 grep。它们默认执行递归搜索、跳过二进制文件并尊重 `.gitignore`。

- ack — 基于 Perl 的 grep 替代品，aimed at programmers with large trees of heterogeneous source code.

  https://beyondgrep.com/ || ack

- ripgrep (rg) — A search tool that combines the usability of ag with the raw speed of grep.

  https://github.com/BurntSushi/ripgrep || ripgrep

- The Silver Searcher (ag) — 类似 Ack 的代码搜索工具，不过更快。

  https://github.com/ggreer/the_silver_searcher || the_silver_searcher

#### 交互式过滤器

- fzf — General-purpose command-line fuzzy finder, powered by find by default.

  https://github.com/junegunn/fzf || fzf

- fzy — A fast, simple fuzzy text selector with an advanced scoring algorithm.

  https://github.com/jhawthorn/fzy || fzy

- peco — Simplistic interactive filtering tool.

  https://github.com/peco/peco || peco

- percol — Adds flavor of interactive filtering to the traditional pipe concept of the UNIX shell.

  https://github.com/mooz/percol || percolAUR

- skim — Fuzzy finder written in Rust, similar to fzf.

  https://github.com/lotabout/skim || skim

## 参阅

- GNU Coreutils 文档
- POSIX 工具

Categories:

- Command-line (简体中文)
- Lists of software (简体中文)

Hidden categories:

- Pages or sections flagged with Template:Translateme (简体中文)
- Pages with broken section links
- Pages with broken package links