mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-12 01:40:10 +08:00
commit
5d6178db66
@ -1,11 +1,12 @@
|
||||
[递归:梦中梦][1]
|
||||
递归:梦中梦
|
||||
======
|
||||
|
||||
**递归**是很神奇的,但是在大多数的编程类书藉中对递归讲解的并不好。它们只是给你展示一个递归阶乘的实现,然后警告你递归运行的很慢,并且还有可能因为栈缓冲区溢出而崩溃。“你可以将头伸进微波炉中去烘干你的头发,但是需要警惕颅内高压以及让你的头发生爆炸,或者你可以使用毛巾来擦干头发。”难怪人们不愿意使用递归。但这种建议是很糟糕的,因为在算法中,递归是一个非常强大的观点。
|
||||
> “方其梦也,不知其梦也。梦之中又占其梦焉,觉而后知其梦也。” —— 《庄子·齐物论》
|
||||
|
||||
**递归**是很神奇的,但是在大多数的编程类书藉中对递归讲解的并不好。它们只是给你展示一个递归阶乘的实现,然后警告你递归运行的很慢,并且还有可能因为栈缓冲区溢出而崩溃。“你可以将头伸进微波炉中去烘干你的头发,但是需要警惕颅内高压并让你的头发生爆炸,或者你可以使用毛巾来擦干头发。”难怪人们不愿意使用递归。但这种建议是很糟糕的,因为在算法中,递归是一个非常强大的思想。
|
||||
|
||||
我们来看一下这个经典的递归阶乘:
|
||||
|
||||
递归阶乘 - factorial.c
|
||||
```
|
||||
#include <stdio.h>
|
||||
|
||||
@ -28,15 +29,18 @@ int main(int argc)
|
||||
}
|
||||
```
|
||||
|
||||
*递归阶乘 - factorial.c*
|
||||
|
||||
|
||||
函数调用自身的这个观点在一开始是让人很难理解的。为了让这个过程更形象具体,下图展示的是当调用 `factorial(5)` 并且达到 `n == 1`这行代码 时,[栈上][3] 端点的情况:
|
||||
|
||||

|
||||
|
||||
每次调用 `factorial` 都生成一个新的 [栈帧][4]。这些栈帧的创建和 [销毁][5] 是使得递归版本的阶乘慢于其相应的迭代版本的原因。在调用返回之前,累积的这些栈帧可能会耗尽栈空间,进而使你的程序崩溃。
|
||||
|
||||
而这些担心经常是存在于理论上的。例如,对于每个 `factorial` 的栈帧占用 16 字节(这可能取决于栈排列以及其它因素)。如果在你的电脑上运行着现代的 x86 的 Linux 内核,一般情况下你拥有 8 GB 的栈空间,因此,`factorial` 程序中的 `n` 最多可以达到 512,000 左右。这是一个 [巨大无比的结果][6],它将花费 8,971,833 比特来表示这个结果,因此,栈空间根本就不是什么问题:一个极小的整数 - 甚至是一个 64 位的整数 - 在我们的栈空间被耗尽之前就早已经溢出了成千上万次了。
|
||||
而这些担心经常是存在于理论上的。例如,对于每个 `factorial` 的栈帧占用 16 字节(这可能取决于栈排列以及其它因素)。如果在你的电脑上运行着现代的 x86 的 Linux 内核,一般情况下你拥有 8 GB 的栈空间,因此,`factorial` 程序中的 `n` 最多可以达到 512,000 左右。这是一个 [巨大无比的结果][6],它将花费 8,971,833 比特来表示这个结果,因此,栈空间根本就不是什么问题:一个极小的整数 —— 甚至是一个 64 位的整数 —— 在我们的栈空间被耗尽之前就早已经溢出了成千上万次了。
|
||||
|
||||
过一会儿我们再去看 CPU 的使用,现在,我们先从比特和字节回退一步,把递归看作一种通用技术。我们的阶乘算法可归结为:将整数 N、N-1、 … 1 推入到一个栈,然后将它们按相反的顺序相乘。实际上我们使用了程序调用栈来实现这一点,这是它的细节:我们在堆上分配一个栈并使用它。虽然调用栈具有特殊的特性,但是它也只是额外的一种数据结构,你可以随意处置。我希望示意图可以让你明白这一点。
|
||||
过一会儿我们再去看 CPU 的使用,现在,我们先从比特和字节回退一步,把递归看作一种通用技术。我们的阶乘算法可归结为:将整数 N、N-1、 … 1 推入到一个栈,然后将它们按相反的顺序相乘。实际上我们使用了程序调用栈来实现这一点,这是它的细节:我们在堆上分配一个栈并使用它。虽然调用栈具有特殊的特性,但是它也只是又一种数据结构而已,你可以随意使用。我希望这个示意图可以让你明白这一点。
|
||||
|
||||
当你将栈调用视为一种数据结构,有些事情将变得更加清晰明了:将那些整数堆积起来,然后再将它们相乘,这并不是一个好的想法。那是一种有缺陷的实现:就像你拿螺丝刀去钉钉子一样。相对更合理的是使用一个迭代过程去计算阶乘。
|
||||
|
||||
@ -48,7 +52,6 @@ int main(int argc)
|
||||
|
||||
每到边缘(线)都让老鼠左转或者右转来到达一个新的位置。如果向哪边转都被拦住,说明相关的边缘不存在。现在,我们来讨论一下!这个过程无论你是调用栈还是其它数据结构,它都离不开一个递归的过程。而使用调用栈是非常容易的:
|
||||
|
||||
递归迷宫求解 [下载][2]
|
||||
|
||||
```
|
||||
#include <stdio.h>
|
||||
@ -75,21 +78,24 @@ int explore(maze_t *node)
|
||||
int found = explore(&maze);
|
||||
}
|
||||
```
|
||||
|
||||
*递归迷宫求解 [下载][2]*
|
||||
|
||||
当我们在 `maze.c:13` 中找到奶酪时,栈的情况如下图所示。你也可以在 [GDB 输出][8] 中看到更详细的数据,它是使用 [命令][9] 采集的数据。
|
||||
|
||||

|
||||
|
||||
它展示了递归的良好表现,因为这是一个适合使用递归的问题。而且这并不奇怪:当涉及到算法时,递归是规则,而不是例外。它出现在如下情景中:当进行搜索时、当进行遍历树和其它数据结构时、当进行解析时、当需要排序时:它无处不在。正如众所周知的 pi 或者 e,它们在数学中像“神”一样的存在,因为它们是宇宙万物的基础,而递归也和它们一样:只是它在计算的结构中。
|
||||
它展示了递归的良好表现,因为这是一个适合使用递归的问题。而且这并不奇怪:当涉及到算法时,*递归是规则,而不是例外*。它出现在如下情景中——进行搜索时、进行遍历树和其它数据结构时、进行解析时、需要排序时——它无处不在。正如众所周知的 pi 或者 e,它们在数学中像“神”一样的存在,因为它们是宇宙万物的基础,而递归也和它们一样:只是它存在于计算结构中。
|
||||
|
||||
Steven Skienna 的优秀著作 [算法设计指南][10] 的精彩之处在于,他通过“战争故事” 作为手段来诠释工作,以此来展示解决现实世界中的问题背后的算法。这是我所知道的拓展你的算法知识的最佳资源。另一个读物是 McCarthy 的 [关于 LISP 实现的的原创论文][11]。递归在语言中既是它的名字也是它的基本原理。这篇论文既可读又有趣,在工作中能看到大师的作品是件让人兴奋的事情。
|
||||
Steven Skienna 的优秀著作 [算法设计指南][10] 的精彩之处在于,他通过 “战争故事” 作为手段来诠释工作,以此来展示解决现实世界中的问题背后的算法。这是我所知道的拓展你的算法知识的最佳资源。另一个读物是 McCarthy 的 [关于 LISP 实现的的原创论文][11]。递归在语言中既是它的名字也是它的基本原理。这篇论文既可读又有趣,在工作中能看到大师的作品是件让人兴奋的事情。
|
||||
|
||||
回到迷宫问题上。虽然它在这里很难离开递归,但是并不意味着必须通过调用栈的方式来实现。你可以使用像 `RRLL` 这样的字符串去跟踪转向,然后,依据这个字符串去决定老鼠下一步的动作。或者你可以分配一些其它的东西来记录追寻奶酪的整个状态。你仍然是去实现一个递归的过程,但是需要你实现一个自己的数据结构。
|
||||
回到迷宫问题上。虽然它在这里很难离开递归,但是并不意味着必须通过调用栈的方式来实现。你可以使用像 `RRLL` 这样的字符串去跟踪转向,然后,依据这个字符串去决定老鼠下一步的动作。或者你可以分配一些其它的东西来记录追寻奶酪的整个状态。你仍然是实现了一个递归的过程,只是需要你实现一个自己的数据结构。
|
||||
|
||||
那样似乎更复杂一些,因为栈调用更合适。每个栈帧记录的不仅是当前节点,也记录那个节点上的计算状态(在这个案例中,我们是否只让它走左边,或者已经尝试向右)。因此,代码已经变得不重要了。然而,有时候我们因为害怕溢出和期望中的性能而放弃这种优秀的算法。那是很愚蠢的!
|
||||
|
||||
正如我们所见,栈空间是非常大的,在耗尽栈空间之前往往会遇到其它的限制。一方面可以通过检查问题大小来确保它能够被安全地处理。而对 CPU 的担心是由两个广为流传的有问题的示例所导致的:哑阶乘(dumb factorial)和可怕的无记忆的 O(2n) [Fibonacci 递归][12]。它们并不是栈递归算法的正确代表。
|
||||
正如我们所见,栈空间是非常大的,在耗尽栈空间之前往往会遇到其它的限制。一方面可以通过检查问题大小来确保它能够被安全地处理。而对 CPU 的担心是由两个广为流传的有问题的示例所导致的:<ruby>哑阶乘<rt>dumb factorial</rt></ruby>和可怕的无记忆的 O( 2^n ) [Fibonacci 递归][12]。它们并不是栈递归算法的正确代表。
|
||||
|
||||
事实上栈操作是非常快的。通常,栈对数据的偏移是非常准确的,它在 [缓存][13] 中是热点,并且是由专门的指令来操作它。同时,使用你自己定义的堆上分配的数据结构的相关开销是很大的。经常能看到人们写的一些比栈调用递归更复杂、性能更差的实现方法。最后,现代的 CPU 的性能都是 [非常好的][14] ,并且一般 CPU 不会是性能瓶颈所在。在考虑牺牲程序的简单性时要特别注意,就像经常考虑程序的性能及性能的[测量][15]那样。
|
||||
事实上栈操作是非常快的。通常,栈对数据的偏移是非常准确的,它在 [缓存][13] 中是热数据,并且是由专门的指令来操作它的。同时,使用你自己定义的在堆上分配的数据结构的相关开销是很大的。经常能看到人们写的一些比栈调用递归更复杂、性能更差的实现方法。最后,现代的 CPU 的性能都是 [非常好的][14] ,并且一般 CPU 不会是性能瓶颈所在。在考虑牺牲程序的简单性时要特别注意,就像经常考虑程序的性能及性能的[测量][15]那样。
|
||||
|
||||
下一篇文章将是探秘栈系列的最后一篇了,我们将了解尾调用、闭包、以及其它相关概念。然后,我们就该深入我们的老朋友—— Linux 内核了。感谢你的阅读!
|
||||
|
@ -0,0 +1,122 @@
|
||||
ImageMagick 的一些高级图片查看技巧
|
||||
======
|
||||
|
||||
> 用这些 ImageMagick 命令行图像编辑应用的技巧更好的管理你的数码照片集。
|
||||
|
||||

