From cd15d91e7c81c2a4cdce522137086566b435ba3a Mon Sep 17 00:00:00 2001 From: tianci li Date: Wed, 27 Apr 2022 09:30:09 +0800 Subject: [PATCH 1/2] Supplementary explanation of option and error modification of content --- docs/books/admin_guide/03-commands.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/books/admin_guide/03-commands.md b/docs/books/admin_guide/03-commands.md index 7cf2ef1ea3..6b032f4b7d 100644 --- a/docs/books/admin_guide/03-commands.md +++ b/docs/books/admin_guide/03-commands.md @@ -981,25 +981,25 @@ The `sort` command sorts the lines of a file. 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. ```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 | +| `-k` | Specify the columns to be separated. You can specify multiple columns | | `-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` | Only keeps unique results | +| `-t` | Specify a delimiter, which requires that the contents of the corresponding file must be regularly delimited column contents, otherwise they cannot be sorted properly | +| `-r` | Reverse the order of the result. Used in conjunction with the `-n` option to sort in order from largest to smallest | +| `-u` | Only keeps unique results | 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 `>`. @@ -1008,9 +1008,10 @@ By default, the numbers are sorted according to their character. Thus, "110" wil The `sort` command reverses the order of the results, with the `-r` option: ```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. From 164d824667b74a94f040e9e79a1719e846a2dada Mon Sep 17 00:00:00 2001 From: tianci li Date: Wed, 27 Apr 2022 09:36:26 +0800 Subject: [PATCH 2/2] update --- docs/books/admin_guide/03-commands.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/books/admin_guide/03-commands.md b/docs/books/admin_guide/03-commands.md index 6b032f4b7d..dee7d876b6 100644 --- a/docs/books/admin_guide/03-commands.md +++ b/docs/books/admin_guide/03-commands.md @@ -999,7 +999,7 @@ adm:x:3:4:adm:/var/adm/:/sbin/nologin | `-o file` | Saves the sort to the specified file | | `-t` | Specify a delimiter, which requires that the contents of the corresponding file must be regularly delimited column contents, otherwise they cannot be sorted properly | | `-r` | Reverse the order of the result. Used in conjunction with the `-n` option to sort in order from largest to smallest | -| `-u` | Only keeps unique results | +| `-u` | Remove duplicates after sorting. Equivalent to `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 `>`.