This commit is contained in:
geekpi 2018-11-09 08:49:56 +08:00
commit 4fc7fd9206
14 changed files with 573 additions and 469 deletions

View File

@ -1,4 +1,5 @@
# KeeWeb 一个开源且跨平台的密码管理工具 KeeWeb一个开源且跨平台的密码管理工具
======
![](https://www.ostechnix.com/wp-content/uploads/2018/10/keeweb-720x340.png) ![](https://www.ostechnix.com/wp-content/uploads/2018/10/keeweb-720x340.png)
@ -6,64 +7,60 @@
**KeePass** 就是一个这样的开源密码管理工具,它有一个官方客户端,但功能非常简单。也有许多 PC 端和手机端的其他密码管理工具,并且与 KeePass 存储加密密码的文件格式兼容。其中一个就是 **KeeWeb** **KeePass** 就是一个这样的开源密码管理工具,它有一个官方客户端,但功能非常简单。也有许多 PC 端和手机端的其他密码管理工具,并且与 KeePass 存储加密密码的文件格式兼容。其中一个就是 **KeeWeb**
KeeWeb 是一个开源、跨平台的密码管理工具具有云同步键盘快捷键和插件等功能。KeeWeb使用 Electron 框架,这意味着它可以在 WindowsLinux 和 Mac OS 上运行。 KeeWeb 是一个开源、跨平台的密码管理工具具有云同步键盘快捷键和插件等功能。KeeWeb使用 Electron 框架,这意味着它可以在 WindowsLinux 和 Mac OS 上运行。
### KeeWeb 的使用 ### KeeWeb 的使用
有两种方式可以使用 KeeWeb。第一种无需安装直接在网页上使用第二中就是在本地系统中安装 KeeWeb 客户端。 有两种方式可以使用 KeeWeb。第一种无需安装直接在网页上使用第二中就是在本地系统中安装 KeeWeb 客户端。
**在网页上使用 KeeWeb** #### 在网页上使用 KeeWeb
如果不想在系统中安装应用,可以去 [**https://app.keeweb.info/**][1] 使用KeeWeb。 如果不想在系统中安装应用,可以去 [https://app.keeweb.info/][1] 使用KeeWeb。
![](https://www.ostechnix.com/wp-content/uploads/2018/10/KeeWeb-webapp.png) ![](https://www.ostechnix.com/wp-content/uploads/2018/10/KeeWeb-webapp.png)
网页端具有桌面客户端的所有功能,当然也需要联网才能进行使用。 网页端具有桌面客户端的所有功能,当然也需要联网才能进行使用。
**在计算机中安装 KeeWeb** #### 在计算机中安装 KeeWeb
如果喜欢客户端的舒适性和离线可用性,也可以将其安装在系统中。 如果喜欢客户端的舒适性和离线可用性,也可以将其安装在系统中。
如果使用Ubuntu/Debian你可以去 [**releases pages**][2] 下载 KeeWeb 最新的 **.deb ** 文件,然后通过下面的命令进行安装: 如果使用 Ubuntu/Debian你可以去 [发布页][2] 下载 KeeWeb 最新的 .deb 文件,然后通过下面的命令进行安装:
``` ```
$ sudo dpkg -i KeeWeb-1.6.3.linux.x64.deb $ sudo dpkg -i KeeWeb-1.6.3.linux.x64.deb
``` ```
如果用的是 Arch在 [**AUR**][3] 上也有 KeeWeb可以使用任何 AUR 助手进行安装,例如 [**Yay**][4] 如果用的是 Arch在 [AUR][3] 上也有 KeeWeb可以使用任何 AUR 助手进行安装,例如 [Yay][4]
``` ```
$ yay -S keeweb $ yay -S keeweb
``` ```
安装后,从菜单中或应用程序启动器启动 KeeWeb。默认界面长这样 安装后,从菜单中或应用程序启动器启动 KeeWeb。默认界面如下
![](https://www.ostechnix.com/wp-content/uploads/2018/10/KeeWeb-desktop-client.png) ![](https://www.ostechnix.com/wp-content/uploads/2018/10/KeeWeb-desktop-client.png)
### 总体布局 ### 总体布局
KeeWeb 界面主要显示所有密码的列表,在左侧展示所有标签。单击标签将对密码进行过滤,只显示带有那个标签的密码。在右侧,显示所选帐户的所有字段。你可以设置用户名,密码,网址,或者添加自定义的备注。你甚至可以创建自己的字段并将其标记为安全字段,这在存储信用卡信息等内容时非常有用。你只需单击即可复制密码。 KeeWeb 还显示账户的创建和修改日期。已删除的密码会保留在回收站中,可以在其中还原或永久删除。 KeeWeb 界面主要显示所有密码的列表,在左侧展示所有标签。单击标签将对密码进行筛选,只显示带有那个标签的密码。在右侧,显示所选帐户的所有字段。你可以设置用户名、密码、网址,或者添加自定义的备注。你甚至可以创建自己的字段并将其标记为安全字段,这在存储信用卡信息等内容时非常有用。你只需单击即可复制密码。 KeeWeb 还显示账户的创建和修改日期。已删除的密码会保留在回收站中,可以在其中还原或永久删除。
![](https://www.ostechnix.com/wp-content/uploads/2018/10/KeeWeb-general-layout.png) ![](https://www.ostechnix.com/wp-content/uploads/2018/10/KeeWeb-general-layout.png)
### KeeWeb 功能 ### KeeWeb 功能
**云同步** #### 云同步
KeeWeb 的主要功能之一是支持各种远程位置和云服务。除了加载本地文件,你可以从以下位置打开文件: KeeWeb 的主要功能之一是支持各种远程位置和云服务。除了加载本地文件,你可以从以下位置打开文件:
```
1. WebDAV Servers 1. WebDAV Servers
2. Google Drive 2. Google Drive
3. Dropbox 3. Dropbox
4. OneDrive 4. OneDrive
```
这意味着如果你使用多台计算机,就可以在它们之间同步密码文件,因此不必担心某台设备无法访问所有密码。 这意味着如果你使用多台计算机,就可以在它们之间同步密码文件,因此不必担心某台设备无法访问所有密码。
**密码生成器** #### 密码生成器
![](https://www.ostechnix.com/wp-content/uploads/2018/10/KeeWeb-password-generator.png) ![](https://www.ostechnix.com/wp-content/uploads/2018/10/KeeWeb-password-generator.png)
@ -71,13 +68,13 @@ KeeWeb 的主要功能之一是支持各种远程位置和云服务。除了加
为此KeeWeb 有一个内置密码生成器,可以生成特定长度、包含指定字符的自定义密码。 为此KeeWeb 有一个内置密码生成器,可以生成特定长度、包含指定字符的自定义密码。
**插件** #### 插件
![](https://www.ostechnix.com/wp-content/uploads/2018/10/KeeWeb-plugins.png) ![](https://www.ostechnix.com/wp-content/uploads/2018/10/KeeWeb-plugins.png)
你可以使用插件扩展 KeeWeb 的功能。 其中一些插件用于更改界面语言,而其他插件则添加新功能,例如访问 **<https://haveibeenpwned.com>** 以查看密码是否暴露。 你可以使用插件扩展 KeeWeb 的功能。其中一些插件用于更改界面语言,而其他插件则添加新功能,例如访问 https://haveibeenpwned.com 以查看密码是否暴露。
**本地备份** #### 本地备份
![](https://www.ostechnix.com/wp-content/uploads/2018/10/KeeWeb-backup.png) ![](https://www.ostechnix.com/wp-content/uploads/2018/10/KeeWeb-backup.png)
@ -94,7 +91,7 @@ via: https://www.ostechnix.com/keeweb-an-open-source-cross-platform-password-man
作者:[EDITOR][a] 作者:[EDITOR][a]
选题:[lujun9972](https://github.com/lujun9972) 选题:[lujun9972](https://github.com/lujun9972)
译者:[jlztan](https://github.com/jlztan) 译者:[jlztan](https://github.com/jlztan)
校对:[校对者ID](https://github.com/校对者ID) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,13 +1,13 @@
理解 Linux 链接 (二) 理解 Linux 链接(二)
====== ======
> 我们继续这个系列,来看一些你所不知道的微妙之处。
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/links-fikri-rasyid-7853.jpg?itok=0jBT_1M2) ![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/links-fikri-rasyid-7853.jpg?itok=0jBT_1M2)
在[本系列的第一篇文章中][1],我们认识了硬链接软链接,知道在很多时候链接是非常有用的。链接看起来比较简单,但是也有一些不易察觉的奇怪的地方需要注意。这就是我们这篇文章中要讲的。例如,像一下我们在前一篇文章中创建的指向 `libblah` 的链接。请注意,我们是如何从目标文件夹中创建链接的。 在[本系列的第一篇文章中][1],我们认识了硬链接软链接,知道在很多时候链接是非常有用的。链接看起来比较简单,但是也有一些不易察觉的奇怪的地方需要注意。这就是我们这篇文章中要讲的。例如,像一下我们在前一篇文章中创建的指向 `libblah` 的链接。请注意,我们是如何从目标文件夹中创建链接的。
``` ```
cd /usr/local/lib cd /usr/local/lib
ln -s /usr/lib/libblah ln -s /usr/lib/libblah
``` ```
@ -15,35 +15,32 @@ ln -s /usr/lib/libblah
``` ```
cd /usr/lib cd /usr/lib
ln -s libblah /usr/local/lib ln -s libblah /usr/local/lib
``` ```
也就是说,从原始文件夹内到目标文件夹之间的链接将不起作用。 也就是说,从原始文件夹内到目标文件夹之间的链接将不起作用。
出现这种情况的原因是 `ln` 会把它当作是你在 `/usr/local/lib` 中创建一个到 `/usr/local/lib` 的链接,并在 `/usr/local/lib` 中创建了从 `libblah``libblah` 的一个链接。这是因为所有链接文件获取的是文件的名称(`libblah`),而不是文件的路径,最终的结果将会产生一个坏的链接。 出现这种情况的原因是 `ln` 会把它当作是你在 `/usr/local/lib` 中创建一个到 `/usr/local/lib` 的链接,并在 `/usr/local/lib` 中创建了从 `libblah``libblah` 的一个链接。这是因为所有链接文件获取的是文件的名称`libblah,而不是文件的路径,最终的结果将会产生一个坏的链接。
然而,请看下面的这种情况。 然而,请看下面的这种情况。
``` ```
cd /usr/lib cd /usr/lib
ln -s /usr/lib/libblah /usr/local/lib ln -s /usr/lib/libblah /usr/local/lib
``` ```
是可以工作的。奇怪的事情又来了,不管你在文件系统的任何位置执行指令,它都可以好好的工作。使用绝对路径,也就是说,指定整个完整的路径,从根目录(`/`)开始到需要的文件或者是文件夹,是最好的实现方式。 是可以工作的。奇怪的事情又来了,不管你在文件系统的任何位置执行这个指令,它都可以好好的工作。使用绝对路径,也就是说,指定整个完整的路径,从根目录`/`开始到需要的文件或者是文件夹,是最好的实现方式。
其它需要注意的事情是,只要 `/usr/lib``/usr/local/lib` 在一个分区上,做一个如下的硬链接: 其它需要注意的事情是,只要 `/usr/lib``/usr/local/lib` 在一个分区上,做一个如下的硬链接:
``` ```
cd /usr/lib cd /usr/lib
ln libblah /usr/local/lib ln libblah /usr/local/lib
``` ```
也是可以工作的,因为硬链接不依赖于指向文件系统内的文件来工作。 也是可以工作的,因为硬链接不依赖于指向文件系统内的文件来工作。
如果硬链接不起作用那么可能是你想跨分区之间建立一个硬链接。就比如说你有分区A上有文件 `fileA` ,并且把这个分区挂载到 `/path/to/partitionA/directory` 目录,而你又想从 `fileA` 链接到分区B上 `/path/to/partitionB/directory` 目录,这样是行不通的。 如果硬链接不起作用,那么可能是你想跨分区之间建立一个硬链接。就比如说,你有分区 A 上有文件 `fileA` ,并且把这个分区挂载到 `/path/to/partitionA/directory` 目录,而你又想从 `fileA` 链接到分区 B `/path/to/partitionB/directory` 目录,这样是行不通的。
``` ```
ln /path/to/partitionA/directory/file /path/to/partitionB/directory ln /path/to/partitionA/directory/file /path/to/partitionB/directory
@ -63,15 +60,15 @@ ln -s /path/to/some/directory /path/to/some/other/directory
这将在 `/path/to/some/other/directory` 中创建 `/path/to/some/directory` 的链接,没有任何问题。 这将在 `/path/to/some/other/directory` 中创建 `/path/to/some/directory` 的链接,没有任何问题。
当你使用硬链接做同样的事情的时候会提示你一个错误说不允许那么做。而不允许这么做的原因量会导致无休止的递归如果你在目录A中有一个目录B然后你在目录B中链接A就会出现同样的情况在目录A中目录A包含了目录B而在目录B中又包含了A然后又包含了B等等无穷无尽。 当你使用硬链接做同样的事情的时候,会提示你一个错误,说不允许那么做。而不允许这么做的原因量会导致无休止的递归:如果你在目录 A 中有一个目录 B然后你在目录 B 中链接 A就会出现同样的情况在目录 A 中,目录 A 包含了目录 B而在目录 B 中又包含了 A然后又包含了 B等等无穷无尽。
当然你可以在递归中使用软链接,但你为什么要那样做呢? 当然你可以在递归中使用软链接,但你为什么要那样做呢?
### 我应该使用硬链接还是软链接呢? ### 我应该使用硬链接还是软链接呢?
通常,你可以在任何地方使用软链接做任何事情。实际上,在有些情况下你只能使用软链接。话说回来,硬链接的效率要稍高一些:它们占用的磁盘空间更少,访问速度更快。在大多数的机器上,你可以忽略这一点点的差异,因为:在磁盘空间越来越大,访问速度越来越快的今天,空间和速度的差异可以忽略不计。不过,如果你是在一个有小存储和低功耗的处理器上使用嵌入式系统上使用 linux 则可能需要考虑使用硬链接。 通常,你可以在任何地方使用软链接做任何事情。实际上,在有些情况下你只能使用软链接。话说回来,硬链接的效率要稍高一些:它们占用的磁盘空间更少,访问速度更快。在大多数的机器上,你可以忽略这一点点的差异,因为:在磁盘空间越来越大,访问速度越来越快的今天,空间和速度的差异可以忽略不计。不过,如果你是在一个有小存储和低功耗的处理器上使用嵌入式系统上使用 Linux 则可能需要考虑使用硬链接。
另一个使用硬链接的原因是硬链接不容易破碎。假设你有一个软链接,而你意外的移动或者删除了它指向的文件,那么你的软链接将会破碎,并指向了一个不存在的东西。这种情况是不会发生在硬链接中的,因为硬链接直接指向的是磁盘上的数据。实际上,磁盘上的空间不会被标记为空闲,除非最后一个指向它的硬链接把它从文件系统中擦除掉。 另一个使用硬链接的原因是硬链接不容易损坏。假设你有一个软链接,而你意外的移动或者删除了它指向的文件,那么你的软链接将会损坏,并指向了一个不存在的东西。这种情况是不会发生在硬链接中的,因为硬链接直接指向的是磁盘上的数据。实际上,磁盘上的空间不会被标记为空闲,除非最后一个指向它的硬链接把它从文件系统中擦除掉。
软链接,在另一方面比硬链接可以做更多的事情,而且可以指向任何东西,可以是文件或目录。它也可以指向不在同一个分区上的文件和目录。仅这两个不同,我们就可以做出唯一的选择了。 软链接,在另一方面比硬链接可以做更多的事情,而且可以指向任何东西,可以是文件或目录。它也可以指向不在同一个分区上的文件和目录。仅这两个不同,我们就可以做出唯一的选择了。
@ -79,7 +76,7 @@ ln -s /path/to/some/directory /path/to/some/other/directory
现在我们已经介绍了文件和目录以及操作它们的工具,你是否已经准备好转到这些工具,可以浏览目录层次结构,可以查找文件中的数据,也可以检查目录。这就是我们下一期中要做的事情。下期见。 现在我们已经介绍了文件和目录以及操作它们的工具,你是否已经准备好转到这些工具,可以浏览目录层次结构,可以查找文件中的数据,也可以检查目录。这就是我们下一期中要做的事情。下期见。
你可以通过Linux 基金会和edX [Linux 简介][2]了解更多关于Linux的免费课程。 你可以通过 Linux 基金会和 edX [Linux 简介][2]了解更多关于 Linux 的免费课程。
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -87,12 +84,12 @@ via: https://www.linux.com/blog/2018/10/understanding-linux-links-part-2
作者:[Paul Brown][a] 作者:[Paul Brown][a]
选题:[lujun9972][b] 选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID) 译者:[Jamkr](https://github.com/Jamkr)
校对:[校对者ID](https://github.com/校对者ID) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.linux.com/users/bro66 [a]: https://www.linux.com/users/bro66
[b]: https://github.com/lujun9972 [b]: https://github.com/lujun9972
[1]: https://www.linux.com/blog/intro-to-linux/2018/10/linux-links-part-1 [1]: https://linux.cn/article-10173-1.html
[2]: https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux [2]: https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux

View File

@ -3,33 +3,34 @@
![](https://www.ostechnix.com/wp-content/uploads/2018/10/Ultimate-Plumber-720x340.jpg) ![](https://www.ostechnix.com/wp-content/uploads/2018/10/Ultimate-Plumber-720x340.jpg)
管道命令的作用是将一个命令/程序/进程的输出发送给另一个命令/程序/进程,以便将输出结果进行进一步的处理。我们可以通过使用管道命令把多个命令组合起来,使一个命令的标准输入或输出重定向到另一个命令。两个或多个 Linux 命令之间的竖线字符(|)表示在命令之间使用管道命令。管道命令的一般语法如下所示: 管道命令的作用是将一个命令/程序/进程的输出发送给另一个命令/程序/进程,以便将输出结果进行进一步的处理。我们可以通过使用管道命令把多个命令组合起来,使一个命令的标准输入或输出重定向到另一个命令。两个或多个 Linux 命令之间的竖线字符(`|`)表示在命令之间使用管道命令。管道命令的一般语法如下所示:
``` ```
Command-1 | Command-2 | Command-3 | …| Command-N Command-1 | Command-2 | Command-3 | …| Command-N
``` ```
`Ultimate Plumber`(简称 `UP`)是一个命令行工具,它可以用于即时预览管道命令结果。如果你在使用 Linux 时经常会用到管道命令,就可以通过它更好地运用管道命令了。它可以预先显示执行管道命令后的结果,而且是即时滚动地显示,让你可以轻松构建复杂的管道。 Ultimate Plumber简称 UP是一个命令行工具它可以用于即时预览管道命令结果。如果你在使用 Linux 时经常会用到管道命令,就可以通过它更好地运用管道命令了。它可以预先显示执行管道命令后的结果,而且是即时滚动地显示,让你可以轻松构建复杂的管道。
下文将会介绍如何安装 `UP` 并用它将复杂管道命令的编写变得简单。 下文将会介绍如何安装 UP 并用它将复杂管道命令的编写变得简单。
**重要警告:** **重要警告:**
在生产环境中请谨慎使用 `UP`!在使用它的过程中,有可能会在无意中删除重要数据,尤其是搭配 `rm``dd` 命令时需要更加小心。勿谓言之不预。 在生产环境中请谨慎使用 UP在使用它的过程中有可能会在无意中删除重要数据尤其是搭配 `rm``dd` 命令时需要更加小心。勿谓言之不预。
### 使用 Ultimate Plumber 即时预览管道命令 ### 使用 Ultimate Plumber 即时预览管道命令
下面给出一个简单的例子介绍 `UP` 的使用方法。如果需要将 `lshw` 命令的输出传递给 `UP`,只需要在终端中输入以下命令,然后回车: 下面给出一个简单的例子介绍 `up` 的使用方法。如果需要将 `lshw` 命令的输出传递给 `up`,只需要在终端中输入以下命令,然后回车:
``` ```
$ lshw |& up $ lshw |& up
``` ```
你会在屏幕顶部看到一个输入框,如下图所示。 你会在屏幕顶部看到一个输入框,如下图所示。
![](https://www.ostechnix.com/wp-content/uploads/2018/10/Ultimate-Plumber.png) ![](https://www.ostechnix.com/wp-content/uploads/2018/10/Ultimate-Plumber.png)
在输入命令的过程中,输入管道符号并回车,就可以立即执行已经输入了的命令。`Ultimate Plumber` 会在下方的可滚动窗口中即时显示管道命令的输出。在这种状态下,你可以通过 `PgUp`/`PgDn` 键或 `ctrl + ←`/`ctrl + →` 组合键来查看结果。 在输入命令的过程中输入管道符号并回车就可以立即执行已经输入了的命令。Ultimate Plumber 会在下方的可滚动窗口中即时显示管道命令的输出。在这种状态下,你可以通过 `PgUp`/`PgDn` 键或 `ctrl + ←`/`ctrl + →` 组合键来查看结果。
当你满意执行结果之后,可以使用 `ctrl + x` 组合键退出 `UP`。而退出前编写的管道命令则会保存在当前工作目录的文件中,并命名为 `up1.sh`。如果这个文件名已经被占用,就会命名为 `up2.sh`、`up3.sh` 等等以此类推,直到第 1000 个文件。如果你不需要将管道命令保存输出,只需要使用 `ctrl + c` 组合键退出即可。 当你满意执行结果之后,可以使用 `ctrl + x` 组合键退出 `UP`。而退出前编写的管道命令则会保存在当前工作目录的文件中,并命名为 `up1.sh`。如果这个文件名已经被占用,就会命名为 `up2.sh`、`up3.sh` 等等以此类推,直到第 1000 个文件。如果你不需要将管道命令保存输出,只需要使用 `ctrl + c` 组合键退出即可。
@ -41,29 +42,29 @@ $ cat up2.sh
grep network -A5 | grep : | cut -d: -f2- | paste - - grep network -A5 | grep : | cut -d: -f2- | paste - -
``` ```
如果通过管道发送到 `UP` 的命令运行时间太长,终端窗口的左上角会显示一个波浪号(~)字符,这就表示 `UP` 在等待前一个命令的输出结果作为输入。在这种情况下,你可能需要使用 `ctrl + s` 组合键暂时冻结 `UP` 的输入缓冲区大小。在需要解冻的时候,使用 `ctrl + q` 组合键即可。`Ultimate Plumber` 的输入缓冲区大小一般为 40 MB到达这个限制之后屏幕的左上角会显示一个加号。 如果通过管道发送到 `up` 的命令运行时间太长,终端窗口的左上角会显示一个波浪号(~)字符,这就表示 `up` 在等待前一个命令的输出结果作为输入。在这种情况下,你可能需要使用 `ctrl + s` 组合键暂时冻结 `up` 的输入缓冲区大小。在需要解冻的时候,使用 `ctrl + q` 组合键即可。Ultimate Plumber 的输入缓冲区大小一般为 40 MB到达这个限制之后屏幕的左上角会显示一个加号。
以下是 `up` 命令的一个简单演示:
以下是 `UP` 命令的一个简单演示:
![](https://www.ostechnix.com/wp-content/uploads/2018/10/up.gif) ![](https://www.ostechnix.com/wp-content/uploads/2018/10/up.gif)
### 安装 Ultimate Plumber ### 安装 Ultimate Plumber
喜欢这个工具的话,你可以在你的 Linux 系统上安装使用。安装过程也相当简单,只需要在终端里执行以下两个命令就可以安装 `UP` 了。 喜欢这个工具的话,你可以在你的 Linux 系统上安装使用。安装过程也相当简单,只需要在终端里执行以下两个命令就可以安装 `up` 了。
首先从 Ultimate Plumber 的[发布页面][1]下载最新的二进制文件,并将放在你系统的某个路径下,例如`/usr/local/bin/`。 首先从 Ultimate Plumber 的[发布页面][1]下载最新的二进制文件,并将放在你系统的某个路径下,例如 `/usr/local/bin/`
``` ```
$ sudo wget -O /usr/local/bin/up wget https://github.com/akavel/up/releases/download/v0.2.1/up $ sudo wget -O /usr/local/bin/up wget https://github.com/akavel/up/releases/download/v0.2.1/up
``` ```
然后向 `UP` 二进制文件赋予可执行权限: 然后向 `up` 二进制文件赋予可执行权限:
``` ```
$ sudo chmod a+x /usr/local/bin/up $ sudo chmod a+x /usr/local/bin/up
``` ```
至此,你已经完成了 `UP` 的安装,可以开始编写你的管道命令了。 至此,你已经完成了 `up` 的安装,可以开始编写你的管道命令了。
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -73,7 +74,7 @@ via: https://www.ostechnix.com/ultimate-plumber-writing-linux-pipes-with-instant
作者:[SK][a] 作者:[SK][a]
选题:[lujun9972][b] 选题:[lujun9972][b]
译者:[HankChow](https://github.com/HankChow) 译者:[HankChow](https://github.com/HankChow)
校对:[校对者ID](https://github.com/校对者ID) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,32 +1,28 @@
Python 机器学习的必备技巧 Python 机器学习的必备技巧
====== ======
> 尝试使用 Python 掌握机器学习、人工智能和深度学习。 > 尝试使用 Python 掌握机器学习、人工智能和深度学习。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming-code-keyboard-laptop.png?itok=pGfEfu2S) ![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming-code-keyboard-laptop.png?itok=pGfEfu2S)
想要入门机器学习并不难。除了<ruby>大规模网络公开课<rt>Massive Open Online Courses</rt></ruby>MOOCs)之外,还有很多其它优秀的免费资源。下面我分享一些我觉得比较有用的方法。 想要入门机器学习并不难。除了<ruby>大规模网络公开课<rt>Massive Open Online Courses</rt></ruby>MOOC之外还有很多其它优秀的免费资源。下面我分享一些我觉得比较有用的方法。
1. 阅览一些关于这方面的视频、文章或者书籍,例如 [The Master Algorithm: How the Quest for the Ultimate Learning Machine Will Remake Our World][29],你肯定会喜欢这些[关于机器学习的互动页面][30]。 1. 从一些 YouTube 上的好视频开始,阅览一些关于这方面的文章或者书籍,例如 《[主算法:终极学习机器的探索将如何重塑我们的世界][29]》,而且我觉得你肯定会喜欢这些[关于机器学习的很酷的互动页面][30]。
2. 对于“<ruby>机器学习<rt>machine learning</rt></ruby>”、“<ruby>人工智能<rt>artificial intelligence</rt></ruby>”、“<ruby>深度学习<rt>deep learning</rt></ruby>”、“<ruby>数据科学<rt>data science</rt></ruby>”、“<ruby>计算机视觉<rt>computer vision</rt></ruby>”和“<ruby>机器人技术<rt>robotics</rt></ruby>”这一堆新名词,你需要知道它们之间的区别。你可以阅览或聆听这些领域的专家们的演讲,例如这位有影响力的[数据科学家 Brandon Rohrer 的精彩视频][1]。或者这个讲述了数据科学相关的[各种角色之间的区别][2]的视频。
2. 对于“机器学习”、“人工智能”、“深度学习”、“数据科学”、“计算机视觉”和“机器人技术”这一堆新名词,你需要知道它们之前的区别。你可以阅览这些领域的专家们的演讲,例如[数据科学家 Brandon Rohrer 的这个视频][1]。 3. 明确你自己的学习目标,并选择合适的 [Coursera 课程][3],或者参加高校的网络公开课,例如[华盛顿大学的课程][4]就很不错。
4. 关注优秀的博客:例如 [KDnuggets][32] 的博客、[Mark Meloon][33] 的博客、[Brandon Rohrer][34] 的博客、[Open AI][35] 的研究博客,这些都值得推荐。
3. 明确你自己的学习目标,并选择合适的 [Coursera 课程][3],或者参加高校的网络公开课。例如[华盛顿大学的课程][4]就很不错。 5. 如果你热衷于在线课程,后文中会有如何[正确选择 MOOC 课程][31]的指导。
6. 最重要的是,培养自己对这些技术的兴趣。加入一些优秀的社交论坛,不要被那些耸人听闻的头条和新闻所吸引,专注于阅读和了解,将这些技术的背景知识和发展方向理解透彻,并积极思考在日常生活和工作中如何应用机器学习或数据科学的原理。例如建立一个简单的回归模型来预测下一次午餐的成本,又或者是从电力公司的网站上下载历史电费数据,在 Excel 中进行简单的时序分析以发现某种规律。在你对这些技术产生了浓厚兴趣之后,可以观看以下这个视频。
4. 关注优秀的博客:例如 [KDnuggets][32] 的博客、[Mark Meloon][33] 的博客、[Brandon Rohrer][34] 的博客、[Open AI][35] 的博客,这些都值得推荐。
5. 如果你对在线课程有很大兴趣,后文中会有如何[正确选择 MOOC 课程][31]的指导。
6. 最重要的是,培养自己对这些技术的兴趣。加入一些优秀的社交论坛,专注于阅读和了解,将这些技术的背景知识和发展方向理解透彻,并积极思考在日常生活和工作中如何应用机器学习或数据科学的原理。例如建立一个简单的回归模型来预测下一次午餐的成本,又或者是从电力公司的网站上下载历史电费数据,在 Excel 中进行简单的时序分析以发现某种规律。在你对这些技术产生了浓厚兴趣之后,可以观看以下这个视频。
<https://www.youtube.com/embed/IpGxLWOIZy4> <https://www.youtube.com/embed/IpGxLWOIZy4>
### Python 是机器学习和人工智能方面的最佳语言吗? ### Python 是机器学习和人工智能方面的最佳语言吗?
除非你是一名专业的研究一些复杂算法纯理论证明的研究人员,否则,对于一个机器学习的入门者来说,需要熟悉至少一种高级编程语言一家相关的专业知识。因为大多数情况下都是需要考虑如何将机器学习算法应用于解决实际问题,而这需要有一定的编程能力作为基础。 除非你是一名专业的研究一些复杂算法纯理论证明的研究人员,否则,对于一个机器学习的入门者来说,需要熟悉至少一种高级编程语言。因为大多数情况下都是需要考虑如何将现有的机器学习算法应用于解决实际问题,而这需要有一定的编程能力作为基础。
哪一种语言是数据科学的最佳语言?这个讨论一直没有停息过。对于这方面,你可以提起精神来看一下 FreeCodeCamp 上这一篇关于[数据科学语言][6]的文章,又或者是 KDnuggets 关于 [Python 和 R][7] 之间的深入探讨。 哪一种语言是数据科学的最佳语言?这个讨论一直没有停息过。对于这方面,你可以提起精神来看一下 FreeCodeCamp 上这一篇关于[数据科学语言][6]的文章,又或者是 KDnuggets 关于 [Python 和 R 之争][7]的深入探讨。
目前人们普遍认为 Python 在开发、部署、维护各方面的效率都是比较高的。与 Java、C 和 C++ 这些较为传统的语言相比Python 的语法更为简单和高级。而且 Python 拥有活跃的社区群体、广泛的开源文化、数百个专用于机器学习的优质代码库以及来自业界巨头包括Google、Dropbox、Airbnb 等)的强大技术支持。 目前人们普遍认为 Python 在开发、部署、维护各方面的效率都是比较高的。与 Java、C 和 C++ 这些较为传统的语言相比Python 的语法更为简单和高级。而且 Python 拥有活跃的社区群体、广泛的开源文化、数百个专用于机器学习的优质代码库,以及来自业界巨头(包括 Google、Dropbox、Airbnb 等)的强大技术支持。
### 基础 Python 库 ### 基础 Python 库
@ -46,7 +42,7 @@ Pandas 是 Python 生态中用于进行通用数据分析的最受欢迎的库
* 选择数据子集 * 选择数据子集
* 跨行列计算 * 跨行列计算
* 查找并补充缺失的数据 * 查找并补充缺失的数据
* 将操作应用于数据中的独立组 * 将操作应用于数据中的独立
* 按照多种格式转换数据 * 按照多种格式转换数据
* 组合多个数据集 * 组合多个数据集
* 高级时间序列功能 * 高级时间序列功能
@ -68,7 +64,7 @@ Pandas 是 Python 生态中用于进行通用数据分析的最受欢迎的库
#### Scikit-learn #### Scikit-learn
Scikit-learn 是机器学习方面通用的重要 Python 包。它实现了多种[分类][16]、[回归][17]和[聚类][18]算法,包括[支持向量机][19]、[随机森林][20]、[梯度增强][21]、[k-means 算法][22]和 [DBSCAN 算法][23],可以与 Python 的数值库 NumPy 和科学计算库 [SciPy][24] 结合使用。它通过兼容的接口提供了有监督和无监督的学习算法。Scikit-learn 的强壮性让它可以稳定运行在生产环境中,同时它在易用性、代码质量、团队协作、文档和性能等各个方面都有良好的表现。可以参考这篇基于 Scikit-learn 的[机器学习入门][25],或者这篇基于 Scikit-learn 的[简单机器学习用例演示][26]。 Scikit-learn 是机器学习方面通用的重要 Python 包。它实现了多种[分类][16]、[回归][17]和[聚类][18]算法,包括[支持向量机][19]、[随机森林][20]、[梯度增强][21]、[k-means 算法][22]和 [DBSCAN 算法][23],可以与 Python 的数值库 NumPy 和科学计算库 [SciPy][24] 结合使用。它通过兼容的接口提供了有监督和无监督的学习算法。Scikit-learn 的强壮性让它可以稳定运行在生产环境中,同时它在易用性、代码质量、团队协作、文档和性能等各个方面都有良好的表现。可以参考[这篇基于 Scikit-learn 的机器学习入门][25],或者[这篇基于 Scikit-learn 的简单机器学习用例演示][26]。
本文使用 [CC BY-SA 4.0][28] 许可,在 [Heartbeat][27] 上首发。 本文使用 [CC BY-SA 4.0][28] 许可,在 [Heartbeat][27] 上首发。
@ -79,7 +75,7 @@ via: https://opensource.com/article/18/10/machine-learning-python-essential-hack
作者:[Tirthajyoti Sarkar][a] 作者:[Tirthajyoti Sarkar][a]
选题:[lujun9972][b] 选题:[lujun9972][b]
译者:[HankChow](https://github.com/HankChow) 译者:[HankChow](https://github.com/HankChow)
校对:[校对者ID](https://github.com/校对者ID) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,134 +0,0 @@
translating by belitex
What breaks our systems: A taxonomy of black swans
======
Find and fix outlier events that create issues before they trigger severe production problems.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/black-swan-pair_0.png?itok=MkshwqVg)
Black swans are a metaphor for outlier events that are severe in impact (like the 2008 financial crash). In production systems, these are the incidents that trigger problems that you didn't know you had, cause major visible impact, and can't be fixed quickly and easily by a rollback or some other standard response from your on-call playbook. They are the events you tell new engineers about years after the fact.
Black swans, by definition, can't be predicted, but sometimes there are patterns we can find and use to create defenses against categories of related problems.
For example, a large proportion of failures are a direct result of changes (code, environment, or configuration). Each bug triggered in this way is distinctive and unpredictable, but the common practice of canarying all changes is somewhat effective against this class of problems, and automated rollbacks have become a standard mitigation.
As our profession continues to mature, other kinds of problems are becoming well-understood classes of hazards with generalized prevention strategies.
### Black swans observed in the wild
All technology organizations have production problems, but not all of them share their analyses. The organizations that publicly discuss incidents are doing us all a service. The following incidents describe one class of a problem and are by no means isolated instances. We all have black swans lurking in our systems; it's just some of us don't know it yet.
#### Hitting limits
Running headlong into any sort of limit can produce very severe incidents. A canonical example of this was [Instapaper's outage in February 2017][1] . I challenge any engineer who has carried a pager to read the outage report without a chill running up their spine. Instapaper's production database was on a filesystem that, unknown to the team running the service, had a 2TB limit. With no warning, it stopped accepting writes. Full recovery took days and required migrating its database.
Limits can strike in various ways. Sentry hit [limits on maximum transaction IDs in Postgres][2] . Platform.sh hit [size limits on a pipe buffer][3] . SparkPost [triggered AWS's DDoS protection][4] . Foursquare hit a performance cliff when one of its [datastores ran out of RAM][5]
One way to get advance knowledge of system limits is to test periodically. Good load testing (on a production replica) ought to involve write transactions and should involve growing each datastore beyond its current production size. It's easy to forget to test things that aren't your main datastores (such as Zookeeper). If you hit limits during testing, you have time to fix the problems. Given that resolution of limits-related issues can involve major changes (like splitting a datastore), time is invaluable.
When it comes to cloud services, if your service generates unusual loads or uses less widely used products or features (such as older or newer ones), you may be more at risk of hitting limits. It's worth load testing these, too. But warn your cloud provider first.
Finally, where limits are known, add monitoring (with associated documentation) so you will know when your systems are approaching those ceilings. Don't rely on people still being around to remember.
#### Spreading slowness
> "The world is much more correlated than we give credit to. And so we see more of what Nassim Taleb calls 'black swan events'—rare events happen more often than they should because the world is more correlated."
> —[Richard Thaler][6]
HostedGraphite's postmortem on how an [AWS outage took down its load balancers][7] (which are not hosted on AWS) is a good example of just how much correlation exists in distributed computing systems. In this case, the load-balancer connection pools were saturated by slow connections from customers that were hosted in AWS. The same kinds of saturation can happen with application threads, locks, and database connections—any kind of resource monopolized by slow operations.
HostedGraphite's incident is an example of externally imposed slowness, but often slowness can result from saturation somewhere in your own system creating a cascade and causing other parts of your system to slow down. An [incident at Spotify][8] demonstrates such spread—the streaming service's frontends became unhealthy due to saturation in a different microservice. Enforcing deadlines for all requests, as well as limiting the length of request queues, can prevent such spread. Your service will serve at least some traffic, and recovery will be easier because fewer parts of your system will be broken.
Retries should be limited with exponential backoff and some jitter. An outage at Square, in which its [Redis datastore became overloaded][9] due to a piece of code that retried failed transactions up to 500 times with no backoff, demonstrates the potential severity of excessive retries. The [Circuit Breaker][10] design pattern can be helpful here, too.
Dashboards should be designed to clearly show [utilization, saturation, and errors][11] for all resources so problems can be found quickly.
#### Thundering herds
Often, failure scenarios arise when a system is under unusually heavy load. This can arise organically from users, but often it arises from systems. A surge of cron jobs that starts at midnight is a venerable example. Mobile clients can also be a source of coordinated demand if they are programmed to fetch updates at the same time (of course, it is much better to jitter such requests).
Events occurring at pre-configured times aren't the only source of thundering herds. Slack experienced [multiple outages][12] over a short time due to large numbers of clients being disconnected and immediately reconnecting, causing large spikes of load. CircleCI saw a [severe outage][13] when a GitLab outage ended, leading to a surge of builds queued in its database, which became saturated and very slow.
Almost any service can be the target of a thundering herd. Planning for such eventualities—and testing that your plan works as intended—is therefore a must. Client backoff and [load shedding][14] are often core to such approaches.
If your systems must constantly ingest data that can't be dropped, it's key to have a scalable way to buffer this data in a queue for later processing.
#### Automation systems are complex systems
> "Complex systems are intrinsically hazardous systems."
> —[Richard Cook, MD][15]
If your systems must constantly ingest data that can't be dropped, it's key to have a scalable way to buffer this data in a queue for later processing.
The trend for the past several years has been strongly towards more automation of software operations. Automation of anything that can reduce your system's capacity (e.g., erasing disks, decommissioning devices, taking down serving jobs) needs to be done with care. Accidents (due to bugs or incorrect invocations) with this kind of automation can take down your system very efficiently, potentially in ways that are hard to recover from.
The trend for the past several years has been strongly towards more automation of software operations. Automation of anything that can reduce your system's capacity (e.g., erasing disks, decommissioning devices, taking down serving jobs) needs to be done with care. Accidents (due to bugs or incorrect invocations) with this kind of automation can take down your system very efficiently, potentially in ways that are hard to recover from.
Christina Schulman and Etienne Perot of Google describe some examples in their talk [Help Protect Your Data Centers with Safety Constraints][16]. One incident sent Google's entire in-house content delivery network (CDN) to disk-erase.
Schulman and Perot suggest using a central service to manage constraints, which limits the pace at which destructive automation can operate, and being aware of system conditions (for example, avoiding destructive operations if the service has recently had an alert).
Automation systems can also cause havoc when they interact with operators (or with other automated systems). [Reddit][17] experienced a major outage when its automation restarted a system that operators had stopped for maintenance. Once you have multiple automation systems, their potential interactions become extremely complex and impossible to predict.
It will help to deal with the inevitable surprises if all this automation writes logs to an easily searchable, central place. Automation systems should always have a mechanism to allow them to be quickly turned off (fully or only for a subset of operations or targets).
### Defense against the dark swans
These are not the only black swans that might be waiting to strike your systems. There are many other kinds of severe problem that can be avoided using techniques such as canarying, load testing, chaos engineering, disaster testing, and fuzz testing—and of course designing for redundancy and resiliency. Even with all that, at some point your system will fail.
To ensure your organization can respond effectively, make sure your key technical staff and your leadership have a way to coordinate during an outage. For example, one unpleasant issue you might have to deal with is a complete outage of your network. It's important to have a fail-safe communications channel completely independent of your own infrastructure and its dependencies. For instance, if you run on AWS, using a service that also runs on AWS as your fail-safe communication method is not a good idea. A phone bridge or an IRC server that runs somewhere separate from your main systems is good. Make sure everyone knows what the communications platform is and practices using it.
Another principle is to ensure that your monitoring and your operational tools rely on your production systems as little as possible. Separate your control and your data planes so you can make changes even when systems are not healthy. Don't use a single message queue for both data processing and config changes or monitoring, for example—use separate instances. In [SparkPost: The Day the DNS Died][4], Jeremy Blosser presents an example where critical tools relied on the production DNS setup, which failed.
### The psychology of battling the black swan
To ensure your organization can respond effectively, make sure your key technical staff and your leadership have a way to coordinate during an outage.
Dealing with major incidents in production can be stressful. It really helps to have a structured incident-management process in place for these situations. Many technology organizations (
Dealing with major incidents in production can be stressful. It really helps to have a structured incident-management process in place for these situations. Many technology organizations ( [including Google][18] ) successfully use a version of FEMA's Incident Command System. There should be a clear way for any on-call individual to call for assistance in the event of a major problem they can't resolve alone.
For long-running incidents, it's important to make sure people don't work for unreasonable lengths of time and get breaks to eat and sleep (uninterrupted by a pager). It's easy for exhausted engineers to make a mistake or overlook something that might resolve the incident faster.
### Learn more
There are many other things that could be said about black (or formerly black) swans and strategies for dealing with them. If you'd like to learn more, I highly recommend these two books dealing with resilience and stability in production: Susan Fowler's [Production-Ready Microservices][19] and Michael T. Nygard's [Release It!][20].
Laura Nolan will present [What Breaks Our Systems: A Taxonomy of Black Swans][21] at [LISA18][22], October 29-31 in Nashville, Tennessee, USA.
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/10/taxonomy-black-swans
作者:[Laura Nolan][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/lauranolan
[b]: https://github.com/lujun9972
[1]: https://medium.com/making-instapaper/instapaper-outage-cause-recovery-3c32a7e9cc5f
[2]: https://blog.sentry.io/2015/07/23/transaction-id-wraparound-in-postgres.html
[3]: https://medium.com/@florian_7764/technical-post-mortem-of-the-august-incident-82ab4c3d6547
[4]: https://www.usenix.org/conference/srecon18americas/presentation/blosser
[5]: https://groups.google.com/forum/#!topic/mongodb-user/UoqU8ofp134
[6]: https://en.wikipedia.org/wiki/Richard_Thaler
[7]: https://blog.hostedgraphite.com/2018/03/01/spooky-action-at-a-distance-how-an-aws-outage-ate-our-load-balancer/
[8]: https://labs.spotify.com/2013/06/04/incident-management-at-spotify/
[9]: https://medium.com/square-corner-blog/incident-summary-2017-03-16-2f65be39297
[10]: https://en.wikipedia.org/wiki/Circuit_breaker_design_pattern
[11]: http://www.brendangregg.com/usemethod.html
[12]: https://slackhq.com/this-was-not-normal-really
[13]: https://circleci.statuspage.io/incidents/hr0mm9xmm3x6
[14]: https://www.youtube.com/watch?v=XNEIkivvaV4
[15]: https://web.mit.edu/2.75/resources/random/How%20Complex%20Systems%20Fail.pdf
[16]: https://www.usenix.org/conference/srecon18americas/presentation/schulman
[17]: https://www.reddit.com/r/announcements/comments/4y0m56/why_reddit_was_down_on_aug_11/
[18]: https://landing.google.com/sre/book/chapters/managing-incidents.html
[19]: http://shop.oreilly.com/product/0636920053675.do
[20]: https://www.oreilly.com/library/view/release-it/9781680500264/
[21]: https://www.usenix.org/conference/lisa18/presentation/nolan
[22]: https://www.usenix.org/conference/lisa18

View File

@ -1,71 +0,0 @@
Excellent Free Roguelike Games
======
![Dungeon][1]
Roguelike is a sub-genre of role-playing games. It literally means "a game like Rogue". Rogue is a dungeon crawling video game, first released in 1980 by developers Michel Toy, Glenn Wichman and Ken Arnold. The game stood out from the crowd by being fiendishly addictive. The game's goal was to retrieve the Amulet of Yendor, hidden deep in the 26th level, and ascend back to the top, all set in a world based on Dungeons & Dragons.
The game is rightly considered to be a classic, formidably difficult yet compelling addictive. While it was popular in college and university campuses, it wasn't a big seller. At the time of its release, Rogue wasn't published under an open source license, which led to many clones being developed.
There is no exact definition of a roguelike, but this type of game typically has the following characteristics:
* High fantasy narrative background
* Procedural level generation. Most of the game world is generated by the game for every new gameplay session. This is meant to encourage replayability
* Turn-based dungeon exploration and combat
* Tile-based graphics that are randomly generated
* Random conflict outcomes
* Permanent death - death works realistically, once you're gone, you're gone
* High difficulty
This article compiles a wide selection of roguelike games available for Linux. If you enjoy addictive gameplay with real intensity, I heartily recommended downloading these games. Don't be put off by the primitive graphics offered by many of the games, you'll soon forget the visuals once you get immersed in playing. Remember, in roguelikes game mechanics tend to be the primary focus, with graphics being a welcome, but not essential, addition.
There are 16 games recommended here. All of the games are available to download without charge, and almost all are released under an open source license.
| **Roguelike Games** |
| --- |
| **[Dungeon Crawl Stone Soup][1]** | A continuation of Linleys Dungeon Crawl |
| **[Prospector][2]** | Roguelike game set in a science fiction universe |
| **[Dwarf Fortress][3]** | Adventure and Dwarf Fortress modes |
| **[NetHack][4]** | Wonderfully silly, and addictive Dungeons and Dragons-style adventure game |
| **[Angband][5]** | Along the lines of Rogue and NetHack. It is derived from the games Moria and Umoria |
| **[Ancient Domains of Mystery][6]** | Very mature Roguelike game |
| **[Tales of MajEyal][7]** | Features tactical turn-based combat and advanced character building |
| **[UnNetHack][8]** | Inspired fork of NetHack |
| **[Hydra Slayer][9]** | Roguelike game based on mathematical puzzles |
| **[Cataclysm DDA][10]** | Post-apocalyptic roguelike, set in the countryside of fictional New England |
| **[Brogue][11]** | A direct descendant of Rogue |
| **[Goblin Hack][12]** | Inspired by the likes of NetHack, but faster with fewer keys |
| **[Ascii Sector][13]** | 2D trading and space flight simulator with roguelike action |
| **[SLASH'EM][14]** | Super Lotsa Added Stuff Hack - Extended Magic |
| **[Everything Is Fodder][15]** | Seven Day Roguelike competition entry |
| **[Woozoolike][16]** | A simple space exploration roguelike for 7DRL 2017. |
--------------------------------------------------------------------------------
via: https://www.linuxlinks.com/excellent-free-roguelike-games/
作者:[Steve Emms][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.linuxlinks.com/author/linuxlinks/
[1]:https://www.linuxlinks.com/dungeoncrawlstonesoup/
[2]:https://www.linuxlinks.com/Prospector-roguelike/
[3]:https://www.linuxlinks.com/dwarffortress/
[4]:https://www.linuxlinks.com/nethack/
[5]:https://www.linuxlinks.com/angband/
[6]:https://www.linuxlinks.com/ADOM/
[7]:https://www.linuxlinks.com/talesofmajeyal/
[8]:https://www.linuxlinks.com/unnethack/
[9]:https://www.linuxlinks.com/hydra-slayer/
[10]:https://www.linuxlinks.com/cataclysmdda/
[11]:https://www.linuxlinks.com/brogue/
[12]:https://www.linuxlinks.com/goblin-hack/
[13]:https://www.linuxlinks.com/asciisector/
[14]:https://www.linuxlinks.com/slashem/
[15]:https://www.linuxlinks.com/everything-is-fodder/
[16]:https://www.linuxlinks.com/Woozoolike/
[17]:https://i2.wp.com/www.linuxlinks.com/wp-content/uploads/2017/12/dungeon.jpg?resize=300%2C200&ssl=1

View File

@ -1,3 +1,4 @@
translating by Auk7F7
How to dual-boot Linux and Windows How to dual-boot Linux and Windows
====== ======

View File

@ -1,3 +1,5 @@
translating---geekpi
A single-user, lightweight OS for your next home project | Opensource.com A single-user, lightweight OS for your next home project | Opensource.com
====== ======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/robot_arm_artificial_ai.png?itok=8CUU3U_7) ![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/robot_arm_artificial_ai.png?itok=8CUU3U_7)

View File

@ -0,0 +1,119 @@
@flowsnow is translating
How I organize my knowledge as a Software Engineer
============================================================
Software Development and Technology in general are areas that evolve at a very fast pace and continuous learning is essential.
Some minutes navigating in the internet, in places like Twitter, Medium, RSS feeds, Hacker News and other specialized sites and communities, are enough to find lots of great pieces of information from articles, case studies, tutorials, code snippets, new applications and much more.
Saving and organizing all that information can be a daunting task. In this post I will present some tools tools that I use to do it.
One of the points I consider very important regarding knowledge management is to avoid lock-in in a particular platform. All the tools I use, allow to export your data in standard formats like Markdown and HTML.
Note that, My workflow is not perfect and I am constantly searching for new tools and ways to optimize it. Also everyone is different, so what works for me might not working well for you.
### Knowledge base with NotionHQ
For me, the fundamental piece of Knowledge management is to have some kind of personal Knowledge base / wiki. A place where you can save links, bookmarks, notes etc in an organized manner.
I use [NotionHQ][7] for that matter. I use it to keep notes on various topics, having lists of resources like great libraries or tutorials grouped by programming language, bookmarking interesting blog posts and tutorials, and much more, not only related to software development but also my personal life.
What I really like about Notion, is how simple it is to create new content. You write it using Markdown and it is organized as tree.
Here is my top level pages of my "Development" workspace:
[![Image](https://res.cloudinary.com/practicaldev/image/fetch/s--uMbaRUtu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/kRnuvMV.png)][8]
Notion has some nice other features like integrated spreadsheets / databases and Task boards.
You will need to subscribe to paid Personal Plan, if you want to use Notion seriously as the free plan is somewhat limited. I think its worth the price. Notion allows to export your entire workspace to Markdown files. The export has some important problems, like loosing the page hierarchy, but hope Notion Team can improve that.
As a free alternative I would probably use [VuePress][9] or [GitBook][10] to host my own.
### Save interesting articles with Pocket
[Pocket][11] is one of my favorite applications ever! With Pocket you can create a reading list of articles from the Internet. 
Every time I see an article that looks interesting, I save it to Pocket using its Chrome Extension. Later on, I will read it and If I found it useful enough, I will use the "Archive" function of Pocket to permanently save that article and clean up my Pocket inbox.
I try to keep the Reading list small enough and keep archiving information that I have dealt with. Pocket allows you to tag articles which will make it simpler to search articles for a particular topic later in time.
You can also save a copy of the article in Pocket servers in case of the original site disappears, but you will need Pocket Premium for that.
Pocket also have a "Discover" feature which suggests similar articles based on the articles you have saved. This is a great way to find new content to read.
### Snippet Management with SnippetStore
From GitHub, to Stack Overflow answers, to blog posts, its common to find some nice code snippets that you want to save for later. It could be some nice algorithm implementation, an useful script or an example of how to do X in Y language.
I tried many apps from simple GitHub Gists to [Boostnote][12] until I discovered [SnippetStore][13].
SnippetStore is an open source snippet management app. What distinguish SnippetStore from others is its simplicity. You can organize snippets by Language or Tags and you can have multi file snippets. Its not perfect but it gets the job done. Boostnote, for example has more features, but I prefer the simpler way of organizing content of SnippetStore.
For abbreviations and snippets that I use on a daily basis, I prefer to use my Editor / IDE snippets feature as it is more convenient to use. I use SnippetStore more like a reference of coding examples.
[Cacher][14] is also an interesting alternative, since it has integrations with many editors, have a cli tool and uses GitHub Gists as backend, but 6$/month for its pro plan, its too much IMO.
### Managing cheat sheets with DevHints
[Devhints][15] is a collection of cheat sheets created by Rico Sta. Cruz. Its open source and powered by Jekyll, one of the most popular static site generator.
The cheat sheets are written in Markdown with some extra formatting goodies like support for columns.
I really like the looks of the interface and being Markdown makes in incredibly easy to add new content and keep it updated and in version control, unlike cheat sheets in PDF or Image format, that you can find on sites like [Cheatography][16].
As it is open source I have created my own fork, removed some cheat sheets that I dont need and add some more.
I use cheat sheets as reference of how to use some library or programming language or to remember some commands. Its very handy to have a single page, with all the basic syntax of a specific programming language for example.
I am still experimenting with this but its working great so far.
### Diigo
[Diigo][17] allows you to Annotate and Highlight parts of websites. I use it to annotate important information when studying new topics or to save particular paragraphs from articles, Stack Overflow answers or inspirational quotes from Twitter! ;)
* * *
And thats it. There might be some overlap in terms of functionality in some of the tools, but like I said in the beginning, this is an always evolving workflow, as I am always experimenting and searching for ways to improve and be more productive.
What about you? How to you organize your Knowledge?. Please feel free to comment below.
Thank you for reading.
------------------------------------------------------------------------
作者简介:
Bruno Paz
Web Engineer. Expert in #PHP and @Symfony Framework. Enthusiast about new technologies. Sports and @FCPorto fan!
--------------------------------------------------------------------------------
via: https://dev.to/brpaz/how-do-i-organize-my-knowledge-as-a-software-engineer-4387
作者:[ Bruno Paz][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
选题:[oska874](https://github.com/oska874)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://brunopaz.net/
[1]:https://dev.to/brpaz
[2]:http://twitter.com/brunopaz88
[3]:http://github.com/brpaz
[4]:https://dev.to/t/knowledge
[5]:https://dev.to/t/learning
[6]:https://dev.to/t/development
[7]:https://www.notion.so/
[8]:https://res.cloudinary.com/practicaldev/image/fetch/s--uMbaRUtu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/kRnuvMV.png
[9]:https://vuepress.vuejs.org/
[10]:https://www.gitbook.com/?t=1
[11]:https://getpocket.com/
[12]:https://boostnote.io/
[13]:https://github.com/ZeroX-DG/SnippetStore
[14]:https://www.cacher.io/
[15]:https://devhints.io/
[16]:https://cheatography.com/
[17]:https://www.diigo.com/index

View File

@ -1,3 +1,5 @@
HankChow translating
Some Good Alternatives To du Command Some Good Alternatives To du Command
====== ======

View File

@ -0,0 +1,122 @@
让系统崩溃的黑天鹅分类
======
在严重的故障发生之前,找到引起问题的异常事件,并修复它。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/black-swan-pair_0.png?itok=MkshwqVg)
黑天鹅用来比喻造成严重影响的小概率事件(比如 2008 年的金融危机)。在生产环境的系统中,黑天鹅是指这样的事情:它引发了你不知道的问题,造成了重大影响,不能快速修复或回滚,也不能用值班说明书上的其他标准响应来解决。它是事发几年后你还在给新人说起的事件。
从定义上看,黑天鹅是不可预测的,不过有时候我们能找到其中的一些模式,针对有关联的某一类问题准备防御措施。
例如,大部分故障的直接原因是变更(代码、环境或配置)。虽然这种方式触发的 bug 是独特的,不可预测的,但是常见的金丝雀发布对避免这类问题有一定的作用,而且自动回滚已经成了一种标准止损策略。
随着我们的专业性不断成熟,一些其他的问题也正逐渐变得容易理解,被归类到某种风险并有普适的预防策略。
### 公布出来的黑天鹅事件
所有科技公司都有生产环境的故障,只不过并不是所有公司都会分享他们的事故分析。那些公开讨论事故的公司帮了我们的忙。下列事故都描述了某一类问题,但它们绝对不是只属于一个类别。我们的系统中都有黑天鹅在潜伏着,只是有些人还不知道而已。
#### 达到上限
达到任何类型的限制都会引发严重事故。这类问题的一个典型例子是 2017 年 2 月 [Instapaper 的一次服务中断][1]。我把这份事故报告给任何一个运维工作者看他们读完都会脊背发凉。Instapaper 生产环境的数据库所在的文件系统有 2 TB 的大小限制,但是数据库服务团队并不知情。在没有任何报错的情况下,数据库不再接受任何写入了。完全恢复需要好几天,而且还得迁移数据库。
资源限制有各式各样的触发场景。Sentry 遇到了 [Postgres 的最大事务 ID 限制][2]。Platform.sh 遇到了[管道缓冲区大小限制][3]。SparkPost [触发了 AWS 的 DDos 保护][4]。Foursquare 在他们的一个 [MongoDB 耗尽内存][5]时遭遇了性能骤降。
提前了解系统限制的一个办法是定期做测试。好的压力测试(在生产环境的副本上做)应该包含写入事务,并且应该把每一种数据存储都写到超过当前生产环境的容量。压力测试时很容易忽略的是次要存储(比如 Zookeeper。如果你是在测试时遇到了资源限制那么你还有时间去解决问题。鉴于这种资源限制问题的解决方案可能涉及重大的变更比如数据存储拆分所以时间是非常宝贵的。
说到云产品的使用,如果你的服务产生了异常的负载,或者你用的产品或功能还没有被广泛使用(比如老旧的或者新兴的),那么你遇到资源上限的风险很大。对这些云产品做一下压力测试是值得的。不过,做之前要提醒一下你的云服务提供商。
最后,知道了哪里有限制之后,要增加监控(和对应文档),这样你才能知道系统在什么时候接近了资源上限。不要寄希望于那些还在维护服务的人会记得。
#### 扩散的慢请求
> “这个世界的关联性远比我们想象中更大。所以我们看到了更多 Nassim Taleb 所说的‘黑天鹅事件’ —— 即罕见事件以更高的频率离谱地发生了,因为世界是相互关联的”
> — [Richard Thaler][6]
HostedGraphite 的负载均衡器并没有托管在 AWS 上,却[被 AWS 的服务中断给搞垮了][7],他们关于这次事故原因的分析报告很好地诠释了分布式计算系统之间存在多么大的关联。在这个事件里,负载均衡器的连接池被来自 AWS 上的客户访问占满了,因为这些连接很耗时。同样的现象还会发生在应用的线程、锁、数据库连接上 —— 任何能被慢操作占满的资源。
这个 HostedGraphite 的例子中,慢速连接是外部系统施加的,不过慢速连接经常是由内部某个系统的饱和所引起的,饱和与慢操作的级联,拖慢了系统中的其他部分。[Spotify 的一个事故][8]就说明了这样的传播 —— 流媒体服务的前端被另一个微服务的饱和所影响,造成健康检查失败。强制给所有请求设置超时时间,以及限制请求队列的长度,可以预防这一类故障传播。这样即使有问题,至少你的服务还能承担一些流量,而且因为整体上你的系统里故障的部分更少了,恢复起来也会更快。
重试的间隔应该用指数退避来限制一下并加入一些时间抖动。Square 有一次服务中断是 [Redis 存储的过载][9],原因是有一段代码对失败的事务重试了 500 次,没有任何重试退避的方案,也说明了过度重试的潜在风险。另外,针对这种情况,[断路器][10]设计模式也是有用的。
应该设计出监控仪表盘来清晰地展示所有资源的[使用率,饱和度和报错][11],这样才能快速发现问题。
#### 突发的高负载
系统在异常高的负载下经常会发生故障。用户天然会引发高负载,不过也常常是由系统引发的。午夜突发的 cron 定时任务是老生常谈了。如果程序让移动客户端同时去获取更新,这些客户端也会造成突发的大流量(当然,给这种请求加入时间抖动会好很多)。
在预定时刻同时发生的事件并不是突发大流量的唯一原因。Slack 经历过一次短时间内的[多次服务中断][12],原因是非常多的客户端断开连接后立即重连,造成了突发的大负载。 CircleCI 也经历过一次[严重的服务中断][13],当时 Gitlab 从故障中恢复了,所以数据库里积累了大量的构建任务队列,服务变得饱和而且缓慢。
几乎所有的服务都会受突发的高负载所影响。所以对这类可能出现的事情做应急预案——并测试一下预案能否正常工作——是必须的。客户端退避和[减载][14]通常是这些方案的核心。
如果你的系统必须不间断地接收数据,并且数据不能被丢掉,关键是用可伸缩的方式把数据缓冲到队列中,后续再处理。
#### 自动化系统是复杂的系统
> “复杂的系统本身就是有风险的系统”
> —— [Richard Cook, MD][15]
过去几年里软件的运维操作趋势是更加自动化。任何可能降低系统容量的自动化操作(比如擦除磁盘,退役设备,关闭服务)都应该谨慎操作。这类自动化操作的故障(由于系统有 bug 或者有不正确的调用)能很快地搞垮你的系统,而且可能很难恢复。
谷歌的 Christina Schulman 和 Etienne Perot 在[用安全规约协助保护你的数据中心][16]的演讲中给了一些例子。其中一次事故是将谷歌整个内部的内容分发网络CDN提交给了擦除磁盘的自动化系统。
Schulman 和 Perot 建议使用一个中心服务来管理规约,限制破坏性自动化操作的速度,并能感知到系统状态(比如避免在最近有告警的服务上执行破坏性的操作)。
自动化系统在与运维人员(或其他自动化系统)交互时,也可能造成严重事故。[Reddit][17] 遭遇过一次严重的服务中断,当时他们的自动化系统重启了一个服务,但是这个服务是运维人员停掉做维护的。一旦有了多个自动化系统,它们之间潜在的交互就变得异常复杂和不可预测。
所有的自动化系统都把日志输出到一个容易搜索的中心存储上,能帮助到对这类不可避免的意外情况的处理。自动化系统总是应该具备这样一种机制,即允许快速地关掉它们(完全关掉或者只关掉其中一部分操作或一部分目标)。
### 防止黑天鹅事件
可能在等着击垮系统的黑天鹅可不止上面这些。有很多其他的严重问题是能通过一些技术来避免的,像金丝雀发布,压力测试,混沌工程,灾难测试和模糊测试——当然还有冗余性和弹性的设计。但是即使用了这些技术,有时候你的系统还是会有故障。
为了确保你的组织能有效地响应,在服务中断期间,请保证关键技术人员和领导层有办法沟通协调。例如,有一种你可能需要处理的烦人的事情,那就是网络完全中断。拥有故障时仍然可用的通信通道非常重要,这个通信通道要完全独立于你们自己的基础设施和基础设施的依赖。举个例子,假如你使用 AWS那么把故障时可用的通信服务部署在 AWS 上就不明智了。在和你的主系统无关的地方,运行电话网桥或 IRC 服务器是比较好的方案。确保每个人都知道这个通信平台,并练习使用它。
另一个原则是,确保监控和运维工具对生产环境系统的依赖尽可能的少。将控制平面和数据平面分开,你才能在系统不健康的时候做变更。不要让数据处理和配置变更或监控使用同一个消息队列,比如——应该使用不同的消息队列实例。在 [SparkPost: DNS 挂掉的那一天][4] 这个演讲中Jeremy Blosser 讲了一个这类例子,很关键的工具依赖了生产环境的 DNS 配置,但是生产环境的 DNS 出了问题。
### 对抗黑天鹅的心理学
处理生产环境的重大事故时会产生很大的压力。为这些场景制定结构化的事故管理流程确实是有帮助的。很多科技公司([包括谷歌][18])成功地使用了联邦应急管理局事故指挥系统的某个版本。对于每一个值班的人,遇到了他们无法独立解决的重大问题时,都应该有一个明确的寻求协助的方法。
对于那些持续很长时间的事故,有一点很重要,要确保工程师不会连续工作到不合理的时长,确保他们不会不吃不睡(没有报警打扰的睡觉)。疲惫不堪的工程师很容易犯错或者漏掉了可能更快解决故障的信息。
### 了解更多
关于黑天鹅或者以前的黑天鹅事件以及应对策略还有很多其他的事情可以说。如果你想了解更多我强烈推荐你去看这两本书它们是关于生产环境中的弹性和稳定性的Susan Fowler 写的[生产微服务][19],还有 Michael T. Nygard 的 [Release It!][20]。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/10/taxonomy-black-swans
作者:[Laura Nolan][a]
选题:[lujun9972][b]
译者:[BeliteX](https://github.com/belitex)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/lauranolan
[b]: https://github.com/lujun9972
[1]: https://medium.com/making-instapaper/instapaper-outage-cause-recovery-3c32a7e9cc5f
[2]: https://blog.sentry.io/2015/07/23/transaction-id-wraparound-in-postgres.html
[3]: https://medium.com/@florian_7764/technical-post-mortem-of-the-august-incident-82ab4c3d6547
[4]: https://www.usenix.org/conference/srecon18americas/presentation/blosser
[5]: https://groups.google.com/forum/#!topic/mongodb-user/UoqU8ofp134
[6]: https://en.wikipedia.org/wiki/Richard_Thaler
[7]: https://blog.hostedgraphite.com/2018/03/01/spooky-action-at-a-distance-how-an-aws-outage-ate-our-load-balancer/
[8]: https://labs.spotify.com/2013/06/04/incident-management-at-spotify/
[9]: https://medium.com/square-corner-blog/incident-summary-2017-03-16-2f65be39297
[10]: https://en.wikipedia.org/wiki/Circuit_breaker_design_pattern
[11]: http://www.brendangregg.com/usemethod.html
[12]: https://slackhq.com/this-was-not-normal-really
[13]: https://circleci.statuspage.io/incidents/hr0mm9xmm3x6
[14]: https://www.youtube.com/watch?v=XNEIkivvaV4
[15]: https://web.mit.edu/2.75/resources/random/How%20Complex%20Systems%20Fail.pdf
[16]: https://www.usenix.org/conference/srecon18americas/presentation/schulman
[17]: https://www.reddit.com/r/announcements/comments/4y0m56/why_reddit_was_down_on_aug_11/
[18]: https://landing.google.com/sre/book/chapters/managing-incidents.html
[19]: http://shop.oreilly.com/product/0636920053675.do
[20]: https://www.oreilly.com/library/view/release-it/9781680500264/
[21]: https://www.usenix.org/conference/lisa18/presentation/nolan
[22]: https://www.usenix.org/conference/lisa18

View File

@ -0,0 +1,70 @@
最棒的免费 Roguelike 游戏
======
![地牢][1]
Roguelike 属于角色扮演游戏的一个子流派,它从字面上理解就是“类 Rogue 游戏”。Rogue 是一个地牢爬行视频游戏,第一个版本由开发者 Michel Toy、Glenn Wichman 和 Ken Arnold 在 1980 年发布,由于极易上瘾使得它从一众游戏中脱颖而出。整个游戏的目标是深入第 26 层,取回 Yendor 的护身符并回到地面,所有设定都基于龙与地下城的世界观。
Rogue 被认为是一个经典、极其困难并且让人废寝忘食的游戏。虽然它在大学校园中非常受欢迎,但并不十分畅销。在 Rogue 发布时,它并没有使用开源证书,导致了爱好者们开发了许多克隆版本。
对于 Roguelike 游戏并没有一个明确的定义,但是此类游戏会拥有下述的典型特征:
* 高度魔幻的叙事背景;
* 程序化生成关卡。游戏世界中的大部分地图在每次开始游戏时重新生成,也就意味着鼓励多周目;
* 回合制的地牢探险和战斗;
* 基于图块随机生成的图形;
* 随机的战斗结果;
* 永久死亡——死亡现实地起作用,一旦死亡你就需要重新开始
* 高难度
此篇文章收集了大量 Linux 平台可玩的 Roguelike 游戏。如果你享受提供真实紧张感的上瘾游戏体验,我衷心推荐你下载这些游戏。不要被其中很多游戏的原始画面劝退,一旦你沉浸其中你会很快忽略简陋的画面。记住,在 Roguelike 游戏中应是游戏机制占主导,画面只是一个加分项而不是必需项。
此处推荐 16 款游戏。所有的游戏都可免费下载,并且大部分采用开源证书发布。
| **Roguelike 游戏** |
| --- |
| **[Dungeon Crawl Stone Soup][1]** | Linleys Dungeon Crawl 的续作 |
| **[Prospector][2]** | 基于科幻小说世界观的 Roguelike 游戏 |
| **[Dwarf Fortress][3]** | 冒险和侏儒塔防 |
| **[NetHack][4]** | 非常怪诞并且令人上瘾的龙与地下城风格冒险游戏 |
| **[Angband][5]** | 沿着 Rogue 和 NetHack 的路线,它源于游戏 Moria 和 Umoria |
| **[Ancient Domains of Mystery][6]** | 非常成熟的 Roguelike 游戏 |
| **[Tales of MajEyal][7]** | 特色的策略回合制战斗与先进的角色培养系统 |
| **[UnNetHack][8]** | NetHack 的创新复刻 |
| **[Hydra Slayer][9]** | 基于数学谜题的 Roguelike 游戏 |
| **[Cataclysm DDA][10]** | 后启示录风格 Roguelike 游戏,设定于虚构的新英格兰乡下|
| **[Brogue][11]** | Rogue 的正统续作 |
| **[Goblin Hack][12]** | 受 NetHack 启发的游戏, 但密钥更少游戏流程更快 |
| **[Ascii Sector][13]** | 拥有 Roguelike 动作系统的 2D 版贸易和太空飞行模拟器 |
| **[SLASH'EM][14]** | Super Lotsa Added Stuff Hack - Extended Magic |
| **[Everything Is Fodder][15]** | Seven Day Roguelike 比赛入口 |
| **[Woozoolike][16]** | 7DRL 2017 比赛中一款简单的太空探索 Roguelike 游戏 |
--------------------------------------------------------------------------------
via: https://www.linuxlinks.com/excellent-free-roguelike-games/
作者:[Steve Emms][a]
译者:[cycoe](https://github.com/cycoe)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.linuxlinks.com/author/linuxlinks/
[1]:https://www.linuxlinks.com/dungeoncrawlstonesoup/
[2]:https://www.linuxlinks.com/Prospector-roguelike/
[3]:https://www.linuxlinks.com/dwarffortress/
[4]:https://www.linuxlinks.com/nethack/
[5]:https://www.linuxlinks.com/angband/
[6]:https://www.linuxlinks.com/ADOM/
[7]:https://www.linuxlinks.com/talesofmajeyal/
[8]:https://www.linuxlinks.com/unnethack/
[9]:https://www.linuxlinks.com/hydra-slayer/
[10]:https://www.linuxlinks.com/cataclysmdda/
[11]:https://www.linuxlinks.com/brogue/
[12]:https://www.linuxlinks.com/goblin-hack/
[13]:https://www.linuxlinks.com/asciisector/
[14]:https://www.linuxlinks.com/slashem/
[15]:https://www.linuxlinks.com/everything-is-fodder/
[16]:https://www.linuxlinks.com/Woozoolike/
[17]:https://i2.wp.com/www.linuxlinks.com/wp-content/uploads/2017/12/dungeon.jpg?resize=300%2C200&ssl=1

View File

@ -1,6 +1,7 @@
Sed 命令完全指南 Sed 命令完全指南
====== ======
在前面的文章中,我展示了 [Sed 命令的基本用法][1],它是一个功能强大的流编辑器。今天,我们准备去了解关于 Sed 更多的知识,深入了解 Sed 的运行模式。这将是你全面了解 Sed 命令的一个机会,深入挖掘它的运行细节和精妙之处。因此,如果你已经做好了准备,那就打开终端吧,[下载测试文件][2] 然后坐在电脑前:开始我们的探索之旅吧!
在前面的文章中,我展示了 [Sed 命令的基本用法][1] Sed 是一个实用的流编辑器。今天,我们准备去了解关于 Sed 更多的知识,深入了解 Sed 的运行模式。这将是你全面了解 Sed 命令的一个机会,深入挖掘它的运行细节和精妙之处。因此,如果你已经做好了准备,那就打开终端吧,[下载测试文件][2] 然后坐在电脑前:开始我们的探索之旅吧!
### 关于 Sed 的一点点理论知识 ### 关于 Sed 的一点点理论知识
@ -10,24 +11,17 @@ Sed 命令完全指南
要准确理解 Sed 命令,你必须先了解工具的运行模式。 要准确理解 Sed 命令,你必须先了解工具的运行模式。
当处理数据时Sed 从输入源一次读入一行,并将它保存到所谓的 `pattern` 空间中。所有 Sed 的变动都发生在 `pattern` 空间。变动都是由命令行上或外部 Sed 脚本文件提供的单字母命令来描述的。大多数 Sed 命令都可以由一个地址或一个地址范围作为前导来限制它们的作用范围。 当处理数据时Sed 从输入源一次读入一行,并将它保存到所谓的<ruby>模式空间<rt>pattern space</rt></ruby>中。所有 Sed 的变换都发生在模式空间。变换都是由命令行上或外部 Sed 脚本文件提供的单字母命令来描述的。大多数 Sed 命令都可以由一个地址或一个地址范围作为前导来限制它们的作用范围。
默认情况下Sed 在结束每个处理循环后输出 `pattern` 空间中的内容,也就是说,输出发生在输入的下一个行覆盖 `pattern` 空间之前。我们可以将这种运行模式总结如下: 默认情况下Sed 在结束每个处理循环后输出模式空间中的内容,也就是说,输出发生在输入的下一个行覆盖模式空间之前。我们可以将这种运行模式总结如下:
1. 尝试将下一个行读入到 `pattern` 空间中
2. 如果读取成功:
1. 尝试将下一个行读入到模式空间中
2. 如果读取成功:
1. 按脚本中的顺序将所有命令应用到与那个地址匹配的当前输入行上 1. 按脚本中的顺序将所有命令应用到与那个地址匹配的当前输入行上
2. 如果 sed 没有以静默模式(`-n`)运行,那么将输出模式空间中的所有内容(可能会是修改过的)。
2. 如果 sed 没有以静默(`-n`)模式运行,那么将输出 `pattern` 空间中的所有内容(可能会是修改过的)。
3. 重新回到 1。 3. 重新回到 1。
因此在每个行被处理完毕之后模式空间中的内容将被丢弃它并不适合长时间保存内容。基于这种目的Sed 有第二个缓冲区:<ruby>保持空间<rt>hold space</rt></ruby>。除非你显式地要求它将数据置入到保持空间、或从保持空间中取得数据,否则 Sed 从不清除保持空间的内容。在我们后面学习到 `exchange`、`get`、`hold` 命令时将深入研究它。
因此,在每个行被处理完毕之后, `pattern` 空间中的内容将被丢弃它并不适合长时间保存内容。基于这种目的Sed 有第二个缓冲区:`hold` 空间。除非你显式地要求它将数据置入到 `hold` 空间、或从`hode` 空间中取得数据,否则 Sed 从不清除 `hold` 空间的内容。在我们后面学习到 `exchange`、`get`、`hold` 命令时将深入研究它。
#### Sed 的抽象机制 #### Sed 的抽象机制
@ -35,47 +29,42 @@ Sed 命令完全指南
的确Sed 可以被视为是[抽象机制][5]的实现,它的[状态][6]由三个[缓冲区][7] 、两个[寄存器][8]和两个[标志][9]来定义的: 的确Sed 可以被视为是[抽象机制][5]的实现,它的[状态][6]由三个[缓冲区][7] 、两个[寄存器][8]和两个[标志][9]来定义的:
* **三个缓冲区**用于去保存任意长度的文本。是的,是三个!在前面的基本运行模式中我们谈到了两个: `pattern` 空间和 `hold` 空间,但是 Sed 还有第三个缓冲区:追加队列。从 Sed 脚本的角度来看它是一个只写缓冲区Sed 将在它运行时的预定义阶段来自动刷新它(一般是在从输入源读入一个新行之前,或仅在它退出运行之前)。 * **三个缓冲区**用于去保存任意长度的文本。是的,是三个!在前面的基本运行模式中我们谈到了两个:模式空间和保持空间,但是 Sed 还有第三个缓冲区:<ruby>追加队列<rt>append queue</rt></ruby>。从 Sed 脚本的角度来看它是一个只写缓冲区Sed 将在它运行时的预定义阶段来自动刷新它(一般是在从输入源读入一个新行之前,或仅在它退出运行之前)。
* Sed 也维护**两个寄存器**<ruby>行计数器<rt>line counter</rt></ruby>LC用于保存从输入源读取的行数<ruby>程序计数器<rt>program counter</rt></ruby>PC总是用来保存下一个将要运行的命令的索引就是脚本中的位置Sed 将它作为它的主循环的一部分来自动增加 PC。但在使用特定的命令时脚本也可以直接修改 PC 去跳过或重复执行程序的一部分。这就像使用 Sed 实现的一个循环或条件语句。更多内容将在下面的专用分支一节中描述。
* Sed 也维护**两个寄存器**行计数器LC用于保存从输入源读取的行数而程序计数器PC总是用来保存下一个将要运行的命令的索引就是脚本中的位置Sed 将它作为它的主循环的一部分来自动增加 PC。但在使用特定的命令时脚本也会直接修改 PC 去跳过或重复程序的一部分。这就像使用 Sed 实现的一个循环或条件语句。更多内容将在下面的专用分支一节中描述。 * 最后,**两个标志**可以修改某些 Sed 命令的行为:<ruby>自动输出<rt>auto-print</rt></ruby>AP标志和<ruby替换<rt> substitution</rt></ruby>SF标志。当自动输出标志 AP 被设置时Sed 将在模式空间的内容被覆盖前自动输出尤其是包括但不限于在从输入源读入一个新行之前。当自动输出标志被清除时没有设置Sed 在脚本中没有显式命令的情况下,将不会输出模式空间中的内容。你可以通过在“静默模式”(使用命令行选项 `-n` 或者在第一行或脚本中使用特殊注释 `#n`)运行 Sed 命令来清除自动输出标志。当它的地址和查找模式与模式空间中的内容都匹配时,替换标志 SF 将被替换命令(`s` 命令)设置。替换标志在每个新的循环开始时、或当从输入源读入一个新行时、或获得条件分支之后将被清除。我们将在分支一节中详细研究这一话题。
* 最后,**两个标志**可以被某些 Sed 命令的行为所修改自动输出AP标志和替换标志SF。当自动输出标志 AP 被设置时Sed 将在 `pattern` 空间的内容被覆盖前自动输出尤其是包括但不限于在从输入源读入一个新行之前。当自动输出标准被清除时没有设置Sed 在脚本中没有显式命令的情况下,将不会输出 `pattern` 空间中的内容。你可以通过在“静默模式”(使用命令行选项 `-n` 或者在第一行或脚本中使用特殊注释 `#n`)运行 Sed 命令来清除自动输出标志。当它的地址和查找模式与 `pattern` 空间中的内容都匹配时,“替换标志”将被替换命令(`s` 命令)设置。替换标志在每个新的循环开始时、或当从输入源读入一个新行时、或获得条件分支之后将被清除。我们将在分支一节中详细研究这一话题。
另外Sed 维护一个进入到它的地址范围(关于地址范围的更多知识将在地址范围一节详细描述)的命令列表,以及用于读取和写入数据的两个文件句柄(你将在读取和写入命令的描述中获得更多有关文件句柄的内容)。 另外Sed 维护一个进入到它的地址范围(关于地址范围的更多知识将在地址范围一节详细描述)的命令列表,以及用于读取和写入数据的两个文件句柄(你将在读取和写入命令的描述中获得更多有关文件句柄的内容)。
#### 一个更精确的 Sed 运行模式 #### 一个更精确的 Sed 运行模式
由于图胜千言万语,所以我画了一个流程图去描述 Sed 的运行模式。我将两个东西放在了旁边,像处理多个输入文件或错误处理,但是我认为这足够你去理解任何 Sed 程序的行为了,并且可以避免你在编写你自己的 Sed 脚本时浪费在摸索上的时间。 一图胜千言,所以我画了一个流程图去描述 Sed 的运行模式。我将两个东西放在了旁边,像处理多个输入文件或错误处理,但是我认为这足够你去理解任何 Sed 程序的行为了,并且可以避免你在编写你自己的 Sed 脚本时浪费在摸索上的时间。
![The Sed execution model][10] ![The Sed execution model][10]
你可能已经注意到,在上面的流程图上我并没有描述特定的命令动作。对于命令,我们将逐个详细讲解。因此,不用着急,我们马上开始! 你可能已经注意到,在上面的流程图上我并没有描述特定的命令动作。对于命令,我们将逐个详细讲解。因此,不用着急,我们马上开始!
### print 命令 ### 打印命令
print 命令(`p`)是用于输出在它运行时 `pattern` 空间中的内容。它并不会以任何方式改变 Sed 抽象机制中的状态。 打印命令(`p`)是用于输出在它运行那一刻模式空间中的内容。它并不会以任何方式改变 Sed 抽象机制中的状态。
![The Sed `print` command][11] ![The Sed `print` command][11]
示例: 示例:
``` ```
sed -e 'p' inputfile sed -e 'p' inputfile
``` ```
上面的命令将输出输入文件中每一行的内容两次,因为你一旦显式地要求使用 `print` 命令时,将会在每个处理循环结束时再隐式地输出一次(因为在这里我们不是在“静默模式”中运行 Sed 上面的命令将输出输入文件中每一行的内容……两次,因为你一旦显式地要求使用 `p` 命令时,将会在每个处理循环结束时再隐式地输出一次(因为在这里我们不是在“静默模式”中运行 Sed
如果我们不想每个行看到两次,我们可以用两种方式去解决它: 如果我们不想每个行看到两次,我们可以用两种方式去解决它:
``` ```
sed -n -e 'p' inputfile # 在静默模式中显式输出 sed -n -e 'p' inputfile # 在静默模式中显式输出
sed -e '' inputfile # 空的"什么都不做的"程序,隐式输出 sed -e '' inputfile # 空的“什么都不做的”程序,隐式输出
``` ```
注意:`-e` 选项是引入一个 Sed 命令。它被用于区分命令和文件名。由于一个 Sed 表达式必须包含至少一个命令,所以对于第一个命令,`-e` 标志不是必需的。但是,由于我个人使用习惯问题,为了与在这里的大多数的一个命令行上给出多个 Sed 表达式的更复杂的案例保持一致性。你自己去判断这是一个好习惯还是坏习惯,并且在本文的后面部分还将延用这一习惯。 注意:`-e` 选项是引入一个 Sed 命令。它被用于区分命令和文件名。由于一个 Sed 表达式必须包含至少一个命令,所以对于第一个命令,`-e` 标志不是必需的。但是,由于我个人使用习惯问题,为了与在这里的大多数的一个命令行上给出多个 Sed 表达式的更复杂的案例保持一致性,我添加了它。你自己去判断这是一个好习惯还是坏习惯,并且在本文的后面部分还将延用这一习惯。
### 地址 ### 地址
@ -83,20 +72,20 @@ sed -e '' inputfile # 空的"什么都不做的"程序,隐式输出
#### 行号 #### 行号
一个 Sed 的地址既可以是一个行号(`$` 表示“最后一行”)也可以是一个正则表达式。在使用行号时,你需要记住 Sed 中的行数是从 1 开始的 — 并且需要注意的是,它不是从 0 行开始的。 Sed 的地址既可以是一个行号(`$` 表示“最后一行”)也可以是一个正则表达式。在使用行号时,你需要记住 Sed 中的行数是从 1 开始的 —— 并且需要注意的是,它**不是**从 0 行开始的。
``` ```
sed -n -e '1p' inputfile # 仅输出文件的第一行 sed -n -e '1p' inputfile # 仅输出文件的第一行
sed -n -e '5p' inputfile # 仅输出第 5 行 sed -n -e '5p' inputfile # 仅输出第 5 行
sed -n -e '$p' inputfile # 输出文件的最后一行 sed -n -e '$p' inputfile # 输出文件的最后一行
sed -n -e '0p' inputfile # 结果将是报错,因为 0 不是有效的行号 sed -n -e '0p' inputfile # 结果将是报错,因为 0 不是有效的行号
``` ```
根据 [POSIX 规范][12],如果你指定了几个输出文件,那么它的行号是累加的。换句话说,当 Sed 打开一个新输入文件时,它的行计数器是不会被重置的。因此,以下的两个命令所做的事情是一样的。仅输出一行文本: 根据 [POSIX 规范][12],如果你指定了几个输出文件,那么它的行号是累加的。换句话说,当 Sed 打开一个新输入文件时,它的行计数器是不会被重置的。因此,以下的两个命令所做的事情是一样的。仅输出一行文本:
``` ```
sed -n -e '1p' inputfile1 inputfile2 inputfile3 sed -n -e '1p' inputfile1 inputfile2 inputfile3
cat inputfile1 inputfile2 inputfile3 | sed -n -e '1p' cat inputfile1 inputfile2 inputfile3 | sed -n -e '1p'
``` ```
实际上,确实在 POSIX 中规定了多个文件是如何处理的: 实际上,确实在 POSIX 中规定了多个文件是如何处理的:
@ -104,9 +93,9 @@ cat inputfile1 inputfile2 inputfile3 | sed -n -e '1p'
> 如果指定了多个文件,将按指定的文件命名顺序进行读取并被串联编辑。 > 如果指定了多个文件,将按指定的文件命名顺序进行读取并被串联编辑。
但是,一些 Sed 的实现提供了命令行选项去改变这种行为,比如, GNU Sed 的 `-s` 标志(在使用 GNU Sed `-i` 标志时,它也被隐式地应用): 但是,一些 Sed 的实现提供了命令行选项去改变这种行为,比如, GNU Sed 的 `-s` 标志(在使用 GNU Sed `-i` 标志时,它也被隐式地应用):
``` ```
sed -sn -e '1p' inputfile1 inputfile2 inputfile3 sed -sn -e '1p' inputfile1 inputfile2 inputfile3
``` ```
如果你的 Sed 实现支持这种非标准选项,那么关于它的具体细节请查看 `man` 手册页。 如果你的 Sed 实现支持这种非标准选项,那么关于它的具体细节请查看 `man` 手册页。
@ -117,123 +106,137 @@ sed -sn -e '1p' inputfile1 inputfile2 inputfile3
正如它的名字,一个[正则表达式][13]是描述一个字符串集合的方法。如果一个指定的字符串符合一个正则表达式所描述的集合,那么我们就认为这个字符串与正则表达式匹配。 正如它的名字,一个[正则表达式][13]是描述一个字符串集合的方法。如果一个指定的字符串符合一个正则表达式所描述的集合,那么我们就认为这个字符串与正则表达式匹配。
一个正则表达式也可以包含必须完全匹配的文本字符。例如,所有的字母和数字,以及大部分可以打印的字符。但是,一些符号有特定意义: 正则表达式可以包含必须完全匹配的文本字符。例如,所有的字母和数字,以及大部分可以打印的字符。但是,一些符号有特定意义:
* 它们可能相当于锚,像 `^``$` 它们分别表示一个行的开始和结束;
* 对于整个字符集,另外的符号可能做为占位符(比如圆点 `.` 可以匹配任意单个字符,或者方括号用于定义一个自定义的字符集);
* 另外的是表示重复出现的数量(像 [Kleene 星号][14] 表示前面的模式出现 0、1 或多次);
* 它们相当于锚,像 `^``$` 它们分别表示一个行的开始和结束;
* 能够做为整个字符集的占位符的其它符号(比如圆点 `.` 可以匹配任意单个字符,或者方括号 `[]` 用于定义一个自定义的字符集);
* 另外的是表示重复出现的数量(像 [克莱尼星号(`*`][14] 表示前面的模式出现 0、1 或多次);
这篇文章的目的不是给大家讲正则表达式。因此,我只粘几个示例。但是,你可以在网络上随便找到很多关于正则表达式的教程,正则表达式的功能非常强大,它可用于许多标准的 Unix 命令和编程语言中,并且是每个 Unix 用户应该掌握的技能。 这篇文章的目的不是给大家讲正则表达式。因此,我只粘几个示例。但是,你可以在网络上随便找到很多关于正则表达式的教程,正则表达式的功能非常强大,它可用于许多标准的 Unix 命令和编程语言中,并且是每个 Unix 用户应该掌握的技能。
下面是使用 Sed 地址的几个示例: 下面是使用 Sed 地址的几个示例:
``` ```
sed -n -e '/systemd/p' inputfile # 仅输出包含字符串"systemd"的行 sed -n -e '/systemd/p' inputfile # 仅输出包含字符串“systemd”的行
sed -n -e '/nologin$/p' inputfile # 仅输出以"nologin"结尾的行 sed -n -e '/nologin$/p' inputfile # 仅输出以“nologin”结尾的行
sed -n -e '/^bin/p' inputfile # 仅输出以"bin"开头的行 sed -n -e '/^bin/p' inputfile # 仅输出以“bin”开头的行
sed -n -e '/^$/p' inputfile # 仅输出空行(即:开始和结束之间什么都没有的行) sed -n -e '/^$/p' inputfile # 仅输出空行(即:开始和结束之间什么都没有的行)
sed -n -e '/./p' inputfile # 仅输出包含一个字符的行(即:非空行) sed -n -e '/./p' inputfile # 仅输出包含字符的行(即:非空行)
sed -n -e '/^.$/p' inputfile # 仅输出确实只包含一个字符的行 sed -n -e '/^.$/p' inputfile # 仅输出只包含一个字符的行
sed -n -e '/admin.*false/p' inputfile # 仅输出包含字符串"admin"后面有字符串"false"的行(在它们之间有任意数量的任意字符) sed -n -e '/admin.*false/p' inputfile # 仅输出包含字符串“admin”后面有字符串“false”的行在它们之间有任意数量的任意字符
sed -n -e '/1[0,3]/p' inputfile # 仅输出包含一个"1"并且后面是一个"0"或"3"的行 sed -n -e '/1[0,3]/p' inputfile # 仅输出包含一个“1”并且后面是一个“0”或“3”的行
sed -n -e '/1[0-2]/p' inputfile # 仅输出包含一个"1"并且后面是一个"0"、"1"、"2"或"3"的行 sed -n -e '/1[0-2]/p' inputfile # 仅输出包含一个“1”并且后面是一个“0”、“1”、“2”或“3”的行
sed -n -e '/1.*2/p' inputfile # 仅输出包含字符"1"后面是一个"2"(在它们之间有任意数量的字符)的行 sed -n -e '/1.*2/p' inputfile # 仅输出包含字符“1”后面是一个“2”在它们之间有任意数量的字符的行
sed -n -e '/1[0-9]*2/p' inputfile # 仅输出包含字符"1"后面跟着0、1、或更多数字最后面是一个"2"的行 sed -n -e '/1[0-9]*2/p' inputfile # 仅输出包含字符“1”后面跟着“0”、“1”、或更多数字最后面是一个“2”的行
``` ```
如果你想在正则表达式(包括正则表达式分隔符)中去除字符的特殊意义,你可以在它前面使用一个斜杠: 如果你想在正则表达式(包括正则表达式分隔符)中去除字符的特殊意义,你可以在它前面使用一个反斜杠:
``` ```
# 输出所有包含字符串"/usr/sbin/nologin"的行 # 输出所有包含字符串“/usr/sbin/nologin”的行
sed -ne '/\/usr\/sbin\/nologin/p' inputfile sed -ne '/\/usr\/sbin\/nologin/p' inputfile
``` ```
并不是限制你只能使用反斜杠作为地址中正则表达式的分隔符。你可以通过在第一个分隔符前面加上斜杠的方式,来使用任何你认为适合你需要和偏好的其它字符作为正则表达式的分隔符。当你用地址与带文件路径的字符一起来匹配的时,是非常有用的: 并不限制你只能使用斜杠作为地址中正则表达式的分隔符。你可以通过在第一个分隔符前面加上反斜杠(`\`)的方式,来使用任何你认为适合你需要和偏好的其它字符作为正则表达式的分隔符。当你用地址与带文件路径的字符一起来匹配的时,是非常有用的:
``` ```
# 以下两个命令是完全相同的 # 以下两个命令是完全相同的
sed -ne '/\/usr\/sbin\/nologin/p' inputfile sed -ne '/\/usr\/sbin\/nologin/p' inputfile
sed -ne '\=/usr/sbin/nologin=p' inputfile sed -ne '\=/usr/sbin/nologin=p' inputfile
``` ```
#### 扩展的正则表达式 #### 扩展的正则表达式
默认情况下Sed 的正则表达式引擎仅理解 [POSIX 基本正则表达式][15] 的语法。如果你需要用到 [扩展的正则表达式][16],你必须在 Sed 命令上添加 `-E` 标志。扩展的正则表达式在基本的正则表达式基础上增加了一组额外的特性,并且很多都是很重要的,他们所要求的斜杠要少很多。我们来比较一下: 默认情况下Sed 的正则表达式引擎仅理解 [POSIX 基本正则表达式][15] 的语法。如果你需要用到 [扩展正则表达式][16],你必须在 Sed 命令上添加 `-E` 标志。扩展正则表达式在基本正则表达式基础上增加了一组额外的特性,并且很多都是很重要的,它们所要求的反斜杠要少很多。我们来比较一下:
``` ```
sed -n -e '/\(www\)\|\(mail\)/p' inputfile sed -n -e '/\(www\)\|\(mail\)/p' inputfile
sed -En -e '/(www)|(mail)/p' inputfile sed -En -e '/(www)|(mail)/p' inputfile
``` ```
#### 括号量词 #### 括号量词
正则表达式之所以强大的一个原因是[范围量词][17]`{,}`。事实上,当你写一个不太精确匹配的正则表达式时,量词 `*` 就是一个非常完美的符号。但是,你需要显式在它边上添加一个下限和上限,这样就有了很好的灵活性。当量词范围的下限省略时,下限被假定为 0。当上限被省略时上限被假定为无限大 正则表达式之所以强大的一个原因是[范围量词][17] `{,}`。事实上,当你写一个不太精确匹配的正则表达式时,量词 `*` 就是一个非常完美的符号。但是,(用花括号量词)你可以显式在它边上添加一个下限和上限,这样就有了很好的灵活性。当量词范围的下限省略时,下限被假定为 0。当上限被省略时上限被假定为无限大
|括号| 速记词 |解释| | 括号 | 速记词 | 解释 |
| --- | ----- | ---- |
| `{,}` | `*` | 前面的规则出现 0、1、或许多遍 |
| `{,1}` | `?` | 前面的规则出现 0 或 1 遍 |
| `{1,}` | `+` | 前面的规则出现 1 或许多遍 |
| `{n,n}` | `{n}` | 前面的规则精确地出现 n 遍 |
| {,} | * | 前面的规则出现 0、1、或许多遍 | 花括号在基本正则表达式中也是可以使用的,但是它要求使用反斜杠。根据 POSIX 规范,在基本正则表达式中可以使用的量词仅有星号(`*`)和花括号(使用反斜杠,如 `\{m,n\}`)。许多正则表达式引擎都扩展支持 `\?``\+`。但是,为什么魔鬼如此有诱惑力呢?因为,如果你需要这些量词,使用扩展正则表达式将不但易于写而且可移植性更好。
| {,1} | ? | 前面的规则出现 0 或 1 遍 |
| {1,} | + | 前面的规则出现 1 或许多遍 |
| {n,n} | {n} | 前面的规则精确地出现 n 遍 |
括号在基本的正则表达式中也是可以使用的,但是它要求使用反斜杠。根据 POSIX 规范,在基本的正则表达式中可以使用的量词仅有星号(`*`)和括号(使用反斜杠 `\{m,n\}`)。许多正则表达式引擎都扩展支持 `\?``\+`。但是,为什么魔鬼如此有诱惑力呢?因为,如果你需要这些量词,使用扩展的正则表达式将不但易于写而且可移植性更好 为什么我要花点时间去讨论关于正则表达式的花括号量词,这是因为在 Sed 脚本中经常用这个特性去计数字符。
为什么我要花点时间去讨论关于正则表达式的括号量词,这是因为在 Sed 脚本中经常用这个特性去计数字符。
``` ```
sed -En -e '/^.{35}$/p' inputfile # 输出精确包含 35 个字符的行 sed -En -e '/^.{35}$/p' inputfile # 输出精确包含 35 个字符的行
sed -En -e '/^.{0,35}$/p' inputfile # 输出包含 35 个字符或更少字符的行 sed -En -e '/^.{0,35}$/p' inputfile # 输出包含 35 个字符或更少字符的行
sed -En -e '/^.{,35}$/p' inputfile # 输出包含 35 个字符或更少字符的行 sed -En -e '/^.{,35}$/p' inputfile # 输出包含 35 个字符或更少字符的行
sed -En -e '/^.{35,}$/p' inputfile # 输出包含 35 个字符或更多字符的行 sed -En -e '/^.{35,}$/p' inputfile # 输出包含 35 个字符或更多字符的行
sed -En -e '/.{35}/p' inputfile # 你自己指出它的输出内容(这是留给你的测试题) sed -En -e '/.{35}/p' inputfile # 你自己指出它的输出内容(这是留给你的测试题)
``` ```
#### 地址范围 #### 地址范围
到目前为止我们使用的所有地址都是唯一地址。在我们使用一个唯一地址时命令是应用在与那个地址匹配的行上。但是Sed 也支持地址范围。Sed 命令可以应用到那个地址范围中从开始到结束的所有地址中的所有行上: 到目前为止我们使用的所有地址都是唯一地址。在我们使用一个唯一地址时命令是应用在与那个地址匹配的行上。但是Sed 也支持地址范围。Sed 命令可以应用到那个地址范围中从开始到结束的所有地址中的所有行上:
``` ```
sed -n -e '1,5p' inputfile # 仅输出 1 到 5 行 sed -n -e '1,5p' inputfile # 仅输出 1 到 5 行
sed -n -e '5,$p' inputfile # 从第 5 行输出到文件结尾 sed -n -e '5,$p' inputfile # 从第 5 行输出到文件结尾
sed -n -e '/www/,/systemd/p' inputfile # 输出与正则表达式 /www/ 匹配的第一行到与接下来匹配正则表达式 /systemd/ 的行为止
```
LCTT 译注:下面用的一个生成的列表例子,如下供参考:)
sed -n -e '/www/,/systemd/p' inputfile # 输出与正则表达式 /www/ 匹配的第一行到与正则表达式 /systemd/ 匹配的接下来的行 ```
printf "%s\n" {a,b,c}{d,e,f} | cat -n
1 ad
2 ae
3 af
4 bd
5 be
6 bf
7 cd
8 ce
9 cf
``` ```
如果在开始和结束地址上使用了同一个行号,那么范围就缩小为那个行。事实上,如果第二个地址的数字小于或等于地址范围中选定的第一个行的数字,那么仅有一个行被选定: 如果在开始和结束地址上使用了同一个行号,那么范围就缩小为那个行。事实上,如果第二个地址的数字小于或等于地址范围中选定的第一个行的数字,那么仅有一个行被选定:
``` ```
printf "%s\n" {a,b,c}{d,e,f} | cat -n | sed -ne '4,4p' printf "%s\n" {a,b,c}{d,e,f} | cat -n | sed -ne '4,4p'
4 bd 4 bd
printf "%s\n" {a,b,c}{d,e,f} | cat -n | sed -ne '4,3p' printf "%s\n" {a,b,c}{d,e,f} | cat -n | sed -ne '4,3p'
4 bd 4 bd
``` ```
这就有点难了但是在前面的段落中给出的规则也适用于起始地址是正则表达式的情况。在那种情况下Sed 将对正则表达式匹配的第一个行的行号和给定的作为结束地址的显式的行号进行比较。再强调一次,如果结束行号小于或等于起始行号,那么这个范围将缩小为一行: 下面有点难了但是在前面的段落中给出的规则也适用于起始地址是正则表达式的情况。在那种情况下Sed 将对正则表达式匹配的第一个行的行号和给定的作为结束地址的显式的行号进行比较。再强调一次,如果结束行号小于或等于起始行号,那么这个范围将缩小为一行:
LCTT 译注此处作者陈述有误Sed 会在处理以正则表达式表示的开始行时,并不会同时测试结束表达式:从匹配开始行的正则表达式开始,直到不匹配时,才会测试结束行的表达式——无论是否是正则表达式——并在结束的表达式测试不通过时停止,并循环此测试。)
``` ```
# 这个 /b/,4 地址将匹配三个单行 # 这个 /b/,4 地址将匹配三个单行
# 因为每个匹配的行有一个行号 >= 4 # 因为每个匹配的行有一个行号 >= 4
#LCTT 译注结果正确但是说明不正确。4、5、6 行都会因为匹配开始正则表达式而通过,第 7 行因为不匹配开始正则表达式,所以开始比较行数: 7 > 4遂停止。
printf "%s\n" {a,b,c}{d,e,f} | cat -n | sed -ne '/b/,4p' printf "%s\n" {a,b,c}{d,e,f} | cat -n | sed -ne '/b/,4p'
4 bd 4 bd
5 be 5 be
6 bf 6 bf
# 你自己指出匹配的范围是多少 # 你自己指出匹配的范围是多少
# 第二个例子: # 第二个例子:
printf "%s\n" {a,b,c}{d,e,f} | cat -n | sed -ne '/d/,4p' printf "%s\n" {a,b,c}{d,e,f} | cat -n | sed -ne '/d/,4p'
1 ad 1 ad
2 ae 2 ae
3 af 3 af
4 bd 4 bd
7 cd 7 cd
``` ```
但是当结束地址是一个正则表达式时Sed 的行为将不一样。在那种情况下,地址范围的第一行将不会与结束地址进行检查,因此地址范围将至少包含两行(当然,如果输入数据不足的情况除外): 但是当结束地址是一个正则表达式时Sed 的行为将不一样。在那种情况下,地址范围的第一行将不会与结束地址进行检查,因此地址范围将至少包含两行(当然,如果输入数据不足的情况除外):
LCTT 译注:如上译注,当满足开始的正则表达式时,并不会测试结束的表达式;仅当不满足开始的表达式时,才会测试结束表达式。)
``` ```
printf "%s\n" {a,b,c}{d,e,f} | cat -n | sed -ne '/b/,/d/p' printf "%s\n" {a,b,c}{d,e,f} | cat -n | sed -ne '/b/,/d/p'
4 bd 4 bd
@ -246,60 +249,64 @@ printf "%s\n" {a,b,c}{d,e,f} | cat -n | sed -ne '4,/d/p'
5 be 5 be
6 bf 6 bf
7 cd 7 cd
``` ```
#### 互补 LCTT 译注:对地址范围的总结,当满足开始的条件时,从该行开始,并不测试该行是否满足结束的条件;从下一行开始测试结束条件,并在结束条件不满足时结束;然后对剩余的行,再从开始条件开始匹配,以此循环——也就是说,匹配结果可以是非连续的单/多行。大家可以调整上述命令行的条件以理解。)
#### 补集
在一个地址选择行后面添加一个感叹号(`!`)表示不匹配那个地址。例如: 在一个地址选择行后面添加一个感叹号(`!`)表示不匹配那个地址。例如:
``` ```
sed -n -e '5!p' inputfile # 输出除了第 5 行外的所有行 sed -n -e '5!p' inputfile # 输出除了第 5 行外的所有行
sed -n -e '5,10!p' inputfile # 输出除了第 5 到 10 之间的所有行 sed -n -e '5,10!p' inputfile # 输出除了第 5 到 10 之间的所有行
sed -n -e '/sys/!p' inputfile # 输出除了包含字符串"sys"的所有行 sed -n -e '/sys/!p' inputfile # 输出除了包含字符串“sys”的所有行
``` ```
#### 连接 #### 交集
LCTT 译注:原文标题为“合集”,应为“交集”)
Sed 允许在一个块中使用花括号 `{…}` 组合命令。你可以利用这个特性去组合几个地址的交集。例如,我们来比较下面两个命令的输出:
Sed 允许在一个块中使用括号 (`{…}`) 组合命令。你可以利用这个特性去组合几个地址。例如,我们来比较下面两个命令的输出:
``` ```
sed -n -e '/usb/{ sed -n -e '/usb/{
/daemon/p /daemon/p
}' inputfile }' inputfile
sed -n -e '/usb.*daemon/p' inputfile sed -n -e '/usb.*daemon/p' inputfile
``` ```
通过在一个块中嵌套命令,我们将在任意顺序中选择包含字符串 “usb” 和 “daemon” 的行。而正则表达式 “usb.*daemon” 将仅匹配在字符串 “daemon” 前面包含 “usb” 字符串的行。 通过在一个块中嵌套命令,我们将在任意顺序中选择包含字符串 “usb” 和 “daemon” 的行。而正则表达式 “usb.*daemon” 将仅匹配在字符串 “daemon” 前面包含 “usb” 字符串的行。
离题太长时间后,我们现在重新回去学习各种 Sed 命令。 离题太长时间后,我们现在重新回去学习各种 Sed 命令。
### quit 命令 ### 退出命令
quit 命令(`q`)是指在当前的迭代循环处理结束之后停止 Sed。 退出命令(`q`)是指在当前的迭代循环处理结束之后停止 Sed。
![The Sed `quit` command][18] ![The Sed quit command][18]
quit 命令是在到达输入文件的尾部之前停止处理输入的方法。为什么会有人想去那样做呢? `q` 命令是在到达输入文件的尾部之前停止处理输入的方法。为什么会有人想去那样做呢?
很好的问题,如果你还记得,我们可以使用下面的命令来输出文件中第 1 到第 5 的行: 很好的问题,如果你还记得,我们可以使用下面的命令来输出文件中第 1 到第 5 的行:
``` ```
sed -n -e '1,5p' inputfile sed -n -e '1,5p' inputfile
``` ```
对于 大多数 Sed 的实现,工具将循环读取输入文件的所有行,那怕是你只处理结果中的前 5 行。如果你的输入文件包含了几百万行(或者更糟糕的情况是,你从一个无限的数据流(比如像 `/dev/urandom` )中读取)。 对于大多数 Sed 的实现方式,工具将循环读取输入文件的所有行,那怕是你只处理结果中的前 5 行。如果你的输入文件包含了几百万行(或者更糟糕的情况是,你从一个无限的数据流,比如像 `/dev/urandom` 中读取)将有重大影响。
使用退出命令,相同的程序可以被修改的更高效:
使用 quit 命令,相同的程序可以被修改的更高效:
``` ```
sed -e '5q' inputfile sed -e '5q' inputfile
``` ```
由于我在这里并不使用 `-n` 选项Sed 将在每个循环结束后隐式输出 `pattern` 空间的内容。但是在你处理完第 5 行后,它将退出,并且因此不会去读取更多的数据。 由于我在这里并不使用 `-n` 选项Sed 将在每个循环结束后隐式输出模式空间的内容。但是在你处理完第 5 行后,它将退出,并且因此不会去读取更多的数据。
我们能够使用一个类似的技巧只输出文件中一个特定的行。这也是从命令行中提供多个 Sed 表达式的几种方法。下面的三个变体都可以从 Sed 中接受几个命令,要么是不同的 `-e` 选项,要么是在相同的表达式中新起一行,或用分号(`;`)隔开:
我们能够使用一个类似的技巧只输出文件中一个特定的行。那将是一个好机会,你将看到从命令行中提供多个 Sed 表达式的几种方法。下面的三个变体都可以从 Sed 中接受命令,要么是不同的 `-e` 选项,要么是在相同的表达式中新起一行或用分号(`;`)隔开:
``` ```
sed -n -e '5p' -e '5q' inputfile sed -n -e '5p' -e '5q' inputfile
@ -309,10 +316,10 @@ sed -n -e '
' inputfile ' inputfile
sed -n -e '5p;5q' inputfile sed -n -e '5p;5q' inputfile
``` ```
如果你还记得,我们在前面看到过能够使用括号将命令组合起来,在这里我们使用它来防止相同的地址重复两次: 如果你还记得,我们在前面看到过能够使用花括号将命令组合起来,在这里我们使用它来防止相同的地址重复两次:
``` ```
# 组合命令 # 组合命令
sed -e '5{ sed -e '5{
@ -320,15 +327,14 @@ sed -e '5{
q q
}' inputfile }' inputfile
# Which can be shortened as: # 可以简写为:
sed '5{p;q;}' inputfile sed '5{p;q;}' inputfile
# As a POSIX extension, some implementations makes the semi-colon before the closing bracket optional: # 作为 POSIX 扩展,有些实现方式可以省略闭花括号之前的分号:
sed '5{p;q}' inputfile sed '5{p;q}' inputfile
``` ```
### substitution 命令 ### 替换命令
你可以将替换命令想像为 Sed 的“查找替换”功能这个功能在大多数的“所见即所得”的编辑器上都能找到。Sed 的替换命令与之类似,但比它们更强大。替换命令是 Sed 中最著名的命令之一,在网上有大量的关于这个命令的文档。 你可以将替换命令想像为 Sed 的“查找替换”功能这个功能在大多数的“所见即所得”的编辑器上都能找到。Sed 的替换命令与之类似,但比它们更强大。替换命令是 Sed 中最著名的命令之一,在网上有大量的关于这个命令的文档。
@ -340,9 +346,9 @@ sed '5{p;q}' inputfile
* 命令和它的参数是用任意一个字符来分隔的。这主要看你的习惯,在 99% 的时间中我都使用斜杠,但也会用其它的字符:`sed s%:%-----% inputfile`、`sed sX:X-----X inputfile` 或者甚至是 `sed 's : ----- ' inputfile` * 命令和它的参数是用任意一个字符来分隔的。这主要看你的习惯,在 99% 的时间中我都使用斜杠,但也会用其它的字符:`sed s%:%-----% inputfile`、`sed sX:X-----X inputfile` 或者甚至是 `sed 's : ----- ' inputfile`
* 默认情况下,替换命令仅被应用到 `pattern` 空间中匹配到的第一个字符串上。你可以通过在命令之后指定一个匹配指数作为标志来改变这种情况:`sed 's/:/-----/1' inputfile`、`sed 's/:/-----/2' inputfile`、`sed 's/:/-----/3' inputfile`、… * 默认情况下,替换命令仅被应用到模式空间中匹配到的第一个字符串上。你可以通过在命令之后指定一个匹配指数作为标志来改变这种情况:`sed 's/:/-----/1' inputfile`、`sed 's/:/-----/2' inputfile`、`sed 's/:/-----/3' inputfile`、…
* 如果你想执行一个全面的替换(即:在 `pattern` 空间上的每个非重叠匹配),你需要增加 `g` 标志:`sed 's/:/-----/g' inputfile` * 如果你想执行一个全面的替换(即:在模式空间上的每个非重叠匹配),你需要增加 `g` 标志:`sed 's/:/-----/g' inputfile`
* 在字符串替换中,出现的任何一个 `&` 符号都将被与查找模式匹配的子字符串替换:`sed 's/:/-&&&-/g' inputfile`、`sed 's/…./& /g' inputfile` * 在字符串替换中,出现的任何一个 `&` 符号都将被与查找模式匹配的子字符串替换:`sed 's/:/-&&&-/g' inputfile`、`sed 's/…./& /g' inputfile`
@ -373,9 +379,9 @@ sed -En -e '
``` ```
注意在替换命令结束部分的 `g` 选项。这个选项改变了它的行为,因此它将查找全部的 `pattern` 空间并替换,如果没有那个选项,它只替换查找到的第一个。 注意在替换命令结束部分的 `g` 选项。这个选项改变了它的行为,因此它将查找全部的模式空间并替换,如果没有那个选项,它只替换查找到的第一个。
顺便说一下,这也是使用前面讲过的输出(`p`)命令的好机会,可以在命令运行时输出修改前后时刻 `pattern` 空间的内容。因此,为了获得替换前后的内容,我可以这样写: 顺便说一下,这也是使用前面讲过的输出(`p`)命令的好机会,可以在命令运行时输出修改前后时刻模式空间的内容。因此,为了获得替换前后的内容,我可以这样写:
``` ```
sed -En -e ' sed -En -e '
/sonia/{ /sonia/{
@ -396,7 +402,7 @@ sed -En -e '/sonia/s/[0-9]+/1100/gp' inputfile
#### delete 命令 #### delete 命令
删除命令(`d`)用于清除 `pattern` 空间的内容,然后立即开始下一个处理循环。这样它将会跳过隐式输出 `pattern` 空间内容的行为即便是你设置了自动输出标志AP也不会输出。 删除命令(`d`)用于清除模式空间的内容,然后立即开始下一个处理循环。这样它将会跳过隐式输出模式空间内容的行为即便是你设置了自动输出标志AP也不会输出。
![The Sed `delete` command][22] ![The Sed `delete` command][22]
@ -416,7 +422,7 @@ sed -e '/systemd/d' inputfile
#### next 命令 #### next 命令
如果 Sed 命令不是在静默模式中运行,这个命令将输出当前 `pattern` 空间的内容,然后,在任何情况下它将读取下一个输入行到 `pattern` 空间中,并使用新的 `pattern` 空间中的内容来运行当前循环中剩余的命令。 如果 Sed 命令不是在静默模式中运行,这个命令将输出当前模式空间的内容,然后,在任何情况下它将读取下一个输入行到模式空间中,并使用新的模式空间中的内容来运行当前循环中剩余的命令。
![The Sed `next` command][23] ![The Sed `next` command][23]
@ -426,7 +432,7 @@ cat -n inputfile | sed -n -e 'n;n;p'
``` ```
在上面的例子中Sed 将隐式地读取输入文件的第一行。但是 `next` 命令将丢弃对 `pattern` 空间中的内容的输出(不输出是因为使用了 `-n` 选项),并从输入文件中读取下一行来替换 `pattern` 空间中的内容。而第二个 `next` 命令做的事情和前一个是一模一样的,这就实现了跳过输入文件 2 行的目的。最后,这个脚本显式地输出包含在 `pattern ` 空间中的输入文件的第三行的内容。然后Sed 将启动一个新的循环,由于 `next` 命令,它会隐式地读取第 4 行的内容,然后跳过它,同样地也跳过第 5 行,并输出第 6 行。如此循环,直到文件结束。总体来看,这个脚本就是读取输入文件然后每三行输出一行。 在上面的例子中Sed 将隐式地读取输入文件的第一行。但是 `next` 命令将丢弃对模式空间中的内容的输出(不输出是因为使用了 `-n` 选项),并从输入文件中读取下一行来替换模式空间中的内容。而第二个 `next` 命令做的事情和前一个是一模一样的,这就实现了跳过输入文件 2 行的目的。最后,这个脚本显式地输出包含在 `pattern ` 空间中的输入文件的第三行的内容。然后Sed 将启动一个新的循环,由于 `next` 命令,它会隐式地读取第 4 行的内容,然后跳过它,同样地也跳过第 5 行,并输出第 6 行。如此循环,直到文件结束。总体来看,这个脚本就是读取输入文件然后每三行输出一行。
使用 next 命令,我们也可以找到一些显示输入文件的前五行的几种方法: 使用 next 命令,我们也可以找到一些显示输入文件的前五行的几种方法:
``` ```
@ -446,13 +452,13 @@ cat -n inputfile | sed -n '/pulse/{n;n;p}' # 输出下面的行
``` ```
### 使用 `hold` 空间 ### 使用保持空间
到目前为止,我们所看到的命令都是仅使用了 `pattern` 空间。但是,我们在文章的开始部分已经提到过,还有第二个缓冲区:`hold` 空间,它完全由用户管理。它就是我们在第二节中描述的目标。 到目前为止,我们所看到的命令都是仅使用了模式空间。但是,我们在文章的开始部分已经提到过,还有第二个缓冲区:保持空间,它完全由用户管理。它就是我们在第二节中描述的目标。
#### exchange 命令 #### exchange 命令
正如它的名字所表示的exchange 命令(`x`)将交换 `hold` 空间和 `pattern` 空间的内容。记住,你只要没有把任何东西放入到 `hold` 空间中,那么 `hold` 空间就是空的。 正如它的名字所表示的exchange 命令(`x`)将交换保持空间和模式空间的内容。记住,你只要没有把任何东西放入到保持空间中,那么保持空间就是空的。
![The Sed `exchange` command][24] ![The Sed `exchange` command][24]
@ -462,7 +468,7 @@ cat -n inputfile | sed -n -e 'x;n;p;x;p;q'
``` ```
当然,在你设置 `hold` 之后你并没有立即使用它的内容,因为只要你没有显式地去修改它, `hold` 空间中的内容就保持不变。在下面的例子中,我在输入一个文件的前五行后,使用它去删除第一行: 当然,在你设置 `hold` 之后你并没有立即使用它的内容,因为只要你没有显式地去修改它,保持空间中的内容就保持不变。在下面的例子中,我在输入一个文件的前五行后,使用它去删除第一行:
``` ```
cat -n inputfile | sed -n -e ' cat -n inputfile | sed -n -e '
1{x;n} # 交换 hold 和 pattern 空间 1{x;n} # 交换 hold 和 pattern 空间
@ -484,13 +490,13 @@ cat -n inputfile | sed -n -e '
#### hold 命令 #### hold 命令
hold 命令(`h`)是用于将 `pattern` 空间中的内容保存到 `hold` 空间中。但是,与 exchange 命令不同的是,`pattern` 空间中的内容不会被改变。hold 命令有两种用法: hold 命令(`h`)是用于将模式空间中的内容保存到保持空间中。但是,与 exchange 命令不同的是,模式空间中的内容不会被改变。hold 命令有两种用法:
* `h` * `h`
将复制 `pattern` 空间中的内容到 `hold` 空间中,将覆盖 `hold` 空间中任何已经存在的内容。 将复制模式空间中的内容到保持空间中,将覆盖保持空间中任何已经存在的内容。
* `H` * `H`
使用一个独立的新行,追加 `pattern` 空间中的内容到 `hold` 空间中。 使用一个独立的新行,追加模式空间中的内容到保持空间中。
@ -518,13 +524,13 @@ cat -n inputfile | sed -n -e '
#### get 命令 #### get 命令
get 命令(`g`)与 hold 命令恰好相反:它从 `hold` 空间中取得内容并将它置入到 `pattern` 空间中。同样它也有两种方式: get 命令(`g`)与 hold 命令恰好相反:它从保持空间中取得内容并将它置入到模式空间中。同样它也有两种方式:
* `g` * `g`
它将复制 `hold` 空间中的内容并将其放入到 `pattern` 空间,覆盖 `pattern`空间中已存在的任何内容 它将复制保持空间中的内容并将其放入到模式空间,覆盖 `pattern`空间中已存在的任何内容
* `G` * `G`
使用一个单独的新行,追加 `hold` 空间中的内容到 `pattern` 空间中 使用一个单独的新行,追加保持空间中的内容到模式空间中
@ -551,13 +557,13 @@ cat -n inputfile | sed -En -e '
现在你已经更熟悉使用 hold 空间了,我们回到 print、delete 和 next 命令。我们已经讨论了小写的 `p`、`d` 和 `n` 命令了。而它们也有大写的版本。因为每个命令都有大小写版本,似乎是 Sed 的习惯,这些命令的大写版本将与多行缓冲区有关: 现在你已经更熟悉使用 hold 空间了,我们回到 print、delete 和 next 命令。我们已经讨论了小写的 `p`、`d` 和 `n` 命令了。而它们也有大写的版本。因为每个命令都有大小写版本,似乎是 Sed 的习惯,这些命令的大写版本将与多行缓冲区有关:
* `P` * `P`
`pattern` 空间中第一个新行之前的内容输出 模式空间中第一个新行之前的内容输出
* `D` * `D`
删除 `pattern` 空间中的内容并且包含新行,然后不读取任何新的输入而是使用剩余的文本去重启一个循环 删除模式空间中的内容并且包含新行,然后不读取任何新的输入而是使用剩余的文本去重启一个循环
* `N` * `N`
使用一个换行符作为新旧数据的分隔符,然后读取并追加一个输入的新行到 `pattern` 空间。继续运行当前的循环。 使用一个换行符作为新旧数据的分隔符,然后读取并追加一个输入的新行到模式空间。继续运行当前的循环。
@ -600,7 +606,7 @@ sed < inputfile -En -e '
### 分支 ### 分支
我们刚才已经看到Sed 因为有 `hold` 空间所以有了缓存的功能。其实它还有测试和分支的指令。因为有这些特性使得 Sed 是一个[图灵完备][30]的语言。虽然它可能看起来很傻,但意味着你可以使用 Sed 写任何程序。你可以实现任何你的目的,但并不意味着实现起来会很容易,而且结果也不一定会很高效。 我们刚才已经看到Sed 因为有保持空间所以有了缓存的功能。其实它还有测试和分支的指令。因为有这些特性使得 Sed 是一个[图灵完备][30]的语言。虽然它可能看起来很傻,但意味着你可以使用 Sed 写任何程序。你可以实现任何你的目的,但并不意味着实现起来会很容易,而且结果也不一定会很高效。
但是,不用担心。在本文中,我们将使用能够展示测试和分支功能的最简单的例子。虽然这些功能乍一看似乎很有限,但请记住,有些人用 Sed 写了 <http://www.catonmat.net/ftp/sed/dc.sed> [calculators]、<http://www.catonmat.net/ftp/sed/sedtris.sed> [Tetris] 或许多其它类型的应用程序! 但是,不用担心。在本文中,我们将使用能够展示测试和分支功能的最简单的例子。虽然这些功能乍一看似乎很有限,但请记住,有些人用 Sed 写了 <http://www.catonmat.net/ftp/sed/dc.sed> [calculators]、<http://www.catonmat.net/ftp/sed/sedtris.sed> [Tetris] 或许多其它类型的应用程序!
@ -769,7 +775,7 @@ $a\# end
#### change 命令 #### change 命令
change 命令(`c\`)就像 `d` 命令一样删除 `pattern` 空间的内容并开始一个新的循环。唯一的不同在于,当命令运行之后,用户提供的文本是写往输出的。 change 命令(`c\`)就像 `d` 命令一样删除模式空间的内容并开始一个新的循环。唯一的不同在于,当命令运行之后,用户提供的文本是写往输出的。
![The Sed `change` command][34] ![The Sed `change` command][34]
``` ```
@ -861,7 +867,7 @@ Sed 的设计思想是,所有的文本转换都将写入到进程的标准输
#### write 命令 #### write 命令
write 命令(`w`)追加 `pattern` 空间的内容到给定的目标文件中。POSIX 要求在 Sed 处理任何数据之前,目标文件能够被 Sed 所创建。如果给定的目标文件已经存在,它将被覆写。 write 命令(`w`)追加模式空间的内容到给定的目标文件中。POSIX 要求在 Sed 处理任何数据之前,目标文件能够被 Sed 所创建。如果给定的目标文件已经存在,它将被覆写。
![The Sed `write` command][38] ![The Sed `write` command][38]
@ -887,7 +893,7 @@ cat server
#### 替换命令的写入标志 #### 替换命令的写入标志
在前面,我们已经学习了替换命令,它有一个 `p` 选项用于在替换之后输出 `pattern` 空间的内容。同样它也提供一个类似功能的 `w` 选项,用于在替换之后将 `pattern` 空间的内容输出到一个文件中: 在前面,我们已经学习了替换命令,它有一个 `p` 选项用于在替换之后输出模式空间的内容。同样它也提供一个类似功能的 `w` 选项,用于在替换之后将模式空间的内容输出到一个文件中:
``` ```
sed < inputfile -ne ' sed < inputfile -ne '
s/:.*\/nologin$//w server s/:.*\/nologin$//w server
@ -921,7 +927,7 @@ cat server
#### 明确的 print 命令 #### 明确的 print 命令
这个 `l`(小写的字母 `l`)作用类似于 print 命令(`p`),但它是以精确的格式去输出 `pattern` 空间的内容。以下引用自 [POSIX 标准][12] 这个 `l`(小写的字母 `l`)作用类似于 print 命令(`p`),但它是以精确的格式去输出模式空间的内容。以下引用自 [POSIX 标准][12]
> 在 XBD 转义序列中列出的字符和相关的动作(‘\\\’、‘\a\b\f\r\t\v将被写为相应的转义序列在那个表中的 \n 是不适用的。不在那个表中的不可打印字符将被写为一个三位八进制数字(在前面使用一个 <反斜杠>),表示字符中的每个字节(最重要的字节在前面)。长行应该被换行,通过写一个 <反斜杠>后跟一个 <换行符> 来表示换行点;发生换行时的长度是不确定的,但应该适合输出设备的具体情况。每个行应该以一个 $ 标记结束。 > 在 XBD 转义序列中列出的字符和相关的动作(‘\\\’、‘\a\b\f\r\t\v将被写为相应的转义序列在那个表中的 \n 是不适用的。不在那个表中的不可打印字符将被写为一个三位八进制数字(在前面使用一个 <反斜杠>),表示字符中的每个字节(最重要的字节在前面)。长行应该被换行,通过写一个 <反斜杠>后跟一个 <换行符> 来表示换行点;发生换行时的长度是不确定的,但应该适合输出设备的具体情况。每个行应该以一个 $ 标记结束。
@ -931,7 +937,7 @@ cat server
#### transliterate 命令 #### transliterate 命令
<ruby>移译<rt>transliterate</rt></ruby>`y`)命令允许映射 `pattern` 空间的字符从一个源集到一个目标集。它非常类似于 `tr` 命令,但是限制更多。 <ruby>移译<rt>transliterate</rt></ruby>`y`)命令允许映射模式空间的字符从一个源集到一个目标集。它非常类似于 `tr` 命令,但是限制更多。
![The Sed `transliterate` command][43] ![The Sed `transliterate` command][43]
``` ```

View File

@ -1,53 +1,50 @@
zianglei translating # 我们如何得知安装的包来自哪个仓库?
How Do We Find Out The Installed Packages Came From Which Repository?
======
Sometimes you might want to know the installed packages came from which repository. This will helps you to troubleshoot when you are facing the package conflict issue.
Because [third party vendor repositories][1] are holding the latest version of package and sometime it will causes the issue when you are trying to install any packages due to incompatibility. 有时候你可能想知道安装的软件包来自于哪个仓库。这将帮助你在遇到包冲突问题时进行故障排除。
Everything is possible in Linux because you can able to install a packages on your system even though when the package is not available on your distribution. 因为[第三方仓库][1]拥有最新版本的软件包,所以有时候当你试图安装一些包的时候会出现兼容性的问题。
Also, you can able to install a package with latest version when your distribution dont have it. How? 在 Linux 上一切都是可能的,因为你可以安装一个即使在你的发行版系统上不能使用的包。
Thats why third party repositories are came in the picture. They are allowing users to install all the available packages from their repositories. 你也可以安装一个最新版本的包即使你的发行版系统仓库还没有这个版本,怎么做到的呢?
Almost all the distributions are allowing third party repositories. Some of the distribution officially suggesting few of third party repositories which are not replacing the base packages badly like CentOS officially suggesting us to install [EPEL repository][2]. 这就是为什么出现了第三方仓库。它们允许用户从库中安装所有可用的包。
[List of Major repositories][1] and its details are below. 几乎所有的发行版系统都允许第三方软件库。一些发行版还会官方推荐一些不会取代基础仓库的第三方仓库,例如 CentOS 官方推荐安装 [EPEL 库][2]。
* **`CentOS:`** [EPEL][2], [ELRepo][3], etc is [CentOS Community Approved Repositories][4]. 下面是常用的仓库列表和它们的详细信息。
* **`Fedora:`** [RPMfusion repo][5] is commonly used by most of the [Fedora][6] users.
* **`ArchLinux:`** ArchLinux community repository contains packages that have been adopted by Trusted Users from the Arch User Repository.
* **`openSUSE:`** [Packman repo][7] offers various additional packages for openSUSE, especially but not limited to multimedia related applications and libraries that are on the openSUSE Build Service application blacklist. Its the largest external repository of openSUSE packages.
* **`Ubuntu:`** Personal Package Archives (PPAs) are a kind of repository. Developers create them in order to distribute their software. You can find this information on the PPAs Launchpad page. Also, you can enable Cananical partners repositories.
* **`CentOS:`** [EPEL][2], [ELRepo][3] 等是 [Centos 社区认证仓库](4)。
* **`Fedora:`** [RPMfusion repo][5] 是经常被很多 [Fedora][6] 用户使用的仓库。
* **`ArchLinux:`** ArchLinux 社区仓库包含了来自于 Arch 用户仓库的已经被信任用户 ( Trusted User ) 审核通过的软件包。
* **`openSUSE:`** [Packman repo][7] 为 openSUSE 提供了各种附加的软件包,特别是但不限于那些在 openSUSE Build Service 应用黑名单上的与多媒体相关的应用和库。它是 openSUSE 软件包的最大外部软件库。
* **`Ubuntu:`** Personal Package Archives (PPAs) 是一种软件仓库。开发者们可以创建这种仓库来分发他们的软件。你可以在 PPA 导航页面( PPAs Launchpad page )找到相关信息。同时,你也可以启用 Cananical 合作伙伴软件仓库。
### 仓库是什么?
### What Is Repository? 软件仓库是存储特定的应用程序的软件包的集中场所。
A software repository is a central place which stores the software packages for the particular application. 所有的 Linux 发行版都在维护他们自己的仓库,并允许用户在他们的机器上获取和安装包。
All the Linux distributions are maintaining their own repositories and they allow users to retrieve and install packages on their machine. 每个厂商都提供了各自的包管理工具来管理它们的仓库,例如搜索、安装、更新、升级、删除等等。
Each vendor offered a unique package management tool to manage their repositories such as search, install, update, upgrade, remove, etc. 大部分 Linux 发行版除了 RHEL 和 SUSE 以外都是免费的。要访问付费的仓库,你需要购买订阅。
Most of the Linux distributions comes as freeware except RHEL and SUSE. To access their repositories you need to buy a subscriptions. ### 为什么我们需要启用第三方仓库?
### Why do we need to enable third party repositories? 在 Linux 里,并不建议从源代码安装包,因为这样做可能会在升级软件和系统的时候产生很多问题,这也是为什么我们建议从库中安装包而不是从源代码安装。
In Linux, installing a package from source is not advisable as this might cause so many issues while upgrading the package or system thats why we are advised to install a package from repo instead of source. ### 在 RHEL/CentOS 系统上我们如何得知安装的软件包来自哪个仓库?
### How Do We Find Out The Installed Packages Came From Which Repository on RHEL/CentOS Systems? 这可以通过很多方法实现。我们会给你所有可能的选择,你可以选择一个对你来说最合适的。
This can be done in multiple ways. Here we will be giving you all the possible options and you can choose which one is best for you. ### 方法-1使用 Yum 命令
### Method-1: Using Yum Command RHEL 和 CentOS 系统使用 RPM 包因此我们能够使用 [Yum 包管理器][8] 来获得信息。
RHEL & CentOS systems are using RPM packages hence we can use the [Yum Package Manager][8] to get this information. YUM 即 Yellodog UpdaterModified 是适用于基于 RPM 的系统例如 Red Hat Enterpise Linux RHEL和 CentOS 的一个开源命令行前端包管理工具。
YUM stands for Yellowdog Updater, Modified is an open-source command-line front-end package-management utility for RPM based systems such as Red Hat Enterprise Linux (RHEL) and CentOS. Yum 是从发行版仓库和其他第三方库中获取、安装、删除、查询和管理 RPM 包的一个主要工具。
Yum is the primary tool for getting, installing, deleting, querying, and managing RPM packages from distribution repositories, as well as other third-party repositories.
``` ```
# yum info apachetop # yum info apachetop
@ -70,11 +67,12 @@ Description : ApacheTop watches a logfile generated by Apache (in standard commo
: fields in combined) and generates human-parsable output in realtime. : fields in combined) and generates human-parsable output in realtime.
``` ```
The **`apachetop`** package is coming from **`epel repo`**.
### Method-2: Using Yumdb Command **`apachetop`** 包来自 **`epel repo`**。
Yumdb info provides information similar to yum info but additionally it provides package checksum data, type, user info (who installed the package). Since yum 3.2.26 yum has started storing additional information outside of the rpmdatabase (where user indicates it was installed by the user, and dep means it was brought in as a dependency). ### 方法-2使用 Yumdb 命令
Yumdb info 提供了类似于 yum info 的信息但是它又提供了包校验和数据、类型、用户信息(谁安装的软件包)。从 yum 3.2.26 开始yum 已经开始在 rpmdatabase 之外存储额外的信息( user 表示软件是用户安装的dep 表示它是作为依赖项引入的)。
``` ```
# yumdb info lighttpd # yumdb info lighttpd
@ -95,13 +93,13 @@ lighttpd-1.4.50-1.el7.x86_64
var_uuid = ce328b07-9c0a-4765-b2ad-59d96a257dc8 var_uuid = ce328b07-9c0a-4765-b2ad-59d96a257dc8
``` ```
The **`lighttpd`** package is coming from **`epel repo`**. **`lighttpd`** 包来自 **`epel repo`**。
### Method-3: Using RPM Command ### 方法-3使用 RPM 命令
[RPM command][9] stands for Red Hat Package Manager is a powerful, command line Package Management utility for Red Hat based system such as (RHEL, CentOS, Fedora, openSUSE & Mageia) distributions. [RPM 命令][9] 即 Red Hat Package Manager 是一个适用于基于 Red Hat 的系统(例如 RHEL, CentOS, Fedora, openSUSE & Mageia的强大的命令行包管理工具。
The utility allow you to install, upgrade, remove, query & verify the software on your Linux system/server. RPM files comes with .rpm extension. RPM package built with required libraries and dependency which will not conflicts other packages were installed on your system. 这个工具允许你在你的 Linux 系统/服务器上安装、更新、移除、查询和验证软件。RPM 文件具有 .rpm 后缀名。RPM 包是用必需的库和依赖关系构建的,不会与系统上安装的其他包冲突。
``` ```
# rpm -qi apachetop # rpm -qi apachetop
@ -128,12 +126,11 @@ combined logformat, although it doesn't (yet) make use of any of the extra
fields in combined) and generates human-parsable output in realtime. fields in combined) and generates human-parsable output in realtime.
``` ```
The **`apachetop`** package is coming from **`epel repo`**. **`apachetop`** 包来自 **`epel repo`**。
### Method-4: Using Repoquery Command ### Method-4: Using Repoquery Command
repoquery is a program for querying information from YUM repositories similarly to rpm queries. repoquery 是一个从 YUM 库查询信息的程序,类似于 rpm 查询。
``` ```
# repoquery -i httpd # repoquery -i httpd
@ -153,13 +150,13 @@ The Apache HTTP Server is a powerful, efficient, and extensible
web server. web server.
``` ```
The **`httpd`** package is coming from **`CentOS updates repo`**. **`httpd`** 包来自 **`CentOS updates repo`**。
### How Do We Find Out The Installed Packages Came From Which Repository on Fedora System? ### 在 Fedora 系统上我们如何得知安装的包来自哪个仓库?
DNF stands for Dandified yum. We can tell DNF, the next generation of yum package manager (Fork of Yum) using hawkey/libsolv library for back-end. Aleš Kozumplík started working on DNF since Fedora 18 and its implemented/launched in Fedora 22 finally. DNF 是 Dandified yum 的缩写。我们可以说 DNF 是使用 hawkey/libsolv 库作为后端的下一代 yum 包管理器( yum 的分支)。从 Fedora 18 开始 Aleš Kozumplík 开始开发 DNF 并最终在 Fedora 22 上得以应用/启用。
[Dnf command][10] is used to install, update, search & remove packages on Fedora 22 and later system. It automatically resolve dependencies and make it smooth package installation without any trouble. [Dnf 命令][10] 用于在 Fedora 22 以及之后的系统上安装、更新、搜索和删除包。它会自动解决依赖并使安装包的过程变得顺畅,不会出现任何问题。
``` ```
$ dnf info tilix $ dnf info tilix
@ -195,12 +192,11 @@ Description : Tilix is a tiling terminal emulator with the following features:
: GNOME Human Interface Guidelines (HIG). : GNOME Human Interface Guidelines (HIG).
``` ```
The **`tilix`** package is coming from **`Fedora updates repo`**. **`tilix`** 包来自 **`Fedora updates repo`**。
### How Do We Find Out The Installed Packages Came From Which Repository on openSUSE System? ### 在 openSUSE 系统上我们如何得知安装的包来自哪个仓库?
Zypper is a command line package manager which makes use of libzypp. [Zypper command][11] provides functions like repository access, dependency solving, package installation, etc.
Zypper 是一个使用 libzypp 的命令行包管理器。[Zypper 命令][11] 提供了存储库访问、依赖处理、包安装等功能。
``` ```
$ zypper info nano $ zypper info nano
@ -226,10 +222,11 @@ Description :
``` ```
The **`nano`** package is coming from **`openSUSE Main repo (OSS)`**. The **`nano`** package is coming from **`openSUSE Main repo (OSS)`**.
**`nano`** 包来自于 **`openSUSE Main repoOSS`**。
### How Do We Find Out The Installed Packages Came From Which Repository on ArchLinux System? ### 在 ArchLinux 系统上我们如何得知安装的包来自哪个仓库?
[Pacman command][12] stands for package manager utility. pacman is a simple command-line utility to install, build, remove and manage Arch Linux packages. Pacman uses libalpm (Arch Linux Package Management (ALPM) library) as a back-end to perform all the actions. [Pacman 命令][12] 即包管理器工具( package manager utility ),是一个简单的用来安装、构建、删除和管理 Arch Linux 软件包的命令行工具。Pacman 使用 libalpm Arch Linux Package Managment ALPM library作为后端来执行所有的操作。
``` ```
# pacman -Ss chromium # pacman -Ss chromium
@ -247,9 +244,9 @@ community/fcitx-mozc 2.17.2313.102-1
Input) Input)
``` ```
The **`chromium`** package is coming from **`ArchLinux extra repo`**. **`chromium`** 包来自 **`ArchLinux extra repo`**。
Alternatively, we can use the following option to get the detailed information about the package. 或者,我们可以使用以下选项获得关于包的详细信息。
``` ```
# pacman -Si chromium # pacman -Si chromium
@ -277,15 +274,15 @@ Build Date : Fri 19 Feb 2016 04:17:12 AM IST
Validated By : MD5 Sum SHA-256 Sum Signature Validated By : MD5 Sum SHA-256 Sum Signature
``` ```
The **`chromium`** package is coming from **`ArchLinux extra repo`**. **`chromium`** 包来自 **`ArchLinux extra repo`**。
### How Do We Find Out The Installed Packages Came From Which Repository on Debian Based Systems? ### 在基于 Debian 的系统上我们如何得知安装的包来自哪个仓库?
It can be done in two ways on Debian based systems such as Ubuntu, LinuxMint, etc., 在基于 Debian 的系统例如 UbuntuLinuxMint 上可以使用两种方法实现。
### Method-1: Using apt-cache Command ### 方法-1使用 apt-cache 命令
The [apt-cache command][13] can display much of the information stored in APTs internal database. This information is a sort of cache since it is gathered from the different sources listed in the sources.list file. This happens during the apt update operation. [apt-cache 命令][13] 可以显示存储在 APT 内部数据库的很多信息。这些信息是一种缓存,因为它们是从列在 source.list 文件里的不同的源中获得的。这个过程发生在 apt 更新操作期间。
``` ```
$ apt-cache policy python3 $ apt-cache policy python3
@ -300,11 +297,11 @@ python3:
100 /var/lib/dpkg/status 100 /var/lib/dpkg/status
``` ```
The **`python3`** package is coming from **`Ubuntu updates repo`**. **`python3`** 包来自 **`Ubuntu updates repo`**。
### Method-2: Using apt Command ### 方法-2使用 apt 命令
[APT command][14] stands for Advanced Packaging Tool (APT) which is replacement for apt-get, like how DNF came to picture instead of YUM. Its feature rich command-line tools with included all the futures in one command (APT) such as apt-cache, apt-search, dpkg, apt-cdrom, apt-config, apt-key, etc..,. and several other unique features. For example we can easily install .dpkg packages through APT but we cant do through Apt-Get similar more features are included into APT command. APT-GET replaced by APT Due to lock of futures missing in apt-get which was not solved. [APT 命令][14] 即 Advanced Packaging ToolAPT是 apt-get 命令的替代品,就像 DNF 是如何取代 YUM 一样。它是具有丰富功能的命令行工具并将所有的功能例如 apt-cache、apt-search、dpkg、apt-cdrom、apt-config、apt-ket 等包含在一个命令APT并且还有几个独特的功能。例如我们可以通过 APT 轻松安装 .dpkg 包但我们不能使用 Apt-Get 命令安装,更多类似的功能都被包含进了 APT 命令。APT-GET 因缺失了很多未被解决的特性而被 apt 取代。
``` ```
$ apt -a show notepadqq $ apt -a show notepadqq
@ -337,8 +334,7 @@ Description: Notepad++-like editor for Linux
Text editor with support for multiple programming Text editor with support for multiple programming
languages, multiple encodings and plugin support. languages, multiple encodings and plugin support.
``` ```
**`notepadqq`** 包来自 **`Launchpad PPA`**。
The **`notepadqq`** package is coming from **`Launchpad PPA`**.
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -346,7 +342,7 @@ via: https://www.2daygeek.com/how-do-we-find-out-the-installed-packages-came-fro
作者:[Prakash Subramanian][a] 作者:[Prakash Subramanian][a]
选题:[lujun9972][b] 选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID) 译者:[zianglei](https://github.com/zianglei)
校对:[校对者ID](https://github.com/校对者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出