|
||||
|
||||
图片源于 [Internet Archive Book Images](https://www.flickr.com/photos/internetarchivebookimages/14759826206/in/photolist-ougY7b-owgz5y-otZ9UN-waBxfL-oeEpEf-xgRirT-oeMHfj-wPAvMd-ovZgsb-xhpXhp-x3QSRZ-oeJmKC-ovWeKt-waaNUJ-oeHPN7-wwMsfP-oeJGTK-ovZPKv-waJnTV-xDkxoc-owjyCW-oeRqJh-oew25u-oeFTm4-wLchfu-xtjJFN-oxYznR-oewBRV-owdP7k-owhW3X-oxXxRg-oevDEY-oeFjP1-w7ZB6f-x5ytS8-ow9C7j-xc6zgV-oeCpG1-oewNzY-w896SB-wwE3yA-wGNvCL-owavts-oevodT-xu9Lcr-oxZqZg-x5y4XV-w89d3n-x8h6fi-owbfiq),Opensource.com 修改,[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)协议
|
||||
|
||||
在我先前的[ImageMagick 入门:使用命令行来编辑图片][1] 文章中,我展示了如何使用 ImageMagick 的菜单栏进行图片的编辑和变换风格。在这篇续文里,我将向你展示使用这个开源的图像编辑器来查看图片的另外方法。
|
||||
|
||||
### 别样的风格
|
||||
|
||||
在深入 ImageMagick 的高级图片查看技巧之前,我想先分享另一个使用 `convert` 达到的有趣但简单的效果,在[上一篇文章][1]中我已经详细地介绍了 `convert` 命令,这个技巧涉及这个命令的 `edge` 和 `negate` 选项:
|
||||
|
||||
```
|
||||
convert DSC_0027.JPG -edge 3 -negate edge3+negate.jpg
|
||||
```
|
||||
|
||||
![在图片上使用 `edge` 和 `negate` 选项][3]
|
||||
|
||||
*使用`edge` 和 `negate` 选项前后的图片对比*
|
||||
|
||||
这些使我更喜爱编辑后的图片:海的外观,作为前景和背景的植被,特别是太阳及其在海上的反射,最后是天空。
|
||||
|
||||
### 使用 display 来查看一系列图片
|
||||
|
||||
假如你跟我一样是个命令行用户,你就知道 shell 为复杂任务提供了更多的灵活性和快捷方法。下面我将展示一个例子来佐证这个观点。ImageMagick 的 `display` 命令可以克服我在 GNOME 桌面上使用 [Shotwell][4] 图像管理器导入图片时遇到的问题。
|
||||
|
||||
Shotwell 会根据每张导入图片的 [Exif][5] 数据,创建以图片被生成或者拍摄时的日期为名称的目录结构。最终的效果是最上层的目录以年命名,接着的子目录是以月命名 (01、 02、 03 等等),然后是以每月的日期命名的子目录。我喜欢这种结构,因为当我想根据图片被创建或者拍摄时的日期来查找它们时将会非常方便。
|
||||
|
||||
但这种结构也并不是非常完美的,当我想查看最近几个月或者最近一年的所有图片时就会很麻烦。使用常规的图片查看器,我将不停地在不同层级的目录间跳转,但 ImageMagick 的 `display` 命令可以使得查看更加简单。例如,假如我想查看最近一年的图片,我便可以在命令行中键入下面的 `display` 命令:
|
||||
|
||||
```
|
||||
display -resize 35% 2017/*/*/*.JPG
|
||||
```
|
||||
|
||||
我可以一个月又一个月,一天又一天地遍历这一年。
|
||||
|
||||
现在假如我想查看某张图片,但我不确定我是在 2016 年的上半年还是在 2017 的上半年拍摄的,那么我便可以使用下面的命令来找到它:
|
||||
|
||||
```
|
||||
display -resize 35% 201[6-7]/0[1-6]/*/*.JPG
|
||||
```
|
||||
|
||||
这限制查看的图片拍摄于 2016 和 2017 年的一月到六月
|
||||
|
||||
### 使用 montage 来查看图片的缩略图
|
||||
|
||||
假如现在我要查找一张我想要编辑的图片,使用 `display` 的一个问题是它只会显示每张图片的文件名,而不显示其在目录结构中的位置,所以想要找到那张图片并不容易。另外,假如我很偶然地在从相机下载图片的过程中将这些图片从相机的内存里面清除了它们,结果使得下次拍摄照片的名称又从 `DSC_0001.jpg` 开始命名,那么当使用 `display` 来展示一整年的图片时,将会在这 12 个月的图片中花费很长的时间来查找它们。
|
||||
|
||||
这时 `montage` 命令便可以派上用场了。它可以将一系列的图片缩略图放在一张图片中,这样就会非常有用。例如可以使用下面的命令来完成上面的任务:
|
||||
|
||||
```
|
||||
montage -label %d/%f -title 2017 -tile 5x -resize 10% -geometry +4+4 2017/0[1-4]/*/*.JPG 2017JanApr.jpg
|
||||
```
|
||||
|
||||
从左到右,这个命令以标签开头,标签的形式是包含文件名(`%f`)和以 `/` 分割的目录(`%d`)结构,接着这个命令以目录的名称(2017)来作为标题,然后将图片排成 5 列,每个图片缩放为 10% (这个参数可以很好地匹配我的屏幕)。`geometry` 的设定将在每张图片的四周留白,最后指定那些图片要包括到这张合成图片中,以及一个合适的文件名称(`2017JanApr.jpg`)。现在图片 `2017JanApr.jpg` 便可以成为一个索引,使得我可以不时地使用它来查看这个时期的所有图片。
|
||||
|
||||
### 注意内存消耗
|
||||
|
||||
你可能会好奇为什么我在上面的合成图中只特别指定了为期 4 个月(从一月到四月)的图片。因为 `montage` 将会消耗大量内存,所以你需要多加注意。我的相机产生的图片每张大约有 2.5MB,我发现我的系统可以很轻松地处理 60 张图片。但一旦图片增加到 80 张,如果此时还有另外的程序(例如 Firefox 、Thunderbird)在后台工作,那么我的电脑将会死机,这似乎和内存使用相关,`montage`可能会占用可用 RAM 的 80% 乃至更多(你可以在此期间运行 `top` 命令来查看内存占用)。假如我关掉其他的程序,我便可以在我的系统死机前处理 80 张图片。
|
||||
|
||||
下面的命令可以让你知晓在你运行 `montage` 命令前你需要处理图片张数:
|
||||
|
||||
```
|
||||
ls 2017/0[1-4/*/*.JPG > filelist; wc -l filelist
|
||||
```
|
||||
|
||||
`ls` 命令生成我们搜索的文件的列表,然后通过重定向将这个列表保存在任意以名为 `filelist` 的文件中。接着带有 `-l` 选项的 `wc` 命令输出该列表文件共有多少行,换句话说,展示出了需要处理的文件个数。下面是我运行命令后的输出:
|
||||
|
||||
```
|
||||
163 filelist
|
||||
```
|
||||
|
||||
啊呀!从一月到四月我居然有 163 张图片,使用这些图片来创建一张合成图一定会使得我的系统死机的。我需要将这个列表减少点,可能只处理到 3 月份或者更早的图片。但如果我在 4 月 20 号到 30 号期间拍摄了很多照片,我想这便是问题的所在。下面的命令便可以帮助指出这个问题:
|
||||
|
||||
```
|
||||
ls 2017/0[1-3]/*/*.JPG > filelist; ls 2017/04/0[1-9]/*.JPG >> filelist; ls 2017/04/1[0-9]/*.JPG >> filelist; wc -l filelist
|
||||
```
|
||||
|
||||
上面一行中共有 4 个命令,它们以分号分隔。第一个命令特别指定从一月到三月期间拍摄的照片;第二个命令使用 `>>` 将拍摄于 4 月 1 日至 9 日的照片追加到这个列表文件中;第三个命令将拍摄于 4 月 10 日到 19 日的照片追加到列表中。最终它的显示结果为:
|
||||
|
||||
```
|
||||
81 filelist
|
||||
```
|
||||
|
||||
我知道假如我关掉其他的程序,处理 81 张图片是可行的。
|
||||
|
||||
使用 `montage` 来处理它们是很简单的,因为我们只需要将上面所做的处理添加到 `montage` 命令的后面即可:
|
||||
|
||||
```
|
||||
montage -label %d/%f -title 2017 -tile 5x -resize 10% -geometry +4+4 2017/0[1-3]/*/*.JPG 2017/04/0[1-9]/*.JPG 2017/04/1[0-9]/*.JPG 2017Jan01Apr19.jpg
|
||||
```
|
||||
|
||||
从左到右,`montage` 命令后面最后的那个文件名将会作为输出,在它之前的都是输入。这个命令将花费大约 3 分钟来运行,并生成一张大小约为 2.5MB 的图片,但我的系统只是有一点反应迟钝而已。
|
||||
|
||||
### 展示合成图片
|
||||
|
||||
当你第一次使用 `display` 查看一张巨大的合成图片时,你将看到合成图的宽度很合适,但图片的高度被压缩了,以便和屏幕相适应。不要慌,只需要左击图片,然后选择 `View > Original Size` 便会显示整个图片。再次点击图片便可以使菜单栏隐藏。
|
||||
|
||||
我希望这篇文章可以在你使用新方法查看图片时帮助你。在我的下一篇文章中,我将讨论更加复杂的图片操作技巧。
|
||||
|
||||
### 作者简介
|
||||
|
||||
Greg Pittman - Greg 肯塔基州路易斯维尔的一名退休的神经科医生,对计算机和程序设计有着长期的兴趣,最早可以追溯到 1960 年代的 Fortran IV 。当 Linux 和开源软件相继出现时,他开始学习更多的相关知识,并分享自己的心得。他是 Scribus 团队的成员。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/17/9/imagemagick-viewing-images
|
||||
|
||||
作者:[Greg Pittman][a]
|
||||
译者:[FSSlc](https://github.com/FSSlc)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/greg-p
|
||||
[1]:https://linux.cn/article-8851-1.html
|
||||
[3]:https://opensource.com/sites/default/files/u128651/edge3negate.jpg "Using the edge and negate options on an image."
|
||||
[4]:https://wiki.gnome.org/Apps/Shotwell
|
||||
[5]:https://en.wikipedia.org/wiki/Exif
|
@ -1,4 +1,4 @@
|
||||
DevOps 将让你失业?
|
||||
DevOps 会让你失业吗?
|
||||
======
|
||||
|
||||
>你是否担心工作中自动化将代替人?可能是对的,但是这并不是件坏事。
|
||||
@ -8,19 +8,19 @@ DevOps 将让你失业?
|
||||
|
||||
这是一个很正常的担心:DevOps 最终会让你失业?毕竟,DevOps 意味着开发人员做运营,对吗?DevOps 是自动化的。如果我的工作都自动化了,我去做什么?实行持续分发和容器化意味着运营已经过时了吗?对于 DevOps 来说,所有的东西都是代码:基础设施是代码、测试是代码、这个和那个都是代码。如果我没有这些技能怎么办?
|
||||
|
||||
[DevOps][1] 是一个即将到来的变化,将颠覆这一领域,狂热的拥挤者们正在谈论,如何使用 [三种方法][2] 去改变世界 —— 即 DevOps 的三大基础 —— 去推翻一个旧的世界。它是势不可档的。那么,问题来了 —— DevOps 将会让我失业吗?
|
||||
[DevOps][1] 是一个即将到来的变化,它将颠覆这一领域,狂热的拥挤者们正在谈论,如何使用 [三种方法][2] 去改变世界 —— 即 DevOps 的三大基础 —— 去推翻一个旧的世界。它是势不可档的。那么,问题来了 —— DevOps 将会让我失业吗?
|
||||
|
||||
### 第一个担心:再也不需要我了
|
||||
### 第一个担心:再也不需要我了
|
||||
|
||||
由于开发者来管理应用程序的整个生命周期,接受 DevOps 的理念很容易。容器化可能是影响这一想法的重要因素。当容器化在各种场景下铺开之后,它们被吹嘘成开发者构建、测试、和部署他们代码的一站式解决方案。DevOps 对于运营、测试、以及 QA 团队来说,有什么作用呢?
|
||||
由于开发者来管理应用程序的整个生命周期,接受 DevOps 的理念很容易。容器化可能是影响这一想法的重要因素。当容器化在各种场景下铺开之后,它们被吹嘘成开发者构建、测试和部署他们代码的一站式解决方案。DevOps 对于运营、测试、以及 QA 团队来说,有什么作用呢?
|
||||
|
||||
这源于对 DevOps 原则的误解。DevOps 的第一原则,或者第一方法是,_系统思考_ ,或者强调整体管理方法和了解应用程序或服务的整个生命周期。这并不意味着应用程序的开发者将学习和管理整个过程。相反,是拥有各个专业和技能的人共同合作,以确保成功。让开发者对这一过程完全负责的作法,几乎是将开发者置于使用者的对立面—— 本质上就是 “将鸡蛋放在了一个篮子里”。
|
||||
这源于对 DevOps 原则的误解。DevOps 的第一原则,或者第一方法是,<ruby>系统思考<rt>Systems Thinking</rt></ruby>,或者强调整体管理方法和了解应用程序或服务的整个生命周期。这并不意味着应用程序的开发者将学习和管理整个过程。相反,是拥有各个专业和技能的人共同合作,以确保成功。让开发者对这一过程完全负责的作法,几乎是将开发者置于使用者的对立面 —— 本质上就是 “将鸡蛋放在了一个篮子里”。
|
||||
|
||||
在 DevOps 中有一个为你保留的专门职位。就像将一个受过传统教育的、拥有线性回归和二分查找知识的软件工程师,被用去写一些 Ansible playbooks 和 Docker 文件,这是一种浪费。而对于那些拥有高级技能,知道如何保护一个系统和优化数据库执行的系统管理员,被浪费在写一些 CSS 和设计用户流这样的工作上。写代码、做测试、和维护应用程序的高效团队一般是跨学科、跨职能的、拥有不同专业技术和背景的人组成的混编团队。
|
||||
|
||||
### 第二个担心:我的工作将被自动化
|
||||
|
||||
或许是,或许不是,DevOps 可能在有时候是自动化的同义词。当自动化构建、测试、部署、监视、以及提醒等事项,已经占据了整个应用程序生命周期管理的时候,还会给我们剩下什么工作呢?这种对自动化的关注可能与第二个方法有关:_放大反馈循环_。DevOps 的第二个方法是在团队和部署的应用程序之间,采用相反的方向优先处理快速反馈 —— 从监视和维护部署、测试、开发、等等,通过强调,使反馈更加重要并且可操作。虽然这第二种方式与自动化并不是特别相关,许多自动化工具团队在它们的部署流水线中使用,以促进快速提醒和快速行动,或者基于对使用者的支持业务中产生的反馈来改进。传统的做法是靠人来完成的,这就可以理解为什么自动化可能会导致未来一些人失业的焦虑了。
|
||||
或许是,或许不是,DevOps 可能在有时候是自动化的同义词。当自动化构建、测试、部署、监视,以及提醒等事项,已经占据了整个应用程序生命周期管理的时候,还会给我们剩下什么工作呢?这种对自动化的关注可能与第二个方法有关:<ruby>放大反馈循环<rt>Amplify Feedback Loops</rt></ruby>。DevOps 的第二个方法是在团队和部署的应用程序之间,采用相反的方向优先处理快速反馈 —— 从监视和维护部署、测试、开发、等等,通过强调,使反馈更加重要并且可操作。虽然这第二种方式与自动化并不是特别相关,许多自动化工具团队在它们的部署流水线中使用,以促进快速提醒和快速行动,或者基于对使用者的支持业务中产生的反馈来改进。传统的做法是靠人来完成的,这就可以理解为什么自动化可能会导致未来一些人失业的焦虑了。
|
||||
|
||||
自动化只是一个工具,它并不能代替人。聪明的人使用它来做一些重复的工作,不去开发智力和创造性的财富,而是去按红色的 “George Jetson” 按钮是一种极大的浪费。让每天工作中的苦活自动化,意味着有更多的时间去解决真正的问题和即将到来的创新的解决方案。人类需要解决更多的 “怎么做和为什么” 问题,而计算机只能处理 “复制和粘贴”。
|
||||
|
||||
@ -28,17 +28,17 @@ DevOps 将让你失业?
|
||||
|
||||
### 第三个担心:我没有这些技能怎么办
|
||||
|
||||
"我怎么去继续做这些事情?我不懂如何自动化。现在所有的工作都是代码 —— 我不是开发人员,我不会做 DevOps 中写代码的工作“,第三个担心是一种不自信的担心。由于文化的改变,是的,团队将也会要求随之改变,一些人可能担心,他们缺乏继续做他们工作的技能。
|
||||
“我怎么去继续做这些事情?我不懂如何自动化。现在所有的工作都是代码 —— 我不是开发人员,我不会做 DevOps 中写代码的工作”,第三个担心是一种不自信的担心。由于文化的改变,是的,团队将也会要求随之改变,一些人可能担心,他们缺乏继续做他们工作的技能。
|
||||
|
||||
然而,大多数人或许已经比他们所想的更接近。Dockerfile 是什么,或者像 Puppet 或 Ansible 配置管理是什么,但是环境即代码,系统管理员已经写了 shell 脚本和 Python 程序去处理他们重复的任务。学习更多的知识并使用已有的工具处理他们的更多问题 —— 编排、部署、维护即代码 —— 尤其是当从繁重的手动任务中解放出来,专注于成长时。
|
||||
然而,大多数人或许已经比他们所想的更接近。Dockerfile 是什么,或者像 Puppet 或 Ansible 配置管理是什么,这就是环境即代码,系统管理员已经写了 shell 脚本和 Python 程序去处理他们重复的任务。学习更多的知识并使用已有的工具处理他们的更多问题 —— 编排、部署、维护即代码 —— 尤其是当从繁重的手动任务中解放出来,专注于成长时。
|
||||
|
||||
在 DevOps 的使用者中去回答这第三个担心,第三个方法是:_一种不断实验和学习的文化_。尝试、失败、并从错误中吸取教训而不是责怪它们的能力,是设计出更有创意的解决方案的重要因素。第三个方法是为前两个方法授权—— 允许快速检测和修复问题,并且开发人员可以自由地尝试和学习,其它的团队也是如此。从未使用过配置管理或者写过自动供给基础设施程序的运营团队也要自由尝试并学习。测试和 QA 团队也要自由实现新测试流水线,并且自动批准和发布新流程。在一个拥抱学习和成长的文化中,每个人都可以自由地获取他们需要的技术,去享受工作带来的成功和喜悦。
|
||||
在 DevOps 的使用者中去回答这第三个担心,第三个方法是:<ruby>一种不断实验和学习的文化<rt>A Culture of Continual Experimentation and Learning</ruby>。尝试、失败,并从错误中吸取教训而不是责怪它们的能力,是设计出更有创意的解决方案的重要因素。第三个方法是为前两个方法授权 —— 允许快速检测和修复问题,并且开发人员可以自由地尝试和学习,其它的团队也是如此。从未使用过配置管理或者写过自动供给基础设施程序的运营团队也要自由尝试并学习。测试和 QA 团队也要自由实现新测试流水线,并且自动批准和发布新流程。在一个拥抱学习和成长的文化中,每个人都可以自由地获取他们需要的技术,去享受工作带来的成功和喜悦。
|
||||
|
||||
### 结束语
|
||||
|
||||
在一个行业中,任何可能引起混乱的实践或变化都会产生担心和不确定,DevOps 也不例外。对自己工作的担心是对成百上千的文章和演讲的合理回应,其中列举了无数的实践和技术,而这些实践和技术正致力于授权开发者对行业的各个方面承担职责。
|
||||
|
||||
然而,事实上,DevOps 是 "[一个跨学科的沟通实践,致力于研究构建、进化、和运营快速变化的弹性系统][3]"。 DevOps 意味着终结 ”筒仓“,但并不专业化。它是受委托去做苦差事的自动化系统,解放你,让你去做人类更擅长做的事:思考和想像。并且,如果你愿意去学习和成长,它将不会终结你解决新的、挑战性的问题的机会。
|
||||
然而,事实上,DevOps 是 “[一个跨学科的沟通实践,致力于研究构建、进化、和运营快速变化的弹性系统][3]”。 DevOps 意味着终结 “筒仓”,但并不专业化。它是受委托去做苦差事的自动化系统,解放你,让你去做人类更擅长做的事:思考和想像。并且,如果你愿意去学习和成长,它将不会终结你解决新的、挑战性的问题的机会。
|
||||
|
||||
DevOps 会让你失业吗?会的,但它同时给你提供了更好的工作。
|
||||
|
||||
@ -48,7 +48,7 @@ via: https://opensource.com/article/17/12/will-devops-steal-my-job
|
||||
|
||||
作者:[Chris Collins][a]
|
||||
译者:[qhwdw](https://github.com/qhwdw)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,29 +1,32 @@
|
||||
如何使用 Npm 管理 NodeJS 包
|
||||
如何使用 npm 管理 NodeJS 包
|
||||
=====
|
||||
|
||||

|
||||
|
||||
前一段时间,我们发布了一个[**使用 PIP 管理 Python 包**][3]的指南。今天,我们将讨论如何使用 Npm 管理 NodeJS 包。NPM 是最大的软件注册中心,包含 600,000 多个包。每天,世界各地的开发人员通过 npm 共享和下载软件包。在本指南中,我将解释使用 npm 基础知识,例如安装包(本地和全局)、安装特定版本的包、更新、删除和管理 NodeJS 包等等。
|
||||
前一段时间,我们发布了一个[使用 pip 管理 Python 包][3]的指南。今天,我们将讨论如何使用 npm 管理 NodeJS 包。npm 是最大的软件注册中心,包含 600,000 多个包。每天,世界各地的开发人员通过 npm 共享和下载软件包。在本指南中,我将解释使用 npm 基础知识,例如安装包(本地和全局)、安装特定版本的包、更新、删除和管理 NodeJS 包等等。
|
||||
|
||||
### 使用 Npm 管理 NodeJS 包
|
||||
|
||||
##### 安装 NPM
|
||||
### 安装 npm
|
||||
|
||||
用于 npm 是用 NodeJS 编写的,我们需要安装 NodeJS 才能使用 npm。要在不同的 Linux 发行版上安装 NodeJS,请参考下面的链接。
|
||||
|
||||
- [在 Linux 上安装 NodeJS](https://www.ostechnix.com/install-node-js-linux/)
|
||||
|
||||
检查 node 安装的位置:
|
||||
|
||||
```
|
||||
$ which node
|
||||
/home/sk/.nvm/versions/node/v9.4.0/bin/node
|
||||
```
|
||||
|
||||
检查它的版本:
|
||||
|
||||
```
|
||||
$ node -v
|
||||
v9.4.0
|
||||
```
|
||||
|
||||
进入 Node 交互式解释器:
|
||||
|
||||
```
|
||||
$ node
|
||||
> .help
|
||||
@ -38,43 +41,46 @@ $ node
|
||||
```
|
||||
|
||||
检查 npm 安装的位置:
|
||||
|
||||
```
|
||||
$ which npm
|
||||
/home/sk/.nvm/versions/node/v9.4.0/bin/npm
|
||||
```
|
||||
|
||||
还有版本:
|
||||
|
||||
```
|
||||
$ npm -v
|
||||
5.6.0
|
||||
```
|
||||
|
||||
棒极了!Node 和 NPM 已安装并能工作!正如你可能已经注意到,我已经在我的 $HOME 目录中安装了 NodeJS 和 NPM,这样是为了避免在全局模块时出现权限问题。这是 NodeJS 团队推荐的方法。
|
||||
棒极了!Node 和 npm 已安装好!正如你可能已经注意到,我已经在我的 `$HOME` 目录中安装了 NodeJS 和 NPM,这样是为了避免在全局模块时出现权限问题。这是 NodeJS 团队推荐的方法。
|
||||
|
||||
那么,让我们继续看看如何使用 npm 管理 NodeJS 模块(或包)。
|
||||
|
||||
##### 安装 NodeJS 模块
|
||||
### 安装 NodeJS 模块
|
||||
|
||||
NodeJS 模块可以安装在本地或全局(系统范围)。现在我将演示如何在本地安装包。
|
||||
NodeJS 模块可以安装在本地或全局(系统范围)。现在我将演示如何在本地安装包(LCTT 译注:即将包安装到一个 NodeJS 项目当中,所以下面会先创建一个空项目做演示)。
|
||||
|
||||
**在本地安装包**
|
||||
#### 在本地安装包
|
||||
|
||||
为了在本地管理包,我们通常使用 **package.json** 文件来管理。
|
||||
为了在本地管理包,我们通常使用 `package.json` 文件来管理。
|
||||
|
||||
首先,让我们创建我们的项目目录。
|
||||
|
||||
```
|
||||
$ mkdir demo
|
||||
```
|
||||
```
|
||||
$ cd demo
|
||||
```
|
||||
|
||||
在项目目录中创建一个 package.json 文件。为此,运行:
|
||||
在项目目录中创建一个 `package.json` 文件。为此,运行:
|
||||
|
||||
```
|
||||
$ npm init
|
||||
```
|
||||
|
||||
输入你的包的详细信息,例如名称,版本,作者,github 页面等等,或者按下 ENTER 键接受默认值并键入 **YES** 确认。
|
||||
输入你的包的详细信息,例如名称、版本、作者、GitHub 页面等等,或者按下回车键接受默认值并键入 `yes` 确认。
|
||||
|
||||
```
|
||||
This utility will walk you through creating a package.json file.
|
||||
It only covers the most common items, and tries to guess sensible defaults.
|
||||
@ -112,19 +118,22 @@ About to write to /home/sk/demo/package.json:
|
||||
Is this ok? (yes) yes
|
||||
```
|
||||
|
||||
上面的命令初始化你的项目并创建了 package.json 文件。
|
||||
上面的命令初始化你的项目并创建了 `package.json` 文件。
|
||||
|
||||
你也可以使用命令以非交互式方式执行此操作:
|
||||
|
||||
```
|
||||
npm init --y
|
||||
```
|
||||
|
||||
现在让我们安装名为 [**commander**][2] 的包。
|
||||
现在让我们安装名为 [commander][2] 的包。
|
||||
|
||||
```
|
||||
$ npm install commander
|
||||
```
|
||||
|
||||
示例输出:
|
||||
|
||||
```
|
||||
npm notice created a lockfile as package-lock.json. You should commit this file.
|
||||
npm WARN demo@1.0.0 No repository field.
|
||||
@ -133,11 +142,12 @@ npm WARN demo@1.0.0 No repository field.
|
||||
added 1 package in 2.519s
|
||||
```
|
||||
|
||||
这将在项目的根目录中创建一个名为 **" node_modules"** 的目录(如果它不存在的话),并在其中下载包。
|
||||
这将在项目的根目录中创建一个名为 `node_modules` 的目录(如果它不存在的话),并在其中下载包。
|
||||
|
||||
让我们检查 `pachage.json` 文件。
|
||||
|
||||
让我们检查 pachage.json 文件。
|
||||
```
|
||||
$ cat package.json
|
||||
$ cat package.json
|
||||
{
|
||||
"name": "demo",
|
||||
"version": "1.0.0",
|
||||
@ -148,30 +158,33 @@ $ cat package.json
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
**"dependencies": {**
|
||||
**"commander": "^2.13.0"**
|
||||
"dependencies": {
|
||||
"commander": "^2.13.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
你会看到添加了依赖文件,版本号前面的插入符号 ( **^** ) 表示在安装时,npm 将取出它可以找到的最高版本的包。
|
||||
你会看到添加了依赖文件,版本号前面的插入符号 ( `^` ) 表示在安装时,npm 将取出它可以找到的最高版本的包。
|
||||
|
||||
```
|
||||
$ ls node_modules/
|
||||
commander
|
||||
```
|
||||
|
||||
package.json 文件的优点是,如果你的项目目录中有 package.json 文件,只需键入 "npm install",那么 npm 将查看文件中列出的依赖关系并下载它们。你甚至可以与其他开发人员共享它或将其推送到你的 GitHub 仓库。因此,当他们键入 “npm install” 时,他们将获得你拥有的所有相同的包。
|
||||
`package.json` 文件的优点是,如果你的项目目录中有 `package.json` 文件,只需键入 `npm install`,那么 `npm` 将查看文件中列出的依赖关系并下载它们。你甚至可以与其他开发人员共享它或将其推送到你的 GitHub 仓库。因此,当他们键入 `npm install` 时,他们将获得你拥有的所有相同的包。
|
||||
|
||||
你也可能会注意到另一个名为 **package-lock.json** 的文件,该文件确保在项目安装的所有系统上都保持相同的依赖关系。
|
||||
你也可能会注意到另一个名为 `package-lock.json` 的文件,该文件确保在项目安装的所有系统上都保持相同的依赖关系。
|
||||
|
||||
要在你的程序中使用已安装的包,使用实际代码在项目目录中创建一个 `index.js`(或者其他任何名称)文件,然后使用以下命令运行它:
|
||||
|
||||
要在你的程序中使用已安装的包,使用实际代码在项目目录中创建一个 **index.js**(或者其他任何名称)文件,然后使用以下命令运行它:
|
||||
```
|
||||
$ node index.js
|
||||
```
|
||||
|
||||
**在全局安装包**
|
||||
#### 在全局安装包
|
||||
|
||||
如果你想使用一个包作为命令行工具,那么最好在全局安装它。这样,无论你的当前目录是哪个目录,它都能正常工作。
|
||||
|
||||
```
|
||||
$ npm install async -g
|
||||
+ async@2.6.0
|
||||
@ -179,23 +192,27 @@ added 2 packages in 4.695s
|
||||
```
|
||||
|
||||
或者
|
||||
|
||||
```
|
||||
$ npm install async --global
|
||||
```
|
||||
|
||||
要安装特定版本的包,我们可以:
|
||||
|
||||
```
|
||||
$ npm install async@2.6.0 --global
|
||||
```
|
||||
|
||||
##### 更新 NodeJS 模块
|
||||
### 更新 NodeJS 模块
|
||||
|
||||
要更新本地包,转到 `package.json` 所在的项目目录并运行:
|
||||
|
||||
要更新本地包,转到 package.json 所在的项目目录并运行:
|
||||
```
|
||||
$ npm update
|
||||
```
|
||||
|
||||
然后,运行以下命令确保所有包都更新了。
|
||||
|
||||
```
|
||||
$ npm outdated
|
||||
```
|
||||
@ -203,6 +220,7 @@ $ npm outdated
|
||||
如果没有需要更新的,那么它返回空。
|
||||
|
||||
要找出哪一个全局包需要更新,运行:
|
||||
|
||||
```
|
||||
$ npm outdated -g --depth=0
|
||||
```
|
||||
@ -210,32 +228,37 @@ $ npm outdated -g --depth=0
|
||||
如果没有输出,意味着所有包都已更新。
|
||||
|
||||
更新单个全局包,运行:
|
||||
|
||||
```
|
||||
$ npm update -g <package-name>
|
||||
```
|
||||
|
||||
更新所有的全局包,运行:
|
||||
|
||||
```
|
||||
$ npm update -g <package>
|
||||
$ npm update -g
|
||||
```
|
||||
|
||||
##### 列出 NodeJS 模块
|
||||
### 列出 NodeJS 模块
|
||||
|
||||
列出本地包,转到项目目录并运行:
|
||||
|
||||
```
|
||||
$ npm list
|
||||
demo@1.0.0 /home/sk/demo
|
||||
└── commander@2.13.0
|
||||
```
|
||||
|
||||
如你所见,我在本地安装了 "commander" 这个包。
|
||||
如你所见,我在本地安装了 `commander` 这个包。
|
||||
|
||||
要列出全局包,从任何位置都可以运行以下命令:
|
||||
|
||||
```
|
||||
$ npm list -g
|
||||
```
|
||||
|
||||
示例输出:
|
||||
|
||||
```
|
||||
/home/sk/.nvm/versions/node/v9.4.0/lib
|
||||
├─┬ async@2.6.0
|
||||
@ -252,7 +275,8 @@ $ npm list -g
|
||||
|
||||
该命令将列出所有模块及其依赖关系。
|
||||
|
||||
要仅仅列出顶级模块,使用 -depth=0 选项:
|
||||
要仅仅列出顶级模块,使用 `-depth=0` 选项:
|
||||
|
||||
```
|
||||
$ npm list -g --depth=0
|
||||
/home/sk/.nvm/versions/node/v9.4.0/lib
|
||||
@ -260,43 +284,48 @@ $ npm list -g --depth=0
|
||||
└── npm@5.6.0
|
||||
```
|
||||
|
||||
##### 寻找 NodeJS 模块
|
||||
#### 寻找 NodeJS 模块
|
||||
|
||||
要搜索一个模块,使用 `npm search` 命令:
|
||||
|
||||
要搜索一个模块,使用 "npm search" 命令:
|
||||
```
|
||||
npm search <search-string>
|
||||
```
|
||||
|
||||
例如:
|
||||
|
||||
```
|
||||
$ npm search request
|
||||
```
|
||||
|
||||
该命令将显示包含搜索字符串 "request" 的所有模块。
|
||||
该命令将显示包含搜索字符串 `request` 的所有模块。
|
||||
|
||||
##### 移除 NodeJS 模块
|
||||
|
||||
要删除本地包,转到项目目录并运行以下命令,这会从 **node_modules** 目录中删除包:
|
||||
要删除本地包,转到项目目录并运行以下命令,这会从 `node_modules` 目录中删除包:
|
||||
|
||||
```
|
||||
$ npm uninstall <package-name>
|
||||
```
|
||||
|
||||
要从 **package.json** 文件中的依赖关系中删除它,使用如下所示的 **save** 标志:
|
||||
要从 `package.json` 文件中的依赖关系中删除它,使用如下所示的 `save` 选项:
|
||||
|
||||
```
|
||||
$ npm uninstall --save <package-name>
|
||||
|
||||
```
|
||||
|
||||
要删除已安装的全局包,运行:
|
||||
|
||||
```
|
||||
$ npm uninstall -g <package>
|
||||
```
|
||||
|
||||
##### 清楚 NPM 缓存
|
||||
### 清除 npm 缓存
|
||||
|
||||
默认情况下,NPM 在安装包时,会将其副本保存在 $HOME 目录中名为 npm 的缓存文件夹中。所以,你可以在下次安装时不必再次下载。
|
||||
默认情况下,npm 在安装包时,会将其副本保存在 `$HOME` 目录中名为 `.npm` 的缓存文件夹中。所以,你可以在下次安装时不必再次下载。
|
||||
|
||||
查看缓存模块:
|
||||
|
||||
```
|
||||
$ ls ~/.npm
|
||||
```
|
||||
@ -304,28 +333,33 @@ $ ls ~/.npm
|
||||
随着时间的推移,缓存文件夹会充斥着大量旧的包。所以不时清理缓存会好一些。
|
||||
|
||||
从 npm@5 开始,npm 缓存可以从 corruption 问题中自行修复,并且保证从缓存中提取的数据有效。如果你想确保一切都一致,运行:
|
||||
|
||||
```
|
||||
$ npm cache verify
|
||||
```
|
||||
|
||||
清楚整个缓存,运行:
|
||||
清除整个缓存,运行:
|
||||
|
||||
```
|
||||
$ npm cache clean --force
|
||||
```
|
||||
|
||||
##### 查看 NPM 配置
|
||||
### 查看 npm 配置
|
||||
|
||||
要查看 npm 配置,键入:
|
||||
|
||||
要查看 NPM 配置,键入:
|
||||
```
|
||||
$ npm config list
|
||||
```
|
||||
|
||||
或者
|
||||
或者:
|
||||
|
||||
```
|
||||
$ npm config ls
|
||||
```
|
||||
|
||||
示例输出:
|
||||
|
||||
```
|
||||
; cli configs
|
||||
metrics-registry = "https://registry.npmjs.org/"
|
||||
@ -339,26 +373,25 @@ user-agent = "npm/5.6.0 node/v9.4.0 linux x64"
|
||||
```
|
||||
|
||||
要显示当前的全局位置:
|
||||
|
||||
```
|
||||
$ npm config get prefix
|
||||
/home/sk/.nvm/versions/node/v9.4.0
|
||||
```
|
||||
|
||||
好吧,这就是全部了。我们刚才介绍的只是基础知识,NPM 是一个广泛话题。有关更多详细信息,参阅 [**NPM Getting Started**][3] 指南。
|
||||
好吧,这就是全部了。我们刚才介绍的只是基础知识,npm 是一个广泛话题。有关更多详细信息,参阅 [**NPM Getting Started**][3] 指南。
|
||||
|
||||
希望这对你有帮助。更多好东西即将来临,敬请关注!
|
||||
|
||||
干杯!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/manage-nodejs-packages-using-npm/
|
||||
|
||||
作者:[SK][a]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,24 +1,26 @@
|
||||
如何使用 virsh 命令创建、还原和删除 KVM 虚拟机快照
|
||||
======
|
||||
[![KVM-VirtualMachine-Snapshot][1]![KVM-VirtualMachine-Snapshot][2]][2]
|
||||
|
||||
在虚拟化平台上进行系统管理工作时经常在开始主要活动比如部署补丁和代码前先设置一个虚拟机快照。
|
||||
![KVM-VirtualMachine-Snapshot][2]
|
||||
|
||||
在虚拟化平台上进行系统管理工作时,经常需要在开始重大操作比如部署补丁和代码前先设置一个虚拟机<ruby>快照<rt>snapshot</rt></ruby>。
|
||||
|
||||
虚拟机**快照**是特定时间点的虚拟机磁盘的副本。换句话说,快照保存了给定的时间点虚拟机的状态和数据。
|
||||
|
||||
### 我们可以在哪里使用虚拟机快照?
|
||||
|
||||
如果你在使用基于 **KVM** 的**虚拟机管理程序**,那么可以使用 virsh 命令获取虚拟机或域快照。快照在一种情况下变得非常有用,当你已经在虚拟机上安装或应用了最新的补丁,但是由于某些原因,虚拟机上的程序变得不稳定,程序团队想要还原所有的更改和补丁。如果你在应用补丁之前设置了虚拟机的快照,那么可以使用快照将虚拟机恢复到之前的状态。
|
||||
如果你在使用基于 **KVM** 的**虚拟机管理程序**,那么可以使用 `virsh` 命令获取虚拟机或域快照。快照在一种情况下变得非常有用,当你已经在虚拟机上安装或应用了最新的补丁,但是由于某些原因,虚拟机上的程序变得不稳定,开发团队想要还原所有的更改和补丁。如果你在应用补丁之前设置了虚拟机的快照,那么可以使用快照将虚拟机恢复到之前的状态。
|
||||
|
||||
**注意:**我们只能对磁盘格式为 **Qcow2** 的虚拟机的进行快照,并且 kvm 的 `virsh` 命令不支持 raw 磁盘格式,请使用以下命令将原始磁盘格式转换为 qcow2。
|
||||
|
||||
**注意:**我们只能设置磁盘格式为 **Qcow2** 的虚拟机的快照,并且 kvm virsh 命令不支持 raw 磁盘格式,请使用以下命令将原始磁盘格式转换为 qcow2。
|
||||
```
|
||||
# qemu-img convert -f raw -O qcow2 image-name.img image-name.qcow2
|
||||
|
||||
```
|
||||
|
||||
### 创建 KVM 虚拟机(域)快照
|
||||
|
||||
我假设 KVM 管理程序已经在 CentOS 7 / RHEL 7 机器上配置好了,并且有虚拟机正在运行。我们可以使用下面的 virsh 命令列出虚拟机管理程序中的所有虚拟机,
|
||||
我假设 KVM 管理程序已经在 CentOS 7 / RHEL 7 机器上配置好了,并且有虚拟机正在运行。我们可以使用下面的 `virsh` 命令列出虚拟机管理程序中的所有虚拟机,
|
||||
|
||||
```
|
||||
[root@kvm-hypervisor ~]# virsh list --all
|
||||
Id Name State
|
||||
@ -29,35 +31,33 @@
|
||||
103 overcloud-compute1 running
|
||||
114 webserver running
|
||||
115 Test-MTN running
|
||||
[root@kvm-hypervisor ~]#
|
||||
|
||||
```
|
||||
|
||||
假设我们想创建 ‘ **webserver** ‘ 虚拟机的快照,运行下面的命令,
|
||||
假设我们想创建 webserver 虚拟机的快照,运行下面的命令,
|
||||
|
||||
**语法:**
|
||||
|
||||
```
|
||||
# virsh snapshot-create-as –domain {vm_name} –name {snapshot_name} –description “enter description here”
|
||||
```
|
||||
|
||||
```
|
||||
[root@kvm-hypervisor ~]# virsh snapshot-create-as --domain webserver --name webserver_snap --description "snap before patch on 4Feb2018"
|
||||
Domain snapshot webserver_snap created
|
||||
[root@kvm-hypervisor ~]#
|
||||
|
||||
```
|
||||
|
||||
创建快照后,我们可以使用下面的命令列出与虚拟机相关的快照,
|
||||
创建快照后,我们可以使用下面的命令列出与虚拟机相关的快照:
|
||||
|
||||
```
|
||||
[root@kvm-hypervisor ~]# virsh snapshot-list webserver
|
||||
Name Creation Time State
|
||||
------------------------------------------------------------
|
||||
webserver_snap 2018-02-04 15:05:05 +0530 running
|
||||
[root@kvm-hypervisor ~]#
|
||||
|
||||
```
|
||||
|
||||
要列出虚拟机快照的详细信息,请运行下面的 virsh 命令,
|
||||
要列出虚拟机快照的详细信息,请运行下面的 `virsh` 命令:
|
||||
|
||||
```
|
||||
[root@kvm-hypervisor ~]# virsh snapshot-info --domain webserver --snapshotname webserver_snap
|
||||
Name: webserver_snap
|
||||
@ -69,50 +69,44 @@ Parent: -
|
||||
Children: 0
|
||||
Descendants: 0
|
||||
Metadata: yes
|
||||
[root@kvm-hypervisor ~]#
|
||||
|
||||
```
|
||||
|
||||
我们可以使用下面的 qemu-img 命令查看快照的大小,
|
||||
我们可以使用下面的 `qemu-img` 命令查看快照的大小:
|
||||
|
||||
```
|
||||
[root@kvm-hypervisor ~]# qemu-img info /var/lib/libvirt/images/snaptestvm.img
|
||||
|
||||
```
|
||||
|
||||
[![qemu-img-command-output-kvm][1]![qemu-img-command-output-kvm][3]][3]
|
||||
![qemu-img-command-output-kvm][3]
|
||||
|
||||
### 还原 KVM 虚拟机快照
|
||||
|
||||
假设我们想要将 webserver 虚拟机还原到我们在上述步骤中创建的快照。使用下面的 virsh 命令将 Webserver 虚拟机恢复到其快照 “**webserver_snap**” 上。
|
||||
假设我们想要将 webserver 虚拟机还原到我们在上述步骤中创建的快照。使用下面的 `virsh` 命令将 Webserver 虚拟机恢复到其快照 webserver_snap 时。
|
||||
|
||||
**语法:**
|
||||
|
||||
```
|
||||
# virsh snapshot-revert {vm_name} {snapshot_name}
|
||||
```
|
||||
|
||||
```
|
||||
[root@kvm-hypervisor ~]# virsh snapshot-revert webserver webserver_snap
|
||||
[root@kvm-hypervisor ~]#
|
||||
|
||||
```
|
||||
|
||||
### 删除 KVM 虚拟机快照
|
||||
|
||||
要删除 KVM 虚拟机快照,首先使用 “**virsh snapshot-list**” 命令获取虚拟机的快照详细信息,然后使用 “**virsh snapshot-delete**” 命令删除快照。如下示例所示:
|
||||
要删除 KVM 虚拟机快照,首先使用 `virsh snapshot-list` 命令获取虚拟机的快照详细信息,然后使用 `virsh snapshot-delete` 命令删除快照。如下示例所示:
|
||||
|
||||
```
|
||||
[root@kvm-hypervisor ~]# virsh snapshot-list --domain webserver
|
||||
Name Creation Time State
|
||||
------------------------------------------------------------
|
||||
webserver_snap 2018-02-04 15:05:05 +0530 running
|
||||
[root@kvm-hypervisor ~]#
|
||||
|
||||
[root@kvm-hypervisor ~]# virsh snapshot-delete --domain webserver --snapshotname webserver_snap
|
||||
Domain snapshot webserver_snap deleted
|
||||
[root@kvm-hypervisor ~]#
|
||||
|
||||
```
|
||||
|
||||
这就是本文的全部内容,我希望你们能够了解如何使用 virsh 命令来管理 KVM 虚拟机快照。请分享你的反馈,并不要犹豫地分享给你的技术朋友🙂
|
||||
这就是本文的全部内容,我希望你们能够了解如何使用 `virsh` 命令来管理 KVM 虚拟机快照。请分享你的反馈,并不要犹豫地分享给你的技术朋友🙂
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -120,7 +114,7 @@ via: https://www.linuxtechi.com/create-revert-delete-kvm-virtual-machine-snapsho
|
||||
|
||||
作者:[Pradeep Kumar][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,64 +1,51 @@
|
||||
# 在 Linux 上使用 groff -me 格式化你的学术论文
|
||||
在 Linux 上使用 groff -me 格式化你的学术论文
|
||||
===========
|
||||
|
||||
> 学习用简单的宏为你的课程论文添加脚注、引用、子标题及其它格式。
|
||||
|
||||

|
||||
|
||||
当我在 1993 年发现 Linux 时,我还是一名本科生。我很兴奋在我的宿舍里拥有 Unix 系统的强大功能,但是尽管它有很多功能,Linux 却缺乏应用程序。像 LibreOffice 和 OpenOffice 这样的文字处理程序还需要几年的时间。如果你想使用文字处理器,你可能会将你的系统引导到 MS-DOS 中,并使用 WordPerfect、shareware GalaxyWrite 或类似的程序。
|
||||
当我在 1993 年发现 Linux 时,我还是一名本科生。我很兴奋在我的宿舍里拥有 Unix 系统的强大功能,但是尽管它有很多功能,但 Linux 却缺乏应用程序。像 LibreOffice 和 OpenOffice 这样的文字处理程序还需要几年的时间才出现。如果你想使用文字处理器,你可能会将你的系统引导到 MS-DOS 中,并使用 WordPerfect、共享软件 GalaxyWrite 或类似的程序。
|
||||
|
||||
`nroff` 和 `troff ` 。它们是同一系统的不同接口:`nroff` 生成纯文本输出,适用于屏幕或行式打印机,而 `troff` 产生非常优美的输出,通常用于在激光打印机上打印。
|
||||
|
||||
这就是我的方法,因为我需要为我的课程写论文,但我更喜欢呆在 Linux 中。我从我们的 “大 Unix ” 校园计算机实验室得知,Unix 系统提供了一组文本格式化的程序。它们是同一系统的不同接口:生成纯文本的输出,适合于屏幕或行打印机,或者生成非常优美的输出,通常用于在激光打印机上打印。
|
||||
这就是我的方法,因为我需要为我的课程写论文,但我更喜欢呆在 Linux 中。我从我们的 “大 Unix” 校园计算机实验室得知,Unix 系统提供了一组文本格式化的程序 `nroff` 和 `troff ` ,它们是同一系统的不同接口:`nroff` 生成纯文本输出,适用于屏幕或行式打印机,而 `troff` 产生非常优美的输出,通常用于在激光打印机上打印。
|
||||
|
||||
在 Linux 上,`nroff` 和 `troff` 被合并为 GNU troff,通常被称为 [groff][1]。 我很高兴看到早期的 Linux 发行版中包含了某个版本的 groff,因此我着手学习如何使用它来编写课程论文。 我学到的第一个宏集是 `-me` 宏包,一个简单易学的宏集。
|
||||
|
||||
关于 `groff` ,首先要了解的是它根据一组宏处理和格式化文本。一个宏通常是一个两个字符的命令,它自己设置在一行上,并带有一个引导点。宏可能包含一个或多个选项。当 groff 在处理文档时遇到这些宏中的一个时,它会自动对文本进行格式化。
|
||||
关于 `groff` ,首先要了解的是它根据一组宏来处理和格式化文本。宏通常是个两个字符的命令,它自己设置在一行上,并带有一个引导点。宏可能包含一个或多个选项。当 `groff` 在处理文档时遇到这些宏中的一个时,它会自动对文本进行格式化。
|
||||
|
||||
下面,我将分享使用 `groff -me` 编写课程论文等简单文档的基础知识。 我不会深入细节进行讨论,比如如何创建嵌套列表,保存和显示,以及使用表格和数字。
|
||||
|
||||
### 段落
|
||||
|
||||
让我们从一个简单的例子开始,在几乎所有类型的文档中都可以看到:段落。段落可以格式化第一行的缩进或不缩进(即,与左边齐平)。 包括学术论文,杂志,期刊和书籍在内的许多印刷文档都使用了这两种类型的组合,其中文档或章节中的第一个(主要)段落与左侧的所有段落以及所有其他(常规)段落缩进。 在 `groff -me`中,您可以使用两种段落类型:前导段落(`.lp`)和常规段落(`.pp`)。
|
||||
让我们从一个简单的例子开始,在几乎所有类型的文档中都可以看到:段落。段落可以格式化为首行缩进或不缩进(即,与左边齐平)。 包括学术论文,杂志,期刊和书籍在内的许多印刷文档都使用了这两种类型的组合,其中文档或章节中的第一个(主要)段落左侧对齐,而所有其他(常规)的段落缩进。 在 `groff -me`中,您可以使用两种段落类型:前导段落(`.lp`)和常规段落(`.pp`)。
|
||||
|
||||
```
|
||||
.lp
|
||||
|
||||
This is the first paragraph.
|
||||
|
||||
.pp
|
||||
|
||||
This is a standard paragraph.
|
||||
|
||||
```
|
||||
|
||||
### 文本格式
|
||||
|
||||
用粗体格式化文本的宏是 `.b`,斜体格式是 `.i` 。 如果您将 `.b` 或 `.i` 放在一行上,则后面的所有文本将以粗体或斜体显示。 但更有可能你只是想用粗体或斜体来表示一个或几个词。 要将一个词加粗或斜体,将该单词放在与 `.b` 或 `.i` 相同的行上作为选项。 要用**粗体**或斜体格式化多个单词,请将文字用引号引起来。
|
||||
用粗体格式化文本的宏是 `.b`,斜体格式是 `.i` 。 如果您将 `.b` 或 `.i` 放在一行上,则后面的所有文本将以粗体或斜体显示。 但更有可能你只是想用粗体或斜体来表示一个或几个词。 要将一个词加粗或斜体,将该单词放在与 `.b` 或 `.i` 相同的行上作为选项。 要用粗体或斜体格式化多个单词,请将文字用引号引起来。
|
||||
|
||||
```
|
||||
.pp
|
||||
|
||||
You can do basic formatting such as
|
||||
|
||||
.i italics
|
||||
|
||||
or
|
||||
|
||||
.b "bold text."
|
||||
|
||||
```
|
||||
|
||||
在上面的例子中,粗体文本结尾的句点也是粗体。 在大多数情况下,这不是你想要的。 只要文字是粗体字,而不是后面的句点也是粗体字。 要获得您想要的效果,您可以向 `.b` 或 `.i` 添加第二个参数,以指示要以粗体或斜体显示的文本,但是正常类型的文本。 您可以这样做,以确保尾随句点不会以粗体显示。
|
||||
在上面的例子中,粗体文本结尾的句点也是粗体。 在大多数情况下,这不是你想要的。 只要文字是粗体字,而不是后面的句点也是粗体字。 要获得您想要的效果,您可以向 `.b` 或 `.i` 添加第二个参数,以指示以粗体或斜体显示的文本后面跟着的任意文本以正常类型显示。 您可以这样做,以确保尾随句点不会以粗体显示。
|
||||
|
||||
```
|
||||
.pp
|
||||
|
||||
You can do basic formatting such as
|
||||
|
||||
.i italics
|
||||
|
||||
or
|
||||
|
||||
.b "bold text" .
|
||||
|
||||
```
|
||||
|
||||
### 列表
|
||||
@ -67,64 +54,38 @@ or
|
||||
|
||||
```
|
||||
.pp
|
||||
|
||||
Bullet lists are easy to make:
|
||||
|
||||
.bu
|
||||
|
||||
Apple
|
||||
|
||||
.bu
|
||||
|
||||
Banana
|
||||
|
||||
.bu
|
||||
|
||||
Pineapple
|
||||
|
||||
.pp
|
||||
|
||||
Numbered lists are as easy as:
|
||||
|
||||
.np
|
||||
|
||||
One
|
||||
|
||||
.np
|
||||
|
||||
Two
|
||||
|
||||
.np
|
||||
|
||||
Three
|
||||
|
||||
.pp
|
||||
|
||||
Note that numbered lists will reset at the next pp or lp.
|
||||
|
||||
```
|
||||
|
||||
### 副标题
|
||||
|
||||
如果你正在写一篇长论文,你可能想把你的内容分成几部分。使用 `groff -me`,您可以创建编号的标题 (`.sh`) 和未编号的标题 (`.uh`)。在这两种方法中,将节标题作为参数括起来。对于编号的标题,您还需要提供标题级别 `:1` 将给出一个一级标题(例如,1)。同样,`2` 和 `3` 将给出第二和第三级标题,如 2.1 或 3.1.1。
|
||||
如果你正在写一篇长论文,你可能想把你的内容分成几部分。使用 `groff -me`,您可以创建编号的标题(`.sh`) 和未编号的标题 (`.uh`)。在这两种方法中,将节标题作为参数括起来。对于编号的标题,您还需要提供标题级别 `:1` 将给出一个一级标题(例如,`1`)。同样,`2` 和 `3` 将给出第二和第三级标题,如 `2.1` 或 `3.1.1`。
|
||||
|
||||
```
|
||||
.uh Introduction
|
||||
|
||||
.pp
|
||||
|
||||
Provide one or two paragraphs to describe the work
|
||||
|
||||
and why it is important.
|
||||
|
||||
.sh 1 "Method and Tools"
|
||||
|
||||
.pp
|
||||
|
||||
Provide a few paragraphs to describe how you
|
||||
|
||||
did the research, including what equipment you used
|
||||
|
||||
```
|
||||
|
||||
### 智能引号和块引号
|
||||
@ -133,135 +94,88 @@ did the research, including what equipment you used
|
||||
|
||||
```
|
||||
.pp
|
||||
|
||||
Christine Peterson coined the phrase \*(lqopen source.\*(rq
|
||||
|
||||
```
|
||||
|
||||
`groff -me` 中还有一个快捷方式来创建这些引号(`.q`),我发现它更易于使用。
|
||||
|
||||
```
|
||||
.pp
|
||||
|
||||
Christine Peterson coined the phrase
|
||||
|
||||
.q "open source."
|
||||
|
||||
```
|
||||
|
||||
如果引用的是跨越几行的较长的引用,则需要使用一个块引用。为此,在引用的开头和结尾插入块引用宏(
|
||||
|
||||
`.(q`)。
|
||||
如果引用的是跨越几行的较长的引用,则需要使用一个块引用。为此,在引用的开头和结尾插入块引用宏(`.(q`)。
|
||||
|
||||
```
|
||||
.pp
|
||||
|
||||
Christine Peterson recently wrote about open source:
|
||||
|
||||
.(q
|
||||
|
||||
On April 7, 1998, Tim O'Reilly held a meeting of key
|
||||
|
||||
leaders in the field. Announced in advance as the first
|
||||
|
||||
.q "Freeware Summit,"
|
||||
|
||||
by April 14 it was referred to as the first
|
||||
|
||||
.q "Open Source Summit."
|
||||
|
||||
.)q
|
||||
|
||||
```
|
||||
|
||||
### 脚注
|
||||
|
||||
要插入脚注,请在脚注文本前后添加脚注宏(`.(f`),并使用内联宏(`\ **`)添加脚注标记。脚注标记应出现在文本中和脚注中。
|
||||
要插入脚注,请在脚注文本前后添加脚注宏(`.(f`),并使用内联宏(`\**`)添加脚注标记。脚注标记应出现在文本中和脚注中。
|
||||
|
||||
```
|
||||
.pp
|
||||
|
||||
Christine Peterson recently wrote about open source:\**
|
||||
|
||||
.(f
|
||||
|
||||
\**Christine Peterson.
|
||||
|
||||
.q "How I coined the term open source."
|
||||
|
||||
.i "OpenSource.com."
|
||||
|
||||
1 Feb 2018.
|
||||
|
||||
.)f
|
||||
|
||||
.(q
|
||||
|
||||
On April 7, 1998, Tim O'Reilly held a meeting of key
|
||||
|
||||
leaders in the field. Announced in advance as the first
|
||||
|
||||
.q "Freeware Summit,"
|
||||
|
||||
by April 14 it was referred to as the first
|
||||
|
||||
.q "Open Source Summit."
|
||||
|
||||
.)q
|
||||
|
||||
```
|
||||
|
||||
### 封面
|
||||
|
||||
大多数课程论文都需要一个包含论文标题,姓名和日期的封面。 在 `groff -me` 中创建封面需要一些组件。 我发现最简单的方法是使用居中的文本块并在标题,名称和日期之间添加额外的行。 (我倾向于在每一行之间使用两个空行)。在文章顶部,从标题页(`.tp`)宏开始,插入五个空白行(`.sp 5`),然后添加居中文本(`.(c`) 和额外的空白行(`.sp 2`)。
|
||||
大多数课程论文都需要一个包含论文标题,姓名和日期的封面。 在 `groff -me` 中创建封面需要一些组件。 我发现最简单的方法是使用居中的文本块并在标题、名字和日期之间添加额外的行。 (我倾向于在每一行之间使用两个空行)。在文章顶部,从标题页(`.tp`)宏开始,插入五个空白行(`.sp 5`),然后添加居中文本(`.(c`) 和额外的空白行(`.sp 2`)。
|
||||
|
||||
```
|
||||
.tp
|
||||
|
||||
.sp 5
|
||||
|
||||
.(c
|
||||
|
||||
.b "Writing Class Papers with groff -me"
|
||||
|
||||
.)c
|
||||
|
||||
.sp 2
|
||||
|
||||
.(c
|
||||
|
||||
Jim Hall
|
||||
|
||||
.)c
|
||||
|
||||
.sp 2
|
||||
|
||||
.(c
|
||||
|
||||
February XX, 2018
|
||||
|
||||
.)c
|
||||
|
||||
.bp
|
||||
|
||||
```
|
||||
|
||||
最后一个宏(`.bp`)告诉 groff 在标题页后添加一个分页符。
|
||||
|
||||
### 更多内容
|
||||
|
||||
这些是用 `groff-me` 写一份专业的论文非常基础的东西,包括前导和缩进段落,粗体和斜体,有序和无需列表,编号和不编号的章节标题,块引用以及脚注。
|
||||
这些是用 `groff-me` 写一份专业的论文非常基础的东西,包括前导和缩进段落,粗体和斜体,有序和无需列表,编号和不编号的章节标题,块引用以及脚注。
|
||||
|
||||
我已经包含一个示例 groff 文件来演示所有这些格式。 将 `lorem-ipsum.me` 文件保存到您的系统并通过 groff 运行。 `-Tps` 选项将输出类型设置为 `PostScript` ,以便您可以将文档发送到打印机或使用 `ps2pdf` 程序将其转换为 PDF 文件。
|
||||
我已经包含一个[示例 groff 文件](https://opensource.com/sites/default/files/lorem-ipsum.me_.txt)来演示所有这些格式。 将 `lorem-ipsum.me` 文件保存到您的系统并通过 groff 运行。 `-Tps` 选项将输出类型设置为 `PostScript` ,以便您可以将文档发送到打印机或使用 `ps2pdf` 程序将其转换为 [PDF 文件](https://opensource.com/sites/default/files/lorem-ipsum.me_.pdf)。
|
||||
|
||||
```
|
||||
groff -Tps -me lorem-ipsum.me > lorem-ipsum.me.ps
|
||||
|
||||
ps2pdf lorem-ipsum.me.ps lorem-ipsum.me.pdf
|
||||
|
||||
```
|
||||
|
||||
如果你想使用 groff-me 的更多高级功能,请参阅 Eric Allman 所著的 “使用 `Groff-me` 来写论文”,你可以在你系统的 groff 的 `doc` 目录下找到一个名叫 `meintro.me` 的文件。这份文档非常完美的说明了如何使用 `groff-me` 宏来格式化你的论文。
|
||||
如果你想使用 `groff -me` 的更多高级功能,请参阅 Eric Allman 所著的 “使用 Groff -me 来写论文”,你可以在你系统的 groff 的 `doc` 目录下找到一个名叫 `meintro.me` 的文件。这份文档非常完美的说明了如何使用 `groff-me` 宏来格式化你的论文。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -269,7 +183,7 @@ via: https://opensource.com/article/18/2/how-format-academic-papers-linux-groff-
|
||||
|
||||
作者:[Jim Hall][a]
|
||||
译者:[amwps290](https://github.com/amwps290)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,134 +1,120 @@
|
||||
如何使用树莓派测定颗粒物
|
||||
如何使用树莓派测定颗粒物(PM 2.5)
|
||||
======
|
||||
|
||||
> 使用两个简单的硬件设备和几行代码构建一个空气质量探测器。
|
||||
|
||||

|
||||
|
||||
我们在东南亚的学校定期测定空气中的颗粒物。这里的测定值非常高,尤其是在二到五月之间,干燥炎热、土地干旱等各种因素都对空气质量产生了不利的影响。我将会在这篇文章中展示如何使用树莓派来测定颗粒物。
|
||||
|
||||
### 什么是颗粒物?
|
||||
|
||||
颗粒物就是粉尘或者空气中的微小颗粒。其中 PM10 和 PM2.5 之间的差别就是 PM10 指的是粒径小于10微米的颗粒,而 PM2.5 指的是粒径小于2.5微米的颗粒。在粒径小于2.5微米的的情况下,由于它们能被吸入肺泡中并且对呼吸系统造成影响,因此颗粒越小,对人的健康危害越大。
|
||||
颗粒物就是粉尘或者空气中的微小颗粒。其中 PM10 和 PM2.5 之间的差别就是 PM10 指的是粒径小于 10 微米的颗粒,而 PM2.5 指的是粒径小于 2.5 微米的颗粒。在粒径小于 2.5 微米的的情况下,由于它们能被吸入肺泡中并且对呼吸系统造成影响,因此颗粒越小,对人的健康危害越大。
|
||||
|
||||
世界卫生组织的建议[颗粒物浓度][1]是:
|
||||
|
||||
* 年均 PM10 不高于20 µg/m³
|
||||
* 年均 PM2.5 不高于10 µg/m³
|
||||
* 不允许超标时,日均 PM10 不高于50 µg/m³
|
||||
* 不允许超标时,日均 PM2.5 不高于25 µg/m³
|
||||
* 年均 PM10 不高于 20 µg/m³
|
||||
* 年均 PM2.5 不高于 10 µg/m³
|
||||
* 不允许超标时,日均 PM10 不高于 50 µg/m³
|
||||
* 不允许超标时,日均 PM2.5 不高于 25 µg/m³
|
||||
|
||||
以上数值实际上是低于大多数国家的标准的,例如欧盟对于 PM10 所允许的年均值是不高于40 µg/m³。
|
||||
以上数值实际上是低于大多数国家的标准的,例如欧盟对于 PM10 所允许的年均值是不高于 40 µg/m³。
|
||||
|
||||
### 什么是空气质量指数(AQI, Air Quality Index)?
|
||||
### 什么是<ruby>空气质量指数<rt>Air Quality Index</rt></ruby>(AQI)?
|
||||
|
||||
空气质量指数按照颗粒物的测定值来评价空气质量的好坏,然而由于各国之间的计算方式有所不同,这个指数并没有统一的标准。维基百科上关于[空气质量指数][2]的词条对此给出了一个概述。我们学校则以[美国环境保护协会][3](EPA, Environment Protection Agency)建立的分类法来作为依据。
|
||||
空气质量指数是按照颗粒物的测定值来评价空气质量的好坏,然而由于各国之间的计算方式有所不同,这个指数并没有统一的标准。维基百科上关于[空气质量指数][2]的词条对此给出了一个概述。我们学校则以<ruby>[美国环境保护协会][3]<rt>Environment Protection Agency</rt></ruby>(EPA)建立的分类法来作为依据。
|
||||
|
||||
![空气质量指数][5]
|
||||
|
||||
空气质量指数
|
||||
*空气质量指数*
|
||||
|
||||
### 测定颗粒物需要哪些准备?
|
||||
|
||||
测定颗粒物只需要以下两种器材:
|
||||
|
||||
* 树莓派(款式不限,最好带有 WiFi)
|
||||
* SDS011 颗粒物传感器
|
||||
|
||||
|
||||
|
||||
![颗粒物传感器][7]
|
||||
|
||||
颗粒物传感器
|
||||
*颗粒物传感器*
|
||||
|
||||
如果是只带有 Micro USB的树莓派Zero W,那还需要一根连接到标准 USB 端口的适配线,只需要20美元,而传感器则自带适配串行接口的 USB 适配器。
|
||||
如果是只带有 Micro USB 的树莓派 Zero W,那还需要一根连接到标准 USB 端口的适配线,只需要 20 美元,而传感器则自带适配串行接口的 USB 适配器。
|
||||
|
||||
### 安装过程
|
||||
|
||||
对于树莓派,只需要下载对应的 Raspbian Lite 镜像并且[写入到 Micro SD 卡][8]上就可以了(网上很多教程都有介绍如何设置 WLAN 连接,我就不细说了)。
|
||||
|
||||
如果要使用 SSH,那还需要在启动分区建立一个名为 `ssh` 的空文件。树莓派的 IP 通过路由器或者 DHCP 服务器获取,随后就可以通过 SSH 登录到树莓派了(默认密码是 raspberry):
|
||||
|
||||
```
|
||||
$ ssh pi@192.168.1.5
|
||||
|
||||
```
|
||||
|
||||
首先我们需要在树莓派上安装一下这些包:
|
||||
|
||||
```
|
||||
$ sudo apt install git-core python-serial python-enum lighttpd
|
||||
|
||||
```
|
||||
|
||||
在开始之前,我们可以用 `dmesg` 来获取 USB 适配器连接的串行接口:
|
||||
|
||||
```
|
||||
$ dmesg
|
||||
|
||||
[ 5.559802] usbcore: registered new interface driver usbserial
|
||||
|
||||
[ 5.559930] usbcore: registered new interface driver usbserial_generic
|
||||
|
||||
[ 5.560049] usbserial: USB Serial support registered for generic
|
||||
|
||||
[ 5.569938] usbcore: registered new interface driver ch341
|
||||
|
||||
[ 5.570079] usbserial: USB Serial support registered for ch341-uart
|
||||
|
||||
[ 5.570217] ch341 1–1.4:1.0: ch341-uart converter detected
|
||||
|
||||
[ 5.575686] usb 1–1.4: ch341-uart converter now attached to ttyUSB0
|
||||
|
||||
```
|
||||
|
||||
在最后一行,可以看到接口 `ttyUSB0`。然后我们需要写一个 Python 脚本来读取传感器的数据并以 JSON 格式存储,在通过一个 HTML 页面就可以把数据展示出来了。
|
||||
|
||||
### 在树莓派上读取数据
|
||||
|
||||
首先创建一个传感器实例,每5分钟读取一次传感器的数据,持续30秒,这些数值后续都可以调整。在每两次测定的间隔,我们把传感器调到睡眠模式以延长它的使用寿命(厂商认为元件的寿命大约8000小时)。
|
||||
首先创建一个传感器实例,每 5 分钟读取一次传感器的数据,持续 30 秒,这些数值后续都可以调整。在每两次测定的间隔,我们把传感器调到睡眠模式以延长它的使用寿命(厂商认为元件的寿命大约 8000 小时)。
|
||||
|
||||
我们可以使用以下命令来下载 Python 脚本:
|
||||
|
||||
```
|
||||
$ wget -O /home/pi/aqi.py https://raw.githubusercontent.com/zefanja/aqi/master/python/aqi.py
|
||||
|
||||
```
|
||||
|
||||
另外还需要执行以下两条命令来保证脚本正常运行:
|
||||
|
||||
```
|
||||
$ sudo chown pi:pi /var/wwww/html/
|
||||
|
||||
$ echo[] > /var/wwww/html/aqi.json
|
||||
|
||||
$ sudo chown pi:pi /var/www/html/
|
||||
$ echo '[]' > /var/www/html/aqi.json
|
||||
```
|
||||
|
||||
下面就可以执行脚本了:
|
||||
|
||||
```
|
||||
$ chmod +x aqi.py
|
||||
|
||||
$ chmod +x aqi.p
|
||||
$ ./aqi.py
|
||||
|
||||
PM2.5:55.3, PM10:47.5
|
||||
|
||||
PM2.5:55.5, PM10:47.7
|
||||
|
||||
PM2.5:55.7, PM10:47.8
|
||||
|
||||
PM2.5:53.9, PM10:47.6
|
||||
|
||||
PM2.5:53.6, PM10:47.4
|
||||
|
||||
PM2.5:54.2, PM10:47.3
|
||||
|
||||
…
|
||||
|
||||
```
|
||||
|
||||
### 自动化执行脚本
|
||||
|
||||
只需要使用诸如 crontab 的服务,我们就不需要每次都手动启动脚本了。按照以下命令打开 crontab 文件:
|
||||
|
||||
```
|
||||
$ crontab -e
|
||||
|
||||
```
|
||||
|
||||
在文件末尾添加这一行:
|
||||
|
||||
```
|
||||
@reboot cd /home/pi/ && ./aqi.py
|
||||
|
||||
```
|
||||
|
||||
现在我们的脚本就会在树莓派每次重启后自动执行了。
|
||||
@ -138,17 +124,14 @@ $ crontab -e
|
||||
我们在前面已经安装了一个轻量级的 web 服务器 `lighttpd`,所以我们需要把 HTML、JavaScript、CSS 文件放置在 `/var/www/html` 目录中,这样就能通过电脑和智能手机访问到相关数据了。执行下面的三条命令,可以下载到对应的文件:
|
||||
|
||||
```
|
||||
$ wget -O /var/wwww/html/index.html https://raw.githubusercontent.com/zefanja/aqi/master/html/index.html
|
||||
|
||||
$ wget -O /var/wwww/html/aqi.js https://raw.githubusercontent.com/zefanja/aqi/master/html/aqi.js
|
||||
|
||||
$ wget -O /var/wwww/html/style.css https://raw.githubusercontent.com/zefanja/aqi/master/html/style.css
|
||||
|
||||
$ wget -O /var/www/html/index.html https://raw.githubusercontent.com/zefanja/aqi/master/html/index.html
|
||||
$ wget -O /var/www/html/aqi.js https://raw.githubusercontent.com/zefanja/aqi/master/html/aqi.js
|
||||
$ wget -O /var/www/html/style.css https://raw.githubusercontent.com/zefanja/aqi/master/html/style.css
|
||||
```
|
||||
|
||||
在 JavaScript 文件中,实现了打开 JSON 文件、提取数据、计算空气质量指数的过程,随后页面的背景颜色将会根据 EPA 的划分标准而变化。
|
||||
|
||||
你只需要用浏览器访问树莓派的地址,就可以看到当前颗粒物浓度值等数据了。[http://192.168.1.5:][9]
|
||||
你只需要用浏览器访问树莓派的地址,就可以看到当前颗粒物浓度值等数据了: [http://192.168.1.5:][9]
|
||||
|
||||
这个页面比较简单而且可扩展,比如可以添加一个展示过去数小时历史数据的表格等等。
|
||||
|
||||
@ -158,7 +141,7 @@ $ wget -O /var/wwww/html/style.css https://raw.githubusercontent.com/zefanja/aqi
|
||||
|
||||
在资金相对紧张的情况下,树莓派是一种选择。除此以外,还有很多可以用来测定颗粒物的应用,包括室外固定装置、移动测定设备等等。我们学校则同时采用了这两种:固定装置在室外测定全天颗粒物浓度,而移动测定设备在室内检测空调过滤器的效果。
|
||||
|
||||
[Luftdaten.info][12]提供了一个如何设计类似的传感器的介绍,其中的软件效果出众,而且因为它没有使用树莓派,所以硬件更是小巧。
|
||||
[Luftdaten.info][12] 提供了一个如何设计类似的传感器的介绍,其中的软件效果出众,而且因为它没有使用树莓派,所以硬件更是小巧。
|
||||
|
||||
对于学生来说,设计一个颗粒物传感器确实算得上是一个优秀的课外项目。
|
||||
|
||||
@ -170,7 +153,7 @@ via: https://opensource.com/article/18/3/how-measure-particulate-matter-raspberr
|
||||
|
||||
作者:[Stephan Tetzel][a]
|
||||
译者:[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/) 荣誉推出
|
||||
|
@ -1,53 +1,52 @@
|
||||
一个用于追踪工作时间的命令行生产力工具
|
||||
moro:一个用于追踪工作时间的命令行生产力工具
|
||||
======
|
||||
|
||||

|
||||
保持对你的工作小时数的追踪将让你知晓在一个特定时间区间内你所完成的工作总量。在网络上有大量的基于GUI的生产力工具可以用来追踪工作小时数。但我却不能找到一个基于CLI的工具。今天我偶然发现了一个简单而奏效的叫做 **“Moro”** 的追踪工作时间数的工具。Moro是一个芬兰词汇,意为"Hello"。通过使用Moro,你可以找到你在完成某项特定任务时花费了多少时间。这个工具是免费且开源的,它是通过**NodeJS**编写的。
|
||||
|
||||
保持对你的工作小时数的追踪将让你知晓在一个特定时间区间内你所完成的工作总量。在网络上有大量的基于 GUI 的生产力工具可以用来追踪工作小时数。但我却不能找到一个基于 CLI 的工具。今天我偶然发现了一个简单而奏效的叫做 Moro 的追踪工作时间数的工具。Moro 是一个芬兰词汇,意为“Hello”。通过使用 Moro,你可以找到你在完成某项特定任务时花费了多少时间。这个工具是自由开源软件,它是通过 NodeJS 编写的。
|
||||
|
||||
### Moro - 一个追踪工作时间的命令行生产力工具
|
||||
|
||||
由于Moro是使用NodeJS编写的,保证你的系统上已经安装了(NodeJS)。如果你没有安装好NodeJS,跟随下面的链接在你的Linux中安装NodeJS和NPM。
|
||||
由于 Moro 是使用 NodeJS 编写的,保证你的系统上已经安装了 NodeJS。如果你没有安装好 NodeJS,跟随下面的链接在你的 Linux 中安装 NodeJS 和 NPM。
|
||||
|
||||
- [如何在 Linux 上安装 NodeJS](https://www.ostechnix.com/install-node-js-linux/)
|
||||
|
||||
NodeJS 和NPM一旦装好,运行下面的命令来安装 Moro。
|
||||
|
||||
NodeJS和NPM一旦装好,运行下面的命令来安装Moro。
|
||||
```
|
||||
$ npm install -g moro
|
||||
|
||||
```
|
||||
|
||||
### 用法
|
||||
|
||||
Moro的工作概念非常简单。它记录了你的工作开始时间,结束时间和在你的系统上的休息时间。在每天结束时,它将会告知你已经工作了多少时间。
|
||||
Moro 的工作概念非常简单。它记录了你的工作开始时间,结束时间和在你的系统上的休息时间。在每天结束时,它将会告知你已经工作了多少时间。
|
||||
|
||||
当你到达办公室时,只需键入:
|
||||
|
||||
```
|
||||
$ moro
|
||||
|
||||
```
|
||||
|
||||
示例输出:
|
||||
```
|
||||
💙 Moro \o/
|
||||
|
||||
✔ You clocked in at: 9:20
|
||||
|
||||
♥ Moro \o/
|
||||
√ You clocked in at: 9:20
|
||||
```
|
||||
|
||||
Moro将会把这个时间注册为你的开始时间。
|
||||
Moro 将会把这个时间注册为你的开始时间。
|
||||
|
||||
当你离开办公室时,再次键入:
|
||||
|
||||
```
|
||||
$ moro
|
||||
|
||||
```
|
||||
|
||||
示例输出:
|
||||
|
||||
```
|
||||
💙 Moro \o/
|
||||
|
||||
✔ You clocked out at: 19:22
|
||||
|
||||
♥ Moro \o/
|
||||
√ You clocked out at: 19:22
|
||||
ℹ Today looks like this so far:
|
||||
|
||||
┌──────────────────┬─────────────────────────┐
|
||||
│ Today you worked │ 9 Hours and 72 Minutes │
|
||||
├──────────────────┼─────────────────────────┤
|
||||
@ -60,43 +59,37 @@ $ moro
|
||||
│ Date │ 2018-03-19 │
|
||||
└──────────────────┴─────────────────────────┘
|
||||
ℹ Run moro --help to learn how to edit your clock in, clock out or break duration for today
|
||||
|
||||
```
|
||||
|
||||
Moro将会把这个时间注册为你的结束时间。
|
||||
Moro 将会把这个时间注册为你的结束时间。
|
||||
|
||||
现在,Moro将会从结束时间减去开始时间然后从总的时间减去另外的30分钟作为休息时间并给你在那天总的工作时间。抱歉,我的数学计算过程解释实在糟糕。假设你在早上10:00来工作并在晚上17:30离开。所以,你总共在办公室呆了7.30小时(例如17.30-10)。然后在总的时间减去休息时间(默认是30分钟)。因此,你的总工作时间是7小时。明白了?很好!
|
||||
现在,Moro 将会从结束时间减去开始时间,然后从总的时间减去另外的 30 分钟作为休息时间,并给你在那天总的工作时间。抱歉,我的数学计算过程解释实在糟糕。假设你在早上 10:00 来工作并在晚上 17:30 离开。所以,你总共在办公室呆了 7:30 小时(例如 17:30-10)。然后在总的时间减去休息时间(默认是 30 分钟)。因此,你的总工作时间是 7 小时。明白了?很好!
|
||||
|
||||
**注意:**不要像我在写这个手册的时候一样把“moro”和“more”弄混了。
|
||||
**注意:**不要像我在写这个手册的时候一样把 “moro” 和 “more” 弄混了。
|
||||
|
||||
查看你注册的所有小时数,运行:
|
||||
|
||||
```
|
||||
$ moro report --all
|
||||
|
||||
```
|
||||
|
||||
以防万一,如果你忘记注册开始时间或者结束时间,你一样可以在之后指定这些值。
|
||||
|
||||
例如,将上午10点注册为开始时间,运行:
|
||||
例如,将上午 10 点注册为开始时间,运行:
|
||||
|
||||
```
|
||||
$ moro hi 10:00
|
||||
|
||||
💙 Moro \o/
|
||||
|
||||
✔ You clocked in at: 10:00
|
||||
|
||||
♥ Moro \o/
|
||||
√ You clocked in at: 10:00
|
||||
⏰ Working until 18:00 will make it a full (7.5 hours) day
|
||||
|
||||
```
|
||||
|
||||
注册17:30作为结束时间:
|
||||
注册 17:30 作为结束时间:
|
||||
|
||||
```
|
||||
$ moro bye 17:30
|
||||
|
||||
💙 Moro \o/
|
||||
|
||||
✔ You clocked out at: 17:30
|
||||
|
||||
♥ Moro \o/
|
||||
√ You clocked out at: 17:30
|
||||
ℹ Today looks like this so far:
|
||||
|
||||
┌──────────────────┬───────────────────────┐
|
||||
@ -111,79 +104,75 @@ $ moro bye 17:30
|
||||
│ Date │ 2018-03-19 │
|
||||
└──────────────────┴───────────────────────┘
|
||||
ℹ Run moro --help to learn how to edit your clock in, clock out or break duration for today
|
||||
|
||||
```
|
||||
|
||||
你已经知道Moro默认将会减去30分钟的休息时间。如果你需要设置一个自定义的休息时间,你可以简单使用以下命令:
|
||||
你已经知道 Moro 默认将会减去 30 分钟的休息时间。如果你需要设置一个自定义的休息时间,你可以简单使用以下命令:
|
||||
|
||||
```
|
||||
$ moro break 45
|
||||
|
||||
```
|
||||
|
||||
现在,休息时间是45分钟了。
|
||||
现在,休息时间是 45 分钟了。
|
||||
|
||||
若要清除所有的数据:
|
||||
|
||||
```
|
||||
$ moro clear --yes
|
||||
|
||||
💙 Moro \o/
|
||||
|
||||
✔ Database file deleted successfully
|
||||
|
||||
♥ Moro \o/
|
||||
√ Database file deleted successfully
|
||||
```
|
||||
|
||||
**添加笔记**
|
||||
#### 添加笔记
|
||||
|
||||
有时候,你想要在工作时添加笔记。不必去寻找一个独立的作笔记的应用。Moro 将会帮助你添加笔记。要添加笔记,只需运行:
|
||||
|
||||
有时候,你想要在工作时添加笔记。不必去寻找一个独立的作笔记的应用。Moro将会帮助你添加笔记。要添加笔记,只需运行:
|
||||
```
|
||||
$ moro note mynotes
|
||||
|
||||
```
|
||||
|
||||
要在之后搜索所有已经注册的笔记,只需做:
|
||||
|
||||
```
|
||||
$ moro search mynotes
|
||||
|
||||
```
|
||||
|
||||
**修改默认设置**
|
||||
#### 修改默认设置
|
||||
|
||||
默认的完整工作时间是7.5小时。这是因为开发者来自芬兰,这是官方的工作小时数。但是你也可以修改这个设置为你的国家的工作小时数。
|
||||
默认的完整工作时间是 7.5 小时。这是因为开发者来自芬兰,这是官方的工作小时数。但是你也可以修改这个设置为你的国家的工作小时数。
|
||||
|
||||
举个例子,要将其设置为 7 小时,运行:
|
||||
|
||||
举个例子,要将其设置为7小时,运行:
|
||||
```
|
||||
$ moro config --day 7
|
||||
|
||||
```
|
||||
|
||||
同样地,默认的休息时间也可以像下面这样从30分钟修改:
|
||||
同样地,默认的休息时间也可以像下面这样从 30 分钟修改:
|
||||
|
||||
```
|
||||
$ moro config --break 45
|
||||
|
||||
```
|
||||
|
||||
**备份你的数据**
|
||||
#### 备份你的数据
|
||||
|
||||
正如我已经说了的,Moro将时间追踪信息存储在你的家目录,文件名是**.moro-data.db**。
|
||||
正如我已经说了的,Moro 将时间追踪信息存储在你的家目录,文件名是 `.moro-data.db`。
|
||||
|
||||
但是,你可以保存备份数据库到不同的位置。要这样做的话,像下面这样将**.moro-data.db**文件移到你选择的一个不同的位置并告知Moro使用那个数据库文件。
|
||||
但是,你可以保存备份数据库到不同的位置。要这样做的话,像下面这样将 `.moro-data.db` 文件移到你选择的一个不同的位置并告知 Moro 使用那个数据库文件。
|
||||
|
||||
```
|
||||
$ moro config --database-path /home/sk/personal/moro-data.db
|
||||
|
||||
```
|
||||
|
||||
在上面的每一个命令,我都已经把默认的数据库文件分配到了**/home/sk/personal**目录。
|
||||
在上面的每一个命令,我都已经把默认的数据库文件分配到了 `/home/sk/personal` 目录。
|
||||
|
||||
需要帮助的话,运行:
|
||||
|
||||
```
|
||||
$ moro --help
|
||||
|
||||
```
|
||||
|
||||
正如你所见,Moro是非常简单而又能用于追踪你完成你的工作使用了多少时间的。对于自由职业者和任何想要在一定时间范围内完成事情的人,它将会是有用的。
|
||||
正如你所见,Moro 是非常简单而又能用于追踪你完成你的工作使用了多少时间的。对于自由职业者和任何想要在一定时间范围内完成事情的人,它将会是有用的。
|
||||
|
||||
并且,这些只是今天的(内容)。希望这些(内容)能够有所帮助。更多的好东西将会出现。请保持关注!
|
||||
并且,这些只是今天的内容。希望这些内容能够有所帮助。更多的好东西将会出现。请保持关注!
|
||||
|
||||
干杯!
|
||||
|
||||
@ -194,7 +183,7 @@ via: https://www.ostechnix.com/moro-a-command-line-productivity-tool-for-trackin
|
||||
|
||||
作者:[SK][a]
|
||||
译者:[leemeans](https://github.com/leemeans)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,8 +1,9 @@
|
||||
Dry – 一个命令行交互式 Docker 容器管理器
|
||||
Dry:一个命令行交互式 Docker 容器管理器
|
||||
======
|
||||
Docker 是一种实现操作系统级别虚拟化或容器化的软件。
|
||||
|
||||
基于 Linux 内核的 cgroups 和 namespaces 等资源隔离特性,Docker 可以在单个 Linux 实例中运行多个独立的容器。
|
||||
Docker 是一种所谓容器化的操作系统级的虚拟化软件。
|
||||
|
||||
基于 Linux 内核的 cgroup 和 namespace 等资源隔离特性,Docker 可以在单个 Linux 实例中运行多个独立的容器。
|
||||
|
||||
通过将应用依赖和相关库打包进容器,Docker 使得应用可以在容器中安全隔离地运行。
|
||||
|
||||
@ -10,25 +11,26 @@ Docker 是一种实现操作系统级别虚拟化或容器化的软件。
|
||||
|
||||
[Dry][1] 是一个管理并监控 Docker 容器和镜像的命令行工具。
|
||||
|
||||
Dry 给出容器相关的信息,包括对应镜像、容器名称、网络、容器中运行的命令及容器状态;如果运行在 Docker Swarm 中,工具还会给出 Swarm 集群的各种状态信息。
|
||||
Dry 可以给出容器相关的信息,包括对应镜像、容器名称、网络、容器中运行的命令及容器状态;如果运行在 Docker Swarm 中,工具还会给出 Swarm 集群的各种状态信息。
|
||||
|
||||
Dry 可以连接至本地或远程的 Docker 守护进程。如果连接本地 Docker,Docker 主机显示为`unix:///var/run/docker.sock`。
|
||||
Dry 可以连接至本地或远程的 Docker 守护进程。如果连接本地 Docker,Docker 主机显示为 `unix:///var/run/docker.sock`。
|
||||
|
||||
如果连接远程 Docker,Docker 主机显示为 `tcp://IP Address:Port Number` 或 `tcp://Host Name:Port Number`。
|
||||
|
||||
Dry 可以提供类似 `docker ps` 的指标输出,但输出比 “docker ps” 内容详实、富有色彩。
|
||||
Dry 可以提供类似 `docker ps` 的指标输出,但输出比 `docker ps` 内容详实、富有色彩。
|
||||
|
||||
相比 Docker,Dry 还可以手动添加一个额外的名称列,用于降低记忆难度。
|
||||
|
||||
***推荐阅读:**
|
||||
**推荐阅读:**
|
||||
|
||||
**(#)** [Portainer – 用于 Docker 管理的简明 GUI][2]
|
||||
**(#)** [Rancher – 适用于生产环境的完备容器管理平台][3]
|
||||
**(#)** [cTop – Linux环境下容器管理与监控的命令行工具][4]
|
||||
- [Portainer – 用于 Docker 管理的简明 GUI][2]
|
||||
- [Rancher – 适用于生产环境的完备容器管理平台][3]
|
||||
- [cTop – Linux环境下容器管理与监控的命令行工具][4]
|
||||
|
||||
### 如何在 Linux 中安装 Dry
|
||||
|
||||
在 Linux 中,可以通过一个简单的 shell 脚本安装最新版本的 dry 工具。Dry 不依赖外部库。对于绝大多数的 Docker 命令,dry 提供类似样式的命令。
|
||||
在 Linux 中,可以通过一个简单的 shell 脚本安装最新版本的 Dry 工具。Dry 不依赖外部库。对于绝大多数的 Docker 命令,Dry 提供类似样式的命令。
|
||||
|
||||
```
|
||||
$ curl -sSf https://moncho.github.io/dry/dryup.sh | sudo sh
|
||||
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||
@ -38,41 +40,40 @@ dryup: downloading dry binary
|
||||
######################################################################## 100.0%
|
||||
dryup: Moving dry binary to its destination
|
||||
dryup: dry binary was copied to /usr/local/bin, now you should 'sudo chmod 755 /usr/local/bin/dry'
|
||||
|
||||
```
|
||||
|
||||
使用如下命令将文件权限变更为 `755`
|
||||
使用如下命令将文件权限变更为 `755`:
|
||||
|
||||
```
|
||||
$ sudo chmod 755 /usr/local/bin/dry
|
||||
|
||||
```
|
||||
|
||||
对于使用 Arch Linux 的用户,可以使用 **[Packer][5]** or **[Yaourt][6]** 包管理器,从 AUR 源安装该工具。
|
||||
对于使用 Arch Linux 的用户,可以使用 **[Packer][5]** 或 **[Yaourt][6]** 包管理器,从 AUR 源安装该工具。
|
||||
```
|
||||
$ yaourt -S dry-bin
|
||||
或者
|
||||
$ packer -S dry-bin
|
||||
|
||||
```
|
||||
|
||||
如果希望在 Docker 容器中运行 dry,可以运行如下命令。前提条件是已确认在操作系统中安装了 Docker。
|
||||
|
||||
**推荐阅读:**
|
||||
**(#)** [如何在 Linux 中安装 Docker][7]
|
||||
**(#)** [如何在 Linux 中玩转 Docker 镜像][8]
|
||||
**(#)** [如何在 Linux 中玩转 Docker 容器][9]
|
||||
**(#)** [如何在 Docker 容器中安装并运行应用程序][10]
|
||||
|
||||
- [如何在 Linux 中安装 Docker][7]
|
||||
- [如何在 Linux 中玩转 Docker 镜像][8]
|
||||
- [如何在 Linux 中玩转 Docker 容器][9]
|
||||
- [如何在 Docker 容器中安装并运行应用程序][10]
|
||||
|
||||
```
|
||||
$ docker run -it -v /var/run/docker.sock:/var/run/docker.sock moncho/dry
|
||||
|
||||
```
|
||||
|
||||
### 如何启动并运行 Dry
|
||||
|
||||
在控制台运行 `dry` 命令即可启动该工具,其默认输出如下:
|
||||
|
||||
```
|
||||
$ dry
|
||||
|
||||
```
|
||||
|
||||
![][12]
|
||||
@ -80,18 +81,20 @@ $ dry
|
||||
### 如何使用 Dry 监控 Docker
|
||||
|
||||
你可以在 dry 的界面中按下 `m` 键打开监控模式。
|
||||
|
||||
![][13]
|
||||
|
||||
### 如何使用 Dry 管理容器
|
||||
|
||||
在选中的容器上单击 `Enter` 键,即可管理容器。Dry 提供如下操作:查看日志,查看、杀死、删除容器,停止、启动、重启容器,查看容器状态及镜像历史记录等。
|
||||
在选中的容器上单击回车键,即可管理容器。Dry 提供如下操作:查看日志,查看、杀死、删除容器,停止、启动、重启容器,查看容器状态及镜像历史记录等。
|
||||
|
||||
![][14]
|
||||
|
||||
### 如何监控容器资源利用率
|
||||
|
||||
用户可以使用 `Stats+Top` 选项查看指定容器的资源利用率。
|
||||
|
||||
该操作需要在容器管理界面完成(在上一步的基础上,点击 `Stats+Top` 选项)。另外,也可以按下 `s` 打开容器资源利用率界面。
|
||||
该操作需要在容器管理界面完成(在上一步的基础上,点击 `Stats+Top` 选项)。另外,也可以按下 `s` 打开容器资源利用率界面。
|
||||
|
||||
![][15]
|
||||
|
||||
@ -100,35 +103,39 @@ $ dry
|
||||
可以使用 `F8` 键查看容器、镜像及本地卷的磁盘使用情况。
|
||||
|
||||
该界面明确地给出容器、镜像和卷的总数,哪些处于使用状态,以及整体磁盘使用情况、可回收空间大小的详细信息。
|
||||
|
||||
![][16]
|
||||
|
||||
### 如何查看已下载的镜像
|
||||
|
||||
按下 `2` 键即可列出全部的已下载镜像。
|
||||
|
||||
![][17]
|
||||
|
||||
### 如何查看网络列表
|
||||
|
||||
按下 `3` 键即可查看全部网络及网关。
|
||||
|
||||
![][18]
|
||||
|
||||
### 如何查看全部 Docker 容器
|
||||
|
||||
按下 `F2` 键即可列出列出全部容器,包括运行中和已关闭的容器。
|
||||
|
||||
![][19]
|
||||
|
||||
### Dry 快捷键
|
||||
|
||||
查看帮助页面或 [dry github][1] 即可查看全部快捷键。
|
||||
查看帮助页面或 [dry GitHub][1] 即可查看全部快捷键。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/dry-an-interactive-cli-manager-for-docker-containers/
|
||||
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
译者:[pinewall](https://github.com/pinewall)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[pinewall](https://github.com/pinewall)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,4 +1,4 @@
|
||||
我们可以在同一个虚拟机中运行 Python 2 和 Python 3 代码而不需要更改代码吗?
|
||||
我们可以在同一个虚拟机中运行 Python 2 和 3 代码而不需要更改代码吗?
|
||||
=====
|
||||
|
||||
从理论上来说,可以。Zed Shaw 说过一句著名的话,如果不行,那么 Python 3 一定不是图灵完备的。但在实践中,这是不现实的,我将通过给你们举几个例子来说明原因。
|
||||
@ -6,9 +6,8 @@
|
||||
### 对于字典(dict)来说,这意味着什么?
|
||||
|
||||
让我们来想象一台拥有 Python 6 的虚拟机,它可以读取 Python 3.6 编写的 `module3.py`。但是在这个模块中,它可以导入 Python 2.7 编写的 `module2.py`,并成功使用它,没有问题。这显然是实验代码,但假设 `module2.py` 包含以下的功能:
|
||||
|
||||
```
|
||||
|
||||
|
||||
def update_config_from_dict(config_dict):
|
||||
items = config_dict.items()
|
||||
while items:
|
||||
@ -28,14 +27,13 @@ def update_in_place(config_dict):
|
||||
del config_dict[k]
|
||||
elif new_value != v:
|
||||
config_dict[k] = v
|
||||
|
||||
```
|
||||
|
||||
现在,当我们想从 `module3` 中调用这些函数时,我们遇到了一个问题:Python 3.6 中的字典类型与 Python 2.7 中的字典类型不同。在 Python 2 中,dicts 是无序的,它们的 `.keys()`, `.values()`, `.items()` 方法返回了正确的序列,这意味着调用 `.items()` 会在字典中创建状态的副本。在 Python 3 中,这些方法返回字典当前状态的动态视图。
|
||||
现在,当我们想从 `module3` 中调用这些函数时,我们遇到了一个问题:Python 3.6 中的字典类型与 Python 2.7 中的字典类型不同。在 Python 2 中,字典是无序的,它们的 `.keys()`, `.values()`, `.items()` 方法返回了正确的序列,这意味着调用 `.items()` 会在字典中创建状态的副本。在 Python 3 中,这些方法返回字典当前状态的动态视图。
|
||||
|
||||
这意味着如果 `module3` 调用 `module2.update_config_from_dict(some_dictionary)`,它将无法运行,因为 Python 3 中 `dict.items()` 返回的值不是一个列表,并且没有 `.pop()` 方法。反过来也是如此。如果 `module3` 调用 `module2.config_to_dict()`,它可能会返回一个 Python 2 的字典。现在调用 `.items()` 突然返回一个列表,所以这段代码无法正常工作(这对 Python 3 字典来说工作正常):
|
||||
```
|
||||
|
||||
```
|
||||
def main(cmdline_options):
|
||||
d = module2.config_to_dict()
|
||||
items = d.items()
|
||||
@ -45,7 +43,6 @@ def main(cmdline_options):
|
||||
d[k] = v
|
||||
for k, v in items:
|
||||
print(f'Config with cmdline overrides: {k}={v}')
|
||||
|
||||
```
|
||||
|
||||
最后,使用 `module2.update_in_place()` 会失败,因为 Python 3 中 `.items()` 的值现在不允许在迭代过程中改变。
|
||||
@ -54,7 +51,7 @@ def main(cmdline_options):
|
||||
|
||||
### Python 应该神奇地知道类型并会自动转换!
|
||||
|
||||
为什么拥有 Python 6 的虚拟机无法识别 Python 3 的代码,在 Python 2 中调用 `some_dict.keys()` 时,我们还有别的意思吗?好吧,Python 不知道代码的作者在编写代码时,她所认为的 `some_dict` 应该是什么。代码中没有任何内容表明它是否是一个字典。在 Python 2 中没有类型注释,因为它们是可选的,即使在 Python 3 中,大多数代码也不会使用它们。
|
||||
为什么我们的 Python 6 的虚拟机无法识别 Python 3 的代码,在 Python 2 中调用 `some_dict.keys()` 时,我们还有别的意思吗?好吧,Python 不知道代码的作者在编写代码时,她所认为的 `some_dict` 应该是什么。代码中没有任何内容表明它是否是一个字典。在 Python 2 中没有类型注释,因为它们是可选的,即使在 Python 3 中,大多数代码也不会使用它们。
|
||||
|
||||
在运行时,当你调用 `some_dict.keys()` 的时候,Python 只是简单地在对象上查找一个属性,该属性恰好隐藏在 `some_dict` 名下,并试图在该属性上运行 `__call__()`。这里有一些关于方法绑定,描述符,slots 等技术问题,但这是它的核心。我们称这种行为为“鸭子类型”。
|
||||
|
||||
@ -62,33 +59,33 @@ def main(cmdline_options):
|
||||
|
||||
### 好的,让我们在运行时做出这个决定
|
||||
|
||||
Python 6 的虚拟机可以通过标记每个属性查找来实现这一点,信息是“来自 py2 的调用”或“来自 py3 的调用”,并使对象发送正确的属性。这会让事情变得很慢,并且使用更多的内存。这将要求我们使用用户代码使用的代理将两种版本的给定类型保留在内存中。我们需要将这些对象的状态同步到用户背后,使工作加倍。毕竟,新字典的内存表示与 Python 2 不同。
|
||||
Python 6 的虚拟机可以标记每个属性,通过查找“来自 py2 的调用”或“来自 py3 的调用”的信息来实现这一点,并使对象发送正确的属性。这会让它变得很慢,并且使用更多的内存。这将要求我们在内存中保留两种版本的代码,并通过代理来使用它们。我们需要加倍付出努力,在用户背后同步这些对象的状态。毕竟,新字典的内存表示与 Python 2 不同。
|
||||
|
||||
如果你在思考字典问题,考虑 Python 3 中的 Unicode 字符串和 Python 2 中的字节(byte)字符串的所有问题。
|
||||
如果你已经被字典问题绕晕了,那么再想想 Python 3 中的 Unicode 字符串和 Python 2 中的字节(byte)字符串的各种问题吧。
|
||||
|
||||
### 一切都会丢失吗?Python 3 不能运行旧代码?
|
||||
### 没有办法了吗?Python 3 根本就不能运行旧代码吗?
|
||||
|
||||
一切都不会丢失。每天都会有项目移植到 Python 3。将 Python 2 代码移植到两个版本的 Python 上推荐方法是在代码上运行 [Python-Modernize][1]。它会捕获那些在 Python 3 上不起作用的代码,并使用 [six][2] 库将其替换,以便它在 Python 2 和 Python 3 上运行。这是对 `2to3` 的改编,它正在生成 Python 3-only 代码。`Modernize` 是首选,因为它提供了更多的增量迁移路线。所有的这些在 Python 文档中的 [Porting Python 2 Code to Python 3][3]文档中都有很好的概述。
|
||||
不会。每天都会有项目移植到 Python 3。将 Python 2 代码移植到两个版本的 Python 上推荐方法是在你的代码上运行 [Python-Modernize][1]。它会捕获那些在 Python 3 上不起作用的代码,并使用 [six][2] 库将其替换,以便它在 Python 2 和 Python 3 上运行。这是 `2to3` 的一个改编版本,用于生成仅针对 Python 3 代码。`Modernize` 是首选,因为它提供了更多的增量迁移路线。所有的这些在 Python 文档中的 [Porting Python 2 Code to Python 3][3]文档中都有很好的概述。
|
||||
|
||||
但是,等一等,你不是说 Python 6 的虚拟机不能自动执行此操作吗?对。`Modernize` 查看你的代码,并试图猜测哪些是安全的。它会做出一些不必要的改变,还会错过其他必要的改变。但是,它不会帮助你处理字符串。如果你的代码没有保留“来自外部的二进制数据”和“流程中的文本数据”之间的界限,那么这种转换并非微不足道。
|
||||
但是,等一等,你不是说 Python 6 的虚拟机不能自动执行此操作吗?对。`Modernize` 查看你的代码,并试图猜测哪些是安全的。它会做出一些不必要的改变,还会错过其他必要的改变。但是,它不会帮助你处理字符串。如果你的代码没有在“来自外部的二进制数据”和“流程中的文本数据”之间保持界限,那么这种转换就不会那么轻易。
|
||||
|
||||
因此,迁移大项目不能自动完成,并且涉及人类进行测试,发现问题并修复它们。它工作吗?是的,我曾帮助[将一百万行代码迁移到 Python 3][4],并且交换没有造成事故。这一举措重获了我们服务器内存的 1/3,并使代码运行速度提高了 12%。那是在 Python 3.5 上,但是 Python 3.6 的速度要快得多,根据你的工作量,你甚至可以达到 [4 倍加速][5]。
|
||||
因此,大项目的迁移不能自动完成,并且需要人类进行测试,发现问题并修复它们。它工作吗?是的,我曾帮助[将一百万行代码迁移到 Python 3][4],并且这种切换没有造成事故。这一举措让我们重新获得了 1/3 的服务器内存,并使代码运行速度提高了 12%。那是在 Python 3.5 上,但是 Python 3.6 的速度要快得多,根据你的工作量,你甚至可以达到 [4 倍加速][5]。
|
||||
|
||||
### 亲爱的 Zed
|
||||
|
||||
hi,伙计,我关注你已经超过 10 年了。我一直在观察,当你感到沮丧的时候,你对 Mongrel 没有任何信任,尽管 Rails 生态系统几乎全部都在上面运行。当你重新设计它并开始 Mongrel 2 项目时,我一直在观察。我一直在关注你使用 Fossil 这一令人惊讶的举动。随着你发布 “Rails 是一个贫民窟”的帖子,我看到你突然离开了 Ruby 社区。当你开始编写 “Learn Python The Hard Way” 并且开始推荐它时,我感到非常兴奋。2013 年我在 [DjangoCon Europe][6] 见过你,我们谈了很多关于绘画,唱歌和倦怠的内容。关于[这张你的照片][7]是我在 Instagram 上的第一篇文章。
|
||||
hi,伙计,我关注你已经超过 10 年了。我一直在观察,当你感到沮丧的时候,你对 Mongrel 没有任何信任,尽管 Rails 生态系统几乎全部都在上面运行。当你重新设计它并开始 Mongrel 2 项目时,我一直在观察。我一直在关注你使用 Fossil 这一令人惊讶的举动。随着你发布 “Rails 是一个贫民窟”的帖子,我看到你突然离开了 Ruby 社区。当你开始编写《笨方法学 Python》并且开始推荐它时,我感到非常兴奋。2013 年我在 [DjangoCon Europe][6] 见过你,我们谈了很多关于绘画,唱歌和倦怠的内容。[你的这张照片][7]是我在 Instagram 上的第一个帖子。
|
||||
|
||||
你几乎把另一个“贫民区”的行动与 [“反对 Python 3” 案例][8] 文章拉到一起。我认为你本意是好的,但是这篇文章引起了很多混乱,包括许多人认为你认为 Python 3 不是图灵完整的。我花了好几个小时让人们相信,你是在开玩笑。但是,鉴于你对 Python 学习方式的重大贡献,我认为这是值得的。特别是你为 Python 3 更新了你的书。感谢你做这件事。如果我们社区中真的有人要求因你的帖子为由将你和你的书列入黑名单,把他们请出去。这是一个双输的局面,这是错误的。
|
||||
你几乎把另一个“贫民区”的行动与 [“反对 Python 3” 案例][8] 文章拉到一起。我认为你本意是好的,但是这篇文章引起了很多混淆,包括许多人觉得你认为 Python 3 不是图灵完整的。我花了好几个小时让人们相信,你是在开玩笑。但是,鉴于你对《笨方法学 Python》的重大贡献,我认为这是值得的。特别是你为 Python 3 更新了你的书。感谢你做这件事。如果我们社区中真的有人因你的帖子为由要求将你和你的书列入黑名单,而请他们出去。这是一个双输的局面,这是错误的。
|
||||
|
||||
在记录中,没有一个核心 Python 开发人员认为 Python 2 到 Python 3 的转换过程会顺利而且计划得当,[包括 Guido van Rossum][9]。真的,可以看那个视频,这有点事后诸葛亮的意思了。从这个意义上说,我们实际上是积极地相互认同的。如果我们再做一次,它会看起来不一样。但在这一点上,[在 2020 年 1 月 1 日,Python 2 将会到达终结][10]。大多数第三方库已经支持 Python 3,甚至开始发布只支持 Python 3 版本(参见[Django][11]或 [科学项目关于 Python 3 的声明][12])。
|
||||
说实话,没有一个核心 Python 开发人员认为 Python 2 到 Python 3 的转换过程会顺利而且计划得当,[包括 Guido van Rossum][9]。真的,可以看那个视频,这有点事后诸葛亮的意思了。从这个意义上说,*我们实际上是积极地相互认同的*。如果我们再做一次,它会看起来不一样。但在这一点上,[在 2020 年 1 月 1 日,Python 2 将会到达终结][10]。大多数第三方库已经支持 Python 3,甚至开始发布只支持 Python 3 的版本(参见 [Django][11] 或 [科学项目关于 Python 3 的声明][12])。
|
||||
|
||||
我们也积极地就另一件事达成一致。就像你于 Mongrel 一样,Python 核心开发人员是志愿者,他们的工作没有得到报酬。我们大多数人在这个项目上投入了大量的时间和精力,因此[我们自然而然敏感][13]于那些对他们的贡献不屑一顾和激烈的评论。特别是如果这个信息既攻击目前的事态,又要求更多的自由劳动。
|
||||
我们也积极地就另一件事达成一致。就像你于 Mongrel 一样,Python 核心开发人员是志愿者,他们的工作没有得到报酬。我们大多数人在这个项目上投入了大量的时间和精力,因此[我们自然而然敏感][13]于那些对他们的贡献不屑一顾和激烈的评论。特别是如果这个信息既攻击目前的事态,又要求更多的自由贡献。
|
||||
|
||||
我希望到 2018 年你会让忘记 2016 发布的帖子,有一堆好的反驳。[我特别喜欢 eevee][14](译注:eevee 是一个为 Blender 设计的渲染器)。它特别针对“一起运行 Python 2 和 Python 3 ”的场景,这是不现实的,就像在同一个虚拟机中运行 Ruby 1.8 和 Ruby 2.x 一样,或者像 Lua 5.3 和 Lua 5.1 同时运行一样。你甚至不能用 libc.so.6 运行针对 libc.so.5 编译的 C 二进制文件。然而,我发现最令人惊讶的是,你声称 Python 核心开发者是“有目的地”创造诸如 2to3 之类的破坏工具,这些由 Guido 创建,其最大利益就是让每个人尽可能顺利,快速地迁移。我很高兴你在之后的帖子中放弃了这个说法,但是你必须意识到你会激怒那些阅读原始版本的人。对蓄意伤害的指控最好有强有力的证据支持。
|
||||
我希望到 2018 年你会让忘记 2016 发布的帖子,有一堆好的反驳。[我特别喜欢 eevee][14](LCTT 译注:eevee 是一个为 Blender 设计的渲染器)。它特别针对“一起运行 Python 2 和 Python 3 ”的场景,这是不现实的,就像在同一个虚拟机中运行 Ruby 1.8 和 Ruby 2.x 一样,或者像 Lua 5.3 和 Lua 5.1 同时运行一样。你甚至不能用 libc.so.6 运行针对 libc.so.5 编译的 C 二进制文件。然而,我发现最令人惊讶的是,你声称 Python 核心开发者是“有目的地”创造诸如 2to3 之类的破坏工具,这些由 Guido 创建,其最大利益就是让每个人尽可能顺利,快速地迁移。我很高兴你在之后的帖子中放弃了这个说法,但是你必须意识到你会激怒那些阅读了原始版本的人。对蓄意伤害的指控最好有强有力的证据支持。
|
||||
|
||||
但看起来你仍然会这样做。[就在今天][15]你说 Python 核心开发者“忽略”尝试解决 API 的问题,特别是 `six`。正如我上面写的那样,Python 文档中的官方移植指南涵盖了 “six”。更重要的是,`six` 是由 Python 2.7 的发布管理者 Benjamin Peterson 编写。很多人学会了编程,这要归功于你,而且由于你在网上有大量的粉丝,人们会阅读这样的推文,他们会相信它的价值,这是有害的。
|
||||
但看起来你仍然会这样做。[就在今天][15]你说 Python 核心开发者“忽略”尝试解决 API 的问题,特别是 `six`。正如我上面写的那样,Python 文档中的官方移植指南涵盖了 `six`。更重要的是,`six` 是由 Python 2.7 的发布管理者 Benjamin Peterson 编写。很多人学会了编程,这要归功于你,而且由于你在网上有大量的粉丝,人们会阅读这样的推文,他们会相信它的价值,这是有害的。
|
||||
|
||||
我有一个建议,让我们把 “Python 3 管理不善”的争议搁置起来。Python 2 正在死亡,这个过程会很慢,并且它是丑陋而血腥的,但它是一条单行道。争论那些没有用。相反,让我们专注于我们现在可以做什么来使 Python 3.8 比其他任何 Python 版本更好。也许你更喜欢看外面的角色,但作为这个社区的成员,你会更有影响力。请说“我们”而不是“他们”。
|
||||
我有一个建议,让我们把 “Python 3 管理不善”的争议搁置起来。Python 2 正在死亡,这个过程会很慢,并且它是丑陋而血腥的,但它是一条单行道。争论那些没有用。相反,让我们专注于我们现在可以做什么来使 Python 3.8 比其他任何 Python 版本更好。也许你更喜欢看外面的角色,但作为这个社区的成员,你会更有影响力。请说“我们”而不是“他们”。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -96,9 +93,9 @@ hi,伙计,我关注你已经超过 10 年了。我一直在观察,当你
|
||||
via: http://lukasz.langa.pl/13/could-we-run-python-2-and-python-3-code-same-vm/
|
||||
|
||||
作者:[Łukasz Langa][a]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,32 +1,41 @@
|
||||
Linux 下的 4 个命令行笔记记录程序
|
||||
======
|
||||
4 个 Linux 下的命令行笔记程序
|
||||
===============
|
||||
|
||||
> 这些工具可以让你在 Linux 命令行下简单而有效地记录笔记和保存信息。
|
||||
|
||||

|
||||
当你需要保存代码段或 URL、想法或引用时,可能会启动文本编辑器或使用[桌面][1]或[基于 Web 的] [2]笔记记录工具。但那些不是你唯一的选择。如果你在终端窗口中工作,则可以使用 Linux 命令行下的许多笔记记录工具之一。
|
||||
|
||||
当你需要保存代码段或 URL、想法或引用时,可能会启动文本编辑器或使用[桌面][1]或[基于 Web 的][2]笔记记录工具。但那些不是你唯一的选择。如果你在终端窗口中工作,则可以使用 Linux 命令行下的许多笔记记录工具之一。
|
||||
|
||||
我们来看看这四个程序。
|
||||
|
||||
### tnote
|
||||
|
||||
[tnote][3] 使在终端窗口中记笔记很简单 - 几乎太简单了。
|
||||

|
||||
|
||||
tnote 是一个 Python 脚本。首次启动时,它会要求你输入密码和口令来加密存储笔记的[ SQLite 数据库][4]。完成之后,按 “A” 创建一个笔记。输入你的笔记,然后按 CTRL-D 保存。
|
||||
[tnote][3] 使在终端窗口中记笔记很简单 —— 几乎太简单了。
|
||||
|
||||
一旦你有几个(或多个)笔记,你可以查看它们或搜索特定的笔记,单词或短语或标签。tnote 不包含很多功能,但它确实实现了任务。
|
||||
tnote 是一个 Python 脚本。首次启动时,它会要求你输入密码和口令来加密存储笔记的 [SQLite 数据库][4]。完成之后,按 `A` 创建一个笔记。输入你的笔记,然后按 `CTRL-D` 保存。
|
||||
|
||||
一旦你有几个(或多个)笔记,你可以查看它们或搜索特定的笔记,单词或短语或标签。tnote 没有很多功能,但它确实实现了任务。
|
||||
|
||||
### Terminal Velocity
|
||||
|
||||
如果你使用的是 Mac OS,你可能会看到一个名为 [Notational Velocity][5] 的流行开源笔记程序,这是一种记录笔记的简单有效方法。[Terminal Velocity][6] 在将 Notational Velocity 体验带入命令行方面做得很好。
|
||||

|
||||
|
||||
如果你使用过 Mac OS,你可能会看到一个名为 [Notational Velocity][5] 的流行开源笔记程序,这是一种记录笔记的简单有效方法。[Terminal Velocity][6] 在将 Notational Velocity 体验带入命令行方面做得很好。
|
||||
|
||||
Terminal Velocity 打开你的默认文本编辑器(由你的 `.profile` 或 `.bashrc` 文件中的 `$EDITOR` 变量设置)。输入你的笔记,然后保存。该笔记出现在 Terminal Velocity 窗口的列表中。
|
||||
|
||||
使用键盘上的箭头键滚动查看你的笔记列表。要查看或编辑笔记,请按 Enter 键。如果你有一长串笔记,则可以在 `Find or Create` 字段中输入笔记标题的前几个字符以缩小列表的范围。在那里滚动笔记并按下 Enter 键将其打开。
|
||||
使用键盘上的箭头键滚动查看你的笔记列表。要查看或编辑笔记,请按回车键。如果你有一长串笔记,则可以在 `Find or Create` 字段中输入笔记标题的前几个字符以缩小列表的范围。在那里滚动笔记并按下回车键将其打开。
|
||||
|
||||
### pygmynote
|
||||
|
||||

|
||||
|
||||
在本文中的四个应用中,[pygmynote][7] 可能是最不用户友好的。然而,它是最灵活的。
|
||||
|
||||
像 tnote 一样,pygmynote 将你的笔记和附件保存在 SQLite 数据库中。当你启动它时,pygmynote 看起来并不特别有用。在任何时候,输入 `help` 并按下 Enter 键获取命令列表。
|
||||
像 tnote 一样,pygmynote 将你的笔记和附件保存在 SQLite 数据库中。当你启动它时,pygmynote 看起来并不特别有用。在任何时候,输入 `help` 并按下回车键获取命令列表。
|
||||
|
||||
你可以添加、编辑、查看和搜索笔记,并在笔记中添加[标签][8]。标签使找到笔记更容易,特别是如果你有很多笔记的时候。
|
||||
|
||||
@ -34,6 +43,8 @@ pygmynote 的灵活性在于它能够将附件添加到笔记中。这些附件
|
||||
|
||||
### jrnl
|
||||
|
||||

|
||||
|
||||
[jrnl][9] 是这里的一个奇怪应用。正如你可能从它的名字中猜到的那样,jrnl 意在成为一种日记工具。但这并不意味着你不能记笔记。 jrnl 做得很好。
|
||||
|
||||
当你第一次启动 jrnl 时,它会询问你想把文件 `journal.txt` (它存储你的笔记)保存的位置以及是否需要密码保护。如果你决定添加密码,那么你在应用内的操作都需要输入密码。
|
||||
@ -50,7 +61,7 @@ via: https://opensource.com/article/18/3/command-line-note-taking-applications
|
||||
|
||||
作者:[Scott Nesbitt][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,30 +1,33 @@
|
||||
为啥我喜欢 ARM 和 PowerPC
|
||||
为什么我喜欢 ARM 和 PowerPC?
|
||||
======
|
||||
|
||||
> 一个学生在搜寻强劲而节能的工作站的历程中怎样对开源系统的热情与日俱增的。
|
||||
|
||||

|
||||
最近我被问起为啥在博客和推特里经常提到 [ARM][1] 和 [PowerPC][2]。我有两个答案:一个是个人原因,另一个是技术上的。
|
||||
|
||||
最近我被问起为什么在博客和推特里经常提到 [ARM][1] 和 [PowerPC][2]。我有两个答案:一个是个人原因,另一个是技术上的。
|
||||
|
||||
### 个人原因
|
||||
|
||||
从前,我是学环境保护的。在我读博的时候,我准备买个新电脑。作为一个环保人士,我需要一台强劲且环保的电脑。这就是我开始对 PowerPC 感兴趣的原因,我找到了 [Pegasos][3], 一台 [Genesi][4] 公司制造的 PowerPC 工作站。
|
||||
从前,我是学环境保护的。在我读博的时候,我准备买个新电脑。作为一个环保人士,我需要一台强劲且节能的电脑。这就是我开始对 PowerPC 感兴趣的原因,我找到了 [Pegasos][3],这是一台 [Genesi][4] 公司制造的 PowerPC 工作站。
|
||||
|
||||
我还用过 [RS/6000][5] (PowerPC), [SGI][6] (MIPS), [HP-UX][7] (PA-RISC),和[VMS][8] (Alpha)的服务器和工作站,由于我的 PC 使用 Linux 而非 Windows,所以使用不同的 CPU 架构对我来说并没有什么区别。 [Pegasos][9] 是我第一台工作站,它很小而且对家用来说性能足够。
|
||||
我还用过 [RS/6000][5] (PowerPC)、 [SGI][6] (MIPS)、 [HP-UX][7] (PA-RISC)和 [VMS][8] (Alpha)的服务器和工作站,由于我的 PC 使用 Linux 而非 Windows,所以使用不同的 CPU 架构对我来说并没有什么区别。 [Pegasos][9] 是我第一台工作站,它小型而节能而且对家用来说性能足够。
|
||||
|
||||
很快我就开始为 Genesi 工作,为 Pegasos 移植 [openSUSE][10], Ubuntu 和其他 Linux 发行版,并提供质量保证和社区支持。继 Pegasos 之后是 [EFIKA][11],另一款基于 PowerPC 的开发板。在用过工作站之后,刚开始使用嵌入式系统会感觉有点奇怪。但是作为第一代普及价位的开发板,这是一场革命的开端。
|
||||
很快我就开始为 Genesi 工作,为 Pegasos 移植 [openSUSE][10]、 Ubuntu 和其他 Linux 发行版,并提供质量保证和社区支持。继 Pegasos 之后是 [EFIKA][11],这是另一款基于 PowerPC 的开发板。在用过工作站之后,刚开始使用嵌入式系统会感觉有点奇怪。但是作为第一代普及价位的开发板,这是一场革命的开端。
|
||||
|
||||
在我收到 Genesi 的另一块有趣的开发板的时候,我开始了一个大规模的服务器项目:基于 ARM 的 [Smarttop][12] 和 [Smartbook][13]。我最喜欢的 Linux 发行版————openSUSE,也收到了一打这种机器。这在当时 ARM 电脑非常稀缺的情况下,极大地促进了 ARM 版 openSUSE 项目的开发。
|
||||
我工作于一个大规模的服务器项目时,我收到 Genesi 的另一块有趣的开发板:基于 ARM 的 [Smarttop][12] 和 [Smartbook][13]。我最喜欢的 Linux 发行版——openSUSE,也收到了一打这种机器。这在当时 ARM 电脑非常稀缺的情况下,极大地促进了 ARM 版 openSUSE 项目的开发。
|
||||
|
||||
尽管最近我很忙,我尽量保持对 ARM 和 PowerPC 新闻的关注。这有助于我支持非 x86 平台上的 SysLog-NG 用户。只要有半个小时的空,我就会去捣鼓一下 ARM 机器。我在[树莓派2][14]上做了很多 [syslog-ng][15] 的测试,结果令人振奋。我最近在树莓派上做了个音乐播放器,用了一块 USB 声卡和[音乐播放守护进程][17],我经常使用它。
|
||||
尽管最近我很忙,我尽量保持对 ARM 和 PowerPC 新闻的关注。这有助于我支持非 x86 平台上的 syslog-ng 用户。只要有半个小时的空,我就会去捣鼓一下 ARM 机器。我在[树莓派2][14]上做了很多 [syslog-ng][15] 的测试,结果令人振奋。我最近在树莓派上做了个音乐播放器,用了一块 USB 声卡和[音乐播放守护进程][17],我经常使用它。
|
||||
|
||||
### 技术方面
|
||||
|
||||
美好的多样性:它创造了竞争,而竞争创造了更好的产品。虽然 x86 是一款强劲的通用处理器,但 ARM 和 PowerPC (以及许多其他)这样的芯片在多种特定场景下显得更适合。
|
||||
|
||||
如果你有一部运行[安卓][18]的移动设备或者[苹果][19]的 iPhone 或 iPad,极有可能它使用的就是 基于ARM 的 SoC (片上系统)。网络存储服务器也一样。原因很简单:省电。你不会希望手机一直在充电,也不想为你的路由器付更多的电费。
|
||||
如果你有一部运行[安卓][18]的移动设备或者[苹果][19]的 iPhone 或 iPad,极有可能它使用的就是基于ARM 的 SoC (片上系统)。网络存储服务器也一样。原因很简单:省电。你不会希望手机一直在充电,也不想为你的路由器付更多的电费。
|
||||
|
||||
ARM 亦在使用 64-bit ARMv8 芯片征战服务器市场。很多任务只需要极少的计算能力,另一方面省电和快速IO才是关键,比如思维存储(译者注:原文为 think storage),静态网页服务器,电子邮件和其他网络/存储相关的功能。一个最好的例子就是 [Ceph][20],一个分布式的面向对象文件系统。[SoftIron][21] 就是一个基于 ARMv8 开发版,使用 CentOS 作为基准软件,运行在 Ceph 上的完整存储应用。
|
||||
ARM 亦在使用 64 位 ARMv8 芯片征战企业级服务器市场。很多任务只需要极少的计算能力,另一方面省电和快速 IO 才是关键,想想存储、静态网页服务器、电子邮件和其他网络/存储相关的功能。一个最好的例子就是 [Ceph][20],一个分布式的面向对象文件系统。[SoftIron][21] 就是一个基于 ARMv8 开发版,使用 CentOS 作为基准软件,运行在 Ceph 上的完整存储应用。
|
||||
|
||||
众所周知 PowerPC 是旧版苹果 [Mac][22] 电脑上的 CPU。虽然它不再作为通用桌面电脑的 CPU ,它依然在路由器和电信设备里发挥作用。而且 [IBM][23] 仍在为高端服务器制造芯片。几年前,随着 Power8 的引入, IBM 在 [OpenPower 基金会][24] 的支持下开放了架构。 Power8 对于关心内存带宽的设备,比如 HPC , 大数据,数据挖掘来说,是非常理想的平台。目前,Power9 也正呼之欲出。
|
||||
众所周知 PowerPC 是旧版苹果 [Mac][22] 电脑上的 CPU。虽然它不再作为通用桌面电脑的 CPU ,它依然在路由器和电信设备里发挥作用。而且 [IBM][23] 仍在为高端服务器制造芯片。几年前,随着 Power8 的引入, IBM 在 [OpenPower 基金会][24] 的支持下开放了架构。 Power8 对于关心内存带宽的设备,比如 HPC 、大数据、数据挖掘来说,是非常理想的平台。目前,Power9 也正呼之欲出。
|
||||
|
||||
这些都是服务器应用,但也有计划用于终端用户。猛禽工程团队正在开发一款基于 [Power9 的工作站][25],也有一个基于飞思卡尔/恩智浦 QORIQ E6500 芯片[制造笔记本] [26]的倡议。当然,这些电脑并不适合所有人,你不能在它们上面安装 Windows 游戏或者商业应用。但它们对于 PowerPC 开发人员和爱好者,或者任何想要完全开放系统的人来说是理想的选择,因为从硬件到固件到应用程序都是开放的。
|
||||
|
||||
@ -32,7 +35,7 @@ ARM 亦在使用 64-bit ARMv8 芯片征战服务器市场。很多任务只需
|
||||
|
||||
我的梦想是完全没有 x86 的环境,不是因为我讨厌 x86 ,而是因为我喜欢多样化而且总是希望使用最适合工作的工具。如果你看看猛禽工程网页上的[图][27],根据不同的使用情景, ARM 和 POWER 完全可以代替 x86 。现在,我在笔记本的 x86 虚拟机上编译、打包和测试 syslog-ng。如果能用上足够强劲的 ARMv8 或者 PowerPC 电脑,无论工作站还是服务器,我就能避免在 x86 上做这些事。
|
||||
|
||||
现在我正在等待下一代[菠萝本][28]的到来,就像我在二月份 [FOSDEM][29] 上说的,下一代有望提供更高的性能。和 Chrome 本不同的是,这个 ARM 笔记本设计用于运行 Linux 而非仅是个客户端(译者注:Chrome 笔记本只提供基于网页的应用)。作为桌面系统,我在寻找 ARMv8 工作站级别的硬件。有些已经接近完成——就像 Avantek 公司的 [雷神X 台式机][30]——不过他们还没有装备最新最快最重要也最节能的 ARMv8 CPU。当这些都实现了,我将用我的 Pixel C 笔记本运行安卓。它不像 Linux 那样简单灵活,但它以强大的 ARM SoC 和 Linux 内核为基础。
|
||||
现在我正在等待下一代[菠萝本][28]的到来,就像我在二月份 [FOSDEM][29] 上说的,下一代有望提供更高的性能。和 Chrome 本不同的是,这个 ARM 笔记本设计用于运行 Linux 而非仅是个客户端(LCTT 译注:Chrome 笔记本只提供基于网页的应用)。作为桌面系统,我在寻找 ARMv8 工作站级别的硬件。有些已经接近完成——就像 Avantek 公司的 [雷神 X 台式机][30]——不过他们还没有装备最新最快最重要也最节能的 ARMv8 CPU。当这些都实现了,我将用我的 Pixel C 笔记本运行安卓。它不像 Linux 那样简单灵活,但它以强大的 ARM SoC 和 Linux 内核为基础。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -40,7 +43,7 @@ via: https://opensource.com/article/18/4/why-i-love-arm-and-powerpc
|
||||
|
||||
作者:[Peter Czanik][a]
|
||||
译者:[kennethXia](https://github.com/kennethXia)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,8 +1,9 @@
|
||||
另一个 TUI 图形活动监视器,使用 Go 编写
|
||||
Gotop:另一个 TUI 图形活动监视器,使用 Go 编写
|
||||
======
|
||||
|
||||

|
||||
你已经知道 “top” 命令,对么?是的,它提供类 Unix 操作系统中运行中的进程的动态实时信息。一些开发人员为 top 命令构建了图形前端,因此用户可以在图形窗口中轻松找到他们系统的活动。其中之一是 **Gotop**。顾名思义,Gotop 是一个 TUI 图形活动监视器,使用 **Go** 语言编写。它是完全免费、开源的,受到 [gtop][1] 和 [vtop][2] 的启发。
|
||||
|
||||
你已经知道 `top` 命令,对么?是的,它提供类 Unix 操作系统中运行中的进程的动态实时信息。一些开发人员为 `top` 命令构建了图形前端,因此用户可以在图形窗口中轻松找到他们系统的活动。其中之一是 **Gotop**。顾名思义,Gotop 是一个 TUI 图形活动监视器,使用 **Go** 语言编写。它是完全免费、开源的,受到了 [gtop][1] 和 [vtop][2] 的启发。
|
||||
|
||||
在此简要的指南中,我们将讨论如何安装和使用 Gotop 来监视 Linux 系统的活动。
|
||||
|
||||
@ -11,21 +12,21 @@
|
||||
Gotop 是用 Go 编写的,所以我们需要先安装它。要在 Linux 中安装 Go 语言,请参阅以下指南。
|
||||
|
||||
安装 Go 之后,使用以下命令下载最新的 Gotop 二进制文件。
|
||||
|
||||
```
|
||||
$ sh -c "$(curl https://raw.githubusercontent.com/cjbassi/gotop/master/download.sh)"
|
||||
|
||||
```
|
||||
|
||||
然后,将下载的二进制文件移动到您的 $PATH 中,例如 **/usr/local/bin/**。
|
||||
然后,将下载的二进制文件移动到您的 `$PATH` 中,例如 `/usr/local/bin/`。
|
||||
|
||||
```
|
||||
$ cp gotop /usr/local/bin
|
||||
|
||||
```
|
||||
|
||||
最后,用下面的命令使其可执行:
|
||||
|
||||
```
|
||||
$ chmod +x /usr/local/bin/gotop
|
||||
|
||||
```
|
||||
|
||||
如果你使用的是基于 Arch 的系统,Gotop 存在于 **AUR** 中,所以你可以使用任何 AUR 助手程序进行安装。
|
||||
@ -33,92 +34,91 @@ $ chmod +x /usr/local/bin/gotop
|
||||
使用 [**Cower**][3]:
|
||||
```
|
||||
$ cower -S gotop
|
||||
|
||||
```
|
||||
|
||||
使用 [**Pacaur**][4]:
|
||||
|
||||
```
|
||||
$ pacaur -S gotop
|
||||
|
||||
```
|
||||
|
||||
使用 [**Packer**][5]:
|
||||
|
||||
```
|
||||
$ packer -S gotop
|
||||
|
||||
```
|
||||
|
||||
使用 [**Trizen**][6]:
|
||||
|
||||
```
|
||||
$ trizen -S gotop
|
||||
|
||||
```
|
||||
|
||||
使用 [**Yay**][7]:
|
||||
|
||||
```
|
||||
$ yay -S gotop
|
||||
|
||||
```
|
||||
|
||||
使用 [yaourt][8]:
|
||||
|
||||
```
|
||||
$ yaourt -S gotop
|
||||
|
||||
```
|
||||
|
||||
### 用法
|
||||
|
||||
Gotop 的使用非常简单!你所要做的就是从终端运行以下命令。
|
||||
|
||||
```
|
||||
$ gotop
|
||||
|
||||
```
|
||||
|
||||
这样就行了!你将在简单的 TUI 窗口中看到系统 CPU、磁盘、内存、网络、CPU温度和进程列表的使用情况。
|
||||
|
||||
![][10]
|
||||
|
||||
要仅显示CPU、内存和进程组件,请使用下面的 **-m** 标志
|
||||
要仅显示CPU、内存和进程组件,请使用下面的 `-m` 标志:
|
||||
|
||||
```
|
||||
$ gotop -m
|
||||
|
||||
```
|
||||
|
||||
![][11]
|
||||
|
||||
你可以使用以下键盘快捷键对进程表进行排序。
|
||||
|
||||
* **c** – CPU
|
||||
* **m** – 内存
|
||||
* **p** – PID
|
||||
* `c` – CPU
|
||||
* `m` – 内存
|
||||
* `p` – PID
|
||||
|
||||
|
||||
|
||||
对于进程浏览,请使用以下键。
|
||||
|
||||
* **上/下** 箭头或者 **j/k** 键用于上移下移。
|
||||
* **Ctrl-d** 和 **Ctrl-u** – 上移和下移半页。
|
||||
* **Ctrl-f** 和 **Ctrl-b** – 上移和下移整页。
|
||||
* **gg** 和 **G** – 跳转顶部和底部。
|
||||
* `上/下` 箭头或者 `j/k` 键用于上移下移。
|
||||
* `Ctrl-d` 和 `Ctrl-u` – 上移和下移半页。
|
||||
* `Ctrl-f` 和 `Ctrl-b` – 上移和下移整页。
|
||||
* `gg` 和 `G` – 跳转顶部和底部。
|
||||
|
||||
|
||||
|
||||
按下 **< TAB>** 切换进程分组。要杀死选定的进程或进程组,请输入 **dd**。要选择一个进程,只需点击它。要向下/向上滚动,请使用鼠标滚动按钮。要放大和缩小 CPU 和内存图,请使用 **h** 和 **l**。要显示帮助菜单,只需按 **?**。
|
||||
|
||||
**推荐阅读:**
|
||||
按下 `TAB` 切换进程分组。要杀死选定的进程或进程组,请输入 `dd`。要选择一个进程,只需点击它。要向下/向上滚动,请使用鼠标滚动按钮。要放大和缩小 CPU 和内存的图形,请使用 `h` 和 `l`。要显示帮助菜单,只需按 `?`。
|
||||
|
||||
就是这些了。希望这有帮助。还有更多好东西。敬请关注!
|
||||
|
||||
### 资源
|
||||
|
||||
- [Gotop GitHub Repository](https://github.com/cjbassi/gotop)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/gotop-yet-another-tui-graphical-activity-monitor-written-in-go/
|
||||
|
||||
作者:[SK][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
137
published/20180413 Finding what you-re looking for on Linux.md
Normal file
137
published/20180413 Finding what you-re looking for on Linux.md
Normal file
@ -0,0 +1,137 @@
|
||||
在 Linux 上寻找你正在寻找的东西
|
||||
=====
|
||||
|
||||
> 怎样在 Linux 系统上使用 find、locate、mlocate、which、 whereis、 whatis 和 apropos 命令寻找文件。
|
||||
|
||||

|
||||
|
||||
在 Linux 系统上找到你要找的文件或命令并不难, 有很多种方法可以寻找。
|
||||
|
||||
### find
|
||||
|
||||
最显然的无疑是 `find` 命令,并且 `find` 变得比过去几年更容易使用了。它过去需要一个搜索的起始位置,但是现在,如果你想将搜索限制在当下目录中,你还可以使用仅包含文件名或正则表达式的 `find` 命令。
|
||||
|
||||
```
|
||||
$ find e*
|
||||
empty
|
||||
examples.desktop
|
||||
```
|
||||
|
||||
这样,它就像 `ls` 命令一样工作,并没有做太多的搜索。
|
||||
|
||||
对于更专业的搜索,`find` 命令需要一个起点和一些搜索条件(除非你只是希望它提供该起点目录的递归列表)。命令 `find -type f` 从当前目录开始将递归列出所有常规文件,而 `find ~nemo -type f -empty` 将在 nemo 的主目录中找到空文件。
|
||||
|
||||
```
|
||||
$ find ~nemo -type f -empty
|
||||
/home/nemo/empty
|
||||
```
|
||||
|
||||
参见:[11 个好玩的 Linux 终端技巧][1]。
|
||||
|
||||
### locate
|
||||
|
||||
`locate` 命令的名称表明它与 `find` 命令基本相同,但它的工作原理完全不同。`find` 命令可以根据各种条件 —— 名称、大小、所有者、权限、状态(如空文件)等等选择文件并作为搜索选择深度,`locate` 命令通过名为 `/var/lib/mlocate/mlocate.db` 的文件查找你要查找的内容。该数据文件会定期更新,因此你刚创建的文件的位置它可能无法找到。如果这让你感到困扰,你可以运行 `updatedb` 命令立即获得更新。
|
||||
|
||||
```
|
||||
$ sudo updatedb
|
||||
```
|
||||
|
||||
### mlocate
|
||||
|
||||
`mlocate` 命令的工作类似于 `locate` 命令,它使用与 `locate` 相同的 `mlocate.db` 文件。
|
||||
|
||||
### which
|
||||
|
||||
`which` 命令的工作方式与 `find` 命令和 `locate` 命令有很大的区别。它使用你的搜索路径(`$PATH`)并检查其上的每个目录中具有你要查找的文件名的可执行文件。一旦找到一个,它会停止搜索并显示该可执行文件的完整路径。
|
||||
|
||||
`which` 命令的主要优点是它回答了“如果我输入此命令,将运行什么可执行文件?”的问题。它会忽略不可执行文件,并且不会列出系统上带有该名称的所有可执行文件 —— 列出的就是它找到的第一个。如果你想查找具有某个名称的所有可执行文件,则可以像这样运行 `find` 命令,但是要比非常高效 `which` 命令用更长的时间。
|
||||
|
||||
```
|
||||
$ find / -name locate -perm -a=x 2>/dev/null
|
||||
/usr/bin/locate
|
||||
/etc/alternatives/locate
|
||||
```
|
||||
|
||||
在这个 `find` 命令中,我们在寻找名为 “locate” 的所有可执行文件(任何人都可以运行的文件)。我们也选择了不要查看所有“拒绝访问”的消息,否则这些消息会混乱我们的屏幕。
|
||||
|
||||
### whereis
|
||||
|
||||
`whereis` 命令与 `which` 命令非常类似,但它提供了更多信息。它不仅仅是寻找可执行文件,它还寻找手册页(man page)和源文件。像 `which` 命令一样,它使用搜索路径(`$PATH`) 来驱动搜索。
|
||||
|
||||
```
|
||||
$ whereis locate
|
||||
locate: /usr/bin/locate /usr/share/man/man1/locate.1.gz
|
||||
```
|
||||
|
||||
### whatis
|
||||
|
||||
`whatis` 命令有其独特的使命。它不是实际查找文件,而是在手册页中查找有关所询问命令的信息,并从手册页的顶部提供该命令的简要说明。
|
||||
|
||||
```
|
||||
$ whatis locate
|
||||
locate (1) - find files by name
|
||||
```
|
||||
|
||||
如果你询问你刚刚设置的脚本,它不会知道你指的是什么,并会告诉你。
|
||||
|
||||
```
|
||||
$ whatis cleanup
|
||||
cleanup: nothing appropriate.
|
||||
```
|
||||
|
||||
### apropos
|
||||
|
||||
当你知道你想要做什么,但不知道应该使用什么命令来执行此操作时,`apropos` 命令很有用。例如,如果你想知道如何查找文件,那么 `apropos find` 和 `apropos locate` 会提供很多建议。
|
||||
|
||||
```
|
||||
$ apropos find
|
||||
File::IconTheme (3pm) - find icon directories
|
||||
File::MimeInfo::Applications (3pm) - Find programs to open a file by mimetype
|
||||
File::UserDirs (3pm) - find extra media and documents directories
|
||||
find (1) - search for files in a directory hierarchy
|
||||
findfs (8) - find a filesystem by label or UUID
|
||||
findmnt (8) - find a filesystem
|
||||
gst-typefind-1.0 (1) - print Media type of file
|
||||
ippfind (1) - find internet printing protocol printers
|
||||
locate (1) - find files by name
|
||||
mlocate (1) - find files by name
|
||||
pidof (8) - find the process ID of a running program.
|
||||
sane-find-scanner (1) - find SCSI and USB scanners and their device files
|
||||
systemd-delta (1) - Find overridden configuration files
|
||||
xdg-user-dir (1) - Find an XDG user dir
|
||||
$
|
||||
$ apropos locate
|
||||
blkid (8) - locate/print block device attributes
|
||||
deallocvt (1) - deallocate unused virtual consoles
|
||||
fallocate (1) - preallocate or deallocate space to a file
|
||||
IO::Tty (3pm) - Low-level allocate a pseudo-Tty, import constants.
|
||||
locate (1) - find files by name
|
||||
mlocate (1) - find files by name
|
||||
mlocate.db (5) - a mlocate database
|
||||
mshowfat (1) - shows FAT clusters allocated to file
|
||||
ntfsfallocate (8) - preallocate space to a file on an NTFS volume
|
||||
systemd-sysusers (8) - Allocate system users and groups
|
||||
systemd-sysusers.service (8) - Allocate system users and groups
|
||||
updatedb (8) - update a database for mlocate
|
||||
updatedb.mlocate (8) - update a database for mlocate
|
||||
whereis (1) - locate the binary, source, and manual page files for a...
|
||||
which (1) - locate a command
|
||||
```
|
||||
|
||||
### 总结
|
||||
|
||||
Linux 上可用于查找和识别文件的命令有很多种,但它们都非常有用。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3268768/linux/finding-what-you-re-looking-for-on-linux.html
|
||||
|
||||
作者:[Sandra Henry-Stocker][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.networkworld.com/author/Sandra-Henry_Stocker/
|
||||
[1]:http://www.networkworld.com/article/2926630/linux/11-pointless-but-awesome-linux-terminal-tricks.html#tk.nww-fsb
|
@ -1,10 +1,11 @@
|
||||
4 月 COPR 中 4 个新的酷项目
|
||||
4 月 COPR 中的 4 个新酷项目
|
||||
======
|
||||
|
||||

|
||||
COPR 是一个人仓库[收集][1],它不在 Fedora 中运行。某些软件不符合易于打包的标准。或者它可能不符合其他 Fedora 标准,尽管它是免费且开源的。COPR 可以在 Fedora 套件之外提供这些项目。COPR 中的软件不受 Fedora 基础设施支持或项目签名。但是,它可能是尝试新软件或实验软件的一种很好的方式。
|
||||
|
||||
这是 COPR 中一系列新的和有趣的项目。
|
||||
COPR 是一个个人软件仓库[集合][1],它包含 Fedora 所没有提供的软件。这些软件或不符合易于打包的标准,或者它可能不符合其他 Fedora 标准,尽管它是自由且开源的。COPR 可以在 Fedora 套件之外提供这些项目。COPR 中的软件并没有得到 Fedora 基础设施支持,也没有由该项目背书。但是,它可能是尝试新软件或实验软件的一种很好的方式。
|
||||
|
||||
这是 COPR 中一些新的和有趣的项目。
|
||||
|
||||
### Anki
|
||||
|
||||
@ -17,28 +18,28 @@ COPR 是一个人仓库[收集][1],它不在 Fedora 中运行。某些软件
|
||||
#### 安装说明
|
||||
|
||||
仓库目前为 Fedora 27、28 和 Rawhide 提供 Anki。要安装 Anki,请使用以下命令:
|
||||
|
||||
```
|
||||
sudo dnf copr enable thomasfedb/anki
|
||||
sudo dnf install anki
|
||||
|
||||
```
|
||||
|
||||
### Fd
|
||||
|
||||
[Fd][5] 是一个命令行工具,它是简单而稍快的替代 [find][6] 的方法。它可以并行地查找项目。fd 也使用彩色输出,并默认忽略隐藏文件和 .gitignore 中指定模式的文件。
|
||||
[Fd][5] 是一个命令行工具,它是简单而稍快的替代 [find][6] 的方法。它可以并行地查找项目。fd 也使用彩色输出,并默认忽略隐藏文件和 `.gitignore` 中指定模式的文件。
|
||||
|
||||
#### 安装说明
|
||||
|
||||
仓库目前为 Fedora 26、27、28 和 Rawhide 提供 fd。要安装 fd,请使用以下命令:
|
||||
仓库目前为 Fedora 26、27、28 和 Rawhide 提供 `fd`。要安装 fd,请使用以下命令:
|
||||
|
||||
```
|
||||
sudo dnf copr enable keefle/fd
|
||||
sudo dnf install fd
|
||||
|
||||
```
|
||||
|
||||
### KeePass
|
||||
|
||||
[KeePass][7]是一个密码管理器。它将所有密码保存在一个由主密钥或密钥文件锁定的端对端加密数据库中。密码可以组织成组并由程序的内置生成器生成。其他功能包括自动输入,它可以为选定的表单输入用户名和密码。
|
||||
[KeePass][7] 是一个密码管理器。它将所有密码保存在一个由主密钥或密钥文件锁定的端对端加密数据库中。密码可以组织成组并由程序的内置生成器生成。其他功能包括自动输入,它可以为选定的表单输入用户名和密码。
|
||||
|
||||
虽然 KeePass 已经在 Fedora 中,但这个仓库提供了最新版本。
|
||||
|
||||
@ -47,10 +48,10 @@ sudo dnf install fd
|
||||
#### 安装说明
|
||||
|
||||
仓库目前为 Fedora 26 和 27 提供 KeePass。要安装 KeePass,请使用以下命令:
|
||||
|
||||
```
|
||||
sudo dnf copr enable mavit/keepass
|
||||
sudo dnf install keepass
|
||||
|
||||
```
|
||||
|
||||
### jo
|
||||
@ -60,10 +61,10 @@ sudo dnf install keepass
|
||||
#### 安装说明
|
||||
|
||||
目前,仓库为 Fedora 26、27 和 Rawhide 以及 EPEL 6 和 7 提供 jo。要安装 jo,请使用以下命令:
|
||||
|
||||
```
|
||||
sudo dnf copr enable ganto/jo
|
||||
sudo dnf install jo
|
||||
|
||||
```
|
||||
|
||||
|
||||
@ -72,9 +73,9 @@ sudo dnf install jo
|
||||
via: https://fedoramagazine.org/4-try-copr-april-2018/
|
||||
|
||||
作者:[Dominik Turecek][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,104 +0,0 @@
|
||||
fuzheng1998 translating
|
||||
|
||||
Why Linux is better than Windows or macOS for security
|
||||
======
|
||||
|
||||

|
||||
|
||||
Enterprises invest a lot of time, effort and money in keeping their systems secure. The most security-conscious might have a security operations center. They of course use firewalls and antivirus tools. They probably spend a lot of time monitoring their networks, looking for telltale anomalies that could indicate a breach. What with IDS, SIEM and NGFWs, they deploy a veritable alphabet of defenses.
|
||||
|
||||
But how many have given much thought to one of the cornerstones of their digital operations: the operating systems deployed on the workforce’s PCs? Was security even a factor when the desktop OS was selected?
|
||||
|
||||
This raises a question that every IT person should be able to answer: Which operating system is the most secure for general deployment?
|
||||
|
||||
We asked some experts what they think of the security of these three choices: Windows, the ever-more-complex platform that’s easily the most popular desktop system; macOS X, the FreeBSD Unix-based operating system that powers Apple Macintosh systems; and Linux, by which we mean all the various Linux distributions and related Unix-based systems.
|
||||
|
||||
### How we got here
|
||||
|
||||
One reason enterprises might not have evaluated the security of the OS they deployed to the workforce is that they made the choice years ago. Go back far enough and all operating systems were reasonably safe, because the business of hacking into them and stealing data or installing malware was in its infancy. And once an OS choice is made, it’s hard to consider a change. Few IT organizations would want the headache of moving a globally dispersed workforce to an entirely new OS. Heck, they get enough pushback when they move users to a new version of their OS of choice.
|
||||
|
||||
Still, would it be wise to reconsider? Are the three leading desktop OSes different enough in their approach to security to make a change worthwhile?
|
||||
|
||||
Certainly the threats confronting enterprise systems have changed in the last few years. Attacks have become far more sophisticated. The lone teen hacker that once dominated the public imagination has been supplanted by well-organized networks of criminals and shadowy, government-funded organizations with vast computing resources.
|
||||
|
||||
Like many of you, I have firsthand experience of the threats that are out there: I have been infected by malware and viruses on numerous Windows computers, and I even had macro viruses that infected files on my Mac. More recently, a widespread automated hack circumvented the security on my website and infected it with malware. The effects of such malware were always initially subtle, something you wouldn’t even notice, until the malware ended up so deeply embedded in the system that performance started to suffer noticeably. One striking thing about the infestations was that I was never specifically targeted by the miscreants; nowadays, it’s as easy to attack 100,000 computers with a botnet as it is to attack a dozen.
|
||||
|
||||
### Does the OS really matter?
|
||||
|
||||
The OS you deploy to your users does make a difference for your security stance, but it isn’t a sure safeguard. For one thing, a breach these days is more likely to come about because an attacker probed your users, not your systems. A [survey][1] of hackers who attended a recent DEFCON conference revealed that “84 percent use social engineering as part of their attack strategy.” Deploying a secure operating system is an important starting point, but without user education, strong firewalls and constant vigilance, even the most secure networks can be invaded. And of course there’s always the risk of user-downloaded software, extensions, utilities, plug-ins and other software that appears benign but becomes a path for malware to appear on the system.
|
||||
|
||||
And no matter which platform you choose, one of the best ways to keep your system secure is to ensure that you apply software updates promptly. Once a patch is in the wild, after all, the hackers can reverse engineer it and find a new exploit they can use in their next wave of attacks.
|
||||
|
||||
And don’t forget the basics. Don’t use root, and don’t grant guest access to even older servers on the network. Teach your users how to pick really good passwords and arm them with tools such as [1Password][2] that make it easier for them to have different passwords on every account and website they use.
|
||||
|
||||
Because the bottom line is that every decision you make regarding your systems will affect your security, even the operating system your users do their work on.
|
||||
|
||||
**[ To comment on this story, visit[Computerworld's Facebook page][3]. ]**
|
||||
|
||||
### Windows, the popular choice
|
||||
|
||||
If you’re a security manager, it is extremely likely that the questions raised by this article could be rephrased like so: Would we be more secure if we moved away from Microsoft Windows? To say that Windows dominates the enterprise market is to understate the case. [NetMarketShare][4] estimates that a staggering 88% of all computers on the internet are running a version of Windows.
|
||||
|
||||
If your systems fall within that 88%, you’re probably aware that Microsoft has continued to beef up security in the Windows system. Among its improvements have been rewriting and re-rewriting its operating system codebase, adding its own antivirus software system, improving firewalls and implementing a sandbox architecture, where programs can’t access the memory space of the OS or other applications.
|
||||
|
||||
But the popularity of Windows is a problem in itself. The security of an operating system can depend to a large degree on the size of its installed base. For malware authors, Windows provides a massive playing field. Concentrating on it gives them the most bang for their efforts.
|
||||
As Troy Wilkinson, CEO of Axiom Cyber Solutions, explains, “Windows always comes in last in the security world for a number of reasons, mainly because of the adoption rate of consumers. With a large number of Windows-based personal computers on the market, hackers historically have targeted these systems the most.”
|
||||
|
||||
It’s certainly true that, from Melissa to WannaCry and beyond, much of the malware the world has seen has been aimed at Windows systems.
|
||||
|
||||
### macOS X and security through obscurity
|
||||
|
||||
If the most popular OS is always going to be the biggest target, then can using a less popular option ensure security? That idea is a new take on the old — and entirely discredited — concept of “security through obscurity,” which held that keeping the inner workings of software proprietary and therefore secret was the best way to defend against attacks.
|
||||
|
||||
Wilkinson flatly states that macOS X “is more secure than Windows,” but he hastens to add that “macOS used to be considered a fully secure operating system with little chance of security flaws, but in recent years we have seen hackers crafting additional exploits against macOS.”
|
||||
|
||||
In other words, the attackers are branching out and not ignoring the Mac universe.
|
||||
|
||||
Security researcher Lee Muson of Comparitech says that “macOS is likely to be the pick of the bunch” when it comes to choosing a more secure OS, but he cautions that it is not impenetrable, as once thought. Its advantage is that “it still benefits from a touch of security through obscurity versus the still much larger target presented by Microsoft’s offering.”
|
||||
|
||||
Joe Moore of Wolf Solutions gives Apple a bit more credit, saying that “off the shelf, macOS X has a great track record when it comes to security, in part because it isn’t as widely targeted as Windows and in part because Apple does a pretty good job of staying on top of security issues.”
|
||||
|
||||
### And the winner is …
|
||||
|
||||
You probably knew this from the beginning: The clear consensus among experts is that Linux is the most secure operating system. But while it’s the OS of choice for servers, enterprises deploying it on the desktop are few and far between.
|
||||
|
||||
And if you did decide that Linux was the way to go, you would still have to decide which distribution of the Linux system to choose, and things get a bit more complicated there. Users are going to want a UI that seems familiar, and you are going to want the most secure OS.
|
||||
|
||||
As Moore explains, “Linux has the potential to be the most secure, but requires the user be something of a power user.” So, not for everyone.
|
||||
|
||||
Linux distros that target security as a primary feature include [Parrot Linux][5], a Debian-based distro that Moore says provides numerous security-related tools right out of the box.
|
||||
|
||||
Of course, an important differentiator is that Linux is open source. The fact that coders can read and comment upon each other’s work might seem like a security nightmare, but it actually turns out to be an important reason why Linux is so secure, says Igor Bidenko, CISO of Simplex Solutions. “Linux is the most secure OS, as its source is open. Anyone can review it and make sure there are no bugs or back doors.”
|
||||
|
||||
Wilkinson elaborates that “Linux and Unix-based operating systems have less exploitable security flaws known to the information security world. Linux code is reviewed by the tech community, which lends itself to security: By having that much oversight, there are fewer vulnerabilities, bugs and threats.”
|
||||
|
||||
That’s a subtle and perhaps counterintuitive explanation, but by having dozens — or sometimes hundreds — of people read through every line of code in the operating system, the code is actually more robust and the chance of flaws slipping into the wild is diminished. That had a lot to do with why PC World came right out and said Linux is more secure. As Katherine Noyes [explains][6], “Microsoft may tout its large team of paid developers, but it’s unlikely that team can compare with a global base of Linux user-developers around the globe. Security can only benefit through all those extra eyeballs.”
|
||||
|
||||
Another factor cited by PC World is Linux’s better user privileges model: Windows users “are generally given administrator access by default, which means they pretty much have access to everything on the system,” according to Noyes’ article. Linux, in contrast, greatly restricts “root.”
|
||||
|
||||
Noyes also noted that the diversity possible within Linux environments is a better hedge against attacks than the typical Windows monoculture: There are simply a lot of different distributions of Linux available. And some of them are differentiated in ways that specifically address security concerns. Security Researcher Lee Muson of Comparitech offers this suggestion for a Linux distro: “The[Qubes OS][7] is as good a starting point with Linux as you can find right now, with an [endorsement from Edward Snowden][8] massively overshadowing its own extremely humble claims.” Other security experts point to specialized secure Linux distributions such as [Tails Linux][9], designed to run securely and anonymously directly from a USB flash drive or similar external device.
|
||||
|
||||
### Building security momentum
|
||||
|
||||
Inertia is a powerful force. Although there is clear consensus that Linux is the safest choice for the desktop, there has been no stampede to dump Windows and Mac machines in favor of it. Nonetheless, a small but significant increase in Linux adoption would probably result in safer computing for everyone, because in market share loss is one sure way to get Microsoft’s and Apple’s attention. In other words, if enough users switch to Linux on the desktop, Windows and Mac PCs are very likely to become more secure platforms.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.computerworld.com/article/3252823/linux/why-linux-is-better-than-windows-or-macos-for-security.html
|
||||
|
||||
作者:[Dave Taylor][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.computerworld.com/author/Dave-Taylor/
|
||||
[1]:https://www.esecurityplanet.com/hackers/fully-84-percent-of-hackers-leverage-social-engineering-in-attacks.html
|
||||
[2]:http://www.1password.com
|
||||
[3]:https://www.facebook.com/Computerworld/posts/10156160917029680
|
||||
[4]:https://www.netmarketshare.com/operating-system-market-share.aspx?options=%7B%22filter%22%3A%7B%22%24and%22%3A%5B%7B%22deviceType%22%3A%7B%22%24in%22%3A%5B%22Desktop%2Flaptop%22%5D%7D%7D%5D%7D%2C%22dateLabel%22%3A%22Trend%22%2C%22attributes%22%3A%22share%22%2C%22group%22%3A%22platform%22%2C%22sort%22%3A%7B%22share%22%3A-1%7D%2C%22id%22%3A%22platformsDesktop%22%2C%22dateInterval%22%3A%22Monthly%22%2C%22dateStart%22%3A%222017-02%22%2C%22dateEnd%22%3A%222018-01%22%2C%22segments%22%3A%22-1000%22%7D
|
||||
[5]:https://www.parrotsec.org/
|
||||
[6]:https://www.pcworld.com/article/202452/why_linux_is_more_secure_than_windows.html
|
||||
[7]:https://www.qubes-os.org/
|
||||
[8]:https://twitter.com/snowden/status/781493632293605376?lang=en
|
||||
[9]:https://tails.boum.org/about/index.en.html
|
@ -1,101 +0,0 @@
|
||||
translating---geekpi
|
||||
|
||||
|
||||
Easily Install Android Studio in Ubuntu And Linux Mint
|
||||
======
|
||||
[Android Studio][1], Google’s own IDE for Android development, is a nice alternative to Eclipse with ADT plugin. Android Studio can be installed from its source code but in this quick post, we shall see **how to install Android Studio in Ubuntu 18.04, 16.04 and corresponding Linux Mint variants**.
|
||||
|
||||
Before you proceed to install Android Studio, make sure that you have [Java installed in Ubuntu][2].
|
||||
|
||||
![How to install Android Studio in Ubuntu][3]
|
||||
|
||||
### Install Android Studio in Ubuntu and other distributions using Snap
|
||||
|
||||
Ever since Ubuntu started focusing on Snap packages, more software have started providing easy to install Snap packages. Android Studio is one of them. Ubuntu users can simply find the Android Studio application in the Software Center and install it from there.
|
||||
|
||||
![Install Android Studio in Ubuntu from Software Center][4]
|
||||
|
||||
If you see an error while installing Android Studio from Software Center, you can use the [Snap commands][5] to install Android studio.
|
||||
```
|
||||
sudo snap install android-studio --classic
|
||||
|
||||
```
|
||||
|
||||
Easy peasy!
|
||||
|
||||
### Alternative Method 1: Install Android Studio using umake in Ubuntu
|
||||
|
||||
You can also easily install Android Studio using Ubuntu Developer Tools Center, now known as [Ubuntu Make][6]. Ubuntu Make provides a command line tool to install various development tools, IDE etc. Ubuntu Make is available in Ubuntu repository.
|
||||
|
||||
To install Ubuntu Make, use the commands below in a terminal:
|
||||
|
||||
`sudo apt-get install ubuntu-make`
|
||||
|
||||
Once you have installed Ubuntu Make, use the command below to install Android Studio in Ubuntu:
|
||||
```
|
||||
umake android
|
||||
|
||||
```
|
||||
|
||||
It will give you a couple of options in the course of the installation. I presume that you can handle it. If you decide to uninstall Android Studio, you can use the same umake tool in the following manner:
|
||||
```
|
||||
umake android --remove
|
||||
|
||||
```
|
||||
|
||||
### Alternative Method 2: Install Android Studio in Ubuntu and Linux Mint via unofficial PPA
|
||||
|
||||
Thanks to [Paolo Ratolo][7], we have a PPA which can be used to easily install Android Studio in Ubuntu 16.04, 14.04, Linux Mint and other Ubuntu based distributions. Just note that it will download around 650 MB of data. So mind your internet connection as well as data charges (if any).
|
||||
|
||||
Open a terminal and use the following commands:
|
||||
```
|
||||
sudo apt-add-repository ppa:paolorotolo/android-studio
|
||||
sudo apt-get update
|
||||
sudo apt-get install android-studio
|
||||
|
||||
```
|
||||
|
||||
Was it not easy? While installing a program from source code is fun in a way, it is always nice to have such PPAs. Once we have seen how to install Android Studio, lets see how to uninstall it.
|
||||
|
||||
### Uninstall Android Studio:
|
||||
|
||||
If you don’t have already, install PPA Purge:
|
||||
```
|
||||
sudo apt-get install ppa-purge
|
||||
|
||||
```
|
||||
|
||||
Now use the PPA Purge to purge the installed PPA:
|
||||
```
|
||||
sudo apt-get remove android-studio
|
||||
|
||||
sudo ppa-purge ppa:paolorotolo/android-studio
|
||||
|
||||
```
|
||||
|
||||
That’s it. I hope this quick helps you to **install Android Studio in Ubuntu and Linux Mint**. Before you run Android Studio, make sure to [install Java in Ubuntu][8] first. In similar posts, I advise you to read [how to install and configure Ubuntu SDK][9] and [how to easily install Microsoft Visual Studio in Ubuntu][10].
|
||||
|
||||
Any questions or suggestions are always welcomed. Ciao :)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/install-android-studio-ubuntu-linux/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://itsfoss.com/author/abhishek/
|
||||
[1]:http://developer.android.com/sdk/installing/studio.html
|
||||
[2]:https://itsfoss.com/install-java-ubuntu-1404/
|
||||
[3]:https://itsfoss.com/wp-content/uploads/2014/04/Android_Studio_Ubuntu.jpeg
|
||||
[4]:https://itsfoss.com/wp-content/uploads/2014/04/install-android-studio-snap-800x469.jpg
|
||||
[5]:https://itsfoss.com/install-snap-linux/
|
||||
[6]:https://wiki.ubuntu.com/ubuntu-make
|
||||
[7]:https://plus.google.com/+PaoloRotolo
|
||||
[8]:https://itsfoss.com/install-java-ubuntu-1404/ (How To Install Java On Ubuntu 14.04)
|
||||
[9]:https://itsfoss.com/install-configure-ubuntu-sdk/
|
||||
[10]:https://itsfoss.com/install-visual-studio-code-ubuntu/
|
@ -1,3 +1,6 @@
|
||||
Translating by MjSeven
|
||||
|
||||
|
||||
Getting Started with Taskwarrior
|
||||
======
|
||||
Taskwarrior is a flexible [command-line task management program][1]. In their [own words][2]:
|
||||
|
@ -1,3 +1,5 @@
|
||||
translating---geekpi
|
||||
|
||||
HeRM’s - A Commandline Food Recipes Manager
|
||||
======
|
||||

|
||||
|
@ -1,113 +0,0 @@
|
||||
2 scientific calculators for the Linux desktop
|
||||
======
|
||||
|
||||
Translating by zyk2290
|
||||
|
||||

|
||||
|
||||
Image by : opensource.com
|
||||
|
||||
Every Linux desktop environment comes with at least a simple desktop calculator, but most of those simple calculators are just that: a simple tool for simple calculations.
|
||||
|
||||
Fortunately, there are exceptions; programs that go far beyond square roots and a couple of trigonometric functions, yet are still easy to use. Here are two powerful calculator tools for Linux, plus a couple of bonus options.
|
||||
|
||||
### SpeedCrunch
|
||||
|
||||
[SpeedCrunch][1] is a high-precision scientific calculator with a simple Qt5 graphical interface and strong focus on the keyboard.
|
||||
|
||||
![SpeedCrunch graphical interface][3]
|
||||
|
||||
|
||||
SpeedCrunch at work
|
||||
|
||||
It supports working with units and comes loaded with all kinds of functions.
|
||||
|
||||
For example, by writing:
|
||||
`2 * 10^6 newton / (meter^2)`
|
||||
|
||||
you get:
|
||||
`= 2000000 pascal`
|
||||
|
||||
By default, SpeedCrunch delivers its results in the international unit system, but units can be transformed with the "in" instruction.
|
||||
|
||||
For example:
|
||||
`3*10^8 meter / second in kilo meter / hour`
|
||||
|
||||
produces:
|
||||
`= 1080000000 kilo meter / hour`
|
||||
|
||||
With the `F5` key, all results will turn into scientific notation (`1.08e9 kilo meter / hour`), while with `F2` only numbers that are small enough or big enough will change. More options are available on the Configuration menu.
|
||||
|
||||
The list of available functions is really impressive. It works on Linux, Windows, and MacOS, and it's licensed under GPLv2; you can access its source code on [Bitbucket][4].
|
||||
|
||||
### Qalculate!
|
||||
|
||||
[Qalculate!][5] (with the exclamation point) has a long and complex history.
|
||||
|
||||
The project offers a powerful library that can be used by other programs (the Plasma desktop can use it to perform calculations from krunner) and a graphical interface built on GTK3. It allows you to work with units, handle physical constants, create graphics, use complex numbers, matrices, and vectors, choose arbitrary precision, and more.
|
||||
|
||||
|
||||
![Qalculate! Interface][7]
|
||||
|
||||
|
||||
Looking for some physical constants on Qalculate!
|
||||
|
||||
Its use of units is far more intuitive than SpeedCrunch's and it understands common prefixes without problem. Have you heard of an exapascal pressure? I hadn't (the Sun's core stops at `~26 PPa`), but Qalculate! has no problem understanding the meaning of `1 EPa`. Also, Qalculate! is more flexible with syntax errors, so you don't need to worry about closing all those parentheses: if there is no ambiguity, Qalculate! will give you the right answer.
|
||||
|
||||
After a long period on which the project seemed orphaned, it came back to life in 2016 and has been going strong since, with more than 10 versions in just one year. It's licensed under GPLv2 (with source code on [GitHub][8]) and offers versions for Linux and Windows, as well as a MacOS port.
|
||||
|
||||
### Bonus calculators
|
||||
|
||||
#### ConvertAll
|
||||
|
||||
OK, it's not a "calculator," yet this simple application is incredibly useful.
|
||||
|
||||
Most unit converters stop at a long list of basic units and a bunch of common combinations, but not [ConvertAll][9]. Trying to convert from astronomical units per year into inches per second? It doesn't matter if it makes sense or not, if you need to transform a unit of any kind, ConvertAll is the tool for you.
|
||||
|
||||
Just write the starting unit and the final unit in the corresponding boxes; if the units are compatible, you'll get the transformation without protest.
|
||||
|
||||
The main application is written in PyQt5, but there is also an [online version written in JavaScript][10].
|
||||
|
||||
#### (wx)Maxima with the units package
|
||||
|
||||
Sometimes (OK, many times) a desktop calculator is not enough and you need more raw power.
|
||||
|
||||
[Maxima][11] is a computer algebra system (CAS) with which you can do derivatives, integrals, series, equations, eigenvectors and eigenvalues, Taylor series, Laplace and Fourier transformations, as well as numerical calculations with arbitrary precision, graph on two and three dimensions… we could fill several pages just listing its capabilities.
|
||||
|
||||
[wxMaxima][12] is a well-designed graphical frontend for Maxima that simplifies the use of many Maxima options without compromising others. On top of the full power of Maxima, wxMaxima allows you to create "notebooks" on which you write comments, keep your graphics with your math, etc. One of the (wx)Maxima combo's most impressive features is that it works with dimension units.
|
||||
|
||||
On the prompt, just type:
|
||||
`load("unit")`
|
||||
|
||||
press Shift+Enter, wait a few seconds, and you'll be ready to work.
|
||||
|
||||
By default, the unit package works with the basic MKS units, but if you prefer, for instance, to get `N` instead of `kg*m/s2`, you just need to type:
|
||||
`setunits(N)`
|
||||
|
||||
Maxima's help (which is also available from wxMaxima's help menu) will give you more information.
|
||||
|
||||
Do you use these programs? Do you know another great desktop calculator for scientists and engineers or another related tool? Tell us about them in the comments!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/1/scientific-calculators-linux
|
||||
|
||||
作者:[Ricardo Berlasso][a]
|
||||
译者:[译者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/rgb-es
|
||||
[1]:http://speedcrunch.org/index.html
|
||||
[2]:/file/382511
|
||||
[3]:https://opensource.com/sites/default/files/u128651/speedcrunch.png (SpeedCrunch graphical interface)
|
||||
[4]:https://bitbucket.org/heldercorreia/speedcrunch
|
||||
[5]:https://qalculate.github.io/
|
||||
[6]:/file/382506
|
||||
[7]:https://opensource.com/sites/default/files/u128651/qalculate-600.png (Qalculate! Interface)
|
||||
[8]:https://github.com/Qalculate
|
||||
[9]:http://convertall.bellz.org/
|
||||
[10]:http://convertall.bellz.org/js/
|
||||
[11]:http://maxima.sourceforge.net/
|
||||
[12]:https://andrejv.github.io/wxmaxima/
|
@ -1,95 +0,0 @@
|
||||
translating---geekpi
|
||||
|
||||
Enhance your Python with an interactive shell
|
||||
======
|
||||

|
||||
The Python programming language has become one of the most popular languages used in IT. One reason for this success is it can be used to solve a variety of problems. From web development to data science, machine learning to task automation, the Python ecosystem is rich in popular frameworks and libraries. This article presents some useful Python shells available in the Fedora packages collection to make development easier.
|
||||
|
||||
### Python Shell
|
||||
|
||||
The Python Shell lets you use the interpreter in an interactive mode. It’s very useful to test code or try a new library. In Fedora you can invoke the default shell by typing python3 in a terminal session. Some more advanced and enhanced shells are available to Fedora, though.
|
||||
|
||||
### IPython
|
||||
|
||||
IPython provides many useful enhancements to the Python shell. Examples include tab completion, object introspection, system shell access and command history retrieval. Many of these features are also used by the [Jupyter Notebook][1] , since it uses IPython underneath.
|
||||
|
||||
#### Install and run IPython
|
||||
```
|
||||
dnf install ipython3
|
||||
ipython3
|
||||
|
||||
```
|
||||
|
||||
Using tab completion prompts you with possible choices. This features comes in handy when you use an unfamiliar library.
|
||||
|
||||
![][2]
|
||||
|
||||
If you need more information, use the documentation by typing the ? command. For more details, you can use the ?? command.
|
||||
|
||||
![][3]
|
||||
|
||||
Another cool feature is the ability to execute a system shell command using the ! character. The result of the command can then be referenced in the IPython shell.
|
||||
|
||||
![][4]
|
||||
|
||||
A comprehensive list of IPython features is available in the [official documentation][5].
|
||||
|
||||
### bpython
|
||||
|
||||
bpython doesn’t do as much as IPython, but nonetheless it provides a useful set of features in a simple and lightweight package. Among other features, bpython provides:
|
||||
|
||||
* In-line syntax highlighting
|
||||
* Autocomplete with suggestions as you type
|
||||
* Expected parameter list
|
||||
* Ability to send or save code to a pastebin service or file
|
||||
|
||||
|
||||
|
||||
#### Install and run bpython
|
||||
```
|
||||
dnf install bpython3
|
||||
bpython3
|
||||
|
||||
```
|
||||
|
||||
As you type, bpython offers you choices to autocomplete your code.
|
||||
|
||||
![][6]
|
||||
|
||||
When you call a function or method, the expected parameters and the docstring are automatically displayed.
|
||||
|
||||
![][7]
|
||||
|
||||
Another neat feature is the ability to open the current bpython session in an external editor (Vim by default) using the function key F7. This is very useful when testing more complex programs.
|
||||
|
||||
For more details about configuration and features, consult the bpython [documentation][8].
|
||||
|
||||
### Conclusion
|
||||
|
||||
Using an enhanced Python shell is a good way to increase productivity. It gives you enhanced features to write a quick prototype or try out a new library. Are you using an enhanced Python shell? Feel free to mention it in the comment section below.
|
||||
|
||||
Photo by [David Clode][9] on [Unsplash][10]
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/enhance-python-interactive-shell/
|
||||
|
||||
作者:[Clément Verna][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://fedoramagazine.org/author/cverna/
|
||||
[1]:https://ipython.org/notebook.html
|
||||
[2]:https://fedoramagazine.org/wp-content/uploads/2018/03/ipython-tabcompletion.png
|
||||
[3]:https://fedoramagazine.org/wp-content/uploads/2018/03/ipyhton_doc1.png
|
||||
[4]:https://fedoramagazine.org/wp-content/uploads/2018/03/ipython_shell.png
|
||||
[5]:https://ipython.readthedocs.io/en/stable/overview.html#main-features-of-the-interactive-shell
|
||||
[6]:https://fedoramagazine.org/wp-content/uploads/2018/03/bpython1.png
|
||||
[7]:https://fedoramagazine.org/wp-content/uploads/2018/03/bpython2.png
|
||||
[8]:https://docs.bpython-interpreter.org/
|
||||
[9]:https://unsplash.com/photos/d0CasEMHDQs?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
||||
[10]:https://unsplash.com/search/photos/python?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
@ -1,3 +1,5 @@
|
||||
icecoobe translating
|
||||
|
||||
How to Compile a Linux Kernel
|
||||
======
|
||||
|
||||
|
@ -1,92 +0,0 @@
|
||||
translating---geekpi
|
||||
|
||||
How to use FIND in Linux
|
||||
======
|
||||
|
||||

|
||||
|
||||
In [a recent Opensource.com article][1], Lewis Cowles introduced the `find` command.
|
||||
|
||||
`find` is one of the more powerful and flexible command-line programs in the daily toolbox, so it's worth spending a little more time on it.
|
||||
|
||||
At a minimum, `find` takes a path to find things. For example:
|
||||
```
|
||||
find /
|
||||
|
||||
```
|
||||
|
||||
will find (and print) every file on the system. And since everything is a file, you will get a lot of output to sort through. This probably doesn't help you find what you're looking for. You can change the path argument to narrow things down a bit, but it's still not really any more helpful than using the `ls` command. So you need to think about what you're trying to locate.
|
||||
|
||||
Perhaps you want to find all the JPEG files in your home directory. The `-name` argument allows you to restrict your results to files that match the given pattern.
|
||||
```
|
||||
find ~ -name '*jpg'
|
||||
|
||||
```
|
||||
|
||||
But wait! What if some of them have an uppercase extension? `-iname` is like `-name`, but it is case-insensitive.
|
||||
```
|
||||
find ~ -iname '*jpg'
|
||||
|
||||
```
|
||||
|
||||
Great! But the 8.3 name scheme is so 1985. Some of the pictures might have a .jpeg extension. Fortunately, we can combine patterns with an "or," represented by `-o`.
|
||||
```
|
||||
find ~ ( -iname 'jpeg' -o -iname 'jpg' )
|
||||
|
||||
```
|
||||
|
||||
We're getting closer. But what if you have some directories that end in jpg? (Why you named a directory `bucketofjpg` instead of `pictures` is beyond me.) We can modify our command with the `-type` argument to look only for files.
|
||||
```
|
||||
find ~ \( -iname '*jpeg' -o -iname '*jpg' \) -type f
|
||||
|
||||
```
|
||||
|
||||
Or maybe you'd like to find those oddly named directories so you can rename them later:
|
||||
```
|
||||
find ~ \( -iname '*jpeg' -o -iname '*jpg' \) -type d
|
||||
|
||||
```
|
||||
|
||||
It turns out you've been taking a lot of pictures lately, so let's narrow this down to files that have changed in the last week.
|
||||
```
|
||||
find ~ \( -iname '*jpeg' -o -iname '*jpg' \) -type f -mtime -7
|
||||
|
||||
```
|
||||
|
||||
`ctime`), modification time (`mtime`), or access time (`atime`). These are in days, so if you want finer-grained control, you can express it in minutes instead (`cmin`, `mmin`, and `amin`, respectively). Unless you know exactly the time you want, you'll probably prefix the number with `+` (more than) or `–` (less than).
|
||||
|
||||
You can do time filters based on file status change time (), modification time (), or access time (). These are in days, so if you want finer-grained control, you can express it in minutes instead (, and, respectively). Unless you know exactly the time you want, you'll probably prefix the number with(more than) or(less than).
|
||||
|
||||
But maybe you don't care about your pictures. Maybe you're running out of disk space, so you want to find all the gigantic (let's define that as "greater than 1 gigabyte") files in the `log` directory:
|
||||
```
|
||||
find /var/log -size +1G
|
||||
|
||||
```
|
||||
|
||||
Or maybe you want to find all the files owned by bcotton in `/data`:
|
||||
```
|
||||
find /data -owner bcotton
|
||||
|
||||
```
|
||||
|
||||
You can also look for files based on permissions. Perhaps you want to find all the world-readable files in your home directory to make sure you're not oversharing.
|
||||
```
|
||||
find ~ -perm -o=r
|
||||
|
||||
```
|
||||
|
||||
This post only scratches the surface of what `find` can do. Combining tests with Boolean logic can give you incredible flexibility to find exactly the files you're looking for. And with arguments like `-exec` or `-delete`, you can have `find` take action on what it... finds. Have any favorite `find` expressions? Share them in the comments!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/4/how-use-find-linux
|
||||
|
||||
作者:[Ben Cotton][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者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/bcotton
|
||||
[1]:https://opensource.com/article/18/4/how-find-files-linux
|
@ -1,3 +1,5 @@
|
||||
translating---geekpi
|
||||
|
||||
Easily Search And Install Google Web Fonts In Linux
|
||||
======
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
translating---geekpi
|
||||
|
||||
How to build container images with Buildah
|
||||
======
|
||||
|
||||
|
230
sources/tech/20180504 A Beginners Guide To Cron Jobs.md
Normal file
230
sources/tech/20180504 A Beginners Guide To Cron Jobs.md
Normal file
@ -0,0 +1,230 @@
|
||||
A Beginners Guide To Cron Jobs
|
||||
======
|
||||
|
||||

|
||||
**Cron** is one of the most useful utility that you can find in any Unix-like operating system. It is used to schedule commands at a specific time. These scheduled commands or tasks are known as “Cron Jobs”. Cron is generally used for running scheduled backups, monitoring disk space, deleting files (for example log files) periodically which are no longer required, running system maintenance tasks and a lot more. In this brief guide, we will see the basic usage of Cron Jobs in Linux.
|
||||
|
||||
### The Beginners Guide To Cron Jobs
|
||||
|
||||
The typical format of a cron job is:
|
||||
```
|
||||
Minute(0-59) Hour(0-24) Day_of_month(1-31) Month(1-12) Day_of_week(0-6) Command_to_execute
|
||||
|
||||
```
|
||||
|
||||
Just memorize the cron job format or print the following illustration and keep it in your desk.
|
||||
|
||||
![][2]
|
||||
|
||||
In the above picture, the asterisks refers the specific blocks of time.
|
||||
|
||||
To display the contents of the **crontab** file of the currently logged in user:
|
||||
```
|
||||
$ crontab -l
|
||||
|
||||
```
|
||||
|
||||
To edit the current user’s cron jobs, do:
|
||||
```
|
||||
$ crontab -e
|
||||
|
||||
```
|
||||
|
||||
If it is the first time, you will be asked to editor to edit the jobs.
|
||||
```
|
||||
no crontab for sk - using an empty one
|
||||
|
||||
Select an editor. To change later, run 'select-editor'.
|
||||
1. /bin/nano <---- easiest
|
||||
2. /usr/bin/vim.basic
|
||||
3. /usr/bin/vim.tiny
|
||||
4. /bin/ed
|
||||
|
||||
Choose 1-4 [1]:
|
||||
|
||||
```
|
||||
|
||||
Choose any one that suits you. Here it is how a sample crontab file looks like.
|
||||
|
||||
![][3]
|
||||
|
||||
In this file, you need to add your cron jobs.
|
||||
|
||||
To edit the crontab of a different user, for example ostechnix, do:
|
||||
```
|
||||
$ crontab -u ostechnix -e
|
||||
|
||||
```
|
||||
|
||||
Let us see some examples.
|
||||
|
||||
To run a cron job **every minute** , the format should be like below.
|
||||
```
|
||||
* * * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
To run cron job every 5 minute, add the following in your crontab file.
|
||||
```
|
||||
*/5 * * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
To run a cron job at every quarter hour (every 15th minute), add this:
|
||||
```
|
||||
*/15 * * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
To run a cron job every hour at 30 minutes, run:
|
||||
```
|
||||
30 * * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
You can also define multiple time intervals separated by commas. For example, the following cron job will run three times every hour, at minutes 0, 5 and 10:
|
||||
```
|
||||
0,5,10 * * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a cron job every half hour:
|
||||
```
|
||||
*/30 * * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job every hour:
|
||||
```
|
||||
0 * * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job every 2 hours:
|
||||
```
|
||||
0 */2 * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job every day (It will run at 00:00):
|
||||
```
|
||||
0 0 * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job every day at 3am:
|
||||
```
|
||||
0 3 * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job every sunday:
|
||||
```
|
||||
0 0 * * SUN <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Or,
|
||||
```
|
||||
0 0 * * 0 <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
It will run at exactly at 00:00 on Sunday.
|
||||
|
||||
Run a job on every day-of-week from Monday through Friday i.e every weekday:
|
||||
```
|
||||
0 0 * * 1-5 <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
The job will start at 00:00.
|
||||
|
||||
Run a job every month:
|
||||
```
|
||||
0 0 1 * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job at 16:15 on day-of-month 1:
|
||||
```
|
||||
15 16 1 * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job at every quarter i.e on day-of-month 1 in every 3rd month:
|
||||
```
|
||||
0 0 1 */3 * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job on a specific month at a specific time:
|
||||
```
|
||||
5 0 * 4 * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
The job will start at 00:05 in April.
|
||||
|
||||
Run a job every 6 months:
|
||||
```
|
||||
0 0 1 */6 * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
This cron job will start at 00:00 on day-of-month 1 in every 6th month.
|
||||
|
||||
Run a job every year:
|
||||
```
|
||||
0 0 1 1 * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
This cron job will start at 00:00 on day-of-month 1 in January.
|
||||
|
||||
We can also use the following strings to define job.
|
||||
|
||||
@reboot Run once, at startup. @yearly Run once a year. @annually (same as @yearly). @monthly Run once a month. @weekly Run once a week. @daily Run once a day. @midnight (same as @daily). @hourly Run once an hour.
|
||||
|
||||
For example, to run a job every time the server is rebooted, add this line in your crontab file.
|
||||
```
|
||||
@reboot <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
To remove all cron jobs for the current user:
|
||||
```
|
||||
$ crontab -r
|
||||
|
||||
```
|
||||
|
||||
There is also a dedicated website named [**crontab.guru**][4] for learning cron jobs examples. This site provides a lot of cron job examples.
|
||||
|
||||
For more details, check man pages.
|
||||
```
|
||||
$ man crontab
|
||||
|
||||
```
|
||||
|
||||
And, that’s all for now. At this point, you might have a basic understanding of cron jobs and how to use them in real time. More good stuffs to come. Stay tuned!!
|
||||
|
||||
Cheers!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/a-beginners-guide-to-cron-jobs/
|
||||
|
||||
作者:[SK][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.ostechnix.com/author/sk/
|
||||
[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[2]:http://www.ostechnix.com/wp-content/uploads/2018/05/cron-job-format-1.png
|
||||
[3]:http://www.ostechnix.com/wp-content/uploads/2018/05/cron-jobs-1.png
|
||||
[4]:https://crontab.guru/
|
75
sources/tech/20180507 4 Firefox extensions to install now.md
Normal file
75
sources/tech/20180507 4 Firefox extensions to install now.md
Normal file
@ -0,0 +1,75 @@
|
||||
4 Firefox extensions to install now
|
||||
======
|
||||

|
||||
As I mentioned in my [original article][1] on Firefox extensions, the web browser has become a critical component of the computing experience for many users. Modern browsers have evolved into powerful and extensible platforms, and extensions can add or modify their functionality. Extensions for Firefox are built using the WebExtensions API, a cross-browser development system.
|
||||
|
||||
In the first article, I asked readers: "Which extensions should you install?" To reiterate, that decision largely comes down to how you use your browser, your views on privacy, how much you trust extension developers, and other personal preferences. Since that article was published, one extension I recommended (Xmarks) has been discontinued. Additionally, that article received a ton of feedback that has been taken into account for this update.
|
||||
|
||||
Once again, I'd like to point out that browser extensions often require the ability to read and/or change everything on the web pages you visit. You should consider the ramifications of this very carefully. If an extension has modify access to all the web pages you visit, it could act as a keylogger, intercept credit card information, track you online, insert advertisements, and perform a variety of other nefarious activities. That doesn't mean every extension will surreptitiously do these things, but you should carefully consider the installation source, the permissions involved, your risk profile, and other factors before you install any extension. Keep in mind you can use profiles to manage how an extension impacts your attack surface—for example, using a dedicated profile with no extensions to perform tasks such as online banking.
|
||||
|
||||
With that in mind, here are four open source Firefox extensions you may want to consider.
|
||||
|
||||
### uBlock Origin
|
||||
|
||||
![ublock origin ad blocker screenshot][2]
|
||||
|
||||
My first recommendation remains unchanged. [uBlock Origin][3] is a fast, low memory, wide-spectrum blocker that allows you to not only block ads but also enforce your own content filtering. The default behavior of uBlock Origin is to block ads, trackers, and malware sites using multiple, predefined filter lists. From there it allows you to arbitrarily add lists and rules, or even lock down to a default-deny mode. Despite being powerful, the extension has proven to be efficient and performant. It continues to be updated regularly and is one of the best options available for this functionality.
|
||||
|
||||
### Privacy Badger
|
||||
|
||||
![privacy badger ad blocker][4]
|
||||
|
||||
My second recommendation also remains unchanged. If anything, privacy has been brought even more to the forefront since my previous article, making this extension an easy recommendation. As the name indicates, [Privacy Badger][5] is a privacy-focused extension that blocks ads and other third-party trackers. It's a project of the Electronic Freedom Foundation, which says:
|
||||
|
||||
> "Privacy Badger was born out of our desire to be able to recommend a single extension that would automatically analyze and block any tracker or ad that violated the principle of user consent; which could function well without any settings, knowledge, or configuration by the user; which is produced by an organization that is unambiguously working for its users rather than for advertisers; and which uses algorithmic methods to decide what is and isn't tracking."
|
||||
|
||||
Why is Privacy Badger on this list when the previous item may seem similar? A couple reasons. The first is that it fundamentally works differently than uBlock Origin. The second is that a practice of defense in depth is a sound policy to follow. Speaking of defense in depth, the EFF also maintains [HTTPS Everywhere][6] to automatically ensure https is used for many major websites. When you're installing Privacy Badger, you may want to consider HTTPS Everywhere as well.
|
||||
|
||||
In case you were starting to think this article was simply going to be a rehash of the last one, here's where my recommendations diverge.
|
||||
|
||||
### Bitwarden
|
||||
|
||||
![Bitwarden][7]
|
||||
|
||||
When recommending LastPass in the previous article, I mentioned it was likely going to be a controversial selection. That certainly proved true. Whether you should use a password manager at all—and if you do, whether you should choose one that has a browser plugin—is a hotly debated topic, and the answer very much depends on your personal risk profile. I asserted that most casual computer users should use one because it's much better than the most common alternative: using the same weak password everywhere. I still believe that.
|
||||
|
||||
[Bitwarden][8] has really matured since the last time I checked it out. Like LastPass, it is user-friendly, supports two-factor authentication, and is reasonably secure. Unlike LastPass, it is [open source][9]. It can be used with or without the browser plugin and supports importing from other solutions including LastPass. The core functionality is completely free, and there is a premium version that is $10/year.
|
||||
|
||||
### Vimium-FF
|
||||
|
||||
![Vimium][10]
|
||||
|
||||
[Vimium][11] is another open source extension that provides Firefox keyboard shortcuts for navigation and control in the spirit of Vim. They call it "The Hacker's Browser." Modifier keys are specified as **< c-x>**, **< m-x>**, and **< a-x>** for Ctrl+x, Meta+x, and Alt+x, respectively, and the defaults can be easily customized. Once you have Vimium installed, you can see this list of key bindings at any time by typing **?**. Note that if you prefer Emacs, there are also a couple of extensions for those keybindings as well. Either way, I think keyboard shortcuts are an underutilized productivity booster.
|
||||
|
||||
### Bonus: Grammarly
|
||||
|
||||
Not everyone is lucky enough to write a column on Opensource.com—although you should seriously consider writing for the site; if you have questions, are interested, or would like a mentor, reach out and let's chat. But even without a column to write, proper grammar is beneficial in a large variety of situations. Enter [Grammarly][12]. This extension is not open source, unfortunately, but it does make sure everything you type is clear, effective, and mistake-free. It does this by scanning your text for common and complex grammatical mistakes, spanning everything from subject-verb agreement to article use to modifier placement. Basic functionality is free, with a premium version with additional checks available for a monthly charge. I used it for this article and it caught multiple errors that my proofreading didn't.
|
||||
|
||||
Again, Grammarly is the only extension included on this list that is not open source, so if you know of a similar high-quality open source replacement, let us know in the comments.
|
||||
|
||||
These extensions are ones I've found useful and recommend to others. Let me know in the comments what you think of the updated recommendations.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/5/firefox-extensions
|
||||
|
||||
作者:[Jeremy Garcia][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者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/jeremy-garcia
|
||||
[1]:https://opensource.com/article/18/1/top-5-firefox-extensions
|
||||
[2]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/ublock.png?itok=_QFEbDmq (ublock origin ad blocker screenshot)
|
||||
[3]:https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/
|
||||
[4]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/images/life-uploads/privacy_badger_1.0.1.png?itok=qZXQeKtc (privacy badger ad blocker screenshot)
|
||||
[5]:https://www.eff.org/privacybadger
|
||||
[6]:https://www.eff.org/https-everywhere
|
||||
[7]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/bitwarden.png?itok=gZPrCYoi (Bitwarden)
|
||||
[8]:https://bitwarden.com/
|
||||
[9]:https://github.com/bitwarden
|
||||
[10]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/vimium.png?itok=QRESXjWG (Vimium)
|
||||
[11]:https://addons.mozilla.org/en-US/firefox/addon/vimium-ff/
|
||||
[12]:https://www.grammarly.com/
|
@ -0,0 +1,162 @@
|
||||
A reading list for Linux and open source fans
|
||||
======
|
||||
|
||||

|
||||
I recently asked our writer community to share with us what they're reading. These folks come from all different walks of life and roles in tech. What they have in common is that they are living and breathing Linux and open source every day.
|
||||
|
||||
Drink in this fantastic list. Many of them are free and available to download.
|
||||
|
||||
You may see books you've been meaning to get around to, books that are completely new to you, and some that feel like old friends.
|
||||
|
||||
We'd love to hear what you think of this list. Share with us in the comments below or on [Twitter][1] with #Linuxbooks #opensourcebooks.
|
||||
|
||||
### 17 books to add to your reading list
|
||||
|
||||
**Plus, a bonus fiction read.**
|
||||
|
||||
[23 Years of FreeDOS][2] by Jim Hall
|
||||
|
||||
Last year, the [FreeDOS][3] Project turned 23 years old. While there's nothing special about 23 years, the project decided to celebrate that milestone by sharing stories about how different people use or contribute to FreeDOS. The free, CC BY eBook is a collection of essays that describe the history of FreeDOS since 1994, and how people use FreeDOS today. (Recommendation and review by [Jim Hall][4])
|
||||
|
||||
[Eloquent JavaScript][5] by Marijn Haverbeke
|
||||
|
||||
This book teaches you how to write beautifully crafted programs using one of the most ubiquitous programming languages: [Javascript][6]. Learn the basics and advanced concepts of the language, and how to write programs that run in the browser or Node.js environment. The book also includes five fun projects so you can dive into actual programming while making a platform game or even writing your own programming language. (Recommendation and review by [Rahul Thakoor][7])
|
||||
|
||||
[_Forge Your Future with Open Source_][8] by VM (Vicky) Brasseur
|
||||
|
||||
If you're looking to contribute to open source, but you don't know how to start, this is the book for you. It covers how to find a project to join and how to make your first contributions. (Recommendation and review by [Ben Cotton][9])
|
||||
|
||||
[_Git for Teams_][10] by Emma Jane Hogbin Westby
|
||||
|
||||
Git is a widely-used version control system for individuals and teams alike, but its power means it can be complex. This book provides guidance on how to effectively use [git][11] in a team environment. For more, read our [in-depth review][12]. (Recommendation and review by [Ben Cotton][9])
|
||||
|
||||
[Getting to Yes][13] by Fisher, Ury, and Patton
|
||||
|
||||
The Harvard Negotiation Project, formed in the 1970s, was an academic effort involving economists, psychologists, sociologists, and political scientists to create a framework for negotiations which allows better outcomes for all involved. Their framework and techniques have been used in a diverse set of circumstances, including the Camp David Accords between Egypt and Israel in 1978.
|
||||
|
||||
Principled Negotiation involves understanding the real interests of the participants in a negotiation and using this knowledge to generate options acceptable to all. The same techniques can be used to resolve interpersonal issues, negotiations over cars and houses, discussions with insurance companies, and so on.
|
||||
|
||||
What does this have to do with open source software development? Everything in open source is a negotiation, in some sense. Submitting a bug report is outlining a position—that something does not work correctly—and requesting that someone reprioritize their work to fix it. A heated discussion on a mailing list over the right way to do something or a comment on a feature request is a negotiation, often with imperfect knowledge, about the scope and goals of the project.
|
||||
|
||||
Reframing these conversations as explorations, trying to understand why the other person is asking for something, and being transparent about the reasons why you believe another viewpoint to apply, can dramatically change your relationships and effectiveness working in an open source project. (Recommendation and review by [Dave Neary][14])
|
||||
|
||||
[Just for Fun: The Story of an Accidental Revolutionary][15] by Linus Torvalds et al.
|
||||
|
||||
Linux is an amazing and powerful operating system that spawned a movement to transparency and openness. And, the open source ethos that drives it flies in the face of traditional models of business and capital appreciation. In this book, learn about the genius of Linus the man and [Linux][16] the operating system. Get insight into the experiences that shaped Linus's life and fueled his transformation from a nerdy young man who enjoyed toying with his grandfather's clock to the master programmer of the world's predominant operating system. (Recommendation and review by [Don Watkins][17])
|
||||
|
||||
[Linux in a Month of Lunches][18] by Steven Ovadia
|
||||
|
||||
This book is designed to teach non-technical users how to use desktop [Linux][19] in about an hour a day. The book covers everything from choosing a desktop environment to installing software, to using Git. At the end of the month, readers can use Linux fulltime, replacing their other operating systems. (Recommendation and review by [Steven Ovadia][20])
|
||||
|
||||
[Linux in Action][21] by David Clinton
|
||||
|
||||
This book introduces serious Linux administration tools for anyone interested in getting more out of their tech, including IT professionals, developers, [DevOps][22] specialists, and more. Rather than teaching skills in isolation, the book is organized around practical projects like automating off-site data backups, securing a web server, and creating a VPN to safely connect an organization's resources. [Read more][23] by this author. (Recommendation and review by [David Clinton][24])
|
||||
|
||||
[Make: Linux for Makers][25] by Aaron Newcomb
|
||||
|
||||
This book is a must-read for anyone wanting to create and innovate with the [Raspberry Pi][26]. This book will have you up and operating your Raspberry Pi while at the same time understanding the nuances of it Raspbian Linux operating system. This is a masterful basic text that will help any maker unlock the potential of the Raspberry Pi. It’s concise and well written with a lot of fantastic illustrations and practical examples. (Recommendation by Jason Hibbets | Review by [Don Watkins][17])
|
||||
|
||||
[Managing Humans: Biting and Humorous Tales of a Software Engineering Manager][27] by Michael Lopp
|
||||
|
||||
Michael Lopp is better known by the nom de plume Rands, author of the popular blog [Rands in Repose][28]. This book is an edited, curated collection of blog posts, all related to the management of software development teams. What I love about the book and the blog, is that Rands starts from the fundamental principle that the most complex part of software development is human interactions. The book covers a range of topics about reading a group, understanding the personalities that make it up, and figuring out how to get the best out of everyone.
|
||||
|
||||
These things are universal, and as an open source community manager, I come across them all the time. How do you know if someone might be burning out? How do you run a good meeting? How do you evolve the culture of a project and team as it grows? How much process is the right amount? Regardless of the activity, questions like these arise all the time, and Rands's irreverent, humorous take is educational and entertaining. (Recommendation and review by [Dave Neary][14])
|
||||
|
||||
[Open Sources: Voices from the Open Source Revolution][29] (O'Reilly, 1999)
|
||||
|
||||
This book is a must-read for all open source enthusiasts. Linus Torvalds, Eric S. Raymond, Richard Stallman, Michael Tiemann, Tim O'Reilly, and other important figures in the open source movement share their thoughts on the forward momentum of [open source software][30]. (Recommendation by [Jim Hall][4] | Review by Jen Wike Huger)
|
||||
|
||||
[Producing Open Source Software: How to Run a Successful Free Software Project][31] by Karl Fogel
|
||||
|
||||
This book is for anyone who wants to build an open source community, is already building one, or wants to better understand trends in successful open source project community development. Karl Fogel analyzes and studies traits and characteristics of successful open source projects and how they have developed a community around the project. The book offers helpful advice to community managers (or want-to-be community managers) on how to navigate community development around a project. This is a rare book that takes a deeper look into open source community development and offers plenty of ingredients for success, but you have to take it and create the recipe for your project or community. (Recommendation and review by [Justin Flory][32])
|
||||
|
||||
[Programming with Robots][33] by Albert W. Schueller
|
||||
|
||||
This book introduces the basics of programming using the Lego Mindstorms NXT. Instead of writing abstract programs, learn how to program devices that can sense and interface with the physical world. Learn how software and hardware interact with each other while experimenting with sensors, motors or making music using code. (Recommendation and review by [Rahul Thakoor][7])
|
||||
|
||||
[The AWK programming language][34] by Alfred V. Aho, Brian W. Kernighan, and Peter J. Weinberger
|
||||
|
||||
This book, written by the creators of awk, follows a pattern similar to other books about *nix tools written by the original Bell Labs Unix team and published in the 1970s-1990s, explaining the rationale and intended use of awk in clear and compact prose, liberally sprinkled with examples that start simply and are further elaborated by the need to deal with more fully-detailed problems and edge cases. When published, the typical reader of this book would have been someone who had files of textual or numeric data that needed to be processed and transformed, and who wanted to be able to easily create lookup tables, apply regular expressions, react to structure changes within the input, apply mathematical transformations to numbers and easily format the output.
|
||||
|
||||
While that characterization still applies, today the book can also provide a window back into the time when the only user interface available was a terminal, when "modularity" created the ability to string together numerous single-purpose utility programs in shell scripts to create data transformation pipelines that crunched the data and produced the reports that everyone expected of computers. Today, awk should be a part of the operations toolbox, providing a fine ability to further process configuration and log files, and this book still provides a great introduction to that process. (Recommendation by [Jim Hall][4] | Review by [Chris Hermansen][35])
|
||||
|
||||
[Think Python: Think Like a Computer Scientist][36] by Allen Downey
|
||||
|
||||
This book about [Python][37] is part of [a series][38] that covers other languages as well, like Java, [Perl][39], etc. It moves past simple language syntax downloads and approaches the topic through the lens of how a problem solver would build a solution. It's both a great introductory guide to programming through a layering of concepts, but it can serve the dabbler who is looking to develop skills in an area such as classes or inheritance with chapters that have examples and exercises to then apply the skills taught. (Recommendation and review by [Steve Morris][40])
|
||||
|
||||
[Understanding Open Source and Free Software Licensing][41] (O'Reilly, 2004)
|
||||
|
||||
"This book bridges the gap between the open source vision and the practical implications of its legal underpinnings. If open source and free software licenses interest you, this book will help you understand them. If you're an open source/free software developer, this book is an absolute necessity." (Recommendation by [Jim Hall][4] | review from [Amazon][42])
|
||||
|
||||
[Unix Text Processing][43] by Dale Dougherty and Tim O'Reilly
|
||||
|
||||
This book was written in 1987 as an introduction to Unix systems and how writers could use Unix tools to do work. It's still a useful resource for beginners to learn the basics of the Unix shell, the vi editor, awk and shell scripts, and the nroff and troff typesetting system. The original edition is out of print, but O'Reilly has made the book available for free via their website. (Recommendation and review by [Jim Hall][4])
|
||||
|
||||
### Bonus: Fiction book
|
||||
|
||||
[Station Eleven][44] by Emily St. John Mandel
|
||||
|
||||
This story is set in a near future, twenty years after the earth's population has been decimated by a mysterious and deadly flu. We follow Kirsten Raymonde, a young woman who is traveling near the Great Lakes with a nomadic theatre group because "Survival is insufficient," as she makes her way through the post-apocalyptic world. It's a wonderful story, well worth reading.
|
||||
|
||||
What struck me about the book is how tenuous our relationship with technology actually is. In the Douglas Adams book "Mostly Harmless", there is a great line: "Left to his own devices he couldn't build a toaster. He could just about make a sandwich and that was it." This is the world of Kristin Raymonde. Everyone has been left to their own devices: There is no electricity because no one can work the power grid. No cars, no oil refineries.
|
||||
|
||||
There is a fascinating passage where one inventor has rigged up a generator with a bicycle and is trying to turn on a laptop, trying to see if there is still an internet. We discover the Museum of Civilization, stocked with objects which have no use, which has been left over from the old world: passports, mobile phones, credit cards, stilettoes.
|
||||
|
||||
All of the world's technology becomes useless. (Recommendation and review by [Dave Neary][14])
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/5/list-books-Linux-open-source
|
||||
|
||||
作者:[Jen Wike Huger][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者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/remyd
|
||||
[1]:https://twitter.com/opensourceway
|
||||
[2]:http://www.freedos.org/ebook/
|
||||
[3]:https://opensource.com/article/18/5/node/44116
|
||||
[4]:https://opensource.com/users/jim-hall
|
||||
[5]:https://eloquentjavascript.net/
|
||||
[6]:https://opensource.com/article/18/5/node/32826
|
||||
[7]:https://opensource.com/users/rahul27
|
||||
[8]:https://pragprog.com/book/vbopens/forge-your-future-with-open-source
|
||||
[9]:https://opensource.com/users/bcotton
|
||||
[10]:http://gitforteams.com/
|
||||
[11]:https://opensource.com/article/18/5/node/43741
|
||||
[12]:https://opensource.com/business/15/11/git-for-teams-review
|
||||
[13]:http://www.williamury.com/books/getting-to-yes/
|
||||
[14]:https://opensource.com/users/dneary
|
||||
[15]:http://a.co/749s27n
|
||||
[16]:https://opensource.com/article/18/5/node/19796
|
||||
[17]:https://opensource.com/users/don-watkins
|
||||
[18]:https://manning.com/ovadia
|
||||
[19]:https://opensource.com/article/18/5/node/42626
|
||||
[20]:https://opensource.com/users/stevenov
|
||||
[21]:https://www.manning.com/books/linux-in-action?a_aid=bootstrap-it&a_bid=4ca15fc9
|
||||
[22]:https://opensource.com/article/18/5/node/44696
|
||||
[23]:https://bootstrap-it.com/index.php/books/
|
||||
[24]:https://opensource.com/users/dbclinton
|
||||
[25]:https://www.makershed.com/products/make-linux-for-makers
|
||||
[26]:https://opensource.com/article/18/5/node/35731
|
||||
[27]:https://www.amazon.com/Managing-Humans-Humorous-Software-Engineering/dp/1484221575/ref=dp_ob_title_bk
|
||||
[28]:http://randsinrepose.com/
|
||||
[29]:https://www.oreilly.com/openbook/opensources/book/index.html
|
||||
[30]:https://opensource.com/article/18/5/node/42001
|
||||
[31]:https://producingoss.com/
|
||||
[32]:https://opensource.com/users/justinflory
|
||||
[33]:http://engineering.nyu.edu/gk12/amps-cbri/pdf/RobotC%20FTC%20Books/notesRobotC.pdf
|
||||
[34]:https://archive.org/details/pdfy-MgN0H1joIoDVoIC7
|
||||
[35]:https://opensource.com/users/clhermansen
|
||||
[36]:http://greenteapress.com/thinkpython2/thinkpython2.pdf
|
||||
[37]:https://opensource.com/article/18/5/node/40481
|
||||
[38]:http://greenteapress.com/wp/
|
||||
[39]:https://opensource.com/article/18/5/node/35141
|
||||
[40]:https://opensource.com/users/smorris12
|
||||
[41]:http://shop.oreilly.com/product/9780596005818.do
|
||||
[42]:https://www.amazon.com/Understanding-Open-Source-Software-Licensing/dp/0596005814
|
||||
[43]:http://www.oreilly.com/openbook/utp/
|
||||
[44]:http://www.emilymandel.com/stationeleven.html
|
@ -0,0 +1,181 @@
|
||||
Systemd Services: Beyond Starting and Stopping
|
||||
======
|
||||
|
||||

|
||||
[In the previous article][1], we showed how to create a systemd service that you can run as a regular user to start and stop your game server. As it stands, however, your service is still not much better than running the server directly. Let's jazz it up a bit by having it send out emails to the players, alerting them when the server becomes available and warning them when it is about to be turned off:
|
||||
```
|
||||
# minetest.service
|
||||
|
||||
[Unit]
|
||||
Description= Minetest server
|
||||
Documentation= https://wiki.minetest.net/Main_Page
|
||||
|
||||
[Service]
|
||||
Type= simple
|
||||
|
||||
ExecStart= /usr/games/minetest --server
|
||||
ExecStartPost= /home/<username>/bin/mtsendmail.sh "Ready to rumble?" "Minetest Starting up"
|
||||
|
||||
TimeoutStopSec= 180
|
||||
ExecStop= /home/<username>/bin/mtsendmail.sh "Off to bed. Nightie night!" "
|
||||
Minetest Stopping in 2 minutes"
|
||||
ExecStop= /bin/sleep 120
|
||||
ExecStop= /bin/kill -2 $MAINPID
|
||||
|
||||
```
|
||||
|
||||
There are a few new things in here. First, there's the `ExecStartPost` directive. You can use this directive for anything you want to run right after the main application starts. In this case, you run a custom script, `mtsendmail` (see below), that sends an email to your friends telling them that the server is up.
|
||||
```
|
||||
#!/bin/bash
|
||||
# mtsendmail
|
||||
echo $1 | mutt -F /home/<username>/.muttrc -s "$2" my_minetest@mailing_list.com
|
||||
|
||||
```
|
||||
|
||||
You can use [Mutt][2], a command-line email client, to shoot off your messages. Although the script shown above is to all practical effects only one line long, remember you can't have a line with pipes and redirections as a systemd unit argument, so you have to wrap it in a script.
|
||||
|
||||
For the record, there is also an `ExecStartPre` directive for things you want to execute before starting the service proper.
|
||||
|
||||
Next up, you have a block of commands that close down the server. The `TimeoutStopSec` directive pushes up the time before systemd bails on shutting down the service. The default time out value is round about 90 seconds. Anything longer, and systemd will force the service to close down and report a failure. But, as you want to give your users a couple of minutes before closing the server completely, you are going to push the default up to three minutes. This will stop systemd from thinking the closedown has failed.
|
||||
|
||||
Then the close down proper starts. Although there is no `ExecStopPre` as such, you can simulate running stuff before closing down your server by using more than one `ExecStop` directive. They will be executed in order, from topmost to bottommost, and will allow you to send out a message before the server is actually stopped.
|
||||
|
||||
With that in mind, the first thing you do is shoot off an email to your friends, warning them the server is going down. Then you wait two minutes. Finally you close down the server. Minetest likes to be closed down with [Ctrl] + [c], which translates into an interrupt signal ( _SIGINT_ ). That is what you do when you issue the `kill -2 $MAINPID` command. `$MAINPID` is a systemd variable for your service that points to the PID of the main application.
|
||||
|
||||
This is much better! Now, when you run
|
||||
```
|
||||
systemctl --user start minetest
|
||||
|
||||
```
|
||||
|
||||
The service will start up the Minetest server and send out an email to your users. Likewise when you are about to close down, but giving two minutes to users to log off.
|
||||
|
||||
### Starting at Boot
|
||||
|
||||
The next step is to make your service available as soon as the machine boots up, and close down when you switch it off at night.
|
||||
|
||||
Start be moving your service out to where the system services live, The directory youa re looking for is _/etc/systemd/system/_ :
|
||||
```
|
||||
sudo mv /home/<username>/.config/systemd/user/minetest.service /etc/systemd/system/
|
||||
|
||||
```
|
||||
|
||||
If you were to try and run the service now, it would have to be with superuser privileges:
|
||||
```
|
||||
sudo systemctl start minetest
|
||||
|
||||
```
|
||||
|
||||
But, what's more, if you check your service's status with
|
||||
```
|
||||
sudo systemctl status minetest
|
||||
|
||||
```
|
||||
|
||||
You would see it had failed miserably. This is because systemd does not have any context, no links to worlds, textures, configuration files, or details of the specific user running the service. You can solve this problem by adding the `User` directive to your unit:
|
||||
```
|
||||
# minetest.service
|
||||
|
||||
[Unit]
|
||||
Description= Minetest server
|
||||
Documentation= https://wiki.minetest.net/Main_Page
|
||||
|
||||
[Service]
|
||||
Type= simple
|
||||
User= <username>
|
||||
|
||||
ExecStart= /usr/games/minetest --server
|
||||
ExecStartPost= /home/<username>/bin/mtsendmail.sh "Ready to rumble?"
|
||||
"Minetest Starting up"
|
||||
|
||||
TimeoutStopSec= 180
|
||||
ExecStop= /home/<username>/bin/mtsendmail.sh "Off to bed. Nightie night!"
|
||||
"Minetest Stopping in 2 minutes"
|
||||
ExecStop= /bin/sleep 120
|
||||
ExecStop= /bin/kill -2 $MAINPID
|
||||
|
||||
```
|
||||
|
||||
The `User` directive tells systemd which user's environment it should use to correctly run the service. You could use root, but that would probably be a security hazard. You could also use your personal user and that would be a bit better, but what many administrators do is create a specific user for each service, effectively isolating the service from the rest of the system and users.
|
||||
|
||||
The next step is to make your service start when you boot up and stop when you power down your computer. To do that you need to _enable_ your service, but, before you can do that, you have to tell systemd where to _install_ it.
|
||||
|
||||
In systemd parlance, _installing_ means telling systemd when in the boot sequence should your service become activated. For example the _cups.service_ , the service for the _Common UNIX Printing System_ , will have to be brought up after the network framework is activated, but before any other printing services are enabled. Likewise, the _minetest.service_ uses a user's email (among other things) and will have to be slotted in when the network is up and services for regular users become available.
|
||||
|
||||
You do all that by adding a new section and directive to your unit:
|
||||
```
|
||||
...
|
||||
[Install]
|
||||
WantedBy= multi-user.target
|
||||
|
||||
```
|
||||
|
||||
You can read this as "wait until we have everything ready for a multiples user system." Targets in systemd are like the old run levels and can be used to put your machine into one state or another, or, like here, to tell your service to wait until a certain state has been reached.
|
||||
|
||||
Your final _minetest.service_ file will look like this:
|
||||
```
|
||||
# minetest.service
|
||||
[Unit]
|
||||
Description= Minetest server
|
||||
Documentation= https://wiki.minetest.net/Main_Page
|
||||
|
||||
[Service]
|
||||
Type= simple
|
||||
User= <username>
|
||||
|
||||
ExecStart= /usr/games/minetest --server
|
||||
ExecStartPost= /home/<username>/bin/mtsendmail.sh "Ready to rumble?"
|
||||
"Minetest Starting up"
|
||||
|
||||
TimeoutStopSec= 180
|
||||
ExecStop= /home/<username>/bin/mtsendmail.sh "Off to bed. Nightie night!"
|
||||
"Minetest Stopping in 2 minutes"
|
||||
ExecStop= /bin/sleep 120
|
||||
ExecStop= /bin/kill -2 $MAINPID
|
||||
|
||||
[Install]
|
||||
WantedBy= multi-user.target
|
||||
|
||||
```
|
||||
|
||||
Before trying it out, you may have to do some adjustments to your email script:
|
||||
```
|
||||
#!/bin/bash
|
||||
# mtsendmail
|
||||
|
||||
sleep 20
|
||||
echo $1 | mutt -F /home/<username>/.muttrc -s "$2" my_minetest@mailing_list.com
|
||||
sleep 10
|
||||
|
||||
```
|
||||
|
||||
This is because the system will need some time to set up the emailing system (so you wait 20 seconds) and also some time to actually send the email (so you wait 10 seconds). Notice that these are the wait times that worked for me. You may have to adjust these for your own system.
|
||||
|
||||
And you're done! Run:
|
||||
```
|
||||
sudo systemctl enable minetest
|
||||
|
||||
```
|
||||
|
||||
and the Minetest service will come online when you power up and gracefully shut down when you power off, warning your users in the process.
|
||||
|
||||
### Conclusion
|
||||
|
||||
The fact that Debian, Ubuntu, and distros of the same family have a special package called _minetest-server_ that does some of the above for you (but no messaging!) should not deter you from setting up your own customised services. In fact, the version you set up here is much more versatile and does more than Debian's default server.
|
||||
|
||||
Furthermore, the process described here will allow you to set up most simple servers as services, whether they are for games, web applications, or whatever. And those are the first steps towards veritable systemd guruhood.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/blog/learn/2018/5/systemd-services-beyond-starting-and-stopping
|
||||
|
||||
作者:[Paul Brown][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.linux.com/users/bro66
|
||||
[1]:https://www.linux.com/blog/learn/intro-to-linux/2018/5/writing-systemd-services-fun-and-profit
|
||||
[2]:http://www.mutt.org/
|
@ -0,0 +1,104 @@
|
||||
|
||||
为什么 Linux 比 Windows 和 macOS 的安全性好
|
||||
======
|
||||
|
||||

|
||||
|
||||
企业投入了大量时间、精力和金钱来保障系统的安全性。最强的安全意识可能就是有一个安全的运营中心。他们肯定用了防火墙以及反病毒软件。他们可能花费大量时间监控他们的网络,寻找可能表明违规的信号异常。与 IDS、SIEM 和 NGFW 一样,他们部署了一个名副其实的防御字母表。
|
||||
|
||||
然而又有多少人想过数字化操作的基础之一:部署在员工的个人电脑上的操作系统?选择桌面操作系统的安全性是一个考虑的因素吗?
|
||||
|
||||
这就产生了一个 IT 人士都应该能回答的问题:一般部署哪种操作系统最安全呢?
|
||||
|
||||
我们问了一些专家他们对于以下三种选项的看法:Windows,最复杂的平台也是最受欢迎的桌面操作系统;macOS X,基于 FreeBSD 的 Unix 操作系统,驱动着苹果的 Macintosh 系列运行;还有 Linux,这里我们指的是所有的 Linux 发行版以及与基于 Unix 的操作系统相关的系统。
|
||||
|
||||
### 我们怎么会这样
|
||||
|
||||
企业可能没有评估他们部署到工作人员的操作系统的安全性的一个原因是,他们多年前就已经做出了选择。退一步讲,所有操作系统都还算安全,因为侵入他们,窃取数据或安装恶意软件的业务还处于起步阶段。而且一旦选择了操作系统,就很难再想改变。很少有 IT 组织希望将全球分散的员工队伍转移到全新的操作系统上。唉,他们已经受够了把用户搬到一个选好的新版本操作系统时的负面反响。
|
||||
|
||||
还有,重新考虑它是高明的吗?这三款领先的桌面操作系统在安全方面的差异是否足以值得我们去做出改变呢?
|
||||
|
||||
当然商业系统面临的威胁近几年已经改变了。攻击变得成熟多了。曾经支配了公众想象力的独自的青少年黑客已经被组织良好的犯罪分子网络以及具有庞大计算资源的政府资助组织的网络所取代。
|
||||
|
||||
像你们许多人一样,我已经有了很多那儿的亲身经历:我曾经在许多 Windows 电脑上被恶意软件和病毒感染,我甚至被 Mac 文件的宏病毒感染了。最近,一个广泛传播的自动黑客绕开了网站的保护程序并用恶意软件感染了它。这种恶意软件的影响一开始是隐形的,甚至有些东西你没注意,直到恶意软件最终深深地植入系统以至于它的性能开始变差。一件有关病毒蔓延的震惊之事是我从未被不法之徒特定针对过;当今世界,用僵尸网络攻击 100,000 台电脑容易得就像一次攻击几台电脑一样。
|
||||
|
||||
### 操作系统真的很重要吗?
|
||||
|
||||
给你的用户部署的那个操作系统确实对你的安全态度产生了影响,但那并不是一个可靠的安全措施。首先,现在的攻击很可能会发生,因为攻击者探测了你的用户,而不是你的系统。一项对参与过 DEFCON 会议黑客的[调查][1]表明“84%的人使用社交工程作为攻击策略的一部分。”部署安全操作系统只是一个重要的起点,但如果没有用户培训,强大的防火墙和持续的警惕性,即使是最安全的网络也会受到入侵。当然,用户下载的软件,扩展程序,实用程序,插件和其他软件的风险始终良好,但却成为恶意软件出现在系统上的一种途径.
|
||||
|
||||
无论你选择哪种平台,保持你系统安全最好的方法之一就是确保立即应用了软件更新。一旦补丁正式发布,黑客就可以对其进行反向工程并找到一种新的漏洞,以便在下一波攻击中使用。
|
||||
|
||||
而且别忘了最基本的操作。别用 root 权限,别授权用户连接到网络中的老服务器上。教您的用户如何挑选一个真正的好密码并且使用例如 [1Password][2] 这样的工具,以便在每个他们使用的帐户和网站上拥有不同的密码
|
||||
|
||||
因为底线是您对系统做出的每一个决定都会影响您的安全性,即使您的用户工作使用的操作系统也是如此。
|
||||
|
||||
**[ 若要给这个故事写评论, 请访问 [Computerworld's 的 Facebook 主页][3]. ]**
|
||||
|
||||
### Windows,流行之选
|
||||
|
||||
若你是一个安全管理人员,很可能文章中提出的问题就会变成这样:是否我们远离微软的 Windows 会更安全呢?说 Windows 主导商业市场都是低估事实了。[NetMarketShare][4] 估计互联网上 88% 的电脑令人震惊地运行着 Windows 的版本之一。
|
||||
|
||||
如果你的系统在这 88% 之中,你可能知道微软会继续加强 Windows 系统的安全性。改进重写了或者重新改写了他的代码库,增加了它的反病毒软件系统,改进了防火墙以及实现了沙箱架构,这样在沙箱里的程序就不能访问系统的内存空间或者其他应用程序。
|
||||
|
||||
但可能 Windows 的流行本身就是个问题操作系统的安全性可能很大程度上依赖于装机用户量的规模。对于恶意软件作者来说,Windows 提供了大的施展平台。专注其中可以让他们的努力发挥最大作用。
|
||||
|
||||
像 Troy Wilkinson,Axiom Cyber Solutions 的 CEO 解释的的那样,“Windows 总是因为很多原因安全性保障来的最晚,主要是因为消费者的采用率。由于市场上大量基于 Windows 的个人电脑,黑客历来最有针对性地将这些系统作为目标。”
|
||||
|
||||
可以肯定地说,从梅丽莎病毒到 WannaCry 或者更强的,许多世界上可见的恶意软件早已对准了 Windows 系统.
|
||||
|
||||
### macOS X 以及通过隐匿实现的安全
|
||||
|
||||
如果最流行的操作系统总是成为大目标,那么用一个不流行的操作系统能确保安全吗?这个主意是老法新用——而且是完全不可信的概念——“通过隐匿实现的安全,” 这保持了软件专有的持续内部运作因此不为人知是抵御攻击的最好方法。
|
||||
|
||||
Wilkinson 坦言,macOS X “比 Windows 更安全”,但他急于补充说,“macOS 曾被认为是一个安全漏洞很小的完全安全的操作系统,但近年来,我们看到黑客制造了额外的漏洞攻击苹果系统。”
|
||||
|
||||
换句话说,攻击者会扩大活动范围而不会无视 Mac 领域。
|
||||
|
||||
Comparitech 的安全研究员 Lee Muson 说,在选择更安全的操作系统时,“macOS很可能是被挑选的一员”,但他提醒说,这一想法并不令人费解。它的优势在于“它仍然受益于通过隐匿实现的安全感和微软提供的更大的目标。”
|
||||
|
||||
Wolf Solutions 公司的 Joe Moore 给予了苹果更多的信任,称“现成的 macOS X 在安全方面有着良好的记录,部分原因是它不像 Windows 那么广泛,而且部分原因是苹果公司在安全问题上干的不错。”
|
||||
|
||||
### 最终胜者是 …
|
||||
|
||||
你可能一开始就知道它:专家们的明确共识是 Linux 是最安全的操作系统。然而,尽管它是服务器的首选操作系统,但将其部署在桌面上的企业却很少。
|
||||
|
||||
如果你确定 Linux 是要选择的系统,你仍然需要决定选择哪种 Linux 系统,并且事情会变得更加复杂。 用户需要一个看起来很熟悉的用户界面,而你需要最安全的操作系统。
|
||||
|
||||
像 Moore 解释的那样,“Linux 有可能是最安全的,但要求用户是很强大的用户。”所以,它不是针对所有人的。
|
||||
|
||||
将安全性作为主要功能的 Linux 发行版包括 Parrot Linux,这是一个基于 Debian 的发行版,Moore 说,它提供了许多与安全相关开箱即用的工具。
|
||||
|
||||
当然,一个重要的区别是 Linux 是开源的。Simplex Solutions 的 CISO Igor Bidenko 说,编码人员可以阅读和评论彼此工作的现实看起来像是一场安全噩梦,但这确实是让 Linux 如此安全的重要原因。 “Linux 是最安全的操作系统,因为它的源代码是开放的。任何人都可以查看它,并确保没有错误或后门。”
|
||||
|
||||
Wilkinson 阐述说:“Linux 和基于 Unix 的操作系统具有较少的信息安全领域已知的可利用的安全缺陷。技术社区对 Linux 代码进行了审查,该代码有助于提高安全性:通过进行这么多的监督,易受攻击之处、漏洞和威胁就会减少。”
|
||||
|
||||
这是一个微妙的而违反直觉的解释,但是通过让数十人(有时甚至数百人)通读操作系统中的每一行代码,代码实际上更加健壮,并且发布漏洞错误的机会减少了。这与 PC World 为何出来说 Linux 更安全有很大关系。正如 Katherine Noyes 解释的那样,“微软可能吹捧它的大型付费开发者团队,但团队不太可能与基于全球的 Linux 用户开发者进行比较。 安全只能通过所有额外的关注获益。”
|
||||
|
||||
另一个被 PC 世界(一个由 [IDG](https://zh.wikipedia.org/wiki/%E5%9B%BD%E9%99%85%E6%95%B0%E6%8D%AE%E9%9B%86%E5%9B%A2) 发行的电脑杂志)举例的原因是 Linux 更好的用户特权模式:Windows 用户“一般被默认授予管理员权限,那意味着他们几乎可以访问系统中的一切,”Noye 的文章讲到。Linux,反而很好地限制了“root”权限。
|
||||
|
||||
Noyes 还指出,Linux 环境下的多样性可能比典型的 Windows 单一文化更好地对抗攻击:Linux 有很多不同的发行版。其中一些以其特别的安全关注点进行差异化。Comparitech 的安全研究员 Lee Muson 为 Linux 发行版提供了这样的建议:“Qubes OS 对于 Linux 来说是一个很好的出发点,现在你可以发现,爱德华斯诺登的认可大大地掩盖了它自己极其卑劣的主张。”其他安全性专家指向专门的安全 Linux 发行版,如 Tails Linux,它旨在直接从 USB 闪存驱动器或类似的外部设备安全地匿名运行。
|
||||
|
||||
### 构建安全趋势
|
||||
|
||||
惯性是一股强大的力量。虽然人们有明确的共识,认为 Linux 是桌面系统的最安全选择,但并没有出现让 Windows 和 Mac 机器倾倒的倾向。尽管如此,Linux 采用率的小幅增长却可能会产生对所有人都更加安全的计算,因为市场份额的丧失是确定能获得微软和苹果公司关注的一个方式。换句话说,如果有足够的用户在桌面上切换到 Linux,Windows 和 Mac PC 很可能成为更安全的平台。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.computerworld.com/article/3252823/linux/why-linux-is-better-than-windows-or-macos-for-security.html
|
||||
|
||||
作者:[Dave Taylor][a]
|
||||
译者:[fuzheng1998](https://github.com/fuzheng1998)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.computerworld.com/author/Dave-Taylor/
|
||||
[1]:https://www.esecurityplanet.com/hackers/fully-84-percent-of-hackers-leverage-social-engineering-in-attacks.html
|
||||
[2]:http://www.1password.com
|
||||
[3]:https://www.facebook.com/Computerworld/posts/10156160917029680
|
||||
[4]:https://www.netmarketshare.com/operating-system-market-share.aspx?options=%7B%22filter%22%3A%7B%22%24and%22%3A%5B%7B%22deviceType%22%3A%7B%22%24in%22%3A%5B%22Desktop%2Flaptop%22%5D%7D%7D%5D%7D%2C%22dateLabel%22%3A%22Trend%22%2C%22attributes%22%3A%22share%22%2C%22group%22%3A%22platform%22%2C%22sort%22%3A%7B%22share%22%3A-1%7D%2C%22id%22%3A%22platformsDesktop%22%2C%22dateInterval%22%3A%22Monthly%22%2C%22dateStart%22%3A%222017-02%22%2C%22dateEnd%22%3A%222018-01%22%2C%22segments%22%3A%22-1000%22%7D
|
||||
[5]:https://www.parrotsec.org/
|
||||
[6]:https://www.pcworld.com/article/202452/why_linux_is_more_secure_than_windows.html
|
||||
[7]:https://www.qubes-os.org/
|
||||
[8]:https://twitter.com/snowden/status/781493632293605376?lang=en
|
||||
[9]:https://tails.boum.org/about/index.en.html
|
@ -0,0 +1,98 @@
|
||||
在 Ubuntu 和 Linux Mint 中轻松安装 Android Studio
|
||||
======
|
||||
[Android Studio][1] 是谷歌自己的 Android 开发 IDE,是带 ADT 插件的 Eclipse 的不错替代品。Android Studio 可以通过源代码安装,但在这篇文章中,我们将看到**如何在 Ubuntu 18.04、16.04 和相应的 Linux Mint 变体**中安装 Android Studio。
|
||||
|
||||
在继续安装 Android Studio 之前,请确保你已经[在 Ubuntu 中安装了 Java][2]。
|
||||
|
||||
![How to install Android Studio in Ubuntu][3]
|
||||
|
||||
### 使用 Snap 在 Ubuntu 和其他发行版中安装 Android Studio
|
||||
|
||||
自从 Ubuntu 开始专注于 Snap 软件包以来,越来越多的软件开始提供易于安装的 Snap 软件包。Android Studio 就是其中之一。Ubuntu 用户可以直接在软件中心找到 Android Studio 程序并从那里安装。
|
||||
|
||||
![Install Android Studio in Ubuntu from Software Center][4]
|
||||
|
||||
如果你在软件中心安装 Android Studio 时看到错误,则可以使用[ Snap 命令][5] 安装 Android Studio。
|
||||
```
|
||||
sudo snap install android-studio --classic
|
||||
|
||||
```
|
||||
|
||||
非常简单!
|
||||
|
||||
### 另一种方式 1:在 Ubuntu 中使用 umake 安装 Android Studio
|
||||
|
||||
你也可以使用 Ubuntu Developer Tools Center,现在称为 [Ubuntu Make][6],轻松安装 Android Studio。Ubuntu Make 提供了一个命令行工具来安装各种开发工具、IDE等。Ubuntu Make 在 Ubuntu 仓库中就有。
|
||||
|
||||
要安装 Ubuntu Make,请在终端中使用以下命令:
|
||||
|
||||
`sudo apt-get install ubuntu-make`
|
||||
|
||||
安装 Ubuntu Make 后,请使用以下命令在 Ubuntu 中安装 Android Studio:
|
||||
```
|
||||
umake android
|
||||
|
||||
```
|
||||
|
||||
在安装过程中它会给你的几个选项。我认为你可以处理。如果你决定卸载 Android Studio,则可以按照以下方式使用相同的 umake 工具:
|
||||
```
|
||||
umake android --remove
|
||||
|
||||
```
|
||||
|
||||
### 另一种方式 2:通过非官方的 PPA 在 Ubuntu 和 Linux Mint 中安装 Android Studio
|
||||
|
||||
感谢 [Paolo Ratolo][7],我们有一个 PPA,可用于 Ubuntu 16.04、14.04、Linux Mint 和其他基于 Ubuntu 的发行版中轻松安装 Android Studio。请注意,它将下载大约 650MB 的数据。请注意你的互联网连接以及数据费用(如果有的话)。
|
||||
|
||||
打开一个终端并使用以下命令:
|
||||
```
|
||||
sudo apt-add-repository ppa:paolorotolo/android-studio
|
||||
sudo apt-get update
|
||||
sudo apt-get install android-studio
|
||||
|
||||
```
|
||||
|
||||
这不容易吗?虽然从源代码安装程序很有趣,但拥有这样的 PPA 总是不错的。我们看到了如何安装 Android Studio,现在来看看如何卸载它。
|
||||
|
||||
### 卸载 Android Studio:
|
||||
|
||||
如果你还没有安装 PPA Purge:
|
||||
```
|
||||
sudo apt-get install ppa-purge
|
||||
|
||||
```
|
||||
|
||||
现在使用 PPA Purge 来清除已安装的 PPA:
|
||||
```
|
||||
sudo apt-get remove android-studio
|
||||
|
||||
sudo ppa-purge ppa:paolorotolo/android-studio
|
||||
|
||||
```
|
||||
|
||||
就是这些了。我希望这能够帮助你**在 Ubuntu 和 Linux Mint 上安装 Android Studio**。在运行 Android Studio 之前,请确保[在 Ubuntu 中安装了Java][8]。在类似的文章中,我建议你阅读[如何安装和配置 Ubuntu SDK ][9]和[如何在 Ubuntu 中轻松安装 Microsoft Visual Studio][10]。
|
||||
|
||||
欢迎提出任何问题或建议。再见 :)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/install-android-studio-ubuntu-linux/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://itsfoss.com/author/abhishek/
|
||||
[1]:http://developer.android.com/sdk/installing/studio.html
|
||||
[2]:https://itsfoss.com/install-java-ubuntu-1404/
|
||||
[3]:https://itsfoss.com/wp-content/uploads/2014/04/Android_Studio_Ubuntu.jpeg
|
||||
[4]:https://itsfoss.com/wp-content/uploads/2014/04/install-android-studio-snap-800x469.jpg
|
||||
[5]:https://itsfoss.com/install-snap-linux/
|
||||
[6]:https://wiki.ubuntu.com/ubuntu-make
|
||||
[7]:https://plus.google.com/+PaoloRotolo
|
||||
[8]:https://itsfoss.com/install-java-ubuntu-1404/ (How To Install Java On Ubuntu 14.04)
|
||||
[9]:https://itsfoss.com/install-configure-ubuntu-sdk/
|
||||
[10]:https://itsfoss.com/install-visual-studio-code-ubuntu/
|
@ -1,108 +0,0 @@
|
||||
ImageMagick 的一些高级图片查看技巧
|
||||
======
|
||||
|
||||

|
||||
图片源于 [Internet Archive Book Images](https://www.flickr.com/photos/internetarchivebookimages/14759826206/in/photolist-ougY7b-owgz5y-otZ9UN-waBxfL-oeEpEf-xgRirT-oeMHfj-wPAvMd-ovZgsb-xhpXhp-x3QSRZ-oeJmKC-ovWeKt-waaNUJ-oeHPN7-wwMsfP-oeJGTK-ovZPKv-waJnTV-xDkxoc-owjyCW-oeRqJh-oew25u-oeFTm4-wLchfu-xtjJFN-oxYznR-oewBRV-owdP7k-owhW3X-oxXxRg-oevDEY-oeFjP1-w7ZB6f-x5ytS8-ow9C7j-xc6zgV-oeCpG1-oewNzY-w896SB-wwE3yA-wGNvCL-owavts-oevodT-xu9Lcr-oxZqZg-x5y4XV-w89d3n-x8h6fi-owbfiq),Opensource.com 修改,[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)协议
|
||||
|
||||
在我先前的[ImageMagick 入门:使用命令行来编辑图片](https://linux.cn/article-8851-1.html) 文章中,我展示了如何使用 ImageMagick 的菜单栏进行图片的编辑和变换风格。在这篇续文里,我将向你展示使用这个开源的图像编辑器来查看图片的额外方法。
|
||||
|
||||
### 别样的风格
|
||||
|
||||
在深入 ImageMagick 的高级图片查看技巧之前,我想先分享另一个使用 **convert** 达到的有趣但简单的效果,在上一篇文章中我已经详细地介绍了 **convert** 命令,这个技巧涉及这个命令的 `edge` 和 `negate` 选项:
|
||||
```
|
||||
convert DSC_0027.JPG -edge 3 -negate edge3+negate.jpg
|
||||
```
|
||||
|
||||
![在图片上使用 `edge` 和 `negate` 选项][3]
|
||||
使用`edge` 和 `negate` 选项前后的图片对比
|
||||
|
||||
编辑后的图片让我更加喜爱,具体是因为如下因素:海的外观,作为前景和背景的植被,特别是太阳及其在海上的反射,最后是天空。
|
||||
|
||||
### 使用 `display` 来查看一系列图片
|
||||
|
||||
假如你跟我一样是个命令行用户,你就知道 shell 为复杂任务提供了更多的灵活性和快捷方法。下面我将展示一个例子来佐证这个观点。ImageMagick 的 **display** 命令可以克服我在 GNOME 桌面上使用 [Shotwell][4] 图像管理器导入图片时遇到的问题。
|
||||
|
||||
Shotwell 会根据每张导入图片的 [Exif][5] 数据,创建以图片被生成或者拍摄时的日期为名称的目录结构。最终的效果是最上层的目录以年命名,接着的子目录是以月命名 (01, 02, 03 等等),然后是以每月的日期命名的子目录。我喜欢这种结构,因为当我想根据图片被创建或者拍摄时的日期来查找它们时将会非常方便。
|
||||
|
||||
但这种结构也并不是非常完美的,当我想查看最近几个月或者最近一年的所有图片时就会很麻烦。使用常规的图片查看器,我将不停地在不同层级的目录间跳转,但 ImageMagick 的 **display** 命令可以使得查看更加简单。例如,假如我想查看最近一年的图片,我便可以在命令行中键入下面的 **display** 命令:
|
||||
```
|
||||
display -resize 35% 2017/*/*/*.JPG
|
||||
```
|
||||
|
||||
我可以匹配一年中的每一月和每一天。
|
||||
|
||||
现在假如我想查看某张图片,但我不确定我是在 2016 年的上半年还是在 2017 的上半年拍摄的,那么我便可以使用下面的命令来找到它:
|
||||
```
|
||||
display -resize 35% 201[6-7]/0[1-6]/*/*.JPG
|
||||
```
|
||||
限制查看的图片拍摄于 2016 和 2017 年的一月到六月
|
||||
|
||||
### 使用 `montage` 来查看图片的缩略图
|
||||
|
||||
假如现在我要查找一张我想要编辑的图片,使用 **display** 的一个问题是它只会显示每张图片的文件名,而不显示其在目录结构中的位置,所以想要找到那张图片并不容易。另外,假如我很偶然地在从相机下载图片的过程中将这些图片从相机的内存里面清除了它们,结果使得下次拍摄照片的名称又从 **DSC_0001.jpg** 开始命名,那么当使用 **display** 来展示一整年的图片时,将会在这 12 个月的图片中花费很长的时间来查找它们。
|
||||
|
||||
这时 **montage** 命令便可以派上用场了。它可以将一系列的图片放在一张图片中,这样就会非常有用。例如可以使用下面的命令来完成上面的任务:
|
||||
```
|
||||
montage -label %d/%f -title 2017 -tile 5x -resize 10% -geometry +4+4 2017/0[1-4]/*/*.JPG 2017JanApr.jpg
|
||||
```
|
||||
|
||||
从左到右,这个命令以标签开头,标签的形式是包含文件名( **%f** )和以 **/** 分割的目录( **%d** )结构,接着这个命令以目录的名称(2017)来作为标题,然后将图片排成 5 列,每个图片缩放为 10% (这个参数可以很好地匹配我的屏幕)。`geometry` 的设定将在每张图片的四周留白,最后在接上要处理的对象和一个合适的名称( **2017JanApr.jpg** )。现在图片 **2017JanApr.jpg** 便可以成为一个索引,使得我可以不时地使用它来查看这个时期的所有图片。
|
||||
|
||||
### 注意内存消耗
|
||||
|
||||
你可能会好奇为什么我在上面的合成图中只特别指定了为期 4 个月(从一月到四月)的图片。因为 **montage** 将会消耗大量内存,所以你需要多加注意。我的相机产生的图片每张大约有 2.5MB,我发现我的系统可以很轻松地处理 60 张图片。但一旦图片增加到 80 张,如果此时还有另外的程序(例如 Firefox 、Thunderbird)在后台工作,那么我的电脑将会死机,这似乎和内存使用相关,**montage**可能会占用可用 RAM 的 80% 乃至更多(你可以在此期间运行 **top** 命令来查看内存占用)。假如我关掉其他的程序,我便可以在我的系统死机前处理 80 张图片。
|
||||
|
||||
下面的命令可以让你知晓在你运行 **montage** 命令前你需要处理图片张数:
|
||||
```
|
||||
ls 2017/0[1-4/*/*.JPG > filelist; wc -l filelist
|
||||
```
|
||||
|
||||
**ls** 命令生成我们搜索的文件的列表,然后通过重定向将这个列表保存在任意以 filelist 为名称的文件中。接着带有 **-l** 选项的 **wc** 命令输出该列表文件共有多少行,换句话说,展示出需要处理的文件个数。下面是我运行命令后的输出:
|
||||
```
|
||||
163 filelist
|
||||
```
|
||||
|
||||
啊呀!从一月到四月我居然有 163 张图片,使用这些图片来创建一张合成图一定会使得我的系统死机的。我需要将这个列表减少点,可能只处理到 3 月份或者更早的图片。但如果我在4月20号到30号期间拍摄了很多照片,我想这便是问题的所在。下面的命令便可以帮助指出这个问题:
|
||||
```
|
||||
ls 2017/0[1-3]/*/*.JPG > filelist; ls 2017/04/0[1-9]/*.JPG >> filelist; ls 2017/04/1[0-9]/*.JPG >> filelist; wc -l filelist
|
||||
```
|
||||
|
||||
上面一行中共有 4 个命令,它们以分号分隔。第一个命令特别指定从一月到三月期间拍摄的照片;第二个命令使用 **>>** 将拍摄于 4 月 1 日至 9 日的照片追加到这个列表文件中;第三个命令将拍摄于 4 月 1 0 日到 19 日的照片追加到列表中。最终它的显示结果为:
|
||||
```
|
||||
81 filelist
|
||||
```
|
||||
|
||||
我知道假如我关掉其他的程序,处理 81 张图片是可行的。
|
||||
|
||||
使用 **montage** 来处理它们是很简单的,因为我们只需要将上面所做的处理添加到 **montage** 命令的后面即可:
|
||||
```
|
||||
montage -label %d/%f -title 2017 -tile 5x -resize 10% -geometry +4+4 2017/0[1-3]/*/*.JPG 2017/04/0[1-9]/*.JPG 2017/04/1[0-9]/*.JPG 2017Jan01Apr19.jpg
|
||||
```
|
||||
|
||||
从左到右,**montage** 命令后面最后的那个文件名将会作为输出,在它之前的都是输入。这个命令将花费大约 3 分钟来运行,并生成一张大小约为 2.5MB 的图片,但我的系统只是有一点反应迟钝而已。
|
||||
|
||||
### 展示合成图片
|
||||
|
||||
当你第一次使用 **display** 查看一张巨大的合成图片时,你将看到合成图的宽度很合适,但图片的高度被压缩了,以便和屏幕相适应。不要慌,只需要左击图片,然后选择 **View > Original Size** 便会显示整个图片。再次点击图片便可以使菜单栏隐藏。
|
||||
|
||||
我希望这篇文章可以在你使用新方法查看图片时帮助你。在我的下一篇文章中,我将讨论更加复杂的图片操作技巧。
|
||||
|
||||
### 作者简介
|
||||
Greg Pittman - Greg 肯塔基州路易斯维尔的一名退休的神经科医生,对计算机和程序设计有着长期的兴趣,最早可以追溯到 1960 年代的 Fortran IV 。当 Linux 和开源软件相继出现时,他开始学习更多的相关知识,并分享自己的心得。他是 Scribus 团队的成员。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/17/9/imagemagick-viewing-images
|
||||
|
||||
作者:[Greg Pittman][a]
|
||||
译者:[FSSlc](https://github.com/FSSlc)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/greg-p
|
||||
[1]:https://opensource.com/article/17/8/imagemagick
|
||||
[2]:/file/370946
|
||||
[3]:https://opensource.com/sites/default/files/u128651/edge3negate.jpg "Using the edge and negate options on an image."
|
||||
[4]:https://wiki.gnome.org/Apps/Shotwell
|
||||
[5]:https://en.wikipedia.org/wiki/Exif
|
@ -0,0 +1,118 @@
|
||||
两款 Linux 桌面端可用的科学计算器
|
||||
======
|
||||
|
||||
|
||||
|
||||
Translating by zyk2290
|
||||
|
||||

|
||||
|
||||
Image by : opensource.com
|
||||
|
||||
每个Linux 桌面环境都至少带有一个功能简单的桌面计算器,但大多数计算器只能进行一些简单的计算。
|
||||
|
||||
幸运的是,还是有例外的:不仅可以做得比开平方根和一些三角函数还多,而且还很简单。这里将介绍两款强大的计算器,外加一大堆额外的功能。
|
||||
|
||||
### SpeedCrunch
|
||||
|
||||
[SpeedCrunch][1]是一款高精度科学计算器有着 Qt5 图像界面前端,并且强烈依赖键盘。
|
||||
|
||||
![SpeedCrunch graphical interface][3]
|
||||
|
||||
SpeedCrunch 在工作时
|
||||
|
||||
It supports working with units and comes loaded with all kinds of functions.
|
||||
|
||||
所有函数都支持与单位一起工作。
|
||||
|
||||
例如,
|
||||
|
||||
`2 * 10^6 newton / (meter^2)`
|
||||
|
||||
你可以得到
|
||||
|
||||
`= 2000000 pascal`
|
||||
|
||||
SpeedCrunch 会默认地将结果转化为国际标准单位,但还是可以用"in"命令转换
|
||||
|
||||
例如:
|
||||
|
||||
`3*10^8 meter / second in kilo meter / hour`
|
||||
|
||||
结果是:
|
||||
`= 1080000000 kilo meter / hour`
|
||||
|
||||
`F5` 键可以将所有结果转为科学计数法 (`1.08e9 kilo meter / hour`),`F2`键可以只将那些很大的数或很小的数转为科学计数法。更多选项可以在配置(Configuration)页面找到。
|
||||
|
||||
可用的函数的列表看上去非常惊艳。它可以在 Linux 、 Windows、macOS.。许可证是GPLv2,你可以在[Bitbucket][4]上得到它的源码。
|
||||
|
||||
### Qalculate!
|
||||
|
||||
[Qalculate!][5](有感叹号)有一段长而复杂的历史。
|
||||
|
||||
这个项目给了我们一个强大的库,而这个库可以被其它程序使用(在 Plasma 桌面中,krunner 可以用它来计算),以及一个用 GTK3 搭建的图形界面前端。它允许你转换单位,处理物理常量,创建图像,使用复数,矩阵以及向量,选择任意准确度,等等
|
||||
|
||||
|
||||
![Qalculate! Interface][7]
|
||||
|
||||
正在在 Qalculate! 寻找物理常量
|
||||
|
||||
在使用单位上,Qalculate! 会比SppedCrunch 更加直观,而且可以识别一些常用前缀。你有听说过 exapascal 吗?反正我没有(太阳的中心大概在 `~26 PPa`),但 Qalculate! ,可以准确识别出 `1 EPa`。同时,Qalculate! 可以更加灵活地处理语法错误,所以你不需要担心打括号:如果没有歧义,Qalculate! 会直接给出正确答案。
|
||||
|
||||
一段时间之后这个计划看上去被遗弃了。但在2016年,它又变得强大了,在一年里更新了10个版本。它的许可证是 GPLv2 (源码在 [GitHub][8] 上),提供Linux 、Windows 、macOS的版本。
|
||||
|
||||
### Bonus calculators
|
||||
|
||||
#### 转换一切
|
||||
|
||||
好吧,这不是“计算器”,但这个程序非常好用
|
||||
|
||||
大部分单位转换器只是一大个基本单位列表以及一大堆基本组合,但[ConvertAll][9]与它们不一样。有试过把光年转换为英尺每秒吗?不管它们说不说得通,只要你想转换任何种类的单位,ConvertAll 就是你要的工具。
|
||||
|
||||
只需要在相应的输入框内输入转换前和转换后的单位:如果单位相容,你会直接得到答案。
|
||||
|
||||
主程序是在 PyQt5 上搭建的,但也有[JavaScript 的在线版本][10]。
|
||||
|
||||
#### (wx)Maxima with the units package
|
||||
|
||||
有时候(好吧,很多时候)一款桌面计算器时候不够你用的,然后你需要更多的原力(raw power?)
|
||||
|
||||
[Maxima][11]是一款计算机代数系统(LCTT 译者注:进行符号运算的软件。这种系统的要件是数学表示式的符号运算),你可以用它计算导数、积分、方程、特征值和特征向量、泰勒级数、拉普拉斯变换与傅立叶变换,以及任意精度的数字计算、二维或三维图像··· ···列出这些都够我们写几页纸的了。
|
||||
|
||||
[wxMaxima][12]是一个设计精湛的 Maxima 的图形前端,它简化了许多 Maxima 的选项,但并不会影响其它。在 Maxima 的基础上,wxMaxima 还允许你创建 “笔记本”(notebooks),你可以在上面写一些笔记,保存你的图像等。其中一项 (wx)Maxima 最惊艳的功能是它可以处理标注单位(dimension units)。
|
||||
|
||||
`load("unit")`
|
||||
|
||||
只需要输入`load("unit")`
|
||||
|
||||
按 Shift+Enter,等几秒钟的时间,然后你就可以开始了
|
||||
|
||||
默认地,单位包与基本 MKS 单位工作,但如果你喜欢,例如,要拿到 `N`为单位而不是 `kg*m/s2`,你只需要输入:`setunits(N)`
|
||||
|
||||
Maxima 的帮助(也可以在 wxMaxima 的帮助菜单中找到)会给你更多信息。
|
||||
|
||||
你使用这些程序吗?你知道还有其它好的科学、工程用途的桌面计算器或者其它相关的计算器吗?在评论区里告诉我们吧!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/1/scientific-calculators-linux
|
||||
|
||||
作者:[Ricardo Berlasso][a]
|
||||
译者:[译者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/rgb-es
|
||||
[1]:http://speedcrunch.org/index.html
|
||||
[2]:/file/382511
|
||||
[3]:https://opensource.com/sites/default/files/u128651/speedcrunch.png "SpeedCrunch graphical interface"
|
||||
[4]:https://bitbucket.org/heldercorreia/speedcrunch
|
||||
[5]:https://qalculate.github.io/
|
||||
[6]:/file/382506
|
||||
[7]:https://opensource.com/sites/default/files/u128651/qalculate-600.png "Qalculate! Interface"
|
||||
[8]:https://github.com/Qalculate
|
||||
[9]:http://convertall.bellz.org/
|
||||
[10]:http://convertall.bellz.org/js/
|
||||
[11]:http://maxima.sourceforge.net/
|
||||
[12]:https://andrejv.github.io/wxmaxima/
|
@ -1,137 +0,0 @@
|
||||
在 Linux 上寻找你正在寻找的东西
|
||||
=====
|
||||
|
||||

|
||||
在 Linux 系统上找到你要找的东西并不难 - 一个文件或一个命令 - 但是有很多种方法可以寻找。
|
||||
|
||||
### 7 个命令来寻找 Linux 文件
|
||||
|
||||
#### find
|
||||
|
||||
最明显的无疑是 **find** 命令,并且 find 变得比以前更容易使用。它过去需要一个搜索的起始位置,但是现在,如果你想将搜索限制在本地目录中,你还可以使用仅包含文件名或正则表达式的 find 命令。
|
||||
```
|
||||
$ find e*
|
||||
empty
|
||||
examples.desktop
|
||||
|
||||
```
|
||||
|
||||
这样,它就像 **ls** 命令一样工作,并没有做太多的搜索。
|
||||
|
||||
对于更专业的搜索,find 命令需要一个起点和一些搜索条件(除非你只是希望它提供该起点目录的递归列表)。命令 **find -type f** 从当前目录开始将递归列出所有常规文件,而 **find ~nemo -type f -empty** 将在 nemo 的主目录中找到空文件。
|
||||
```
|
||||
$ find ~nemo -type f -empty
|
||||
/home/nemo/empty
|
||||
|
||||
```
|
||||
|
||||
**同样在网络世界:[11 个毫无意义但是很棒的 Linux 终端技巧][1]。**
|
||||
|
||||
#### locate
|
||||
|
||||
**locate** 命令的名称表明它与 find 命令基本相同,但它的工作原理完全不同。**find** 命令可以根据各种条件 - 名称,大小,所有者,权限,状态(如空)等等选择文件并作为搜索选择深度,**locate** 命令通过名为 /var/lib/mlocate/mlocate.db 的文件查找你要查找的内容。该数据文件会定期更新,因此你刚创建的文件的位置它可能无法找到。如果这让你感到困扰,你可以运行 updatedb 文件并立即获得更新。
|
||||
```
|
||||
$ sudo updatedb
|
||||
|
||||
```
|
||||
|
||||
#### mlocate
|
||||
|
||||
**mlocate** 命令的工作类似于 **locate** 命令,它使用与 locate 相同的 mlocate.db 文件。
|
||||
|
||||
#### which
|
||||
|
||||
**which** 命令的工作方式与 **find** 命令和 **locate** 命令有很大的区别。它使用你的搜索路径并检查其上的每个目录,以查找具有你要查找的文件名的可执行文件。一旦找到一个,它会停止搜索并显示该可执行文件的完整路径。
|
||||
|
||||
**which** 命令的主要优点是它回答了“如果我输入此命令,将运行什么可执行文件?”的问题。它会忽略不可执行文件,并且不会列出系统上带有该名称的所有可执行文件 - 列出的就是它找到的第一个。如果你想查找具有某个名称的所有可执行文件,则可以像这样运行 find 命令,但运行非常高效 **which** 命令可能需要相当长的时间。
|
||||
```
|
||||
$ find / -name locate -perm -a=x 2>/dev/null
|
||||
/usr/bin/locate
|
||||
/etc/alternatives/locate
|
||||
|
||||
```
|
||||
|
||||
在这个 find 命令中,我们在寻找名为 “locate” 的所有可执行文件(任何人都可以运行的文件)。我们也选择了不要查看所有“拒绝访问”的消息,否则这些消息会混乱我们的屏幕。
|
||||
|
||||
#### whereis
|
||||
|
||||
**whereis** 命令与 **which** 命令非常类似,但它提供了更多信息。它不仅仅是寻找可执行文件,它还寻找手册页(man page)和源文件。像 **which** 命令一样,它使用搜索路径($PATH) 来驱动搜索。
|
||||
```
|
||||
$ whereis locate
|
||||
locate: /usr/bin/locate /usr/share/man/man1/locate.1.gz
|
||||
|
||||
```
|
||||
|
||||
#### whatis
|
||||
|
||||
**whatis** 命令有其独特的使命。它不是实际查找文件,而是在手册页中查找有关所询问命令的信息,并从手册页的顶部提供该命令的简要说明。
|
||||
```
|
||||
$ whatis locate
|
||||
locate (1) - find files by name
|
||||
|
||||
```
|
||||
|
||||
如果你询问你刚刚设置的脚本,它不会知道你指的是什么,并会告诉你。
|
||||
```
|
||||
$ whatis cleanup
|
||||
cleanup: nothing appropriate.
|
||||
|
||||
```
|
||||
|
||||
#### apropos
|
||||
|
||||
当你知道你想要做什么,但不知道应该使用什么命令来执行此操作时,**apropos** 命令很有用。例如,如果你想知道如何查找文件,那么 “apropos find” 和 “apropos locate” 会提供很多建议。
|
||||
```
|
||||
$ apropos find
|
||||
File::IconTheme (3pm) - find icon directories
|
||||
File::MimeInfo::Applications (3pm) - Find programs to open a file by mimetype
|
||||
File::UserDirs (3pm) - find extra media and documents directories
|
||||
find (1) - search for files in a directory hierarchy
|
||||
findfs (8) - find a filesystem by label or UUID
|
||||
findmnt (8) - find a filesystem
|
||||
gst-typefind-1.0 (1) - print Media type of file
|
||||
ippfind (1) - find internet printing protocol printers
|
||||
locate (1) - find files by name
|
||||
mlocate (1) - find files by name
|
||||
pidof (8) - find the process ID of a running program.
|
||||
sane-find-scanner (1) - find SCSI and USB scanners and their device files
|
||||
systemd-delta (1) - Find overridden configuration files
|
||||
xdg-user-dir (1) - Find an XDG user dir
|
||||
$
|
||||
$ apropos locate
|
||||
blkid (8) - locate/print block device attributes
|
||||
deallocvt (1) - deallocate unused virtual consoles
|
||||
fallocate (1) - preallocate or deallocate space to a file
|
||||
IO::Tty (3pm) - Low-level allocate a pseudo-Tty, import constants.
|
||||
locate (1) - find files by name
|
||||
mlocate (1) - find files by name
|
||||
mlocate.db (5) - a mlocate database
|
||||
mshowfat (1) - shows FAT clusters allocated to file
|
||||
ntfsfallocate (8) - preallocate space to a file on an NTFS volume
|
||||
systemd-sysusers (8) - Allocate system users and groups
|
||||
systemd-sysusers.service (8) - Allocate system users and groups
|
||||
updatedb (8) - update a database for mlocate
|
||||
updatedb.mlocate (8) - update a database for mlocate
|
||||
whereis (1) - locate the binary, source, and manual page files for a...
|
||||
which (1) - locate a command
|
||||
|
||||
```
|
||||
|
||||
### 总结
|
||||
|
||||
Linux 上可用于查找和识别文件的命令有很多种,但它们都非常有用。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3268768/linux/finding-what-you-re-looking-for-on-linux.html
|
||||
|
||||
作者:[Sandra Henry-Stocker][a]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.networkworld.com/author/Sandra-Henry_Stocker/
|
||||
[1]:http://www.networkworld.com/article/2926630/linux/11-pointless-but-awesome-linux-terminal-tricks.html#tk.nww-fsb
|
@ -0,0 +1,93 @@
|
||||
使用交互式 shell 来增强你的 Python
|
||||
======
|
||||

|
||||
Python 编程语言已经成为 IT 中使用的最流行的语言之一。成功的一个原因是它可以用来解决各种问题。从网站开发到数据科学、机器学习到任务自动化,Python 生态系统有丰富的框架和库。本文将介绍 Fedora 软件包集合中提供的一些有用的 Python shell 来简化开发。
|
||||
|
||||
### Python Shell
|
||||
|
||||
Python Shell 让你以交互模式使用解释器。在测试代码或尝试新库时非常有用。在 Fedora 中,你可以通过在终端会话中输入 python3 来调用默认的 shell。虽然 Fedora 提供了一些更高级和增强的 shell。
|
||||
|
||||
### IPython
|
||||
|
||||
IPython 为 Python shell 提供了许多有用的增强功能。例子包括 tab 补全,对象内省,系统 shell 访问和命令历史检索。许多功能也被 [Jupyter Notebook][1] 使用,因为它底层使用 IPython。
|
||||
|
||||
#### 安装和运行 IPython
|
||||
```
|
||||
dnf install ipython3
|
||||
ipython3
|
||||
|
||||
```
|
||||
|
||||
使用 tab 补全会提示你可能的选择。当你使用不熟悉的库时,此功能会派上用场。
|
||||
|
||||
![][2]
|
||||
|
||||
如果你需要更多信息,输入 ? 命令使用文档。有关更多详细信息,你可以使用 ?? 命令。
|
||||
|
||||
![][3]
|
||||
|
||||
另一个很酷的功能是使用 ! 字符执行系统 shell 命令的能力。然后可以在 IPython shell 中引用该命令的结果。
|
||||
|
||||
![][4]
|
||||
|
||||
IPython 完整的功能列表可在[官方文档][5]中找到。
|
||||
|
||||
### bpython
|
||||
|
||||
bpython 并不能像 IPython 做那么多,但它却在一个简单轻量级包中提供了一系列有用功能。除其他功能之外,bpython 提供:
|
||||
|
||||
* 内嵌语法高亮显示
|
||||
* 在你输入时提供自动补全建议
|
||||
* 可预期的参数列表
|
||||
* 能够将代码发送或保存到 pastebin 服务或文件中
|
||||
|
||||
|
||||
|
||||
#### 安装和运行 bpython
|
||||
```
|
||||
dnf install bpython3
|
||||
bpython3
|
||||
|
||||
```
|
||||
|
||||
在你输入的时候,bpython 为你提供了选择来自动补全你的代码。
|
||||
|
||||
![][6]
|
||||
|
||||
当你调用函数或方法时,会自动显示需要的参数和文档字符串。
|
||||
|
||||
![][7]
|
||||
|
||||
另一个很好的功能是可以使用功能键 F7 在外部编辑器(默认为 Vim)中打开当前的 bpython 会话。这在测试更复杂的程序时非常有用。
|
||||
|
||||
有关配置和功能的更多细节,请参考 bpython [文档][8]。
|
||||
|
||||
### 总结
|
||||
|
||||
使用增强的 Python shell 是提高生产力的好方法。它为你提供增强的功能来编写快速原型或尝试新库。你在使用增强的 Python shell 吗?请随意在评论区留言。
|
||||
|
||||
图片由 [David Clode][9] 在 [Unsplash][10] 上发布
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/enhance-python-interactive-shell/
|
||||
|
||||
作者:[Clément Verna][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://fedoramagazine.org/author/cverna/
|
||||
[1]:https://ipython.org/notebook.html
|
||||
[2]:https://fedoramagazine.org/wp-content/uploads/2018/03/ipython-tabcompletion.png
|
||||
[3]:https://fedoramagazine.org/wp-content/uploads/2018/03/ipyhton_doc1.png
|
||||
[4]:https://fedoramagazine.org/wp-content/uploads/2018/03/ipython_shell.png
|
||||
[5]:https://ipython.readthedocs.io/en/stable/overview.html#main-features-of-the-interactive-shell
|
||||
[6]:https://fedoramagazine.org/wp-content/uploads/2018/03/bpython1.png
|
||||
[7]:https://fedoramagazine.org/wp-content/uploads/2018/03/bpython2.png
|
||||
[8]:https://docs.bpython-interpreter.org/
|
||||
[9]:https://unsplash.com/photos/d0CasEMHDQs?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
||||
[10]:https://unsplash.com/search/photos/python?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
88
translated/tech/20180427 How to use FIND in Linux.md
Normal file
88
translated/tech/20180427 How to use FIND in Linux.md
Normal file
@ -0,0 +1,88 @@
|
||||
如何在 Linux 中使用 FIND
|
||||
======
|
||||
|
||||

|
||||
|
||||
在[最近的一篇 Opensource.com 文章][1]中,Lewis Cowles 介绍了 `find` 命令。
|
||||
|
||||
`find` 是日常工具箱中功能更强大、更灵活的命令行工具之一,因此值得花费更多的时间。
|
||||
|
||||
最简单的,`find` 跟上路径寻找一些东西。例如:
|
||||
```
|
||||
find /
|
||||
|
||||
```
|
||||
|
||||
它将找到(并打印)系统中的每个文件。而且由于一切都是文件,你会得到很多输出需要排序。这可能不会帮助你找到你要找的东西。你可以改变路径参数来缩小范围,但它不会比使用 `ls` 命令更有帮助。所以你需要考虑你想要找的东西。
|
||||
|
||||
也许你想在主目录中找到所有的 JPEG 文件。 `-name` 参数允许你将结果限制为与给定模式匹配的文件。
|
||||
```
|
||||
find ~ -name '*jpg'
|
||||
|
||||
```
|
||||
|
||||
可是等等!如果它们中的一些是大写的扩展名会怎么样?`-iname` 就像 `-name`,但是不区分大小写。
|
||||
```
|
||||
find ~ -iname '*jpg'
|
||||
|
||||
```
|
||||
|
||||
很好!但是 8.3 名称方案是如此的老。一些图片可能是 .jpeg 扩展名。幸运的是,我们可以将模式用 “or” 表示为 `-o`,来组合。
|
||||
```
|
||||
find ~ ( -iname 'jpeg' -o -iname 'jpg' )
|
||||
|
||||
```
|
||||
|
||||
我们正在接近。但是如果你有一些以 jpg 结尾的目录呢? (为什么你命名一个 `bucketofjpg` 而不是 `pictures` 的目录超出了我的范围。)我们使用 `-type` 参数修改我们的命令来查找文件。
|
||||
```
|
||||
find ~ \( -iname '*jpeg' -o -iname '*jpg' \) -type f
|
||||
|
||||
```
|
||||
|
||||
或者,也许你想找到那些命名奇怪的目录,以便稍后重命名它们:
|
||||
```
|
||||
find ~ \( -iname '*jpeg' -o -iname '*jpg' \) -type d
|
||||
|
||||
```
|
||||
|
||||
你最近拍了很多照片,所以让我们把它缩小到上周更改的文件。
|
||||
```
|
||||
find ~ \( -iname '*jpeg' -o -iname '*jpg' \) -type f -mtime -7
|
||||
|
||||
```
|
||||
|
||||
你可以根据文件状态更改时间 (ctime),修改时间 (mtime) 或访问时间 (atime) 来执行时间过滤。 这些是在几天内,所以如果你想要更细粒度的控制,你可以表示为在几分钟内(分别是 `cmin`、`mmin` 和 `amin`)。 除非你确切地知道你想要的时间,否则你可能会在 + (大于)或 - (小于)的后面加上数字。
|
||||
|
||||
但也许你不关心你的照片。也许你的磁盘空间不够用,所以你想在 `log` 目录下找到所有巨大的(让我们定义为“大于 1GB”)文件:
|
||||
```
|
||||
find /var/log -size +1G
|
||||
|
||||
```
|
||||
|
||||
或者,也许你想在 `/ data` 中找到 bcotton 拥有的所有文件:
|
||||
```
|
||||
find /data -owner bcotton
|
||||
|
||||
```
|
||||
|
||||
你还可以根据权限查找文件。也许你想在你的主目录中找到对所有人可读的文件,以确保你不会过度分享。
|
||||
```
|
||||
find ~ -perm -o=r
|
||||
|
||||
```
|
||||
|
||||
这篇文章只说了 `find` 能做什么的表面。将测试与布尔逻辑相结合可以为你提供难以置信的灵活性,以便准确找到要查找的文件。并且像 `-exec` 或 `-delete` 这样的参数,你可以让 `find` 对它发现的内容采取行动。你有任何最喜欢的 `find` 表达式么?在评论中分享它们!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/4/how-use-find-linux
|
||||
|
||||
作者:[Ben Cotton][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/bcotton
|
||||
[1]:https://opensource.com/article/18/4/how-find-files-linux
|
Loading…
Reference in New Issue
Block a user