From 1ac18abb5b7333b30c4547d4bd1bd18daaaf5b67 Mon Sep 17 00:00:00 2001
From: Rocky Linux Automation
<75949597+rockylinux-auto@users.noreply.github.com>
Date: Tue, 3 May 2022 10:00:38 -0400
Subject: [PATCH 1/2] New translations 03-commands.md (Chinese Simplified)
---
docs/books/admin_guide/03-commands.zh.md | 1220 ++++++++++++----------
1 file changed, 666 insertions(+), 554 deletions(-)
diff --git a/docs/books/admin_guide/03-commands.zh.md b/docs/books/admin_guide/03-commands.zh.md
index b0c06a8b85..c29382ebf1 100644
--- a/docs/books/admin_guide/03-commands.zh.md
+++ b/docs/books/admin_guide/03-commands.zh.md
@@ -1,26 +1,26 @@
---
-title: Linux Commands
+title: Linux 命令
author: Antoine Le Morvan
-contributors: Steven Spencer, Aditya Putta
+contributors: Steven Spencer, Aditya Putta, tianci li
update: 11-08-2021
---
-# Commands for Linux Users
+# 针对Linux用户的命令
-In this chapter you will learn how to work with Linux with the commands.
+在本章中,您将学习如何使用Linux中的命令。
****
-**Objectives** : In this chapter, future Linux administrators will learn how to:
+**目标** : 在本章中,未来的 Linux 管理员们将学习如何:
-:heavy_check_mark: **move** in the system tree;
-:heavy_check_mark: **create** a text file, **display** its contents and **modify** it;
-:heavy_check_mark: use the most useful Linux commands.
+:heavy_check_mark: 在系统树中 **移动**
+:heavy_check_mark: **创建** 一个文本文件, **显示** 它的内容并 **修改** 它;
+:heavy_check_mark: 使用最实用的Linux命令
-:checkered_flag: **user commands**, **linux**
+:checkered_flag: **用户命令**, **linux**
-**Knowledge**: :star:
-**Complexity**: :star:
+**知识**: :star:
+**复杂度**: :star:
**阅读时间**: 40 分钟
@@ -28,101 +28,101 @@ In this chapter you will learn how to work with Linux with the commands.
## 概论
-Current Linux systems have graphical utilities dedicated to the work of an administrator. However, it is important to be able to use the interface in command line mode for several reasons:
+现代的 Linux 系统配备有专门用于协助管理员工作的图形工具。 但是,能够使用命令行模式也是很重要的,原因如下:
-* The majority of system commands are common to all Linux distributions, which is not the case for graphical tools.
-* It can happen that the system does not start correctly but that a backup command interpreter remains accessible.
-* Remote administration is done on the command line with an SSH terminal.
-* In order to preserve server resources, the graphical interface is either not installed or launched on demand.
-* Administration is done by scripts.
+* 大多数系统命令对于所有Linux发行版都是通用的,而图形工具则不是这样。
+* 可能发生的情况是——系统不能正确启动,但备份的命令解释器仍然可以被访问。
+* 远程管理是通过在 SSH 终端下的命令行完成的。
+* 为了保留服务器资源,图形界面要么不安装,要么按需启动。
+* 管理工作是由脚本完成的。
-Learning these commands allows the administrator to connect to a Linux terminal, to manage its resources, its files, to identify the station, the terminal, and the connected users, etc.
+学习这些命令可以让系统管理员通过一个 Linux 终端来管理服务器的资源、文件,识别站点、终端和已连接的用户等等。
-### The users
+### 用户
-The user of a Linux system is defined in the `/etc/passwd` file, by:
+在 Linux系统中,用户是通过 `/etc/passwd` 文件中的以下条目定义的:
-* a **login name**, more commonly called "login", containing no spaces;
-* a numeric identifier : **UID** (User Identifier);
-* a group identifier : **GID** (Group Identifier);
-* a **command interpreter**, a shell, which can be different from one user to another;
-* a **connection directory**, the __home directory__.
+* **登录名**,更普遍的叫法是 “用户名”,不含有空格;
+* 数字标识符 : **UID** (用户标识符);
+* 用户组标识符:**GID** (用户组标识符);
+* **命令解释器**(shell),不同用户可以不同;
+* **连接目录**,__家目录__。
-In other files by:
+在其他文件中,用户由以下条目定义:
-* a **password**, which will be encrypted before being stored (`/etc/shadow`);
-* a **command prompt**, or __prompt__ login, which will be symbolized by a `#` for administrators and a `$` for other users (`/etc/profile`).
+* **密码**,它会在储存之前被加密 (`/etc/shadow`);
+* **命令提示符**,或登录__提示符__, `#` 代表管理员,`$` 代表其他用户 (`/etc/profile`)。
-Depending on the security policy implemented on the system, the password will have to contain a certain number of characters and meet certain complexity requirements.
+取决于系统执行的安全策略,密码必须包含一定数量的字符,并满足某些复杂度的要求。
-Among the existing command interpreters, the **Bourne-Again Shell** (`/bin/bash`) is the one most frequently used. It is assigned by default to new users. For various reasons, advanced Linux users can choose alternative shells from among the Korn Shell (`ksh`), the C Shell (`csh`), etc.
+在现有的命令解释器中,**Bourne-Again Shell** (`/bin/bash`) 是最常用的。 默认情况下,它会被分配给新用户。 出于各种原因,高阶的 Linux 用户可以选择代替品,如 Korn Shell (`ksh`), C Shell (`csh`) 等。
-The user's login directory is by convention stored in the `/home` directory of the workstation. It will contain the user's personal data and the configuration files of his applications. By default, at login, the login directory is selected as the current directory.
+通常,用户的登录目录被储存在工作站的 `/home` 目录中。 它将包含用户的个人数据和应用程序的配置文件。 默认情况下,登录时会选择 登录目录 作为当前目录。
-A workstation type installation (with graphical interface) starts this interface on terminal 1. Linux being multi-user, it is possible to connect several users several times, on different **physical terminals** (TTY) or **virtual terminals** (PTS). Virtual terminals are available within a graphical environment. A user switches from one physical terminal to another using Alt + Fx from the command line or using CTRL + Alt + Fx.
+一个工作站类型的安装 (带有图形界面) 将在终端 1 上开启此界面。 Linux是多用户的,可以在不同的**物理终端**(TTY) 或**虚拟终端**(PTS) 上连接多个用户。 虚拟终端可以在图形化环境中使用。 一个用户可以通过 Alt + Fx 或 CTRL + Alt + Fx 来切换物理终端。
-### The shell
+### shell
-Once the user is connected to a console, the shell displays the command **prompt**. It then behaves like an infinite loop, with each statement entered:
+一旦用户连接到控制台,shell就会显示命令**prompt**。 然后,在输入每条语句时,它的表现就像一个无限循环:
-* displaying the command prompt;
-* reading the command ;
-* syntax analysis ;
-* substitution of special characters ;
-* execute the command;
-* display the command prompt;
-* etc.
+* 显示命令提示符;
+* 读取命令;
+* 语法分析;
+* 特殊字符的替换;
+* 执行命令;
+* 显示命令提示符;
+* 等等
-The key sequence CTRL + C is used to interrupt a running command.
+CTRL + C两个按键用于中断正在运行的命令。
-The use of a command generally follows this sequence:
+命令的使用通常遵循以下顺序:
```bash
command [option(s)] [arguments(s)]
```
-The name of the command is **often in lower case**.
+命令的名称 **通常为小写**。
-A space separates each item.
+每一项都用空格隔开。
-Short **options** begin with a dash (`-l`), while **long options** begin with two dashes (`--list`). A double dash (`--`) indicates the end of the option list.
+**短选项**以破折号开头(`-l`),而**长选项**以两个破折号(`--list`)开头。 双破折号(`--`)表示选项列表的结尾。
-It is possible to group some short options together:
+可以将一些短选项组合在一起,例如:
```bash
$ ls -l -i -a
```
-is equivalent to:
+等同于:
```bash
$ ls -lia
```
-There can of course be several arguments after an option:
+当然,在选项后面可以跟几个对象:
```bash
$ ls -lia /etc /home /var
```
-In the literature, the term "option" is equivalent to the term "parameter," which is more commonly used in programming. The optional side of an option or argument is symbolized by enclosing it in square brackets `[` and `]`. When more than one option is possible, a vertical bar called a "pipe" separates them `[a|e|i]`.
+在文献资料中,术语 "option"(选项) 相当于术语"parameter"(参数),这在编程中更常用。 选项或参数的可选部分用方括号括起来 —— `[` 和 `]`。 当可能有多个选项时,一个称为 "管道" 的垂直条将它们分隔开来 `[a|e|i]`。
-## General commands
+## 常规命令
-### `apropos`, `whatis` and `man` commands
+### `apropos`,`whatis` 和 `man` 命令
-It is impossible for an administrator at any level to know all the commands and options in detail. A manual is usually available for all installed commands.
+任何级别的管理员都不可能详细了解所有的命令和选项。 所以所有已经安装的命令通常都会有一个手册。
-#### `apropos` command
+#### `apropos` 命令
-The command `apropos` allows you to search by keyword within these manual pages:
+命令 `apropos` 允许您在这些手册页中按关键字搜索:
-| Options | Observations |
-| ------------------------------------------- | ---------------------------------------------------------- |
-| `-s`, `--sections list` or `--section list` | Limited to manual sections. |
-| `-a` or `--and` | Displays only the item matching all the provided keywords. |
+| 选项 | 描述 |
+| ------------------------------------------- | -------------------- |
+| `-s`, `--sections list` 或者 `--section list` | 仅限于手册部分。 |
+| `-a` 或者 `--and` | 只显示与所提供的所有关键词相匹配的项目。 |
-Example:
+示例:
```bash
$ apropos clear
@@ -142,7 +142,7 @@ XClearWindow (3) - clear area or window
XSelectionClearEvent (3) - SelectionClear event structure
```
-To find the command that will allow changing the password of an account:
+要查找允许更改帐户密码的命令,请执行以下操作:
```bash
$ apropos --exact password -a change
@@ -150,83 +150,88 @@ chage (1) - change user password expiry information
passwd (1) - change user password
```
-#### `whatis` command
+#### `whatis` 命令
-The `whatis` command displays the description of the command passed as argument:
+`whatis` 命令显示命令的描述信息:
```bash
whatis clear
```
-Example:
+示例:
```bash
$ whatis clear
clear (1) - clear the terminal screen
```
-#### `man` command
+#### `man` 命令
-Once found by `apropos` or `whatis`, the manual is read by `man` ("Man is your friend"). This set of manuals is divided into 8 sections, grouping information by topic, the default section being 1:
+手册一旦被`apropos` 或 `whatis`发现,就会被`man`读取(“手册是你的朋友”)。 这套手册分为8个部分,按主题对信息进行分组,默认部分为1:
-1. User Commands;
-2. System Calls;
-3. C library functions;
-4. Peripherals and special files;
-5. File formats ;
-6. Games;
-7. Miscellaneous;
-8. System administration tools and daemons. Information about each section can be accessed by typing `man x intro`, where `x` is the section number.
+1. 可执行的程序或命令;
+2. 系统调用(内核给定的函数);
+3. 库调用(库给出的函数);
+4. 特殊文件(通常位于/dev中);
+5. 文件格式和约定(配置文件如/etc/passwd);
+6. 游戏(例如基于角色的应用程序);
+7. 杂项(如:man(7);
+8. 系统管理命令(通常仅适用于root用户);
+9. 跟内核有关的文件。
-The command:
+可以通过键入`man x intro`访问有关每个部分的信息,其中`x`是数字编号。
+
+命令:
```bash
man passwd
```
-will tell the administrator about the passwd command, its options, etc. While a:
+这将告诉管理员 passwd 命令及其选项等。 但这条命令:
```bash
$ man 5 passwd
```
-will inform him about the files related to the command.
+将告知用户 passwd 命令有关的文件。
-Not all pages of the manual are translated from English. However, they are generally very accurate and provide all the information needed. The syntax used and the division may confuse the beginner administrator, but with practice, he will quickly find the information he is looking for.
+并不是所有的手册页都是从英文翻译过来的。 然而,英语手册页通常非常准确,并提供了所需的所有信息。 其使用的语法规则和分隔规则可能会让初学者管理员感到困惑,但经过练习,我相信你会找到你想要的信息。
-The navigation in the manual is done with the arrows ↑ and ↓. The manual is exited by pressing the q key.
+本手册中的导航是使用 ↑ 和 ↓箭头完成的, 按 q 键退出手册。
-### `shutdown` command
+### `shutdown` 命令
-The `shutdown` command allows you to **electrically shut down** a Linux server, either immediately or after a certain period of time.
+`shutdown`命令允许您立即或在一段时间后以 **电方式关闭** Linux服务器。
```bash
shutdown [-h] [-r] time [message]
```
-The shutdown time should be specified in the format `hh:mm` for a precise time, or `+mm` for a delay in minutes.
+应以`hh:mm`格式指定精准的关闭时间,或者以 `+mm` 指定延迟多长时间。
-To force an immediate stop, the word `now` will replace the time. In this case, the optional message is not sent to other users of the system.
+若要强制立即关闭,请使用单词 `now`,用来替代时间。 在这种情况下,可选的消息不会被发送给系统的其他用户。
-Examples:
+示例:
```bash
[root]# shutdown -h 0:30 "Server shutdown at 0:30"
[root]# shutdown -r +5
```
-Options:
+选项:
+
+| 选项 | 备注 |
+| ---- | -------- |
+| `-h` | 以电方式关闭系统 |
+| `-r` | 重启系统 |
-| Options | Remarks |
-| ------- | -------------------------------- |
-| `-h` | Shutdown the system electrically |
-| `-r` | Restarts the system |
+### `history` 命令
-### `history` command
+`history` 命令显示用户输入命令的历史记录。
-The `history` command displays the history of commands that have been entered by the user. The commands are stored in the `.bash_history` file in the user's login directory.
+这些命令存储在用户登录目录的 `.bash_history` 文件中。
-Example of a history command
+history命令示例
```bash
$ history
@@ -234,72 +239,83 @@ $ history
148 man history
```
-| Options | Comments |
-| ------- | ------------------------------------------------------------------------------------------------------------------ |
-| `-w` | The `-w` option will copy the history of the current session to it. |
-| `-c` | The `-c` option will delete the history of the current session (but not the contents of the `.bash_history` file). |
+| 选项 | 解释 |
+| ---- | ----------------------------------------------- |
+| `-w` | 将当前历史记录写入到历史文件 |
+| `-c` | `-c`选项将删除当前会话的历史记录(但不会删除`.bash_history`文件中的内容)。 |
+
+* 操作历史:
+
+要操作历史记录,从命令提示符中输入以下命令即可:
-* Manipulating history:
+| 键盘输入 | 功能 |
+| ------------------ | -------------------- |
+|
在该示例中:
+ +$ >-hard-hard # To create an empty file called -hard-hard
hard-hard
[CTRL+C] To interrupt the creation of the file
$ rm -f -- -hard-hard
-```
+`
-The hard-hard file name starts with a `-`. Without the use of the `--` the shell would have interpreted the `-d` in `-hard-hard` as an option.
+hard-hard的文件名是以`-`开始的。 如果没有使用`--`,shell会将`-hard-hard`中的`-d`解释为一个选项。
-### `mv` command
+### `mv` 命令
-The `mv` command moves and renames a file.
+`mv` 命令用来移动和重命名文件。
```bash
mv file [file ...] destination
```
-Examples:
+示例:
```bash
$ mv /home/rockstar/file1 /home/rockstar/file2
$ mv /home/rockstar/file1 /home/rockstar/file2 /tmp
```
-| Options | Information |
-| ------- | --------------------------------------------------------------- |
-| `-f` | Don't ask for confirmation if overwriting the destination file. |
-| `-i` | Request confirmation if overwriting destination file (default). |
+| 选项 | 信息 |
+| ---- | ------------------- |
+| `-f` | 如果要覆盖目标文件,不要询问。 |
+| `-i` | 如果覆盖目标文件,则请求询问(默认)。 |
-A few concrete cases will help you understand the difficulties that can arise:
+以下几个具体案例将帮助您了解可能出现的困难:
```bash
$ mv /home/rockstar/file1 /home/rockstar/file2
```
-Renames `file1` to `file2`, if `file2` already exists, it will be replaced by `file1`.
+将 `file1` 重命名为 `file2`. 如果 `file2` 已经存在,则将文件内容替换为`file1`。
```bash
$ mv /home/rockstar/file1 /home/rockstar/file2 /tmp
```
-Moves `file1` and `file2` into the `/tmp` directory.
+将 `file1` 和 `file2` 移动到 `/tmp` 目录。
```bash
$ mv file1 /repexist/file2
```
-Moves `file1` into `repexist` and renames it `file2`.
+将 `file1` 移动到 `repext` 并重命名为 `file2`。
```bash
$ mv file1 file2
```
-`file1` is renamed to `file2`.
+`file1`已重命名为`file2`。
```bash
$ mv file1 /repexist
```
-If the destination directory exists, `file1` is moved to `/repexist`.
+如果目标目录存在, `file1` 将移动到 `/repext`。
```bash
$ mv file1 /wrongrep
```
-If the destination directory does not exist, `file1` is renamed to `wrongrep` in the root directory.
+如果目标目录不存在,`file1`将在根目录中被重命名为`errorep`。
-### `cp` command
+### `cp` 命令
-The `cp` command copies a file.
+`cp` 命令用来复制文件。
```bash
cp file [file ...] destination
```
-Example:
+示例:
```bash
$ cp -r /home/rockstar /tmp
```
-| Options | Information |
-| ------- | ---------------------------------------------------------------- |
-| `-i` | Request confirmation if overwriting (default). |
-| `-f` | Do not ask for confirmation if overwriting the destination file. |
-| `-p` | Keeps the owner, permissions and timestamp of the copied file. |
-| `-r` | Copies a directory with its files and subdirectories. |
-| `-s` | Creates a symbolik links rather than copying |
+| 选项 | 信息 |
+| ---- | ------------------- |
+| `-i` | 要求确认是否覆盖(默认)。 |
+| `-f` | 如果覆盖目标文件,不会要求确认。 |
+| `-p` | 保留复制文件时的所有者、权限和时间戳。 |
+| `-r` | 复制目录及其文件和子目录。 |
+| `-s` | 创建符号链接,而不是复制。 |
```bash
cp file1 /repexist/file2
```
-`file1` is copied to `/repexist` under the name `file2`.
+`file1`将复制到 `/repexist`目录下,且文件名为`file2`。
```bash
$ cp file1 file2
```
-`file1` is copied as `file2` to this directory.
+在此目录中,`file1` 已经复制为`file2`。
```bash
$ cp file1 /repexist
```
-If the destination directory exists, `file1` is copied to `/repexist`.
+如果目标目录存在,则`file1`将被复制到`/repexist`目录中。
```bash
$ cp file1 /wrongrep
```
-If the destination directory does not exist, `file1` is copied under the name `wrongrep` to the root directory.
+如果目标目录不存在,`file1`将被复制到根目录下且名称为`wrongrep`。
-## Visualization
+## 可视化
-### `file` command
+### `file` 命令
-The `file` command displays the type of a file.
+`file` 命令用来显示文件的类型。
```bash
file file1 [files]
```
-Example:
+示例:
```bash
$ file /etc/passwd /etc
@@ -793,15 +830,15 @@ $ file /etc/passwd /etc
/etc: directory
```
-### `more` command
+### `more` 命令
-The `more` command displays the contents of one or more files screen by screen.
+`more`命令用来通过屏幕显示一个或多个文件的内容。
```bash
more file1 [files]
```
-Example:
+示例:
```bash
$ more /etc/passwd
@@ -809,56 +846,56 @@ root:x:0:0:root:/root:/bin/bash
...
```
-Using the ENTER key, the move is line by line. Using the SPACE key, the move is page by page. `/text` allows you to search for the occurrence in the file.
+使用ENTER回车键可逐行移动。 使用SPACE空格键可逐页移动。 `/Text`允许您在文件中搜索匹配项。
-### `less` command
+### `less` 命令
-The `less` command displays the contents of one or more files. The `less` command is interactive and has its own commands for use.
+`less`命令用来显示一个或多个文件的内容。 `less`命令是交互式的,并且有自己的命令可供使用。
```bash
less file1 [files]
```
-The commands specific to `less` are:
+`less`的特定命令有:
-| Command | Action |
-| ----------------- | ----------------------------------------------- |
-| `h` | Help. |
-| `Arrows` | Move up, down a line, or to the right or left.. |
-| `Enter` | Move down one line. |
-| `Space` | Move down one page. |
-| `PgUp` and `PgDn` | Move up or down one page. |
-| `Begin` and `End` | Move to the beginning or end of a file. |
-| `/texte` | Search for text. |
-| `q` | Quit the `less` command. |
+| 命令 | 动作 |
+| ------------------------------------------------ | -------------- |
+| h | 帮助。 |
+| ↑↓→← | 向上、向下、向右或向左移动。 |
+| Enter | 下移一行。 |
+| Space | 向下移动一页。 |
+| PgUp 和 PgDn | 向上或向下移动一个页面。 |
+| gg 和 G | 移动到文件的首页或尾页。 |
+| `/texte` | 搜索文本。 |
+| q | 退出`less`交互式命令。 |
-### `cat` command
+### `cat` 命令
-The `cat` command concatenates the contents of multiple files and displays the result on the standard output.
+`cat` 命令用来将多个文件的内容连接起来,且将结果显示在标准输出上。
```bash
cat file1 [files]
```
-Example 1 - Displaying the contents of a file to the standard output:
+例1 - 在标准输出中显示文件的内容:
```bash
$ cat /etc/passwd
```
-Example 2 - Displaying the contents of multiple files to standard output:
+例2 - 在标准输出中显示多个文件的内容:
```bash
$ cat /etc/passwd /etc/group
```
-Example 3 - Displaying the contents of several files in the file `usersAndGroups.txt`:
+例3 - 使用输出重定向将多个文件的内容合并为一个文件:
```bash
$ cat /etc/passwd /etc/group > usersAndGroups.txt
```
-Example 4 - Displaying the line numbering:
+例4 - 显示行号:
```bash
$ cat -n /etc/profile
@@ -871,7 +908,7 @@ $ cat -n /etc/profile
…
```
-Example 5 - Shows the numbering of non-empty lines:
+例5 - 显示非空行的编号:
```bash
$ cat -b /etc/profile
@@ -884,44 +921,44 @@ $ cat -b /etc/profile
…
```
-### `tac` command
+### `tac` 命令
-The `tac` command does almost the opposite of the `cat` command. It displays the contents of a file starting from the end (which is particularly interesting for reading logs!).
+`tac`命令的作用几乎与`cat`命令相反。 它从文件末尾开始显示文件的内容(这对于阅读日志来说特别有趣!)。
-Example: Display a log file by displaying the last line first:
+示例:通过首先显示最后一行来显示日志文件:
```bash
[root]# tac /var/log/messages | less
```
-### `head` command
+### `head` 命令
-The `head` command displays the beginning of a file.
+`head` 命令用来显示文件的开头部分。
```bash
-head [-n x] file
+尾色 [-f] [-n x] 文件
```
-| Option | Observation |
-| ------ | --------------------------------------- |
-| `-n x` | Display the first `x` lines of the file |
+| 选项 | 描述 |
+| ------ | ---------- |
+| `-n x` | 显示文件的前`x`行 |
-By default (without the `-n` option), the `head` command will display the first 10 lines of the file.
+默认情况下(没有 `-n` 选项), `head` 命令将显示文件的前10行。
-### `tail` command
+### `tail` 命令
-The `tail` command displays the end of a file.
+`tail` 命令用来显示文件的结尾部分。
```bash
tail [-f] [-n x] file
```
-| Option | Observation |
-| ------ | ----------------------------------------- |
-| `-n x` | Displays the last `x` lines of the file |
-| `-f` | Displays changes to the file in real time |
+| 选项 | 描述 |
+| ------ | ------------- |
+| `-n x` | 显示文件的最后 `x` 行 |
+| `-f` | 实时显示文件的变化 |
-Example:
+示例:
```bash
tail -n 3 /etc/passwd
@@ -930,66 +967,67 @@ tcpdump::x:72:72::/:/sbin/nologin
user1:x:500:500:grp1:/home/user1:/bin/bash
```
-With the `-f` option, the `tail` command does not give back and runs until the user interrupts it with the sequence CTRL + C. This option is very frequently used to track log files (the logs) in real time.
+对于`-f`选项,除非用户使用CTRL + C退出监控状态,否则将始终输出文件的更改信息。 此选项经常用于实时跟踪日志文件(的日志)。
-Without the `-n` option, the tail command displays the last 10 lines of the file.
+如果不使用`-n`选项, `tail`命令将显示文件的最后10行。
-### `sort` command
+### `sort` 命令
-The `sort` command sorts the lines of a file.
+`sort` 命令用来对文件的行进行排序。
-It allows you to order the result of a command or the content of a file in a given order, numerically, alphabetically, by size (KB, MB, GB) or in reverse order.
+它允许您以给定的顺序对命令的结果或文件的内容进行排序,包括按数字、字母顺序、按大小(KB、MB、GB)或相反的顺序。
```bash
-sort [-kx] [-n] [-u] [-o file] [-ty] file
+sort [-k] [-n] [-u] [-o file] [-t] file
```
-Example:
+示例:
```bash
-$ sort -k3 -t: -n /etc/passwd
+$ sort -k 3,4 -t ":" -n /etc/passwd
root:x:0:0:root:/root:/bin/bash
adm:x:3:4:adm:/var/adm/:/sbin/nologin
```
-| Option | Observation |
-| --------- | -------------------------------------------- |
-| `-kx` | Specifies the `x` column to sort on |
-| `-n` | Requests a numeric sort |
-| `-o file` | Saves the sort to the specified file |
-| `-ty` | Specifies the field separator character `y`. |
-| `-r` | Reverse the order of the result |
-| `- u` | unique |
+| 选项 | 描述 |
+| --------- | ------------------------------------ |
+| `-k` | 指定要分隔的列。 您可以指定多个列 |
+| `-n` | 要求进行数字排序 |
+| `-o file` | 将排序结果保存到指定的文件中 |
+| `-t` | 指定分隔符,要求相应文件的内容必须是以规则分隔的列内容,否则无法正确排序 |
+| `-r` | 将结果的顺序颠倒。 与`-n`选项一起使用,按从大到小的顺序进行排序 |
+| `-u` | 排序后删除重复项。 相当于`sort file | uniq` |
-The `sort` command sorts the file only on the screen. The file is not modified by the sorting. To save the sort, use the `-o` option or an output redirection `>`.
+`sort`命令仅在屏幕上对文件进行排序, 该文件不会因为排序而被修改。 要保存排序后的结果,请使用`-o`选项或者输出重定向 `>` 。
-By default, the numbers are sorted according to their character. Thus, "110" will be before "20", which will itself be before "3". The `-n` option must be specified so that the numeric character blocks are sorted by their value.
+默认情况下,数字会根据其字符进行排序。 因此,"110" 将在 "20" 之前,而 "20" 将在 "3" 之前。 当指定`-n`选项后,将按数值对数字字符块进行排序。
-The `sort` command reverses the order of the results, with the `-r` option:
+`sort`命令使用`-r`选项会将结果的顺序颠倒过来:
```bash
-$ sort -k3 -t: -n -r /etc/passwd
-root:x:0:0:root:/root:/bin/bash
-adm:x:3:4:adm:/var/adm/:/sbin/nologin
+$ sort -k 3 -t ":" -n -r /etc/passwd
+nobody:x:65534:65534:Kernel Overflow User:/:/sbin/nologin
+systemd-coredump:x:999:997:systemd Core Dumper:/:/sbin/nologin
+polkitd:x:998:996:User for polkitd:/:/sbin/nologin
```
-In this example, the `sort` command will sort the contents of the `/etc/passwd` file this time from largest uid to smallest.
+在这个示例中,`sort`命令将对`/etc/passwd`文件的内容进行排序,这次是从最大的uid到最小的uid。
-Some advanced examples of using the `sort` command:
+使用`sort`命令的一些高级示例:
-* Shuffling values
+* 随机排序值
-The `sort` command also allows you to shuffle values with the `-R` option:
+`sort` 命令也允许您用 `-R` 选项来随机排序值:
```bash
$ sort -R /etc/passwd
```
-* Sorting IP addresses
+* 对 IP 地址进行排序
-A system administrator is quickly confronted with the processing of IP addresses from the logs of his services such as SMTP, VSFTP or Apache. These addresses are typically extracted with the `cut` command.
+系统管理员很快就会面临处理其服务(如SMTP、VSFTP或Apache)日志中的IP地址的问题。 通常使用`cut`命令提取这些地址。
-Here is an example with the file `dns-client.txt`:
+以下是文件`dns-client.txt`的示例:
```
192.168.1.10
@@ -1008,11 +1046,11 @@ $ sort -nr dns-client.txt
5.1.150.146
```
-* Sorting file by removing duplicates
+* 通过删除重复项对文件进行排序
-The `sort` command knows how to remove the duplicates from the file output using `-u` as option.
+`sort`命令知道如何使用`-u`作为选项从文件输出中删除重复项。
-Here is an example with the file `colours.txt`:
+这是文件 `colours.txt` 的示例:
```
Red
@@ -1029,11 +1067,11 @@ Pink
Red
```
-* Sorting file by sizes
+* 按大小排序文件
-The `sort` command knows how to recognize file sizes, from commands like `ls` with the `-h` option.
+`sort`命令知道如何从带有`-h`选项的`ls`等命令识别文件大小。
-Here is an example with the file `size.txt`:
+这是文件 `size.txt` 的示例:
```
1,7G
@@ -1062,127 +1100,136 @@ $ sort -hr size.txt
69K
```
-### `wc` command
+### `wc` 命令
-The `wc` command counts the number of lines, words and/or bytes in a file.
+`wc` 命令用来计算文件中的行数、 单词数和字节数。
```bash
wc [-l] [-m] [-w] file [files]
```
-| Option | Observation |
-| ------ | ------------------------------- |
-| `-c` | Count the number of bytes. |
-| `-m` | Count the number of characters. |
-| `-l` | Counts the number of lines. |
-| `-w` | Counts the number of words. |
+| 选项 | 描述 |
+| ---- | ------ |
+| `-c` | 计数字节数。 |
+| `-m` | 计算字符数。 |
+| `-l` | 计算行数。 |
+| `-w` | 计算单词数。 |
-## Search
+## 搜索
-### `find` command
+### `find` 命令
-The `find` command searches for files or directories location.
+`find`命令用来搜索文件或目录的位置。
```bash
find directory [-name name] [-type type] [-user login] [-date date]
```
-Since there are so many options to the `find` command, it is best to refer to the `man`.
+由于`find`命令有这么多选项,因此最好参考`man`。
-If the search directory is not specified, the `find` command will search from the current directory.
+如果未指定搜索目录,`find`命令将从当前目录进行搜索。
-| Option | Observation |
-| ------------------- | -------------------------------------- |
-| `-perm permissions` | Search for files by their permissions. |
-| `-size size` | Search for files by size. |
+| 选项 | 描述 |
+| ---------- | ------------ |
+| `-perm 权限` | 通过它们的权限搜索文件。 |
+| `-size 大小` | 按文件大小搜索文件。 |
-### `-exec` option of the `find` command
+### `find` 命令的`-exec` 选项
-It is possible to use the `-exec` option of the `find` command to execute a command on each result line:
+可以使用`find`命令的`-exec`选项对每个结果行执行命令:
```bash
$ find /tmp -name *.txt -exec rm -f {} \;
```
-The previous command searches for all files in the `/tmp` directory named `*.txt` and deletes them.
-
+如上命令所示,在`/tmp`目录下搜索所有的`*.txt`文件并将其删除。
-!!! Tip "Understand the `-exec` option" In the example above, the `find` command will construct a string representing the command to be executed.
+!!! tip "了解`-exec`选项"
- If the `find` command finds three files named `log1.txt`, `log2.txt`, and `log3.txt`, then the `find` command will construct the string by replacing in the string `rm -f {} \;` the braces with one of the results of the search, and do this as many times as there are results.
+ 在上面的示例中,`find` 命令将组成一个表示执行命令的字符串。
- This will give us:
+ 如果`find`命令找到名为`log1.txt`、`log2.txt`和`log3.txt`这三个文件,则`find`命令通过`rm -f {} \;`将字符串中的大括号替换为搜索结果之一来组合字符串,并尽可能多次地执行此操作。
+
+ 这将给我们带来:
```
rm -f /tmp/log1.txt ; rm -f /tmp/log2.txt ; rm -f /tmp/log3.txt ;
```
- The `;` character is a special shell character that must be protected by a `\` to prevent it from being interpreted too early by the `find` command (and not in the `-exec`).
+ `;`字符是一个特殊的shell字符,必须由`\`保护,以防止被`-find`命令(而不是`-exec`)过早地解释它。
+
+!!! tip "提示"
-!!! Tip `$ find /tmp -name *.txt -delete` does the same thing.
+ `$ find /tmp -name *.txt -delete` 可以做同样的事情。
-### `whereis` command
+### `whereis` 命令
-The `whereis` command searches for files related to a command.
+`whereis` 命令用来搜索与命令相关的文件。
```bash
whereis [-b] [-m] [-s] command
```
-Example:
+示例:
```bash
$ whereis -b ls
ls: /bin/ls
```
-| Option | Observation |
-| ------ | ------------------------------- |
-| `-b` | Search only the binary file. |
-| `-m` | Searches only for man pages. |
-| `-s` | Searches only for source files. |
+| 选项 | 描述 |
+| ---- | --------- |
+| `-b` | 只搜索二进制文件。 |
+| `-m` | 只搜索手册页。 |
+| `-s` | 只搜索源文件。 |
-### `grep` command
+### `grep` 命令
-The `grep` command searches for a string in a file.
+`grep` 命令用来搜索文件中的字符串。
```bash
grep [-w] [-i] [-v] "string" file
```
-Example:
+示例:
```bash
$ grep -w "root:" /etc/passwd
root:x:0:0:root:/root:/bin/bash
```
-| Option | Observation |
-| ------ | --------------------------------------- |
-| `-i` | Ignore the case of the searched string. |
-| `-v` | Excludes lines containing the string. |
-| `-w` | Search for the exact word. |
+| 选项 | 描述 |
+| ---- | ------------ |
+| `-i` | 忽略搜索字符串的大小写。 |
+| `-v` | 排除包含字符串的行。 |
+| `-w` | 搜索准确的单词。 |
-The `grep` command returns the complete line containing the string you are looking for.
-* The `^` special character is used to search for a string at the beginning of a line.
-* The special character `$` searches for a string at the end of a line.
+`grep`命令返回包含您要查找的字符串的完整行。
+* `^`特殊字符用于搜索行首的字符串。
+* 特殊字符`$`用来搜索行尾的字符串。
```bash
$ grep -w "^root" /etc/passwd
```
-!!! Note This command is very powerful and it is highly recommended to consult its manual. It has many derivatives.
+!!! Note "说明"
-It is possible to search for a string in a file tree with the `-R` option.
+ 该命令非常强大,强烈建议参考其手册。 它有很多的衍生产品。
+
+可以使用`-R`选项在文件树中搜索字符串。
```bash
grep -R "Virtual" /etc/httpd
```
-### Meta-characters (wildcards)
+### 元字符(通配符)
+
+在搜索过程中,元字符将代替一个或多个字符(甚至不包含字符)。 这些元字符也称为通配符。
+
+它们可以组合起来使用。
-Meta-characters replace one or more characters (or even an absence of characters) during a search. These meta-characters are also known as wildcards. They can be combined. The `*` character replaces a string composed of any characters. The `*` character can also represent an absence of character.
+`*`字符用来代替由任意字符组成的字符串。 `*` 字符也可以表示没有字符。
```bash
$ find /home -name "test*"
@@ -1193,9 +1240,9 @@ $ find /home -name "test*"
/home/rockstar/test362
```
-Meta-characters allow more complex searches by replacing all or part of a word. Simply replace the unknowns with these special characters.
+元字符可以通过代替单词的全部或部分来进行更复杂的搜索。 只需用这些特殊字符来代替未知的字符。
-The character `?` replaces a single character, whatever it is.
+字符 `?` 代替单个字符,不管它是什么。
```bash
$ find /home -name "test?"
@@ -1203,7 +1250,7 @@ $ find /home -name "test?"
/home/rockstar/tests
```
-The square brackets `[` are used to specify the values that a single character can take.
+方括号`[`和`]`用于指定单个字符可以接受的值。
```bash
$ find /home -name "test[123]*"
@@ -1212,41 +1259,48 @@ $ find /home -name "test[123]*"
/home/rockstar/test362
```
-!!! Note Always surround words containing meta-characters with `"` to prevent them from being replaced by the names of files that meet the criteria.
+!!! Note "说明"
-!!! Warning Do not confuse shell meta-characters with regular expression meta-characters. The `grep` command uses regular expression meta-characters.
+ 始终使用 `"` 括起包含元字符的单词,以防止它们被符合条件的文件名代替。
-## Redirects and pipes
+!!! warning "警告"
-### Standard input and output
+ 不要将shell元字符与正则表达式元字符混淆。 `grep`命令使用正则表达式元字符。
-On UNIX and Linux systems, there are three standard streams. They allow programs, via the `stdio.h` library, to input or output information.
+## 重定向和管道
-These streams are called X channel or X file descriptor.
+### 标准输入和输出
-By default:
-* the keyboard is the input device for channel 0, called **stdin** ;
-* the screen is the output device for channels 1 and 2, called **stdout** and **stderr**.
+关于UNIX和Linux系统,有三个标准流。 它们允许程序通过`stdio.h`库输入或输出信息。
-
+这些流称为X通道或X文件描述符。
-**stderr** receives the error streams returned by a command. The other streams are directed to **stdout**.
+默认情况下:
-These streams point to peripheral files, but since everything is a file in UNIX/Linux, I/O streams can easily be diverted to other files. This principle is the strength of the shell.
+* 键盘是通道0的输入设备,称为 **stdin**;
+* 屏幕是通道1和2的输出设备,称为 **stdout** 和 **stderr**。
-### Input redirection
+
-It is possible to redirect the input stream from another file with the character `<` or `<<`. The command will read the file instead of the keyboard:
+**stderr** 接收命令返回的错误流, 其他流定向到**stdout**。
+
+这些流指向外部文件,但由于在UNIX/Linux中所有文件都是一个文件,所以I/O流可以很容易地被转移到其他文件。 这项原则是shell的长处。
+
+### 输入重定向
+
+可以使用字符 `<` 或 `<<` 重定向来自另一个文件的输入流。 命令将读取文件,而不是键盘:
```bash
$ ftp -in serverftp << ftp-commands.txt
```
-!!! Note Only commands that require keyboard input will be able to handle input redirection.
+!!! Note "说明"
+
+ 只有需要键盘输入的命令才能处理输入重定向。
-Input redirection can also be used to simulate user interactivity. The command will read the input stream until it encounters the defined keyword after the input redirection.
+还可以使用输入重定向来模拟用户交互。 命令将读取输入流,直到在输入重定向后遇到定义的关键字。
-This feature is used to script interactive commands:
+此功能用于编写交互式命令的脚本:
```bash
$ ftp -in serverftp << END
@@ -1256,7 +1310,7 @@ bye
END
```
-The keyword `END` can be replaced by any word.
+关键字`END`可以替换为任何单词。
```bash
$ ftp -in serverftp << STOP
@@ -1266,13 +1320,15 @@ bye
STOP
```
-The shell exits the `ftp` command when it receives a line containing only the keyword.
+当 shell 收到只包含关键字的行时,它将退出`ftp`命令。
-!!! Warning The ending keyword, here `END` or `STOP`, must be the only word on the line and must be at the beginning of the line.
+!!! warning "警告"
-The standard input redirection is rarely used because most commands accept a filename as an argument.
+ 结尾关键字 `END` 或 `STOP` 必须是行中唯一的单词,并且必须位于行的开头。
-The command `wc` could be used like this:
+标准输入重定向很少使用,因为大多数命令都接受一个文件名作为参数。
+
+命令 `wc` 可以像这样使用:
```bash
$ wc -l .bash_profile
@@ -1281,129 +1337,129 @@ $ wc -l < .bash_profile
27 # returns only the number of lines
```
-### Output redirection
+### 输出重定向
-Standard output can be redirected to other files using the `>` or `>>` characters.
+可以使用 `>` 或 `>>` 字符将标准输出重定向到其他文件。
-The simple `>` redirection overwrites the contents of the output file:
+简单的使用 `>` 重定向覆盖输出文件的内容:
```bash
$ date +%F > date_file
```
-while the double redirection `>>` adds (concatenates) to the content of the output file.
+当使用 `>>` 字符时,它表示命令的输出结果被追加到文件内容中。
```bash
$ date +%F >> date_file
```
-In both cases, the file is automatically created when it does not exist.
+在这两种情况下,文件在不存在时自动创建。
-The standard error output can also be redirected to another file. This time it will be necessary to specify the channel number (which can be omitted for channels 0 and 1):
+也可以将标准错误输出重定向到另一个文件。 这一次需要指定通道编号(通道0和1可以省略该编号):
```bash
$ ls -R / 2> errors_file
$ ls -R / 2>> errors_file
```
-### Examples of redirection
+### 重定向示例
-Redirection of 2 outputs to 2 files:
+将2个输出重定向到 2 个文件:
```bash
$ ls -R / >> ok_file 2>> nok_file
```
-Redirection of the 2 outputs to a single file:
+将2个输出重定向到单个文件:
```bash
$ ls -R / >> log_file 2>&1
```
-Redirection of *stderr* to a "bottomless pit" (`/dev/null`):
+*stderr* 重定向到 "无底洞" (`/dev/null`):
```bash
$ ls -R / 2>> /dev/null
```
-When both output streams are redirected, no information is displayed on the screen. To use both the output redirection and to keep the display, you will have to use the command `tee`.
+当两个输出流都被重定向时,屏幕上不会显示任何信息。 要同时使用输出重定向且保持显示,您必须使用命令`tee`。
-### Pipes
+### 管道
-A **pipe** is a mechanism allowing you to link the standard output of a first command to the standard input of a second command.
+**管道**是一种机制,允许您将第一个命令的标准输出链接到第二个命令的标准输入。
-This communication is uni directional and is done with the `|` symbol. The pipe symbol `|` is obtained by pressing the SHIFT + | simultaneously.
+这种传递是单向的,用`|`符号完成。 管道符 `|` 通过同时按 Shift + | 获得。
-
+
-All data sent by the control on the left of the pipe through the standard output channel is sent to the standard input channel of the control on the right.
+管道左侧控件通过标准输出通道发送的所有数据都被发送到右侧控件的标准输入通道。
-The commands particularly used after a pipe are filters.
+管道后使用特别的命令进行过滤筛选
-* Examples:
+* 示例:
-Display only the beginning:
+仅显示开头:
```bash
$ ls -lia / | head
```
-Display only the end:
+只显示末尾:
```bash
$ ls -lia / | tail
```
-Sort the result:
+对结果进行排序:
```bash
$ ls -lia / | sort
```
-Count the number of words / characters:
+计算单词/字符的数量:
```bash
$ ls -lia / | wc
```
-Search for a string in the result:
+在结果中搜索字符串:
```bash
$ ls -lia / | grep fichier
```
-## Special points
+## 特殊点
-### `tee` command
+### `tee` 命令
-The `tee` command is used to redirect the standard output of a command to a file while maintaining the screen display.
+`tee`命令用于将命令的标准输出重定向到文件,同时保持屏幕显示。
-It is combined with the `|` pipe to receive as input the output of the command to be redirected:
+它与`|`管道结合使用,以接收要重定向的命令的输出作为输入:
```bash
$ ls -lia / | tee fic
$ cat fic
```
-The `-a` option adds to the file instead of overwriting it.
+`-a`选项表示添加到文件当中,而不是覆盖文件。
-### `alias` and `unalias` commands
+### `alias` 和 `unalias` 命令
-Using **alias** is a way to ask the shell to remember a particular command with its options and give it a name.
+使用**别名**是要求shell记住特定命令及其选项并为其命名的一种方法。
-For example:
+例如:
```bash
$ ll
```
-will replace the command:
+将替换该命令:
```bash
$ ls -l
```
-The `alias` command lists the aliases for the current session. Aliases are set by default on Linux distributions. Here, the aliases for a Rocky server:
+`alias`命令会列出当前会话的别名。 在Linux发行版上,别名是默认设置的。 这里是 Rocky 服务器的别名:
```bash
$ alias
@@ -1414,48 +1470,50 @@ alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
```
-The aliases are only defined temporarily, for the time of the user session.
+别名仅在用户会话期间临时定义。
+
+要永久使用,必须在以下位置创建它们:
-For permanent use, they must be created in the:
+* 用户登录目录中的`.bashrc`文件;
+* `/etc/bashrc` 文件,适用于所有用户。
-* `.bashrc` file in the user's login directory;
-* `/etc/profile.d/alias.sh` file for all users.
+!!! warning "警告"
-!!! Warning Special care must be taken when using aliases which can be potentially dangerous! For example, an alias set up without the administrator's knowledge:
+ 在使用可能有潜在危险的别名时,必须特别小心! 例如,在管理员不知情的情况下设置的别名:
```bash
alias cd='rm -Rf'
```
-The `unalias` command allows you to delete aliases.
+`unalias` 命令允许您删除别名。
-To delete a single alias:
+删除单个别名:
```bash
$ unalias ll
```
-To delete all aliases:
+要删除所有别名:
```bash
$ unalias -a
```
-To disable an alias temporarily, the combination is `\$ ls /; cd /home; ls -lia; cd /
+
+
++ :heavy_check_mark: Linux下用户的定义是什么? (7个答案) +
+ ++ :heavy_check_mark: 命令的长选项的特点是什么? +
+ ++ :heavy_check_mark: 哪些命令允许您搜索有关命令的帮助? +
+ +google
+ chuck --norris
+ info
+ apropos
+ whatis
+ + :heavy_check_mark: 哪个命令允许您查看用户的历史记录? +
+ ++ :heavy_check_mark: 哪个命令允许您在文件中搜索文本? +
+ +find
+ grep
+ + :heavy_check_mark: 哪个命令允许您搜索文件? +
+ +find
+ grep
+
+ :heavy_check_mark: 哪个命令将命令的错误流重定向到新的 errors.log 文件?
+
ls -R / 2> errors.log
+ ls -R / 2>> errors.log
+ ls -R / 2> errors.log 2>&1
+