出自 Arch Linux 中文维基

Tango-preferences-desktop-locale.png本文或本節需要翻譯。要貢獻翻譯,請訪問簡體中文翻譯團隊Tango-preferences-desktop-locale.png

附註: 請完成翻譯。(在 Talk:核心工具# 中討論)

核心工具GNU/Linux 系統基本、基礎的工具。本文提供對它們不完整的概覽、連結文檔並描述有用的替代品。本文的範圍包括,但不限於 GNU coreutils。大多數核心工具都是傳統的 Unix 工具,它們中的許多已由 POSIX 標準化,但已進一步發展,從而提供更多功能。

大多數命令行界面的文檔都在 man page 中,來自 GNU 項目 的工具的文檔主要在 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
du 估算文件和文件夾占用的空間 du(1), info #du alternatives
GNU tar tar tar 歸檔程序 tar(1), info 歸檔與壓縮
GNU less less 終端分頁程序 less(1) 終端翻頁器
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 日誌
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)

防止數據損失

rmmvcp 和 shell 重定向無需確認即可刪除或覆蓋文件。rmmvcp 都支持 -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.
https://busybox.net || busybox
  • Toybox — An all-in-one Linux command line.
https://landley.net/toybox || toyboxAUR
  • uutils — Cross-platform Rust rewrite of the GNU coreutils.
https://github.com/uutils/coreutils || uutils-coreutils
  • Heirloom Toolchest — Traditional implementations of standard Unix utilities.
https://heirloom.sourceforge.net || heirloom-shAUR, heirloom-doctoolsAUR
  • 9base — A port of various original Plan9 tools to unix.
https://tools.suckless.org/9base || 9base
  • sbase — A suckless variant of the *nix core utilities.
https://core.suckless.org/sbase || sbase-gitAUR
  • ubase — An extension of the sbase utilities.
https://core.suckless.org/ubase || 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
  • autojump — A faster way to navigate your filesystem from the command line.
https://github.com/wting/autojump || autojumpAUR

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

See also 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
  • agrep — 近似搜索。
https://laurikari.net/tre || tre

代碼搜索工具

以下 3 個工具旨在在代碼搜索方面替代 grep。它們默認執行遞歸搜索、跳過二進位文件並遵守 .gitignore

  • ack — 基於 Perl 的 grep 替代品,為搜索大量異構的源碼樹而生。
https://beyondgrep.com/ || ack
  • ripgrep (rg) — 結合了 ag 的易用性和 grep 的速度。
https://github.com/BurntSushi/ripgrep || ripgrep
  • The Silver Searcher (ag) — 類似 Ack 的代碼搜索工具,不過更快。
https://github.com/ggreer/the_silver_searcher || the_silver_searcher
  • ugrep (ug) — Ultrafast grep with interactive user interface, fuzzy search, boolean queries, hexdumps and more.
https://github.com/Genivia/ugrep || ugrep

交互式過濾器

  • 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

dd alternatives

Tango-view-fullscreen.png這篇文章的某些內容需要擴充。Tango-view-fullscreen.png

原因: ddrescue should be added to a list below and briefly described. Given the name similarity, it would be nice to mention the differences from dd_rescue. (在 Talk:核心工具 中討論)

See also: dd and ddrescue

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.
http://sg.danny.cz/sg/ddpt.html || ddptAUR
  • sdd — A dd implementation portable across UNIX environments by Joerg Schilling, that can checksum the copied data and retry reading bad blocks.
https://schilytools.sourceforge.net/ || schily-tools-sddAUR
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.
http://dcfldd.sourceforge.net || dcflddAUR
  • 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.
https://sourceforge.net/projects/dc3dd/ || dc3ddAUR

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.
http://www.garloff.de/kurt/linux/ddrescue/ || dd_rescue
  • 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.
https://www.maier-komor.de/mbuffer.html || mbuffer

df alternatives

  • duf — A disk usage/free utility.
https://github.com/muesli/duf || duf

du alternatives

  • dust — A more intuitive version of du, in rust.
https://github.com/bootandy/dust || dust
  • ncdu — Simple ncurses disk usage analyzer.
https://dev.yorhel.nl/ncdu || ncdu
  • gdu — Disk usage analyzer with console interface, written in Go.
https://github.com/Dundee/gdu || gdu

See also List of applications/Utilities#Disk usage display.

參閱