Merge pull request #3 from LCTT/master

12月15日更新仓库
This commit is contained in:
李明岳 2018-12-15 05:50:47 -06:00 committed by GitHub
commit c7debee9fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
84 changed files with 9473 additions and 3156 deletions

View File

@ -1,4 +0,0 @@
# Linux中国翻译规范
1. 翻译中出现的专有名词可参见Dict.md中的翻译。
2. 英文人名,如无中文对应译名,一般不译。
2. 缩写词,一般不须翻译,可考虑旁注中文全名。

View File

@ -1,42 +1,49 @@
知识共享是怎样造福艺术家和大企业的
你所不知道的知识共享CC
======
> 知识共享为艺术家提供访问权限和原始素材。大公司也从中受益。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/CreativeCommons_ideas_520x292_1112JS.png?itok=otei0vKb)
我毕业于电影学院,毕业后在一所电影学校教书,之后进入一家主流电影工作室,我一直在从事电影相关的工作。创造业的方方面面面临着同一个问题:创造者需要原材料。有趣的是,自由文化运动提出了解决方案,具体来说是在自由文化运动中出现的知识共享组织。
我毕业于电影学院,毕业后在一所电影学校教书,之后进入一家主流电影工作室,我一直在从事电影相关的工作。创意产业的方方面面面临着同一个问题:创作者需要原材料。有趣的是,自由文化运动提出了解决方案,具体来说是在自由文化运动中出现的<ruby>知识共享<rt>Creative Commons</rt></ruby>组织。
###知识共享能够为我们提供展示片段和小样
### 知识共享能够为我们提供展示片段和小样
和其他事情一样,创造力也需要反复练习。幸运的是,在我刚开始接触电脑时,就在一本渲染工场的专业杂志中接触到了开源这个存在。当时我并不理解所谓的“开源”是什么,但我知道只有开源工具能帮助我在领域内稳定发展。对我来说,知识共享也是如此。知识共享可以为艺术家们提供充满丰富艺术资源的工作室。
和其他事情一样,创造力也需要反复练习。幸运的是,在我刚开始接触电脑时,就在一本关于渲染工场的专业杂志中接触到了开源这个存在。当时我并不理解所谓的“开源”是什么,但我知道只有开源工具能帮助我在领域内稳定发展。对我来说,知识共享也是如此。知识共享可以为艺术家们提供充满丰富艺术资源的工作室。
我在电影学院任教时,经常需要给学生们准备练习编辑、录音、拟音、分级、评分的脚本。在 Jim Munroe 的独立作品 [Infest Wisely][1] 中和 [Vimeo][2] 上的知识共享里我总能找到我想要的。这些写实的脚本覆盖内容十分广泛,从独立影院出品到昂贵的高质的升降镜头(一般都会用无人机代替)都有。
我在电影学院任教时,经常需要给学生们准备练习编辑、录音、拟音、分级、评分的示例录像。在 Jim Munroe 的独立作品 [Infest Wisely][1] 中和 [Vimeo][2] 上的知识共享内容里我总能找到我想要的。这些逼真的镜头覆盖内容十分广泛,从独立制作到昂贵的高品质的升降镜头(一般都会用无人机代替)都有。
对实验艺术来说,确有无尽可能。知识共享提供了丰富的底片材料,这些材料可以用来整合,混剪等等,可以满足一位视觉先锋能够想到的任何用途。
![](https://opensource.com/sites/default/files/u128651/bunny.png)
在接触知识共享之前,如果我想要使用写实脚本,我只能用之前的学生和老师拍摄的或者直接使用版权库里的脚本,但这些都有很多局限性
对实验主义艺术来说,确有无尽可能。知识共享提供了丰富的素材,这些材料可以用来整合、混剪等等,可以满足一位视觉先锋能够想到的任何用途
###坚守版权的底线很重要
在接触知识共享之前,如果我想要使用写实镜头,如果在大学,只能用之前的学生和老师拍摄的或者直接使用版权库里的镜头,或者使用有受限的版权保护的镜头。
知识共享同样能够创造经济效益。在某大型计算机公司的渲染工场工作时,我负责在某些硬件设施上测试渲染的运行情况,而这个测试时刻面临着被搁置的风险。做这些测试时,我用的都是[大雄兔][3]的资源因为这个电影和它的组件都是可以免费使用和分享的。如果没有这个小短片在接触写实资源之前我都没法完成我的实验因为对于一个计算机公司来说雇佣一只3D艺术家来应召布景是不太现实的。
### 坚守版权的底线很重要
令我震惊的是,与开源类似,知识共享已经用我们难以想象的方式支撑起了大公司。知识共享的使用或有或无地影响着公司的日常程序,但它填补了不足,让工作流程顺利进行。我没见到谁在他们的书中将流畅工作归功于知识共享的应用,但它确实无处不在
知识共享同样能够创造经济效益。在某大型计算机公司的渲染工场工作时,我负责在某些硬件设施上测试渲染的运行情况,而这个测试时刻面临着被搁置的风险。做这些测试时,我用的都是[大雄兔][3]的资源,因为这个电影和它的组件都是可以免费使用和分享的。如果没有这个小短片,在接触写实资源之前我都没法完成我的实验,因为对于一个计算机公司来说,雇佣一只 3D 艺术家来按需布景是不太现实的
我也见过一些开放版权的电影,比如[辛特尔][4],在最近的电视节目中播放了它的短片,那时的电视比现在的网络媒体要火得多
令我震惊的是,与开源类似,知识共享已经用我们难以想象的方式支撑起了大公司。知识共享的使用可能会也可能不会影响公司的日常流程,但它填补了不足,让工作流程顺利进行。我没见到谁在他们的书中将流畅工作归功于知识共享的应用,但它确实无处不在
###知识共享可以提供大量原材料
![](https://opensource.com/sites/default/files/u128651/sintel.png)
艺术家需要原材料。画家需要颜料,画笔和画布。雕塑家需要陶土和工具。数字内容编辑师需要数字内容,无论它是剪贴画还是音效或者是电子游戏里的成品精灵。
我也见过一些开放版权的电影,比如[辛特尔][4],在最近的电视节目中播放了它的短片,电视的分辨率已经超过了标准媒体。
### 知识共享可以提供大量原材料
艺术家需要原材料。画家需要颜料、画笔和画布。雕塑家需要陶土和工具。数字内容编辑师需要数字内容,无论它是剪贴画还是音效或者是电子游戏里的现成的精灵。
数字媒介赋予了人们超能力,让一个人就能完成需要一组人员才能完成的工作。事实上,我们大部分都好高骛远。我们想做高大上的项目,想让我们的成果不论是视觉上还是听觉上都无与伦比。我们想塑造的是宏大的世界,紧张的情节,能引起共鸣的作品,但我们所拥有的时间精力和技能与之都不匹配,达不到想要的效果。
是知识共享再一次拯救了我们,用 [Freesound.org][5], [Openclipart.org][6], [OpenGameArt.org][7] 等等网站上那些细小的开放版权艺术材料。通过知识共享,艺术家可以使用各种他们自己没办法创造的原材料,来完成他们原本完不成的工作。
是知识共享再一次拯救了我们,在 [Freesound.org][5]、 [Openclipart.org][6]、 [OpenGameArt.org][7] 等等网站上都有大量的开放版权艺术材料。通过知识共享,艺术家可以使用各种他们自己没办法创造的原材料,来完成他们原本完不成的工作。
最神奇的是,不用自己投资,你放在网上给大家使用的原材料就能变成精美的作品,而这是你从没想过的。我在知识共享上面分享了很多音乐素材,它们现在用于无数的专辑和电子游戏里。有些人用了我的材料会通知我,有些是我自己发现的,所以这些材料的应用可能比我知道的还有多得多。有时我会偶然看到我亲手画的标志出现在我从没听说过的软件里。我见到过我为[开源网站][8]写的文章在别处发表,有的是论文的参考文献,白皮书或者参考资料中。
最神奇的是,不用自己投资,你放在网上给大家使用的原材料就能变成精美的作品,而这是你从没想过的。我在知识共享上面分享了很多音乐素材,它们现在用于无数的专辑和电子游戏里。有些人用了我的材料会通知我,有些是我自己发现的,所以这些材料的应用可能比我知道的还有多得多。有时我会偶然看到我亲手画的标志出现在我从没听说过的软件里。我见到过我为 [Opensource.com][8] 写的文章在别处发表,有的是论文的参考文献,白皮书或者参考资料中。
###知识共享所代表的自由文化也是一种文化
### 知识共享所代表的自由文化也是一种文化
“自由文化”这个说法过于累赘,文化,从概念上来说,是一个有机的整体。在这种文化中社会逐渐成长发展,从一个人到另一个。它是人与人之间的互动和思想交流。自由文化是自由缺失的现代世界里的特殊产物。
如果你也想对这样的局限进行反抗,想把你的思想、作品你自己的文化分享给全世界的人,那么就来和我们一起,使用知识共享吧!
如果你也想对这样的局限进行反抗,想把你的思想、作品你自己的文化分享给全世界的人,那么就来和我们一起,使用知识共享吧!
--------------------------------------------------------------------------------
@ -44,7 +51,7 @@ via: https://opensource.com/article/18/1/creative-commons-real-world
作者:[Seth Kenlon][a]
译者:[Valoniakim](https://github.com/Valoniakim)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,9 +1,11 @@
使用开放决策框架收集项目需求
降低项目失败率的三个原则
======
> 透明和包容性的项目要求可以降低您的失败率。 以下是如何协作收集它们。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/suitcase_container_bag.png?itok=q40lKCBY)
众所周知,明确、简洁和可衡量的需求会带来更多成功的项目。一项关于[麦肯锡与牛津大学][1]的大型项目的研究表明:“平均而言,大型 IT 项目超出预算 45时间每推移 7价值就比预期低 56 。该研究还表明,造成这种失败的一些原因是“模糊的业务目标,不同步的利益相关者以及过度的返工
众所周知,明确、简洁和可衡量的需求会带来更多成功的项目。一项[麦肯锡与牛津大学][1]的关于大型项目的研究表明:“平均而言,大型 IT 项目超出预算 45时间每推移 7价值就比预期低 56该研究还表明,造成这种失败的一些原因是“模糊的业务目标,不同步的利益相关者以及过度的返工。
业务分析师经常发现自己通过持续对话来构建这些需求。为此,他们必须吸引多个利益相关方,并确保参与者提供明确的业务目标。这样可以减少返工,提高更多项目的成功率。
@ -29,7 +31,7 @@ via: https://opensource.com/open-organization/18/2/constructing-project-requirem
作者:[Tracy Buckner][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/) 荣誉推出
@ -37,4 +39,4 @@ via: https://opensource.com/open-organization/18/2/constructing-project-requirem
[1]:http://calleam.com/WTPF/?page_id=1445
[2]:https://opensource.com/open-organization/resources/open-decision-framework
[3]:https://opensource.com/open-organization/resources/open-org-definition
[4]:https://opensource.com/open-organization/16/6/introducing-open-decision-framework
[4]:https://opensource.com/open-organization/16/6/introducing-open-decision-framework

View File

@ -1,10 +1,11 @@
12 条实用的 zypper 命令范例
======
zypper 是 Suse Linux 系统的包和补丁管理器,你可以根据下面的 12 条附带输出示例的实用范例来学习 zypper 命令的使用。
`zypper` 是 Suse Linux 系统的包和补丁管理器,你可以根据下面的 12 条附带输出示例的实用范例来学习 `zypper` 命令的使用。
![zypper 命令示例][1]
Suse Linux 使用 zypper 进行包管理,其是一个由 [ZYpp 包管理引擎][2]提供技术支持的包管理系统。在此篇文章中我们将分享 12 条附带输出示例的实用 zypper 命令,能帮助你处理日常的系统管理任务。
Suse Linux 使用 `zypper` 进行包管理,其是一个由 [ZYpp 包管理引擎][2]提供的包管理系统。在此篇文章中我们将分享 12 条附带输出示例的实用 `zypper` 命令,能帮助你处理日常的系统管理任务。
不带参数的 `zypper` 命令将列出所有可用的选项,这比参考详细的 man 手册要容易上手得多。
@ -18,12 +19,12 @@ root@kerneltalks # zypper
--help, -h 帮助
--version, -V 输出版本号
--promptids 输出 zypper 用户提示符列表
--config, -c <file> 使用定的配置文件来替代默认的
--config, -c <file> 使用定的配置文件来替代默认的
--userdata <string> 在历史和插件中使用的用户自定义事务 id
--quiet, -q 忽略正常输出,只打印错误信息
--verbose, -v 增加冗长程度
--color
--no-color 是否启用彩色模式如果 tty 支持
--no-color 是否启用彩色模式如果 tty 支持的话
--no-abbrev, -A 表格中的文字不使用缩写
--table-style, -s 表格样式(整型)
--non-interactive, -n 不询问任何选项,自动使用默认答案
@ -43,7 +44,7 @@ root@kerneltalks # zypper
--gpg-auto-import-keys 自动信任并导入新仓库的签名密钥
--plus-repo, -p <URI> 使用附加仓库
--plus-content <tag> 另外使用禁用的仓库来提供特定的关键词
尝试 '--plus-content debug' 选项来启用仓库
尝试使用 '--plus-content debug' 选项来启用仓库
--disable-repositories 不从仓库中读取元数据
--no-refresh 不刷新仓库
--no-cd 忽略 CD/DVD 中的仓库
@ -55,11 +56,11 @@ root@kerneltalks # zypper
--disable-system-resolvables
不读取已安装包
命令:
命令
help, ? 打印帮助
shell, sh 允许多命令
仓库管理:
仓库管理
repos, lr 列出所有自定义仓库
addrepo, ar 添加一个新仓库
removerepo, rr 移除指定仓库
@ -68,14 +69,14 @@ root@kerneltalks # zypper
refresh, ref 刷新所有仓库
clean 清除本地缓存
服务管理:
服务管理
services, ls 列出所有自定义服务
addservice, as 添加一个新服务
modifyservice, ms 修改指定服务
removeservice, rs 移除指定服务
refresh-services, refs 刷新所有服务
软件管理:
软件管理
install, in 安装包
remove, rm 移除包
verify, ve 确认包依赖的完整性
@ -83,7 +84,7 @@ root@kerneltalks # zypper
install-new-recommends, inr
安装由已安装包建议一并安装的新包
更新管理:
更新管理
update, up 更新已安装包至更新版本
list-updates, lu 列出可用更新
patch 安装必要的补丁
@ -91,7 +92,7 @@ root@kerneltalks # zypper
dist-upgrade, dup 进行发行版更新
patch-check, pchk 检查补丁
查询:
查询
search, se 查找符合匹配模式的包
info, if 展示特定包的完全信息
patch-info 展示特定补丁的完全信息
@ -103,27 +104,28 @@ root@kerneltalks # zypper
products, pd 列出所有可用的产品
what-provides, wp 列出提供特定功能的包
包锁定:
包锁定
addlock, al 添加一个包锁定
removelock, rl 移除一个包锁定
locks, ll 列出当前的包锁定
cleanlocks, cl 移除无用的锁定
其他命令:
其他命令
versioncmp, vcmp 比较两个版本字符串
targetos, tos 打印目标操作系统 ID 字符串
licenses 打印已安装包的证书和 EULAs 报告
download 使用命令行下载指定 rpm 包到本地目录
source-download 下载所有已安装包的源码 rpm 包到本地目录
子命令:
子命令
subcommand 列出可用子命令
输入 'zypper help <command>' 来获得特定命令的帮助。
```
##### 如何使用 zypper 安装包
`zypper` 通过 `in``install` 开关来在你的系统上安装包。它的用法与 [yum package installation][3] 相同。你只需要提供包名作为参数,包管理器(此处是 zypper就会处理所有的依赖并与你指定的包一并安装。
### 如何使用 zypper 安装包
`zypper` 通过 `in``install` 子命令来在你的系统上安装包。它的用法与 [yum 软件包安装][3] 相同。你只需要提供包名作为参数,包管理器(此处是 `zypper`)就会处理所有的依赖并与你指定的包一并安装。
```
# zypper install telnet
@ -147,11 +149,11 @@ Checking for file conflicts: ...................................................
以上是我们安装 `telnet` 包时的输出,供你参考。
推荐阅读 : [在 YUM 和 APT 系统中安装包][3]
推荐阅读[在 YUM 和 APT 系统中安装包][3]
##### 如何使用 zypper 移除包
### 如何使用 zypper 移除包
要在 Suse Linux 中擦除或移除包,使用 `zypper` 命令附带 `remove``rm` 开关
要在 Suse Linux 中擦除或移除包,使用 `zypper` 附带 `remove``rm` 子命令
```
root@kerneltalks # zypper rm telnet
@ -167,13 +169,14 @@ After the operation, 113.3 KiB will be freed.
Continue? [y/n/...? shows all options] (y): y
(1/1) Removing telnet-1.2-165.63.x86_64 ..........................................................................................................................[done]
```
我们在此处移除了先前安装的 telnet 包。
##### 使用 zypper 检查依赖或者认证已安装包的完整性
### 使用 zypper 检查依赖或者认证已安装包的完整性
有时可以通过强制忽略依赖关系来安装软件包。`zypper` 使你能够扫描所有已安装的软件包并检查其依赖性。如果缺少任何依赖项,它将提供你安装或重新安装它的机会,从而保持已安装软件包的完整性。
使用附带 `verify``ve` 开关`zypper` 命令来检查已安装包的完整性。
使用附带 `verify``ve` 子命令`zypper` 命令来检查已安装包的完整性。
```
root@kerneltalks # zypper ve
@ -184,9 +187,10 @@ Reading installed packages...
Dependencies of all installed packages are satisfied.
```
在上面的输出中,你能够看到最后一行说明已安装包的所有依赖都已安装完全,并且无需更多操作。
##### 如何在 Suse Linux 中使用 zypper 下载包
### 如何在 Suse Linux 中使用 zypper 下载包
`zypper` 提供了一种方法使得你能够将包下载到本地目录而不去安装它。你可以在其他具有同样配置的系统上使用这个已下载的软件包。包会被下载至 `/var/cache/zypp/packages/<repo>/<arch>/` 目录。
@ -206,13 +210,14 @@ total 52
-rw-r--r-- 1 root root 53025 Feb 21 03:17 telnet-1.2-165.63.x86_64.rpm
```
你能看到我们使用 `zypper` 将 telnet 包下载到了本地。
推荐阅读 : [在 YUM 和 APT 系统中只下载包而不安装][4]
推荐阅读[在 YUM 和 APT 系统中只下载包而不安装][4]
##### 如何使用 zypper 列出可用包更新
### 如何使用 zypper 列出可用包更新
`zypper` 允许你浏览已安装包的所有可用更新,以便你可以提前计划更新活动。使用 `list-updates``lu` 开关来显示已安装包的所有可用更新。
`zypper` 允许你浏览已安装包的所有可用更新,以便你可以提前计划更新活动。使用 `list-updates``lu` 子命令来显示已安装包的所有可用更新。
```
root@kerneltalks # zypper lu
@ -229,11 +234,12 @@ v | SLE-Module-Containers12-Updates | containerd | 0.2.5+gitr6
v | SLES12-SP3-Updates | crash | 7.1.8-4.3.1 | 7.1.8-4.6.2 | x86_64
v | SLES12-SP3-Updates | rsync | 3.1.0-12.1 | 3.1.0-13.10.1 | x86_64
```
输出特意被格式化以便于阅读。每一列分别代表包所属仓库名称、包名、已安装版本、可用的更新版本和架构。
##### 在 Suse Linux 中列出和安装补丁
### 在 Suse Linux 中列出和安装补丁
使用 `list-patches``lp` 开关来显示你的 Suse Linux 系统需要被应用的所有可用补丁。
使用 `list-patches``lp` 子命令来显示你的 Suse Linux 系统需要被应用的所有可用补丁。
```
root@kerneltalks # zypper lp
@ -260,9 +266,9 @@ Found 37 applicable patches:
你可以通过发出 `zypper patch` 命令安装所有需要的补丁。
##### 如何使用 zypper 更新包
### 如何使用 zypper 更新包
要使用 zypper 更新包,使用 `update``up` 开关后接包名。在上述列出的更新命令中,我们知道在我们的服务器上 `rsync` 包更新可用。让我们现在来更新它吧!
要使用 `zypper` 更新包,使用 `update``up` 子命令后接包名。在上述列出的更新命令中,我们知道在我们的服务器上 `rsync` 包更新可用。让我们现在来更新它吧!
```
root@kerneltalks # zypper update rsync
@ -284,9 +290,9 @@ Checking for file conflicts: ...................................................
(1/1) Installing: rsync-3.1.0-13.10.1.x86_64 .....................................................................................................................[done]
```
##### 在 Suse Linux 上使用 zypper 查找包
### 在 Suse Linux 上使用 zypper 查找包
如果你不确定包的全名也不要担心。你可以使用 zypper 附带 `se``search` 开关并提供查找字符串来查找包。
如果你不确定包的全名也不要担心。你可以使用 `zypper` 附带的 `se``search` 子命令并提供查找字符串来查找包。
```
root@kerneltalks # zypper se lvm
@ -303,14 +309,15 @@ S | Name | Summary | Type
| llvm-devel | Header Files for LLVM | package
| lvm2 | Logical Volume Manager Tools | srcpackage
i+ | lvm2 | Logical Volume Manager Tools | package
| lvm2-devel | Development files for LVM2 | package
| lvm2-devel | Development files for LVM2 | package
```
在上述示例中我们查找了 `lvm` 字符串并得到了如上输出列表。你能在 zypper install/remove/update 命令中使用 `Name` 字段的名字。
##### 使用 zypper 检查已安装包信息
在上述示例中我们查找了 `lvm` 字符串并得到了如上输出列表。你能在 `zypper install/remove/update` 命令中使用 `Name` 字段的名字。
### 使用 zypper 检查已安装包信息
你能够使用 `zypper` 检查已安装包的详细信息。`info` 或 `if` 子命令将列出已安装包的信息。它也可以显示未安装包的详细信息,在该情况下,`Installed` 参数将返回 `No` 值。
你能够使用 zypper 检查已安装包的详细信息。`info` 或 `if` 开关将列出已安装包的信息。它也可以显示未安装包的详细信息,在该情况下,`Installed` 参数将返回 `No` 值。
```
root@kerneltalks # zypper info rsync
Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
@ -343,9 +350,9 @@ Description :
for backups and mirroring and as an improved copy command for everyday use.
```
##### 使用 zypper 列出仓库
### 使用 zypper 列出仓库
使用 zypper 命令附带 `lr``repos` 开关列出仓库。
使用 `zypper` 命令附带 `lr``repos` 子命令列出仓库。
```
root@kerneltalks # zypper lr
@ -364,7 +371,7 @@ Repository priorities are without effect. All enabled repositories share the sam
此处你需要检查 `enabled` 列来确定哪些仓库是已被启用的而哪些没有。
##### 在 Suse Linux 中使用 zypper 添加或移除仓库
### 在 Suse Linux 中使用 zypper 添加或移除仓库
要添加仓库你需要仓库或 .repo 文件的 URI否则你会遇到如下错误。
@ -390,16 +397,17 @@ Priority : 99 (default priority)
Repository priorities are without effect. All enabled repositories share the same priority.
```
在 Suse 中使用附带 `addrepo``ar` 开关的 `zypper` 命令添加仓库,后接 URI 以及你需要提供一个别名。
在 Suse 中使用附带 `addrepo``ar` 子命令的 `zypper` 命令添加仓库,后接 URI 以及你需要提供一个别名。
要在 Suse 中移除一个仓库,使用附带 `removerepo``rr` 子命令的 `zypper` 命令。
要在 Suse 中移除一个仓库,使用附带 `removerepo``rr` 开关的 `zypper` 命令。
```
root@kerneltalks # zypper removerepo nVidia-Driver-SLE12-SP3
Removing repository 'nVidia-Driver-SLE12-SP3' ....................................................................................................................[done]
Repository 'nVidia-Driver-SLE12-SP3' has been removed.
```
##### 清除 zypper 本地缓存
### 清除 zypper 本地缓存
使用 `zypper clean` 命令清除 zypper 本地缓存。
@ -414,7 +422,7 @@ via: https://kerneltalks.com/commands/12-useful-zypper-command-examples/
作者:[KernelTalks][a]
译者:[cycoe](https://github.com/cycoe)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -0,0 +1,138 @@
在 Linux 命令行下进行时间管理
======
> 学习如何在命令行下用这些方法自己组织待办事项。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc_terminals.png?itok=CfBqYBah)
关于如何在命令行下进行<ruby>时间管理<rt>getting things done</rt></ruby>GTD有很多讨论。不知有多少文章在讲使用 ls 晦涩的选项、配合 Sed 和 Awk 的一些神奇的正则表达式,以及用 Perl 解析一大堆的文本。但这些都不是问题的重点。
本文章是关于“[如何完成][1]”在我们不需要图形桌面、网络浏览器或网络连接情况下用命令行操作能实际完成事务的跟踪。为了达到这一点我们将介绍四种跟踪待办事项的方式纯文件文件、Todo.txt、TaskWarrior 和 Org 模式。
### 简单纯文本
![纯文本][3]
*我喜欢用 Vim其实你也可以用 Nano。*
最直接管理你的待办事项的方式就是用纯文本文件来编辑。只需要打开一个空文件,每一行添加一个任务。当任务完成后,删除这一行。简单有效,无论你用它做什么都没关系。不过这个方法也有两个缺点,一但你删除一行并保存了文件,它就是永远消失了。如果你想知道本周或者上周都做了哪些事情,就成了问题。使用简单文本文件很方便却也容易导致混乱。
### Todo.txt: 纯文件的升级版
![todo.txt 截屏][5]
*整洁,有条理,易用*
这就是我们要说的 [Todo.txt][6] 文件格式和应用程序。安装很简单,可从 GitHub [下载][7]最新的版本解压后并执行命令 `sudo make install`
![安装 todo.txt][9]
*也可以从 Git 克隆一个。*
Todo.txt 可以很容易的增加新任务,并能显示任务列表和已完成任务的标记:
| 命令 | 说明 |
| ------------- |:-------------|
| `todo.sh add "某任务"` | 增加 “某任务” 到你的待办列表 |
| `todo.sh ls` | 显示所有的任务 |
| `todo.sh ls due:2018-02-15` | 显示2018-02-15之前的所有任务 |
| `todo.sh do 3` | 标记任务3 为已完成任务 |
这个清单实际上仍然是纯文本,你可以用你喜欢的编辑器遵循[正确的格式][10]编辑它。
该应用程序同时也内置了一个强大的帮助系统。
![在 todo.txt 中语法高亮][12]
*你可以使用语法高亮的功能*
此外,还有许多附加组件可供选择,以及编写自己的附件组件规范。甚至有浏览器组件、移动设备应用程序和桌面应用程序支持 Todo.txt 的格式。
![GNOME extensions in todo.txt][14]
*GNOME的扩展组件*
Todo.txt 最大的缺点是缺少自动或内置的同步机制。大多数(不是全部)的浏览器扩展程序和移动应用程序需要用 Dropbox 实现桌面系统和应用程序直接的数据同步。如果你想内置同步机制,我们有……
### Taskwarrior: 现在我们用 Python 做事了
![Taskwarrior][25]
*花哨吗?*
[Taskwarrior][15] 是一个与 Todo.txt 有许多相同功能的 Python 工具。但不同的是它的数据保存在数据库里并具有内置的数据同步功能。它还可以跟踪即将要做的任务,可以提醒某个任务持续了多久,可以提醒你一些重要的事情应该马上去做。
![][26]
*看起来不错*
[安装][16] Taskwarrior 可以通过通过发行版自带的包管理器,或通过 Python 命令 `pip` 安装,或者用源码编译。用法也和 Todo.txt 的命令完全一样:
| 命令 | 说明 |
| ------------- |:-------------|
| `task add "某任务"` | 增加 “某任务” 到任务清单 |
| `task list` | 列出所有任务 |
| `task list due ``:today` | 列出截止今天的任务 |
| `task do 3` | 标记编号是3的任务为完成状态 |
Taskwarrior 还有漂亮的文本用户界面。
![Taskwarrior in Vit][18]
*我喜欢 Vit, 它的设计灵感来自 Vim*
不同于 Todo.txtTaskwarrior 可以和本地或远程服务器同步信息。如果你希望运行自己的同步服务器可以使用名为 `taskd` 的非常基本的服务器,如果不使用自己的服务器也有好几个可用服务器。
Taskwarriot 还拥有一个蓬勃发展的插件和扩展生态系统,以及移动和桌面系统的应用。
![GNOME in Taskwarrior ][20]
*在 GNOME 下的 Taskwarrior 看起来还是很漂亮的。*
Taskwarrior 有一个唯一的缺点,你是不能直接修改待办任务的,这和其他的工具不一样。你只能把任务清单按照格式导出,然后修改导出文件后,重新再导入,这样相对于编辑器直接编辑任务还是挺麻烦的。
谁能给我们带来最大的希望呢……
### Emacs Org 模式牛X的任务收割机
![Org-mode][22]
*Emacs 啥都有*
Emacs [Org 模式][23] 是目前为止最强大、最灵活的开源待办事项管理器。它支持多文件、使用纯文本、高度可定制、自动识别日期、截止日期和任务计划。相对于我们这里介绍的其他工具,它的配置也更复杂一些。但是一旦配置好,它可以比其他工具完成更多功能。如果你是熟悉或者是 [Bullet Journals][24] 的粉丝Org 模式可能是在桌面程序里最像[Bullet Journals][24] 的了。
Emacs 能运行Org 模式就能运行,一些移动应用程序可以和它很好交互。但是不幸的是,目前没有桌面程序或浏览器插件支持 Org 模式。尽管如此Org 模式仍然是跟踪待办事项最好的应用程序之一,因为它确实很强大。
### 选择适合自己的工具
最后,这些程序目的是帮助你跟踪待办事项,并确保不会忘记做某个事情。这些程序的基础功能都大同小异,那一款适合你取决于多种因素。有的人需要自带同步功能,有的人需要一个移动客户端,有的人要必须支持插件。不管你选择什么,请记住程序本身不会让你更有调理,但是可以帮助你。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/2/getting-to-done-agile-linux-command-line
作者:[Kevin Sonney][a]
译者:[guevaraya](https://github.com/guevaraya)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://opensource.com/users/ksonney (Kevin Sonney)
[1]:https://www.scruminc.com/getting-done/
[3]:https://opensource.com/sites/default/files/u128651/plain-text.png (plaintext)
[5]:https://opensource.com/sites/default/files/u128651/todo-txt.png (todo.txt screen)
[6]:http://todotxt.org/
[7]:https://github.com/todotxt/todo.txt-cli/releases
[9]:https://opensource.com/sites/default/files/u128651/todo-txt-install.png (Installing todo.txt)
[10]:https://github.com/todotxt/todo.txt
[12]:https://opensource.com/sites/default/files/u128651/todo-txt-vim.png (Syntax highlighting in todo.txt)
[14]:https://opensource.com/sites/default/files/u128651/tod-txt-gnome.png (GNOME extensions in todo.txt)
[15]:https://taskwarrior.org/
[16]:https://taskwarrior.org/download/
[18]:https://opensource.com/sites/default/files/u128651/taskwarrior-vit.png (Taskwarrior in Vit)
[20]:https://opensource.com/sites/default/files/u128651/taskwarrior-gnome.png (Taskwarrior on GNOME)
[22]:https://opensource.com/sites/default/files/u128651/emacs-org-mode.png (Org-mode)
[23]:https://orgmode.org/
[24]:http://bulletjournal.com/
[25]:https://opensource.com/sites/default/files/u128651/taskwarrior.png
[26]:https://opensource.com/sites/default/files/u128651/taskwarrior-complains.png

View File

@ -0,0 +1,122 @@
NASA 在开放科学方面做了些什么
======
![][1]
最近我们刚为开设了一个新的“[科学类][2]”的文章分类。其中发表的最新一篇文章名为:[开源是怎样影响科学的][3]。在这篇文章中我们主要讨论了 [NASA][4] 的积极努力,这些努力包括他们通过开源实践来促进科学研究的积极作用。
### NASA 是怎样使用开源手段促进科学研究的
NASA 将他们的整个研究库对整个公共领域开放,这是一项[壮举][5]。
没错!每个人都能访问他们的整个研究库,并能从他们的研究中获益。
他们现已开放的资料可以大致分为以下三类:
* 开源 NASA
* 开放 API
* 开放数据
### 1、开源 NASA
这里有一份 [GitHub][7] 的联合创始人之一和执行总裁 [Chris Wanstrath][6] 的采访,他向我们介绍道,一切都是从很多年前开始的。
- [Chris Wanstrath on NASA, open source and Github](https://youtu.be/dUFzMe8GM3M)
该项目名为 “[code.nasa.gov][8]”截至本文发表为止NASA 已经[通过 GitHub 开源][9]了 365 个科学软件LCTT 译注:本文原文发表于 2018/3/28截止至本译文发布已经有 454 个项目了)。对于一位热爱程序的开发者来说,即使一天研究一个软件,想把 NASA 的这些软件全部研究过来也要整整一年的时间。
即使你不是一位开发者,你也可以在这个门户网站浏览这个壮观的软件合集。
其中就有[阿波罗 11 号][10]的制导计算机的源代码。阿波罗 11 号空间飞行器[首次将两名人类带上月球][11],分别是 [Neil Armstrong][12] 和 [Edwin Aldrin][13] 。如果你对 Edwin Aldrin 感兴趣,可以点击[这里][14]了解更多。
#### NASA 开源代码促进会使用的开源代码许可
它们采用了几种[开源许可证][15],其分类如下:
- [Apache 许可证 2.0](https://www.apache.org/licenses/LICENSE-2.0)
- [Nasa 开源许可证 3.0](https://opensource.org/licenses/NASA-1.3)
- [GPL v3](https://www.gnu.org/licenses/gpl.html)
- [MIT 许可证](https://en.wikipedia.org/wiki/MIT_License)
### 2、开放 API
开放 [API][16] 在推行开放科学中起到了很大作用。与[开源促进会][17]类似,对于 API也有一个 [开放 API 促进会][18]。下面这张示意图可以告诉你 API 是怎样将应用程序和它的开发者连接起来的。
![][19]
记得点击这个[链接](https://sproutsocial.com/insights/what-is-an-api/)看看。链接内的文章使用了简单易懂的方法解读了 API ,文末总结了五大要点。
![][20]
这会让你感受到专有 API 和开放 API 会有多么大的不同。
![][22]
[NASA 的 Open API][23] 主要针对应用程序开发者,旨在显著改善数据的可访问性,也包括图片内容在内。该网站有一个实时编辑器,可供你调用[每日天文一图APOD][24] 的 API。
#### 3、开放数据
![][25]
在[我们发布的第一篇开放科学的文章][3]中,我们在“开放科学”段落下提到的三个国家 —— 法国、印度和美国的多种开放数据形式。NASA 有着类似的想法和行为。这种重要的意识形态已经被[多个国家][26]所接受。
[NASA 的开放数据门户][27]致力于开放拥有不断增长的可供大众自由使用的开放数据。将数据集纳入到这个数据集对于任何研究活动来说都是必要且重要的。NASA 还在他们的门户网站上征集各方的数据需求,以一同收录在他们的数据库中。这一举措不仅是领先的、创新的,还顺应了[数据科学][28]、[AI 和深度学习][29]的趋势。
下面的视频讲的是学者和学生们是怎样通过大量研究得出对数据科学的定义的。这个过程十分的激动人心。瑞尔森大学罗杰斯商学院的 [Murtaza Haider 教授][30]在视频结尾中提到了开源的出现对数据科学的改变,尤其让是旧有的闭源方式逐渐变得开放。而这也确实成为了现实。
- [What is Data Science? Data Science 101](https://youtu.be/z1kPKBdYks4)
![][31]
现在任何人都能在 NASA 上征集数据。正如前面的视频中所说NASA 的举措很大程度上与征集和分析优化数据有关。
![][32]
你只需要免费注册即可。考虑到论坛上的公开讨论以及数据集在可能存在的每一类分析领域中的重要性,这一举措在未来会有非常积极的影响,对数据的统计分析当然也会大幅进展。在之后的文章中我们还会具体讨论这些细节,还有它们和开源模式之间的相关性。
以上就是对 NASA 开放科学模式的一些探索成就,希望您能继续关注我们接下来的相关文章!
--------------------------------------------------------------------------------
via: https://itsfoss.com/nasa-open-science/
作者:[Avimanyu Bandyopadhyay][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[Valoniakim](https://github.com/Valoniakim)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/avimanyu/
[1]:https://itsfoss.com/wp-content/uploads/2018/03/tux-in-space.jpg
[2]:https://itsfoss.com/category/science/
[3]:https://itsfoss.com/open-source-impact-on-science/
[4]:https://www.nasa.gov/
[5]:https://futurism.com/free-science-nasa-just-opened-its-entire-research-library-to-the-public/
[6]:http://chriswanstrath.com/
[7]:https://github.com/
[8]:http://code.nasa.gov
[9]:https://github.com/open-source
[10]:https://www.nasa.gov/mission_pages/apollo/missions/apollo11.html
[11]:https://www.space.com/16758-apollo-11-first-moon-landing.html
[12]:https://www.jsc.nasa.gov/Bios/htmlbios/armstrong-na.html
[13]:https://www.jsc.nasa.gov/Bios/htmlbios/aldrin-b.html
[14]:https://buzzaldrin.com/the-man/
[15]:https://itsfoss.com/open-source-licenses-explained/
[16]:https://en.wikipedia.org/wiki/Application_programming_interface
[17]:https://opensource.org/
[18]:https://www.openapis.org/
[19]:https://itsfoss.com/wp-content/uploads/2018/03/api-bridge.jpeg
[20]:https://itsfoss.com/wp-content/uploads/2018/03/open-api-diagram.jpg
[21]:http://www.apiacademy.co/resources/api-strategy-lesson-201-private-apis-vs-open-apis/
[22]:https://itsfoss.com/wp-content/uploads/2018/03/nasa-open-api-live-example.jpg
[23]:https://api.nasa.gov/
[24]:https://apod.nasa.gov/apod/astropix.html
[25]:https://itsfoss.com/wp-content/uploads/2018/03/nasa-open-data-portal.jpg
[26]:https://www.xbrl.org/the-standard/why/ten-countries-with-open-data/
[27]:https://data.nasa.gov/
[28]:https://en.wikipedia.org/wiki/Data_science
[29]:https://www.kdnuggets.com/2017/07/ai-deep-learning-explained-simply.html
[30]:https://www.ryerson.ca/tedrogersschool/bm/programs/real-estate-management/murtaza-haider/
[31]:https://itsfoss.com/wp-content/uploads/2018/03/suggest-dataset-nasa-1.jpg
[32]:https://itsfoss.com/wp-content/uploads/2018/03/suggest-dataset-nasa-2-1.jpg

View File

@ -0,0 +1,72 @@
Emacs 系列(四):使用 Org 模式自动管理邮件及同步文档
======
这是 [Emacs 和 Org 模式系列][4]的第四篇。
至今为止,你已经见识到了 Org 模式的强大和高效,如果你像我一样,你可能会想:
> “我真的很想让它在我所有的设备上同步。”
或者是说:
> “我能在 Org 模式中转发邮件吗?”
答案当然是肯定的,因为这就是 Emacs。
### 同步
由于 Org 模式只使用文本文件,所以使用任意工具都可以很容易地实现同步。我使用的是 git 的 `git-remote-gcrypt`。由于 `git-remote-gcrypt` 的一些限制每台机器都倾向于推到自己的分支并使用命令来控制。每台机器都会先合并其它所有的分支然后再将合并后的结果推送到主干上。cron 作业可以实现将机器上的分支推送上去,而 elisp 会协调这一切 —— 确保在同步之前保存缓冲区,在同步之后从磁盘刷新缓冲区,等等。
这篇文章的代码有点多,所以我将把它链接到 github 上,而不是写在这里。
我有一个用来存放我所有的 Org 模式的文件的目录 `$HOME/org`,在 `~/org` 目录下有个 [Makefile][2] 文件来处理同步。该文件定义了以下目标:
* `push` 添加、提交和推送到以主机命名的分支上
* `fetch` 一个简单的 `git fetch` 操作
* `sync` 添加、提交和拉取远程的修改,合并,并(假设合并成功)将其推送到以主机命名的分支和主干上
现在,在我的用户 crontab 中有这个:
```
*/15 * * * * make -C $HOME/org push fetch 2>&1 | logger --tag 'orgsync'
```
[与之相关的 elisp 代码][3] 定义了一个快捷键(`C-c s`)来调用同步。多亏了 cronjob只要文件被保存 —— 即使我没有在另一个机器上同步 —— 它们也会被拉取进来。
我发现这个设置非常好用。
### 用 Org 模式发邮件
在继续下去之前,首先要问自己一下:你真的需要它吗? 我用的是带有 [mu4e][4] 的 Org 模式,而且它集成的也很好;任何 Org 模式的任务都可以通过 `Message-id` 链接到电子邮件,这很理想 —— 它可以让一个人做一些事情,比如提醒他在一周内回复一条消息。
然而Org 模式不仅仅只有提醒。它还是一个知识库、创作系统等,但是并不是我所有的邮件客户端都使用 mu4e。(注意:移动设备中有像 MobileOrg 这样的应用)。我并没有像我想的那样经常使用它,但是它有它的用途,所以我认为我也应该在这里记录它。
现在我不仅想处理纯文本电子邮件。我希望能够处理附件、HTML 邮件等。这听起来很快就有问题了 —— 但是通过使用 ripmime 和 pandoc 这样的工具,情况还不错。
第一步就是要用某些方法将获取到的邮件放入指定的文件夹下。扩展名、特殊用户等。然后我用一个 [fetchmail 配置][5] 来将它拉取下来并运行我自己的 [insorgmail][6] 脚本。
这个脚本就是处理所有有趣的部分了。它开始用 ripmime 处理消息,用 pandoc 将 HTML 的部分转换为 Org 模式的格式。 Org 模式的层次结构是用来尽可能最好地表示 email 的结构。使用 HTML 和其他工具时email 可能会变得相当复杂,但我发现这对于我来说是可以接受的。
### 下一篇
我最后一篇关于 Org 模式的文章将讨论如何使用它来编写文档和准备幻灯片 —— 我发现自己对 Org 模式的使用非常满意,但这需要一些调整。
--------------------------------------------------------------------------------
via: http://changelog.complete.org/archives/9898-emacs-4-automated-emails-to-org-mode-and-org-mode-syncing
作者:[John Goerzen][a]
译者:[oneforalone](https://github.com/oneforalone)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://changelog.complete.org/
[1]:https://changelog.complete.org/archives/tag/emacs2018
[2]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/Makefile
[3]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/emacs-config.org
[4]:https://www.emacswiki.org/emacs/mu4e
[5]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/fetchmailrc.orgmail
[6]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/insorgmail

View File

@ -1,59 +1,58 @@
Emacs #5: org-mode 之文档与 Presentations
Emacs 系列Org 模式之文档与演示稿
======
### 1 org-mode 的输出
这是 [Emacs 和 Org 模式系列][20]的第五篇。
这篇博文是由 Org 模式的源文件生成的,其有几种格式:[博客页面][21]、[演示稿][22] 和 [PDF 文档][23]。
### 1 Org 模式的输出
#### 1.1 背景
org-mode 不仅仅只是一个议程生成程序, 它也能输出许多不同的格式: LaTeXPDFBeameriCalendar议程HTMLMarkdownODT普通文本帮助页面man pages和其它更多的复杂的格式比如说网页文件。
Org 模式不仅仅只是一个议程生成程序,它也能输出许多不同的格式: LaTeX、PDF、Beamer、iCalendar议程、HTML、Markdown、ODT、普通文本、手册页和其它更多的复杂的格式,比如说网页文件。
这也不只是一些事后的想法,这是 org-mode 的设计核心部分并且集成的很好。
这也不只是一些事后的想法,这是 Org 模式的设计核心部分并且集成的很好。
一个文件可以同时是源代码,自动生成的输出,任务列表,文档和 presentation
这一个文件可以同时是源代码、自动生成的输出、任务列表、文档和展示
有些人将 org-mode 作为他们首选的标记格式,甚至对于 LaTeX 文档也是如此。org-mode 手册中的 [section on exporting][13] 有更详细的介绍。
有些人将 Org 模式作为他们首选的标记格式,甚至对于 LaTeX 文档也是如此。Org 模式手册中的 [输出一节][13] 有更详细的介绍。
#### 1.2 开始
对于任意的 org-mode 的文档,只要按下 C-c C-e键,就会弹出一个让你选择多种输出格式和选项的菜单。这些选项通常是次键选择,所以很容易设置和执行。例如:要输出一个 PDF 文档,按 C-c C-e l p要输出 HMTL 格式的, 按 C-c C-e h h。
对于任意的 Org 模式的文档,只要按下 `C-c C-e` 键,就会弹出一个让你选择多种输出格式和选项的菜单。这些选项通常是次键选择,所以很容易设置和执行。例如:要输出一个 PDF 文档,按 `C-c C-e l p`,要输出 HMTL 格式的, 按 `C-c C-e h h`
对于所有的输出选项,都有许多可用的设置;详情参见手册。事实上,使用 LaTeX 格式相当于同时使用 LaTeX 和 HTML 模式,在不同的模式中插入任意的前言和设置等。
#### 1.3 第三方插件
[ELPA][19] 中也包含了许多额外的输出格式,详情参见 [ELPA][19].
[ELPA][19] 中也包含了许多额外的输出格式,详情参见 [ELPA][19]
### 2 org-mode 的 Beamer 演示
### 2 Org 模式的 Beamer 演示
#### 2.1 关于 Beamer
[Beamer][14] 是一个生成 presentation 的 LaTeX 环境. 它包括了一下特性:
[Beamer][14] 是一个生成演示稿的 LaTeX 环境. 它包括了以下特性:
* 在 presentation 中自动生成结构化的元素(例如 [the Marburg theme][1])。 在 presentation 时,这个特性可以为观众提供了视觉参考。
* 在演示稿中自动生成结构化的元素(例如 [Marburg 主题][1])。 在演示稿中,这个特性可以为观众提供了视觉参考。
* 对组织演示稿有很大的帮助。
* 主题
* 完全支持 LaTeX
* 对组织 presentation 有很大的帮助。
#### 2.2 Org 模式中 Beamer 的优点
* 主题
* 完全支持 LaTeX
#### 2.2 org-mode 中 Beamer 的优点
在 org-mode 中用 Beamer 有很多好处,总的来说:
* org-mode 很简单而且对可视化支持的很好,同时改变结构可以快速的重组你的材料。
在 Org 模式中用 Beamer 有很多好处,总的来说:
* Org 模式很简单而且对可视化支持的很好,同时改变结构可以快速的重组你的材料。
* 与 org-babel 绑定在一起,实时语法高亮源码和内嵌结果。
* 语法通常更容易使用。
我已经完全用 org-mode 和 beamer 替换掉 LibreOffice/Powerpoint/GoogleDocs 的使用。事实上,当我必须使用其中一种工具时,这是相当令人沮丧的,因为它们在可视化表示结构方面远远比不上 org-mode
我已经完全用 Org 模式和 beamer 替换掉使用 LibreOffice/Powerpoint/GoogleDocs。事实上当我必须使用其中一种工具时这是相当令人沮丧的因为它们在可视化表示演讲稿结构方面远远比不上 Org 模式。
#### 2.3 标题层次
org-mode 的 Beamer 会将你文档中的部分(文中定义了标题的)转换成幻灯片。当然,问题是:哪些部分?这是由 H [export setting][15]org-export-headline-levels)决定的。
Org 模式的 Beamer 会将你文档中的部分(文中定义了标题的)转换成幻灯片。当然,问题是:哪些部分?这是由 H [输出设置][15]`org-export-headline-levels`)决定的。
针对不同的人,有许多不同的方法。我比较喜欢我的 presentation 这样:
针对不同的人,有许多不同的方法。我比较喜欢我的演示稿这样:
```
#+OPTIONS: H:2
@ -64,7 +63,7 @@ org-mode 的 Beamer 会将你文档中的部分(文中定义了标题的)转
#### 2.4 主题和配置
你可以在 org 文件的顶部来插入几行来配置 Beamer 和 LaTeX。在本文中例如你可以这样定义
你可以在 Org 模式的文件顶部来插入几行来配置 Beamer 和 LaTeX。在本文中例如你可以这样定义
```
#+TITLE: Documents and presentations with org-mode
@ -96,13 +95,13 @@ org-mode 的 Beamer 会将你文档中的部分(文中定义了标题的)转
#+BEAMER_HEADER: \setlength{\parskip}{\smallskipamount}
```
在这里, aspectratio=169 将纵横比设为 169, 其它部分都是标准的 LaTeX/Beamer 配置。
在这里`aspectratio=169` 将纵横比设为 16:9, 其它部分都是标准的 LaTeX/Beamer 配置。
#### 2.6 缩小 (适应屏幕)
有时你会遇到一些非常大的代码示例,你可能更倾向与将幻灯片缩小以适应它们。
只要按下 C-c C-c p 将 BEAMER_opt属性设为 shrink=15\.(或者设为更大的 shrink 值)。上一张幻灯片就用到了这个。
只要按下 `C-c C-c p``BEAMER_opt` 属性设为 `shrink=15`\。(或者设为更大的 shrink 值)。上一张幻灯片就用到了这个。
#### 2.7 效果
@ -114,28 +113,24 @@ org-mode 的 Beamer 会将你文档中的部分(文中定义了标题的)转
#### 3.1 交互式的 Emacs 幻灯片
使用 [org-tree-slide package][17] 这个插件的话, 就可以在 Emacs 的右侧显示幻灯片了。 只要按下 M-x然后输入 org-tree-slide-mode回车然后你就可以用 C-> 和 C-< 在幻灯片之间切换了
使用 [org-tree-slide][17] 这个插件的话,就可以在 Emacs 的右侧显示幻灯片了。 只要按下 `M-x`,然后输入 `org-tree-slide-mode`,回车,然后你就可以用 `C->``C-<` 在幻灯片之间切换了。
你可能会发现 C-c C-x C-v (即 org-toggle-inline-images有助于使系统显示内嵌的图像。
你可能会发现 `C-c C-x C-v` (即 `org-toggle-inline-images`)有助于使系统显示内嵌的图像。
#### 3.2 HTML 幻灯片
有许多方式可以将 org-mode 的 presentation 导出为 HTML并有不同级别的 JavaScript 集成。有关详细信息,请参见 org-mode 的 wiki 中的 [non-beamer presentations section][18]。
有许多方式可以将 Org 模式的演讲稿导出为 HTML并有不同级别的 JavaScript 集成。有关详细信息,请参见 Org 模式的 wiki 中的 [非 beamer 演讲稿一节][18]。
### 4 更多
#### 4.1 本文中的附加资源
* [orgmode.org beamer tutorial][2]
* [LaTeX wiki][3]
* [Generating section title slides][4]
* [Shrinking content to fit on slide][5]
* 很棒的资源: refcard-org-beamer 详情参见其 [Github repo][6] 中的 PDF 和 .org 文件。
* 很棒的资源: refcard-org-beamer
* 详情参见其 [Github repo][6] 中的 PDF 和 .org 文件。
* 很漂亮的主题: [Theme matrix][7]
#### 4.2 下一个 Emacs 系列
@ -148,9 +143,9 @@ mu4e 邮件!
via: http://changelog.complete.org/archives/9900-emacs-5-documents-and-presentations-with-org-mode
作者:[John Goerzen][a]
译者:[oneforalone](https://github.com/oneforalone)
校对:[校对者ID](https://github.com/校对者ID)
选题:[lujun9972](https://github.com/lujun9972)
译者:[oneforalone](https://github.com/oneforalone)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
@ -174,3 +169,9 @@ via: http://changelog.complete.org/archives/9900-emacs-5-documents-and-presentat
[17]:https://orgmode.org/worg/org-tutorials/non-beamer-presentations.html#org-tree-slide
[18]:https://orgmode.org/worg/org-tutorials/non-beamer-presentations.html
[19]:https://www.emacswiki.org/emacs/ELPA
[20]:https://changelog.complete.org/archives/tag/emacs2018
[21]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/emacs-org-beamer/emacs-org-beamer.org
[22]:http://changelog.complete.org/archives/9900-emacs-5-documents-and-presentations-with-org-mode
[23]:https://github.com/jgoerzen/public-snippets/raw/master/emacs/emacs-org-beamer/emacs-org-beamer.pdf
[24]:https://github.com/jgoerzen/public-snippets/raw/master/emacs/emacs-org-beamer/emacs-org-beamer-document.pdf

View File

@ -1,11 +1,13 @@
一种新的用于安全检测的方法
一种新的安全检测的方法
======
> 不要只测试已有系统,强安全要求更积极主动的策略。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/security_privacy_lock.png?itok=ZWjrpFzx)
我们当中有多少人曾说出过下面这句话:“我希望这能起到作用!”?
毫无疑问,我们中的大多数人可能都不止一次地说过这句话。这句话不是用来激发信心的,相反它揭示了我们对自身能力和当前正在测试功能的怀疑。不幸的是,这句话非常好地描述了我们传统的安全模型。我们的运营基于这样的假设,并希望我们实施的控制措施——从 web 应用的漏扫到终端上的杀毒软件——防止恶意的病毒和软件进入我们的系统,损坏或偷取我们的信息。
毫无疑问,我们中的大多数人可能都不止一次地说过这句话。这句话不是用来激发信心的,相反它揭示了我们对自身能力和当前正在测试功能的怀疑。不幸的是,这句话非常好地描述了我们传统的安全模型。我们的运营基于这样的假设,并希望我们实施的控制措施 —— 从 web 应用的漏扫到终端上的杀毒软件 —— 防止恶意的病毒和软件进入我们的系统,损坏或偷取我们的信息。
渗透测试通过积极地尝试侵入网络、向 web 应用注入恶意代码或者通过发送钓鱼邮件来传播病毒等等这些步骤来避免我们对假设的依赖。由于我们在不同的安全层面上来发现和渗透漏洞,手动测试无法解决漏洞被主动打开的情况。在安全实验中,我们故意在受控的情形下创造混乱,模拟事故的情形,来客观地检测我们检测、阻止这类问题的能力。
@ -13,15 +15,15 @@
在分布式系统的安全性和复杂性方面,需要反复地重申混沌工程界的一句名言,“希望不是一种有效的策略”。我们多久会主动测试一次我们设计或构建的系统,来确定我们是否已失去对它的控制?大多数组织都不会发现他们的安全控制措施失效了,直到安全事件的发生。我们相信“安全事件不是侦察措施”,而且“希望不要出事也不是一个有效的策略”应该是 IT 专业人士执行有效安全实践的口号。
业在传统上强调预防性的安全措施和纵深防御,但我们的任务是通过侦探实验来驱动对安全工具链的知识和见解。因为过于专注于预防机制,我们很少尝试一次以上地或者年度性地手动测试要求的安全措施,来验证这些控件是否按设计的那样执行。
业在传统上强调预防性的安全措施和纵深防御,但我们的任务是通过侦探实验来驱动对安全工具链的知识和见解。因为过于专注于预防机制,我们很少尝试一次以上地或者年度性地手动测试要求的安全措施,来验证这些控件是否按设计的那样执行。
随着现代分布式系统中的无状态变量的不断改变,人们很难充分理解他们的系统的行为,因为会随时变化。解决这个问题的一种途径是通过强大的系统性的设备进行检测,对于安全性检测,你可以将这个问题分成两个主要方面,测试,和我们称之为实验的部分。测试是对我们已知部分的验证和评估,简单来说,就是我们在开始找之前,要先弄清楚我们在找什么。另一方面,实验是去寻找获得我们之前并不清楚的见解和知识。虽然测试对于一个成熟的安全团队来说是一项重要实践,但以下示例会有助于进一步地阐述两者之间的差异,并对实验的附加价值提供一个更为贴切的描述。
随着现代分布式系统中的无状态变量的不断改变,人们很难充分理解他们的系统的行为,因为会随时变化。解决这个问题的一种途径是通过强大的系统性的设备进行检测,对于安全性检测,你可以将这个问题分成两个主要方面**测试**,和我们称之为**实验**的部分。测试是对我们已知部分的验证和评估,简单来说,就是我们在开始找之前,要先弄清楚我们在找什么。另一方面,实验是去寻找获得我们之前并不清楚的见解和知识。虽然测试对于一个成熟的安全团队来说是一项重要实践,但以下示例会有助于进一步地阐述两者之间的差异,并对实验的附加价值提供一个更为贴切的描述。
### 示例场景:精酿啤酒
思考一个用于接收精酿啤酒订单的 web 服务或者 web 应用。
这是这家精酿啤酒运输公司的一项重要服务,这些订单来自客户的移动设备网页,和通过为这家公司精酿啤酒提供服务的餐厅的 API。这项重要服务运行在 AWS EC2 环境上,并且公司认为它是安全的。这家公司去年成功地通过了 PCI 规则,并且每年都会请第三方进行渗透测试,所以公司认为这个系统是安全的。
这是这家精酿啤酒运输公司的一项重要服务,这些订单来自客户的移动设备网页,和通过为这家公司精酿啤酒提供服务的餐厅的 API。这项重要服务运行在 AWS EC2 环境上,并且公司认为它是安全的。这家公司去年成功地通过了 PCI 规则,并且每年都会请第三方进行渗透测试,所以公司认为这个系统是安全的。
这家公司有时一天两次部署来进行 DevOps 和持续交付工作,公司为其感到自豪。
@ -35,10 +37,8 @@
* 该配置会从已选择的目标中随机指定对象,同时端口的范围和数量也会被改变。
* 团队还会设置进行实验的时间并缩小爆破攻击的范围,来确保对业务的影响最小。
* 对于第一次测试,团队选择在他们的测试环境中运行实验并运行一个单独的测试。
* 在真实的游戏日风格里,团队在预先计划好的两个小时的窗口期内,选择灾难大师来运行实验。在那段窗口期内,灾难大师会在 EC2 实例安全组中的一个上执行这次实验。
* 一旦游戏日结束,团队就会开始进行一个彻底的、无可指责的事后练习。它的重点在于针对稳定状态和原始假设的实验结果。问题会类似于下面这些:
* 在真实的<ruby>游戏日<rt>Game Day</rt></ruby>风格里,团队在预先计划好的两个小时的窗口期内,选择<ruby>灾难大师<rt>Master of Disaster</rt></ruby>来运行实验。在那段窗口期内,灾难大师会在 EC2 实例安全组中的一个实例上执行这次实验。
* 一旦游戏日结束,团队就会开始进行一个彻底的、免于指责的事后练习。它的重点在于针对稳定状态和原始假设的实验结果。问题会类似于下面这些:
### 事后验证问题
@ -53,24 +53,22 @@
* 获得警报的 SOC 分析师是否能对警报采取措施,还是缺少必要的信息?
* 如果 SOC 确定警报是真实的,那么安全事件响应是否能简单地从数据中进行分类活动?
我们系统中对失败的承认和预期已经开始揭示我们对系统工作的假设。我们的使命是利用我们所学到的,并更加广泛地应用它。以此来真正主动地解决安全问题,来超越当前传统主流的被动处理问题的安全模型。
随着我们继续在这个新领域内进行探索,我们一定会发布我们的研究成果。如果您有兴趣想了解更多有关研究的信息或是想参与进来,请随时联系 Aaron Rinehart 或者 Grayson Brewer。
特别感谢 Samuel Roden 对本文提供的见解和想法。
**[看我们相关的文章,是否需要 DevSecOps 这个词?][3]]**
- [看我们相关的文章:是否需要 DevSecOps 这个词?][3]
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/4/new-approach-security-instrumentation
作者:[Aaron Rinehart][a]
译者:[hopefully2333](https://github.com/hopefully2333)
校对:[校对者ID](https://github.com/校对者ID)
选题:[lujun9972](https://github.com/lujun9972)
译者:[hopefully2333](https://github.com/hopefully2333)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -0,0 +1,483 @@
数据科学家的命令行技巧
======
![](https://i.imgur.com/0mzQMcB.png)
对于许多数据科学家来说,数据操作从始至终就是 Pandas 或 Tidyverse。从理论上讲这样做没有任何问题。毕竟这就是这些工具存在的原因。然而对于像分隔符转换这样的简单任务这些工具是大材小用了。
立志掌握命令行应该在每个开发人员的学习清单上,特别是数据科学家。学习 shell 的来龙去脉将无可否认地提高你的生产力。除此之外命令行还是计算领域的一个重要历史课程。例如awk —— 一种数据驱动的脚本语言。1977 年,在 [Brain Kernighan][1](即传奇的 [K&R 书][2]中 K的帮助下awk 首次出现。今天大约五十年过去了awk 仍然活跃在每年[新出版的书][3]里面。因此,可以安全地假设对命令行魔法的付出不会很快贬值。
### 我们将涵盖什么
* ICONV
* HEAD
* TR
* WC
* SPLIT
* SORT & UNIQ
* CUT
* PASTE
* JOIN
* GREP
* SED
* AWK
### ICONV
文件编码可能会很棘手。现在大部分文件都是 UTF-8 编码的。要了解 UTF-8 背后的一些魔力,请查看这个出色的[视频][4]。尽管如此,有时我们收到的文件不是这种编码。这可能引起对改变编码模式的一些胡乱尝试。这里,`iconv` 是一个拯救者。`iconv` 是一个简单的程序,它将获取采用一种编码的文本并输出采用另一种编码的文本。
```
# Converting -f (from) latin1 (ISO-8859-1)
# -t (to) standard UTF_8
iconv -f ISO-8859-1 -t UTF-8 < input.txt > output.txt
```
实用选项:
* `iconv -l` 列出所有已知编码
* `iconv -c` 默默丢弃无法转换的字符
### HEAD
如果你是一个 Pandas 重度用户,那么会很熟悉 `head`。通常在处理新数据时,我们想做的第一件事就是了解其内容。这就得启动 Pandas读取数据然后调用 `df.head()` —— 要说这有点费劲。没有任何选项的 `head` 将打印出文件的前 10 行。`head` 的真正力量在于干净利落的测试操作。例如,如果我们想将文件的分隔符从逗号更改为管道。一个快速测试将是:`head mydata.csv | sed 's/,/|/g'`。
```bash
# Prints out first 10 lines
head filename.csv
# Print first 3 lines
head -n 3 filename.csv
```
实用选项:
* `head -n` 打印特定行数
* `head -c` 打印特定字节数
### TR
`tr` 类似于翻译。这个功能强大的实用程序是文件基础清理的主力。理想的用例是替换文件中的分隔符。
```bash
# Converting a tab delimited file into commas
cat tab_delimited.txt | tr "\t" "," comma_delimited.csv
```
`tr` 另一个功能是你可以用内建 `[:class:]` 变量POSIX 字符类)发挥威力。这些包括了:
- `[:alnum:]` 所有字母和数字
- `[:alpha:]` 所有字母
- `[:blank:]` 所有水平空白
- `[:cntrl:]` 所有控制字符
- `[:digit:]` 所有数字
- `[:graph:]` 所有可打印字符,但不包括空格
- `[:lower:]` 所有小写字母
- `[:print:]` 所有可打印字符,包括空格
- `[:punct:]` 所有标点符号
- `[:space:]` 所有水平或垂直空白
- `[:upper:]` 所有大写字母
- `[:xdigit:]` 所有 16 进制数字
你可以将这些连接在一起以组成强大的程序。以下是一个基本的字数统计程序,可用于检查 README 是否被滥用。
```
cat README.md | tr "[:punct:][:space:]" "\n" | tr "[:upper:]" "[:lower:]" | grep . | sort | uniq -c | sort -nr
```
另一个使用基本正则表达式的例子:
```
# Converting all upper case letters to lower case
cat filename.csv | tr '[A-Z]' '[a-z]'
```
实用选项:
* `tr -d` 删除字符
* `tr -s` 压缩字符
* `\b` 退格
* `\f` 换页
* `\v` 垂直制表符
* `\NNN` 八进制字符
### WC
单词计数。它的价值主要来自其 `-l` 选项,它会给你提供行数。
```
# Will return number of lines in CSV
wc -l gigantic_comma.csv
```
这个工具可以方便地确认各种命令的输出。所以,如果我们在转换文件中的分隔符之后运行 `wc -l`,我们会期待总行数是一样的,如果不一致,我们就知道有地方出错了。
实用选项:
* `wc -c` 打印字节数
* `wc -m` 打印字符数
* `wc -L` 打印最长行的长度
* `wc -w` 打印单词数量
### SPLIT
文件大小的范围可以很广。对于有的任务,拆分文件或许是有好处的,所以使用 `split` 吧。`split` 的基本语法是:
```bash
# We will split our CSV into new_filename every 500 lines
split -l 500 filename.csv new_filename_
# filename.csv
# ls output
# new_filename_aaa
# new_filename_aab
# new_filename_aa
```
它有两个奇怪的地方是命名约定和缺少文件扩展名。后缀约定可以通过 `-d` 标志变为数字。要添加文件扩展名,你需要运行以下 `find` 命令。它将通过附加 `.csv` 扩展名来更改当前目录中所有文件的名称,所以小心了。
```bash
find . -type f -exec mv '{}' '{}'.csv \;
# ls output
# filename.csv.csv
# new_filename_aaa.csv
# new_filename_aab.csv
# new_filename_aac.csv
```
实用选项:
* `split -b N` 按特定字节大小分割
* `split -a N` 生成长度为 N 的后缀
* `split -x` 使用十六进制后缀
### SORT & UNIQ
上面两个命令很明显:它们的作用就是字面意思。这两者结合起来可以提供最强大的冲击 (例如,唯一单词的数量)。这是由于 `uniq` 只作用于重复的相邻行。这也是在输出前进行 `sort` 的原因。一个有趣的事情是 `sort -u` 会达到和典型的 `sort file.txt | uniq` 模式一样的结果。
`sort` 对数据科学家来说确实具有潜在的有用能力:能够根据特定列对整个 CSV 进行排序。
```bash
# Sorting a CSV file by the second column alphabetically
sort -t"," -k2,2 filename.csv
# Numerically
sort -t"," -k2n,2 filename.csv
# Reverse order
sort -t"," -k2nr,2 filename.csv
```
这里的 `-t` 选项将逗号指定为分隔符,通常假设分隔符是空格或制表符。此外,`-k` 选项是为了确定我们的键。这里的语法是 `-km,n``m` 作为开始列,`n` 作为结束列。
实用选项:
* `sort -f` 忽略大小写
* `sort -r` 反向排序
* `sort -R` 乱序
* `uniq -c` 统计出现次数
* `uniq -d` 只打印重复行
### CUT
`cut` 用于删除列。作为演示,如果我们只想删除第一和第三列。
```bash
cut -d, -f 1,3 filename.csv
```
要选择除了第一行外的所有行。
```bash
cut -d, -f 2- filename.csv
```
结合其他命令,将 `cut` 用作过滤器。
```bash
# Print first 10 lines of column 1 and 3, where "some_string_value" is present
head filename.csv | grep "some_string_value" | cut -d, -f 1,3
```
查出第二列中唯一值的数量。
```bash
cat filename.csv | cut -d, -f 2 | sort | uniq | wc -l
# Count occurences of unique values, limiting to first 10 results
cat filename.csv | cut -d, -f 2 | sort | uniq -c | head
```
### PASTE
`paste` 是一个带有趣味性功能的特定命令。如果你有两个需要合并的文件,并且它们已经排序好了,`paste` 帮你解决了接下来的步骤。
```bash
# names.txt
adam
john
zach
# jobs.txt
lawyer
youtuber
developer
# Join the two into a CSV
paste -d ',' names.txt jobs.txt > person_data.txt
# Output
adam,lawyer
john,youtuber
zach,developer
```
更多 SQL 式变种,见下文。
### JOIN
`join` 是一个简单的、<ruby>准切向的<rt>quasi-tangential</rt></ruby> SQL。最大的区别是 `join` 将返回所有列以及只能在一个字段上匹配。默认情况下,`join` 将尝试使用第一列作为匹配键。为了获得不同结果,必须使用以下语法:
```bash
# Join the first file (-1) by the second column
# and the second file (-2) by the first
join -t "," -1 2 -2 1 first_file.txt second_file.txt
```
标准的 `join` 是内连接。然而,外连接通过 `-a` 选项也是可行的。另一个值得一提的技巧是 `-q` 标志,如果发现有缺失的字段,可用于替换值。
```bash
# Outer join, replace blanks with NULL in columns 1 and 2
# -o which fields to substitute - 0 is key, 1.1 is first column, etc...
join -t"," -1 2 -a 1 -a2 -e ' NULL' -o '0,1.1,2.2' first_file.txt second_file.txt
```
它不是最用户友好的命令,而是绝望时刻的绝望措施。
实用选项:
* `join -a` 打印不可配对的行
* `join -e` 替换丢失的输入字段
* `join -j` 相当于 `-1 FIELD -2 FIELD`
### GREP
`grep`<ruby>用正则表达式全局搜索并且打印<rt>Global search for a Regular Expression and Print</rt></ruby>,可能是最有名的命令,并且名副其实。`grep` 很强大,特别适合在大型代码库中查找。在数据科学的王国里,它充当其他命令的提炼机制。虽然它的标准用途也很有价值。
```
# Recursively search and list all files in directory containing 'word'
grep -lr 'word' .
# List number of files containing word
grep -lr 'word' . | wc -l
```
计算包含单词或模式的总行数。
```
grep -c 'some_value' filename.csv
# Same thing, but in all files in current directory by file name
grep -c 'some_value' *
```
对多个值使用“或”运算符: `\|`
```
grep "first_value\|second_value" filename.csv
```
实用选项:
* `alias grep="grep --color=auto"` 使 grep 色彩丰富
* `grep -E` 使用扩展正则表达式
* `grep -w` 只匹配整个单词
* `grep -l` 打印匹配的文件名
* `grep -v` 非匹配
### 大人物们
`sed``awk` 是本文中最强大的两个命令。为简洁起见,我不打算详细讨论这两个命令。相反,我将介绍各种能证明其令人印象深刻的力量的命令。如果你想了解更多,[这儿就有一本书][5]是关于它们的。
### SED
`sed` 本质上是一个流编辑器。它擅长替换,但也可以用于所有输出重构。
最基本的 `sed` 命令由 `s/old/new/g` 组成。它的意思是搜索 `old`,全局替换为 `new`。 如果没有 `/g`,我们的命令将在 `old` 第一次出现后终止。
为了快速了解它的功能,我们可以深入了解一个例子。 在以下情景中,你已有以下文件:
```
balance,name
$1,000,john
$2,000,jack
```
我们可能想要做的第一件事是删除美元符号。`-i` 标志表示原位。`''` 表示零长度文件扩展名,从而覆盖我们的初始文件。理想情况下,你可以单独测试,然后输出到新文件。
```
sed -i '' 's/\$//g' data.txt
# balance,name
# 1,000,john
# 2,000,jack
```
接下来,去除 `blance` 列的逗号。
```
sed -i '' 's/\([0-9]\),\([0-9]\)/\1\2/g' data.txt
# balance,name
# 1000,john
# 2000,jack
```
最后 jack 有一天决定辞职。所以,再见了,我的朋友。
```
sed -i '' '/jack/d' data.txt
# balance,name
# 1000,john
```
正如你所看到的,`sed` 有很多强大的功能,但乐趣并不止于此。
### AWK
最好的留在最后。`awk` 不仅仅是一个简单的命令:它是一个成熟的语言。在本文中涉及的所有内容中,`awk` 是目前为止最酷的。如果你感兴趣,这里有很多很棒的资源 —— 看 [这里][6]、[这里][7] 和 [这里][8]。
`awk` 的常见用例包括:
* 文字处理
* 格式化文本报告
* 执行算术运算
* 执行字符串操作
`awk` 可以以最原生的形式并行 `grep`
```
awk '/word/' filename.csv
```
或者更加神奇:将 `grep``cut` 组合起来。在这里,对于所有带我们指定单词 `word` 的行,`awk` 打印第三和第四列,用 `tab` 分隔。`-F,` 用于指定切分时的列分隔符为逗号。
```bash
awk -F, '/word/ { print $3 "\t" $4 }' filename.csv
```
`awk` 内置了许多精巧的变量。比如,`NF` —— 字段数,和 `NR` —— 记录数。要获取文件中的第 53 条记录:
```bash
awk -F, 'NR == 53' filename.csv
```
更多的花招是其基于一个或多个值进行过滤的能力。下面的第一个示例将打印第一列等于给定字符串的行的行号和列。
```bash
awk -F, ' $1 == "string" { print NR, $0 } ' filename.csv
# Filter based off of numerical value in second column
awk -F, ' $2 == 1000 { print NR, $0 } ' filename.csv
```
多个数值表达式:
```bash
# Print line number and columns where column three greater
# than 2005 and column five less than one thousand
awk -F, ' $3 >= 2005 && $5 <= 1000 { print NR, $0 } ' filename.csv
```
求出第三列的总和:
```bash
awk -F, '{ x+=$3 } END { print x }' filename.csv
```
在第一列等于 `something` 的那些行,求出第三列值的总和。
```bash
awk -F, '$1 == "something" { x+=$3 } END { print x }' filename.csv
```
获取文件的行列数:
```bash
awk -F, 'END { print NF, NR }' filename.csv
# Prettier version
awk -F, 'BEGIN { print "COLUMNS", "ROWS" }; END { print NF, NR }' filename.csv
```
打印出现了两次的行:
```bash
awk -F, '++seen[$0] == 2' filename.csv
```
删除重复的行:
```bash
# Consecutive lines
awk 'a !~ $0; {a=$0}']
# Nonconsecutive lines
awk '! a[$0]++' filename.csv
# More efficient
awk '!($0 in a) {a[$0];print}
```
使用内置函数 `gsub()` 替换多个值。
```bash
awk '{gsub(/scarlet|ruby|puce/, "red"); print}'
```
这个 `awk` 命令将组合多个 CSV 文件,忽略标题,然后在最后附加它。
```bash
awk 'FNR==1 && NR!=1{next;}{print}' *.csv > final_file.csv
```
需要缩小一个庞大的文件? `awk` 可以在 `sed` 的帮助下处理它。具体来说,该命令根据行数将一个大文件分成多个较小的文件。这个一行脚本将增加一个扩展名。
```bash
sed '1d;$d' filename.csv | awk 'NR%NUMBER_OF_LINES==1{x="filename-"++i".csv";}{print > x}'
# Example: splitting big_data.csv into data_(n).csv every 100,000 lines
sed '1d;$d' big_data.csv | awk 'NR%100000==1{x="data_"++i".csv";}{print > x}'
```
### 结语
命令行拥有无穷无尽的力量。本文中介绍的命令足以将你从一无所知提升到英雄人物。除了涵盖的内容之外,还有许多实用程序可以考虑用于日常数据操作。[Csvkit][9]、[xsv][10] 还有 [q][11] 是需要记住的三个。如果你希望更深入地了解命令行数据科学,查看[这本书][12]。它也可以[免费][13]在线获得!
--------------------------------------------------------------------------------
via: http://kadekillary.work/post/cli-4-ds/
作者:[Kade Killary][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[GraveAccent](https://github.com/graveaccent)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://kadekillary.work/authors/kadekillary
[1]:https://en.wikipedia.org/wiki/Brian_Kernighan
[2]:https://en.wikipedia.org/wiki/The_C_Programming_Language
[3]:https://www.amazon.com/Learning-AWK-Programming-cutting-edge-text-processing-ebook/dp/B07BT98HDS
[4]:https://www.youtube.com/watch?v=MijmeoH9LT4
[5]:https://www.amazon.com/sed-awk-Dale-Dougherty/dp/1565922255/ref=sr_1_1?ie=UTF8&qid=1524381457&sr=8-1&keywords=sed+and+awk
[6]:https://www.amazon.com/AWK-Programming-Language-Alfred-Aho/dp/020107981X/ref=sr_1_1?ie=UTF8&qid=1524388936&sr=8-1&keywords=awk
[7]:http://www.grymoire.com/Unix/Awk.html
[8]:https://www.tutorialspoint.com/awk/index.htm
[9]:http://csvkit.readthedocs.io/en/1.0.3/
[10]:https://github.com/BurntSushi/xsv
[11]:https://github.com/harelba/q
[12]:https://www.amazon.com/Data-Science-Command-Line-Time-Tested/dp/1491947853/ref=sr_1_1?ie=UTF8&qid=1524390894&sr=8-1&keywords=data+science+at+the+command+line
[13]:https://www.datascienceatthecommandline.com/

View File

@ -0,0 +1,472 @@
使用 gorilla/mux 进行 HTTP 请求路由和验证
======
> gorilla/mux 包以直观的 API 提供了 HTTP 请求路由、验证和其它服务。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/data_metrics_analytics_desktop_laptop.png?itok=9QXd7AUr)
Go 网络库包括 `http.ServeMux` 结构类型,它支持 HTTP 请求多路复用路由Web 服务器将托管资源的 HTTP 请求与诸如 `/sales4today` 之类的 URI 路由到代码处理程序;处理程序在发送 HTTP 响应(通常是 HTML 页面)之前执行适当的逻辑。 这是该体系的草图:
```
             +-----------+     +--------+     +---------+
HTTP 请求---->| web 服务器 |---->| 路由 |---->| 处理程序 |
             +-----------+     +--------+     +---------+
```
调用 `ListenAndServe` 方法后启动 HTTP 服务器:
```
http.ListenAndServe(":8888", nil) // args: port & router
```
第二个参数 `nil` 意味着 `DefaultServeMux` 用于请求路由。
`gorilla/mux` 库包含 `mux.Router` 类型,可替代 `DefaultServeMux` 或自定义请求多路复用器。 在 `ListenAndServe` 调用中,`mux.Router` 实例将代替 `nil` 作为第二个参数。 下面的示例代码很好的说明了为什么 `mux.Router`如此吸引人:
### 1、一个简单的 CRUD web 应用程序
crud web 应用程序(见下文)支持四种 CRUD创建/读取/更新/删除)操作,它们分别对应四种 HTTP 请求方法POST、GET、PUT 和 DELETE。 在这个 CRUD 应用程序中,所管理的资源是套话与反套话的列表,每个都是套话及其反面的的套话,例如这对:
```
Out of sight, out of mind. Absence makes the heart grow fonder.
```
可以添加新的套话对,可以编辑或删除现有的套话对。
CRUD web 应用程序:
```
package main
import (
"gorilla/mux"
"net/http"
"fmt"
"strconv"
)
const GETALL string = "GETALL"
const GETONE string = "GETONE"
const POST string = "POST"
const PUT string = "PUT"
const DELETE string = "DELETE"
type clichePair struct {
Id int
Cliche string
Counter string
}
// Message sent to goroutine that accesses the requested resource.
type crudRequest struct {
verb string
cp *clichePair
id int
cliche string
counter string
confirm chan string
}
var clichesList = []*clichePair{}
var masterId = 1
var crudRequests chan *crudRequest
// GET /
// GET /cliches
func ClichesAll(res http.ResponseWriter, req *http.Request) {
cr := &crudRequest{verb: GETALL, confirm: make(chan string)}
completeRequest(cr, res, "read all")
}
// GET /cliches/id
func ClichesOne(res http.ResponseWriter, req *http.Request) {
id := getIdFromRequest(req)
cr := &crudRequest{verb: GETONE, id: id, confirm: make(chan string)}
completeRequest(cr, res, "read one")
}
// POST /cliches
func ClichesCreate(res http.ResponseWriter, req *http.Request) {
cliche, counter := getDataFromRequest(req)
cp := new(clichePair)
cp.Cliche = cliche
cp.Counter = counter
cr := &crudRequest{verb: POST, cp: cp, confirm: make(chan string)}
completeRequest(cr, res, "create")
}
// PUT /cliches/id
func ClichesEdit(res http.ResponseWriter, req *http.Request) {
id := getIdFromRequest(req)
cliche, counter := getDataFromRequest(req)
cr := &crudRequest{verb: PUT, id: id, cliche: cliche, counter: counter, confirm: make(chan string)}
completeRequest(cr, res, "edit")
}
// DELETE /cliches/id
func ClichesDelete(res http.ResponseWriter, req *http.Request) {
id := getIdFromRequest(req)
cr := &crudRequest{verb: DELETE, id: id, confirm: make(chan string)}
completeRequest(cr, res, "delete")
}
func completeRequest(cr *crudRequest, res http.ResponseWriter, logMsg string) {
crudRequests<-cr
msg := <-cr.confirm
res.Write([]byte(msg))
logIt(logMsg)
}
func main() {
populateClichesList()
// From now on, this gorountine alone accesses the clichesList.
crudRequests = make(chan *crudRequest, 8)
go func() { // resource manager
for {
select {
case req := <-crudRequests:
if req.verb == GETALL {
req.confirm<-readAll()
} else if req.verb == GETONE {
req.confirm<-readOne(req.id)
} else if req.verb == POST {
req.confirm<-addPair(req.cp)
} else if req.verb == PUT {
req.confirm<-editPair(req.id, req.cliche, req.counter)
} else if req.verb == DELETE {
req.confirm<-deletePair(req.id)
}
}
}()
startServer()
}
func startServer() {
router := mux.NewRouter()
// Dispatch map for CRUD operations.
router.HandleFunc("/", ClichesAll).Methods("GET")
router.HandleFunc("/cliches", ClichesAll).Methods("GET")
router.HandleFunc("/cliches/{id:[0-9]+}", ClichesOne).Methods("GET")
router.HandleFunc("/cliches", ClichesCreate).Methods("POST")
router.HandleFunc("/cliches/{id:[0-9]+}", ClichesEdit).Methods("PUT")
router.HandleFunc("/cliches/{id:[0-9]+}", ClichesDelete).Methods("DELETE")
http.Handle("/", router) // enable the router
// Start the server.
port := ":8888"
fmt.Println("\nListening on port " + port)
http.ListenAndServe(port, router); // mux.Router now in play
}
// Return entire list to requester.
func readAll() string {
msg := "\n"
for _, cliche := range clichesList {
next := strconv.Itoa(cliche.Id) + ": " + cliche.Cliche + " " + cliche.Counter + "\n"
msg += next
}
return msg
}
// Return specified clichePair to requester.
func readOne(id int) string {
msg := "\n" + "Bad Id: " + strconv.Itoa(id) + "\n"
index := findCliche(id)
if index >= 0 {
cliche := clichesList[index]
msg = "\n" + strconv.Itoa(id) + ": " + cliche.Cliche + " " + cliche.Counter + "\n"
}
return msg
}
// Create a new clichePair and add to list
func addPair(cp *clichePair) string {
cp.Id = masterId
masterId++
clichesList = append(clichesList, cp)
return "\nCreated: " + cp.Cliche + " " + cp.Counter + "\n"
}
// Edit an existing clichePair
func editPair(id int, cliche string, counter string) string {
msg := "\n" + "Bad Id: " + strconv.Itoa(id) + "\n"
index := findCliche(id)
if index >= 0 {
clichesList[index].Cliche = cliche
clichesList[index].Counter = counter
msg = "\nCliche edited: " + cliche + " " + counter + "\n"
}
return msg
}
// Delete a clichePair
func deletePair(id int) string {
idStr := strconv.Itoa(id)
msg := "\n" + "Bad Id: " + idStr + "\n"
index := findCliche(id)
if index >= 0 {
clichesList = append(clichesList[:index], clichesList[index + 1:]...)
msg = "\nCliche " + idStr + " deleted\n"
}
return msg
}
//*** utility functions
func findCliche(id int) int {
for i := 0; i < len(clichesList); i++ {
if id == clichesList[i].Id {
return i;
}
}
return -1 // not found
}
func getIdFromRequest(req *http.Request) int {
vars := mux.Vars(req)
id, _ := strconv.Atoi(vars["id"])
return id
}
func getDataFromRequest(req *http.Request) (string, string) {
// Extract the user-provided data for the new clichePair
req.ParseForm()
form := req.Form
cliche := form["cliche"][0] // 1st and only member of a list
counter := form["counter"][0] // ditto
return cliche, counter
}
func logIt(msg string) {
fmt.Println(msg)
}
func populateClichesList() {
var cliches = []string {
"Out of sight, out of mind.",
"A penny saved is a penny earned.",
"He who hesitates is lost.",
}
var counterCliches = []string {
"Absence makes the heart grow fonder.",
"Penny-wise and dollar-foolish.",
"Look before you leap.",
}
for i := 0; i < len(cliches); i++ {
cp := new(clichePair)
cp.Id = masterId
masterId++
cp.Cliche = cliches[i]
cp.Counter = counterCliches[i]
clichesList = append(clichesList, cp)
}
}
```
为了专注于请求路由和验证CRUD 应用程序不使用 HTML 页面作为请求响应。 相反,请求会产生明文响应消息:套话对的列表是对 GET 请求的响应,确认新的套话对已添加到列表中是对 POST 请求的响应,依此类推。 这种简化使得使用命令行实用程序(如 [curl][1])可以轻松地测试应用程序,尤其是 `gorilla/mux` 组件。
`gorilla/mux` 包可以从 [GitHub][2] 安装。 CRUD app 无限期运行;因此,应使用 `Control-C` 或同等命令终止。 CRUD 应用程序的代码,以及自述文件和简单的 curl 测试,可以在[我的网站] [3]上找到。
### 2、请求路由
`mux.Router` 扩展了 REST 风格的路由,它赋给 HTTP 方法例如GET和 URL 末尾的 URI 或路径(例如 `/cliches`)相同的权重。 URI 用作 HTTP 动词(方法)的名词。 例如在HTTP请求中有一个起始行例如
```
GET /cliches
```
意味着得到所有的套话对,而一个起始线,如:
```
POST /cliches
```
意味着从 HTTP 正文中的数据创建一个套话对。
在 CRUD web 应用程序中,有五个函数充当 HTTP 请求的五种变体的请求处理程序:
```
ClichesAll(...)    # GET: 获取所有的套话对
ClichesOne(...)    # GET: 获取指定的套话对
ClichesCreate(...) # POST: 创建新的套话对
ClichesEdit(...)   # PUT: 编辑现有的套话对
ClichesDelete(...) # DELETE: 删除指定的套话对
```
每个函数都有两个参数:一个 `http.ResponseWriter` 用于向请求者发送一个响应,一个指向 `http.Request` 的指针,该指针封装了底层 HTTP 请求的信息。 使用 `gorilla/mux` 包可以轻松地将这些请求处理程序注册到Web服务器并执行基于正则表达式的验证。
CRUD 应用程序中的 `startServer` 函数注册请求处理程序。 考虑这对注册,`router` 作为 `mux.Router` 实例:
```
router.HandleFunc("/", ClichesAll).Methods("GET")
router.HandleFunc("/cliches", ClichesAll).Methods("GET")
```
这些语句意味着对单斜线 `/``/cliches` 的 GET 请求应该路由到 `ClichesAll` 函数,然后处理请求。 例如curl 请求(使用 `` 作为命令行提示符):
```
% curl --request GET localhost:8888/
```
会产生如下结果:
```
1: Out of sight, out of mind.  Absence makes the heart grow fonder.
2: A penny saved is a penny earned.  Penny-wise and dollar-foolish.
3: He who hesitates is lost.  Look before you leap.
```
这三个套话对是 CRUD 应用程序中的初始数据。
在这句注册语句中:
```
router.HandleFunc("/cliches", ClichesAll).Methods("GET")
router.HandleFunc("/cliches", ClichesCreate).Methods("POST")
```
URI 是相同的(`/cliches`),但动词不同:第一种情况下为 GET 请求,第二种情况下为 POST 请求。 此注册举例说明了 REST 样式的路由,因为仅动词的不同就足以将请求分派给两个不同的处理程序。
注册中允许多个 HTTP 方法,尽管这会影响 REST 风格路由的精髓:
```
router.HandleFunc("/cliches", DoItAll).Methods("POST", "GET")
```
除了动词和 URI 之外,还可以在功能上路由 HTTP 请求。 例如,注册
```
router.HandleFunc("/cliches", ClichesCreate).Schemes("https").Methods("POST")
```
要求对 POST 请求进行 HTTPS 访问以创建新的套话对。以类似的方式,注册可能需要具有指定的 HTTP 头元素(例如,认证凭证)的请求。
### 3、 Request validation
`gorilla/mux` 包采用简单,直观的方法通过正则表达式进行请求验证。 考虑此请求处理程序以获取一个操作:
```
router.HandleFunc("/cliches/{id:[0-9]+}", ClichesOne).Methods("GET")
```
此注册排除了 HTTP 请求,例如:
```
% curl --request GET localhost:8888/cliches/foo
```
因为 foo 不是十进制数字。该请求导致熟悉的 404未找到状态码。 在此处理程序注册中包含正则表达式模式可确保仅在请求 URI 以十进制整数值结束时才调用 `ClichesOne` 函数来处理请求:
```
% curl --request GET localhost:8888/cliches/3  # ok
```
另一个例子,请求如下:
```
% curl --request PUT --data "..." localhost:8888/cliches
```
此请求导致状态代码为 405错误方法因为 /cliches URI 在 CRUD 应用程序中仅在 GET 和 POST 请求中注册。 像 GET 请求一样PUT 请求必须在 URI 的末尾包含一个数字 id
```
router.HandleFunc("/cliches/{id:[0-9]+}", ClichesEdit).Methods("PUT")
```
### 4、并发问题
`gorilla/mux` 路由器作为单独的 Go 协程执行对已注册的请求处理程序的每次调用,这意味着并发性被内置于包中。 例如,如果有十个同时发出的请求,例如
```
% curl --request POST --data "..." localhost:8888/cliches
```
然后 `mux.Router` 启动十个 Go 协程来执行 `ClichesCreate` 处理程序。
GET all、GET one、POST、PUT 和 DELETE 中的五个请求操作中,最后三个改变了所请求的资源,即包含套话对的共享 `clichesList`。 因此CRUD app 需要通过协调对 `clichesList` 的访问来保证安全的并发性。 在不同但等效的术语中CRUD app 必须防止 `clichesList` 上的竞争条件。 在生产环境中,可以使用数据库系统来存储诸如 `clichesList` 之类的资源,然后可以通过数据库事务来管理安全并发。
CRUD 应用程序采用推荐的Go方法来实现安全并发
* 只有一个 Go 协程,资源管理器在 CRUD app `startServer` 函数中启动,一旦 Web 服务器开始侦听请求,就可以访问 `clichesList`
* 诸如 `ClichesCreate``ClichesAll` 之类的请求处理程序向 Go 通道发送(指向)`crudRequest` 实例(默认情况下是线程安全的),并且资源管理器单独从该通道读取。 然后,资源管理器对 `clichesList` 执行请求的操作。
安全并发体系结构绘制如下:
```
           crudRequest                读/写
请求处理程序 -------------> 资源托管者 ------------> 套话列表
```
在这种架构中,不需要显式锁定 `clichesList`,因为一旦 CRUD 请求开始进入,只有一个 Go 协程(资源管理器)访问 `clichesList`
为了使 CRUD 应用程序尽可能保持并发,在一方请求处理程序与另一方的单一资源管理器之间进行有效的分工至关重要。 在这里,为了审查,是 `ClichesCreate` 请求处理程序:
```
func ClichesCreate(res http.ResponseWriter, req *http.Request) {
cliche, counter := getDataFromRequest(req)
cp := new(clichePair)
cp.Cliche = cliche
cp.Counter = counter
cr := &crudRequest{verb: POST, cp: cp, confirm: make(chan string)}
completeRequest(cr, res, "create")
}
```
`ClichesCreate` 调用实用函数 `getDataFromRequest`,它从 POST 请求中提取新的套话和反套话。 然后 `ClichesCreate` 函数创建一个新的 `ClichePair`,设置两个字段,并创建一个 `crudRequest` 发送给单个资源管理器。 此请求包括一个确认通道,资源管理器使用该通道将信息返回给请求处理程序。 所有设置工作都可以在不涉及资源管理器的情况下完成,因为尚未访问 `clichesList`
请求处理程序调用实用程序函数,该函数从 POST 请求中提取新的套话和反套话。 然后,该函数创建一个新的,设置两个字段,并创建一个 crudRequest 发送到单个资源管理器。 此请求包括一个确认通道,资源管理器使用该通道将信息返回给请求处理程序。 所有设置工作都可以在不涉及资源管理器的情况下完成,因为尚未访问它。
`completeRequest` 实用程序函数在 `ClichesCreate` 函数和其他请求处理程序的末尾调用:
```
completeRequest(cr, res, "create") // shown above
```
通过将 `crudRequest` 放入 `crudRequests` 频道,使资源管理器发挥作用:
```
func completeRequest(cr *crudRequest, res http.ResponseWriter, logMsg string) {
   crudRequests<-cr          // 向资源托管者发送请求
   msg := <-cr.confirm       // 等待确认
   res.Write([]byte(msg))    // 向请求方发送确认
   logIt(logMsg)             // 打印到标准输出
}
```
对于 POST 请求,资源管理器调用实用程序函数 `addPair`,它会更改 `clichesList` 资源:
```
func addPair(cp *clichePair) string {
   cp.Id = masterId  // 分配一个唯一的 ID
   masterId++        // 更新 ID 计数器
   clichesList = append(clichesList, cp) // 更新列表
   return "\nCreated: " + cp.Cliche + " " + cp.Counter + "\n"
}
```
资源管理器为其他 CRUD 操作调用类似的实用程序函数。 值得重复的是,一旦 Web 服务器开始接受请求,资源管理器就是唯一可以读取或写入 `clichesList` 的 goroutine。
对于任何类型的 Web 应用程序,`gorilla/mux` 包在简单直观的 API 中提供请求路由、请求验证和相关服务。 CRUD web 应用程序突出了软件包的主要功能。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/8/http-request-routing-validation-gorillamux
作者:[Marty Kalin][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[yongshouzhang](https://github.com/yongshouzhang)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://opensource.com/users/mkalindepauledu
[1]:https://curl.haxx.se/
[2]:https://github.com/gorilla/mux
[3]:http://condor.depaul.edu/mkalin

View File

@ -1,52 +1,52 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: subject: (Create a containerized machine learning model)
[#]: via: (https://fedoramagazine.org/create-containerized-machine-learning-model/)
[#]: author: (Sven Bösiger)
[#]: url: ( )
[#]: url: (https://linux.cn/article-10349-1.html)
Create a containerized machine learning model
创建一个容器化的机器学习模型
======
![](https://fedoramagazine.org/wp-content/uploads/2018/10/machinelearning-816x345.jpg)
After data scientists have created a machine learning model, it has to be deployed into production. To run it on different infrastructures, using containers and exposing the model via a REST API is a common way to deploy a machine learning model. This article demonstrates how to roll out a [TensorFlow][1] machine learning model, with a REST API delivered by [Connexion][2] in a container with [Podman][3].
数据科学家在创建机器学习模型后,必须将其部署到生产中。要在不同的基础架构上运行它,使用容器并通过 REST API 公开模型是部署机器学习模型的常用方法。本文演示了如何在 [Podman][3] 容器中使用 [Connexion][2] 推出使用 REST API 的 [TensorFlow][1] 机器学习模型。
### Preparation
### 准备
First, install Podman with the following command:
首先,使用以下命令安装 Podman
```
sudo dnf -y install podman
```
Next, create a new folder for the container and switch to that directory.
接下来,为容器创建一个新文件夹并切换到该目录。
```
mkdir deployment_container && cd deployment_container
```
### REST API for the TensorFlow model
### TensorFlow 模型的 REST API
The next step is to create the REST-API for the machine learning model. This [github repository][4] contains a pretrained model, and well as the setup already configured for getting the REST API working.
下一步是为机器学习模型创建 REST API。这个 [github 仓库][4]包含一个预训练模型,以及能让 REST API 工作的设置。
Clone this in the deployment_container directory with the command:
使用以下命令在 `deployment_container` 目录中克隆它:
```
git clone https://github.com/svenboesiger/titanic_tf_ml_model.git
```
#### prediction.py & ml_model/
#### prediction.py ml_model/
The [prediction.py][5] file allows for a Tensorflow prediction, while the weights for the 20x20x20 neural network are located in folder [ml_model/][6].
[prediction.py][5] 能进行 Tensorflow 预测,而 20x20x20 神经网络的权重位于文件夹 [ml_model/][6] 中。
#### swagger.yaml
The file swagger.yaml defines the API for the Connexion library using the [Swagger specification][7]. This file contains all of the information necessary to configure your server to provide input parameter validation, output response data validation, URL endpoint definition.
[swagger.yaml][12] 使用 [Swagger规范][7] 定义 Connexion 库的 API。此文件包含让你的服务器提供输入参数验证、输出响应数据验证、URL 端点定义所需的所有信息。
As a bonus Connexion will provide you also with a simple but useful single page web application that demonstrates using the API with JavaScript and updating the DOM with it.
额外地Connexion 还将给你提供一个简单但有用的单页 Web 应用,它演示了如何使用 Javascript 调用 API 和更新 DOM。
```
swagger: "2.0"
@ -85,9 +85,9 @@ definitions:
type: object
```
#### server.py & requirements.txt
#### server.py requirements.txt
[server.py][8] defines an entry point to start the Connexion server.
[server.py][8] 定义了启动 Connexion 服务器的入口点。
```
import connexion
@ -100,7 +100,7 @@ if __name__ == '__main__':
app.run(debug=True)
```
[requirements.txt][9] defines the python requirements we need to run the program.
[requirements.txt][9] 定义了运行程序所需的 python 包。
```
connexion
@ -108,9 +108,9 @@ tensorflow
pandas
```
### Containerize!
### 容器化!
For Podman to be able to build an image, create a new file called “Dockerfile” in the **deployment_container** directory created in the preparation step above:
为了让 Podman 构建映像,请在上面的准备步骤中创建的 `deployment_container` 目录中创建一个名为 `Dockerfile` 的新文件:
```
FROM fedora:28
@ -143,25 +143,25 @@ WORKDIR /titanic_tf_ml_model
CMD python3 server.py
```
Next, build the container image with the command:
接下来,使用以下命令构建容器镜像:
```
podman build -t ml_deployment .
```
### Run the container
### 运行容器
With the Container image built and ready to go, you can run it locally with the command:
随着容器镜像的构建和准备就绪,你可以使用以下命令在本地运行它:
```
podman run -p 5000:5000 ml_deployment
```
Navigate to [http://0.0.0.0:5000/ui][10] in your web browser to access the Swagger/Connexion UI and to test-drive the model:
在 Web 浏览器中输入 [http://0.0.0.0:5000/ui][10] 访问 Swagger/Connexion UI 并测试模型:
![][11]
Of course you can now also access the model with your application via the REST-API.
当然,你现在也可以在应用中通过 REST API 访问模型。
--------------------------------------------------------------------------------
@ -170,8 +170,8 @@ via: https://fedoramagazine.org/create-containerized-machine-learning-model/
作者:[Sven Bösiger][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
译者:[geekpi](https://github.com/geekpi)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
@ -188,3 +188,4 @@ via: https://fedoramagazine.org/create-containerized-machine-learning-model/
[9]: https://github.com/svenboesiger/titanic_tf_ml_model/blob/master/requirements.txt
[10]: http://0.0.0.0:5000/
[11]: https://fedoramagazine.org/wp-content/uploads/2018/10/Screenshot-from-2018-10-27-14-46-56-682x1024.png
[12]: https://github.com/svenboesiger/titanic_tf_ml_model/blob/master/swagger.yaml

View File

@ -1,5 +1,3 @@
(本文共两处译注)
一个免费、安全、跨平台的密码管理器
======
@ -7,17 +5,17 @@
在这个现代化的互联网时代你一定在许多网站上有多个账户它可能是个人或官方邮箱账户、社交或专业网络账户、GitHub 账户和电子商务账户等。因此,对于不同的账户,你应该设置多个不同的密码。我相信你应该已经意识到为多个账户设置相同的密码是件疯狂又危险的事情。如果攻击者设法破解了你的一个账户,那么他/她很可能尝试使用相同的密码访问你的其他账户。所以,**强烈建议为不同的账户设置不同的密码**。
不过,记住好几个密码是很困难的。你可以把它们写在纸上,但那也不是一个有效的方法,你可能会在一段时间后失去它们。这时密码管理器就派上用场了。密码管理器就像一个存储库,你可以在其中存储不同账户的所有密码,并用一个主密码将其锁定。这样,你需要记住的就只剩下主密码了。之前我们介绍过一个叫 [**KeeWeb**][1] 的开源密码管理器,今天,我们将介绍另外一款密码管理器———**Buttercup**
不过,记住好几个密码是很困难的。你可以把它们写在纸上,但那也不是一个有效的方法,你可能会在一段时间后失去它们。这时密码管理器就派上用场了。密码管理器就像一个存储库,你可以在其中存储不同账户的所有密码,并用一个主密码将其锁定。这样,你需要记住的就只剩下主密码了。之前我们介绍过一个叫 [KeeWeb][1] 的开源密码管理器,今天,我们将介绍另外一款密码管理器 ——— Buttercup
### 关于 Buttercup
Buttercup 是一个免费、开源、安全、跨平台的使用 **NodeJS** 编写的密码管理器。它可以帮助你将不同账户的所有登录凭证存储到加密存档中,该存档可以保存在本地系统或任何远程服务(如 DropBox、OwnCloud、NextCloud 和基于 WebDAV 的服务)中。它使用强大的 **256 位 AES 加密算法**用主密码保存你的敏感数据。所以除了拥有主密码的人以外没有人可以访问你的登录信息。Buttercup 目前支持 Linux、Mac OS 和 Windows还提供了一个浏览器扩展和移动应用程序。因此你也可以在 Android 和 iOS 设备中的桌面应用程序和浏览器扩展程序中使用相同的存档。
Buttercup 是一个自由、开源、安全、跨平台的密码管理器,使用 **NodeJS** 编写。它可以帮助你将不同账户的所有登录凭证存储到加密存档中,该存档可以保存在本地系统或任何远程服务(如 DropBox、OwnCloud、NextCloud 和基于 WebDAV 的服务)中。它使用强大的 **256 位 AES 加密算法**用主密码保存你的敏感数据。所以除了拥有主密码的人以外没有人可以访问你的登录信息。Buttercup 目前支持 Linux、Mac OS 和 Windows还提供了一个浏览器扩展和移动应用程序。因此你也可以在 Android 和 iOS 设备中的桌面应用程序和浏览器扩展程序中使用相同的存档。
### 安装 Buttercup 密码管理器
译注此处没有找到合适的语言翻译Buttercup 目前可作为 .deb、.rpm 软件包、便携式 AppImage 和用于 Linux 平台的 tar 归档文件使用。转到 [**releases pages**][2] 下载安装你想要的版本。
Buttercup 目前在 Linux 平台上有 .deb、.rpm 软件包、可移植的 AppImage 和 tar 归档文件等安装包。转到其 [发布页][2] 下载安装你想要的版本。
Buttercup 桌面应用程序在 [**AUR**][3] 中也可用,你可以使用 AUR 帮助程序(如 [**Yay**][4])在基于 Arch 的系统上安装,如下所示:
Buttercup 桌面应用程序在 [AUR][3] 中也可用,你可以使用 AUR 帮助程序(如 [Yay][4])在基于 Arch 的系统上安装,如下所示:
```
$ yay -S buttercup-desktop
@ -35,21 +33,23 @@ $ chmod +x buttercup-desktop-1.11.0-x86_64.AppImage
$ ./buttercup-desktop-1.11.0-x86_64.AppImage
```
运行此命令后,会提示是否要将 Buttercup AppImage 集成到你的系统中。如果选择“Yes”则会将其添加到应用程序菜单并安装图标。如果不这样做你仍然可以通过双击 AppImage 或在终端中使用上述命令启动应用程序。
运行此命令后,会提示是否要将 Buttercup AppImage 集成到你的系统中。如果选择 “Yes”则会将其添加到应用程序菜单并安装图标。如果不这样做你仍然可以通过双击 AppImage 或在终端中使用上述命令启动应用程序。
### 添加存档
第一次启动时,会看到下面的欢迎界面:
![](https://www.ostechnix.com/wp-content/uploads/2018/11/buttercup-1.png)
我们还没有添加任何存档所以让我们添加一个吧。单击“New Archive File”按钮输入存档文件的名称并选择它的保存位置。
我们还没有添加任何存档,所以让我们添加一个吧。单击 “New Archive File” 按钮,输入存档文件的名称,并选择它的保存位置。
![](https://www.ostechnix.com/wp-content/uploads/2018/11/buttercup-2.png)
你可以随意命名。我把它命名为“mypass”存档将以 **.bcup** 为扩展名保存在你选择的位置。
你可以随意命名。我把它命名为 “mypass”存档将以 .bcup 为扩展名保存在你选择的位置。
如果你已经创建了一个只需单击“Open Archive File”来选择它。
如果你已经创建了一个,只需单击 “Open Archive File” 来选择它。
接下来,buttercup 将提示你为新创建的存档输入主密码,建议提供一个强级别的密码,以保护存档不受未经授权的访问。
接下来,Buttercup 将提示你为新创建的存档输入主密码,建议提供一个强级别的密码,以保护存档不会被未经授权访问。
![](https://www.ostechnix.com/wp-content/uploads/2018/11/buttercup-3.png)
@ -57,7 +57,7 @@ $ ./buttercup-desktop-1.11.0-x86_64.AppImage
让我们继续在存档中添加账户的详细信息。
### 在存档中添加条目(登凭证)
### 在存档中添加条目(登凭证)
创建或打开存档后,你将看到下面的界面。
@ -65,33 +65,33 @@ $ ./buttercup-desktop-1.11.0-x86_64.AppImage
它就像一个保险库,我们将保存不同账户的登录凭证。如你所见,我们并没有添加任何条目。让我们添加一些。
点击右下角的“ADD ENTRY”按钮来添加新的条目输入你想要保存的账户的信息。
点击右下角的 “ADD ENTRY” 按钮来添加新的条目,输入你想要保存的账户的信息。
![](https://www.ostechnix.com/wp-content/uploads/2018/11/buttercup-5-1.png)
在每个条目下面都有一个“ADD NEW FIELD”选项可以用来添加其他的细节。只需点击它然后添加要包含在条目中的字段。
在每个条目下面都有一个 “ADD NEW FIELD” 选项,可以用来添加其他的细节。只需点击它,然后添加要包含在条目中的字段。
添加完所有条目后,你将在 Buttercup 界面的右侧窗格中看到它们。
![][6]
### 添加新的
### 添加新的
你还可以将登的详细信息分组到不同的名称下以便于识别。例如你可以将所有邮箱账户分组到一个名为“my_mails”的名称下。默认情况下你的登录详细信息将保存在“General”群组下。要创建新的群组请点击“NEW GROUP”按钮并输入名称。在新的群组中创建新条目时与上述的步骤相同只需单击组名并开始添加条目。
你还可以将登的详细信息分组到不同的名称下,以便于识别。例如,你可以将所有邮箱账户分组到一个名为 “my_mails” 的名称下。默认情况下,你的登录详细信息将保存在 “General” 群组下。要创建新的群组,请点击 “NEW GROUP” 按钮并输入名称。在新的群组中创建新条目时,与上述的步骤相同,只需单击组名并开始添加条目。
### 管理和访问登的详细信息
### 管理和访问登的详细信息
存储在存档中的数据可以随时编辑、移动到其他组或彻底删除。例如如果要将用户名或密码复制到剪切板请右击该条目然后选择“Copy to Clipboard”。
存储在存档中的数据可以随时编辑、移动到其他组或彻底删除。例如,如果要将用户名或密码复制到剪切板,请右击该条目,然后选择 “Copy to Clipboard”。
![][7]
(译注:没理解这个 in the future 的意思)要在将来编辑/修改数据只需点击所选条目下的“Edit”按钮。
要进一步编辑/修改数据,只需点击所选条目下的 “Edit” 按钮。
### 在远程保存存档
默认情况下Buttercup 会将数据保存在本地系统上。但是,你可以将它们保存在不同的远程服务(例如 Dropbox、OwnCloud、NextCloud 和基于 WebDAV 的服务)上。
要连接这些服务,请点击 **File - > Connect Cloud Sources**
要连接这些服务,请点击 “File -> Connect Cloud Sources”
![](https://www.ostechnix.com/wp-content/uploads/2018/11/buttercup-8.png)
@ -107,13 +107,16 @@ Buttercup 允许你向其他密码管理器(例如 1Password、Lastpass 和 Ke
![][9]
Buttercup 是一个简单但成熟、功能齐全的密码管理器。多年来它一直在积极发。如果你需要密码管理器Buttercup 可能是个不错的选择。有关更多的详细信息,请参阅项目网站和 GitHub 页面。
Buttercup 是一个简单但成熟、功能齐全的密码管理器。多年来它一直在积极发。如果你需要密码管理器Buttercup 可能是个不错的选择。有关更多的详细信息,请参阅项目网站和 GitHub 页面。
那就介绍到这里,希望它对你有用。更多的精彩内容即将到来,敬请关注!
谢谢!
### 资源
- [Buttercup 网站](https://buttercup.pw/)
- [Buttercup GitHub 仓库](https://github.com/buttercup/buttercup-desktop)
--------------------------------------------------------------------------------
@ -122,13 +125,13 @@ via: https://www.ostechnix.com/buttercup-a-free-secure-and-cross-platform-passwo
作者:[SK][a]
选题:[lujun9972][b]
译者:[seriouszyx](https://github.com/seriouszyx)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.ostechnix.com/author/sk/
[b]: https://github.com/lujun9972
[1]: https://www.ostechnix.com/keeweb-an-open-source-cross-platform-password-manager/
[1]: https://linux.cn/article-10211-1.html
[2]: https://github.com/buttercup/buttercup-desktop/releases/latest
[3]: https://aur.archlinux.org/packages/buttercup-desktop/
[4]: https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/

View File

@ -0,0 +1,95 @@
Cat 命令的源码历史
======
以前我和我的一些亲戚争论过计算机科学的学位值不值得读。当时我正在上大学,并要决定是不是该主修计算机。我姨和我表姐觉得我不应该主修计算机。她们承认知道如何编程肯定是很有用且对自己有利的一件事,但是她们认为计算机科学现在发展的如此迅速以至于我学的东西几乎马上就过时了。建议我更好是把编程作为辅业,选择一个基础原理可以受用终身的领域主修,比如经济学或物理学。
我知道我姨和我表姐说的不对,并决定主修计算机科学。(对不住啊!)平常人可能会觉得像计算机科学领域和软件工程专业每隔几年就完全和之前不一样了。其原因很容易理解。我们有了个人电脑,然后有了互联网,有了手机,之后还有了机器学习…… 科技总是在更新,支撑科技发展的原理和技能当然也在改变。当然,最惊人的是其实原理的改变竟然如此之小。我敢肯定,大多数人在知道了他们电脑里一些重要的软件的历史是多么久远时他们一定会深感震惊。当然我不是说那些刷版本号的浮夸软件 —— 我电脑上的 Firefox 浏览器副本,可能是我用的最多的软件,可能两周前就更新过。如果你看了比如 `grep` 的手册页,你就会发现它在 2010 年后就没有过更新了(至少在 MacOS 上如此)。初版 `grep` 是在 1974 年写就的,那时可以算是计算机世界的侏罗纪了。直到现在,人们(还有程序)仍然依赖 `grep` 来完成日常工作。
我姨和我表姐认为计算机技术就像一系列日渐精致的沙堡,在潮水抹净沙滩后新的沙堡完全取代旧的。但事实上,在很多领域上,我们都是不断积累能够解决问题的程序。我们可能不得不偶尔修改这些程序以避免软件无法使用,但大多数情况下我们都可以不修改。`grep` 是一个简单的程序,可以解决一个仍然存在的需求,所以它能够存活下来。 大多数应用程序编程都是在非常高的级别上完成的,它们建立在解决了旧问题的旧程序的金字塔上。 30 年或 40 年前的思路和概念,远非过时,在很多情况下它们依然在您的笔记本电脑上软件中存在着。
我想追溯这样的老程序自第一次写就以来改变了多少回很有趣。 `cat` 可能是所有 Unix 实用程序中最简单的因此我们以它为例。Ken Thompson 于 1969 年编写了 `cat` 的原始实现。如果我告诉别人我的电脑上安装了个来自 1969 年的程序,这准确吗?我们电脑上的程序多大了?
感谢这种[这种][1]仓库,我们可以完整的看到 `cat` 自 1969 年后是如何发展的。我会先聚焦于可以算得上是我的 MacBook 上的 `cat` 的祖先的 `cat` 实现。随着我们从 Unix 上的第一版 `cat` 追踪到现在 MacOS 上的 `cat`,你会发现,这个程序被重写的次数比你想的还要多 —— 但是直到现在它运行的方式和五十年前多少是完全一致的。
### 研究 Unix
Ken Thompson 和 Dennis Ritchie 在 PDP 7 上开始写 Unix。那还是 1969 年C 还没被发明出来,因此所有早期的 Unix 软件都是用 PDP 7 汇编实现的。他们使用的汇编种类是 Unix 特有的Ken Thompson 在 DECPDP 7 的厂商提供的汇编器之上加了些特性实现了自己的汇编器。Thompson 的更改在[最初的 Unix 程序员手册][2]的 `as`(也就是汇编器)条目下均有所记录。
因此,[最初的][3] `cat` 也是使用 PDP 7 汇编实现的。 我添加了一些注释,试图解释每条指令的作用,但除非你理解 Thompson 在编写汇编器时加的特性,否则程序仍然很难理解。在那些特性中有两个很重要:其一是 `;` 这个字符可以在一行中用来分隔多条语句,它多出现于在使用 `sys` 指令时将系统调用的多个参数放在同一行上。其二是, Thompson 的汇编器支持使用 0 到 9 作为“临时标签”,这是在程序内可以重用的标签。因此。就如 Unix 程序员手册中所说:“对程序员的想象力和汇编程序的符号空间的要求都降低了”。在任何给定的指令内,你都可以使用 `nf``nb` 来引用下一个或最近的临时标签 `n`。 例如,如果存在标记为 `1:` 的代码块,你就可以使用指令 `jmp 1b` 从下游代码跳回该块。 (但是你不使用 `jmp 1f` 的话就没法从上面的代码跳到这里。)
初版 `cat` 最有趣的就是它包含着我们应该认识的符号。有一块指令块标记为 `getc`,还有一个标记为 `putc`,可以看到这两个符号比 C 标准还古老。第一版的 `cat` 函数实际上已经包含了这两个函数的实现。该实现做了输入缓存,这样它就不需要一次只读写一个字母。
`cat` 的第一个版本并没有持续多久。 Ken Thompson 和 Dennis Ritchie 说服贝尔实验室购买了 PDP 11这样他们就能够继续扩展和改进 Unix。 PDP 11 的指令集和之前不一样,因此必须重写 `cat`。 我也注释了[这个第二版][4] `cat`。 它为新的指令集使用新的汇编程序助记符,并利用了 PDP 11 的各种[寻址模式][5]。(如果你对源代码中的括号和美元符号感到困惑,那是因为这些符号用于指示不同的寻址模式。)但它也使用 `;` 字符和临时标签,和 `cat` 的第一个版本一样,这意味着当把 `as` 移植到 PDP 11 上时,必须要保留这些功能。
`cat` 的第二个版本比第一个版本简单得多。 它也更有 Unix 味儿,它不只是依靠参数列表,一旦没给参数列表,它将从 `stdin` 读取数据,这也就是今天 `cat` 仍在做的事情。 你也可以在此版本的 `cat` 中以 `-` 为参数,以表示它应该从`stdin`读取。
在 1973 年,为了准备发布第四版 Unix大部分代码都用 C 语言重写了。但是 `cat` 似乎在之后一段时间内并没有使用 C 重写。 [cat 的第一个 C 语言实现][6]出现在第七版 Unix 中。 这个实现非常有趣,因为它很简单。 在所有以后的实现中,这个实现和在 KR 的 C 语言教科书中用作教学示范的理想化 `cat` 最相似。这个程序的核心就是经典的两行:
```
while ((c = getc(fi)) != EOF)
putchar(c);
```
当然实际代码要比这多一些,额外的代码主要是为了确保你没有在读/写同一个文件。另一个有趣的事情是,`cat` 的这一版实现只识别一个标志位 `-u``-u` 标志可用于避免缓冲输入和输出,否则 `cat` 将以 512 字节为块进行输入输出。
### BSD
在第七版 Unix 之后Unix 出现了各种衍生品和分支。 MacOS 建立于 Darwin 之上,而 Darwin 又源自<ruby>伯克利软件分发版<rt>Berkeley Software Distribution</rt></ruby>BSD因此 BSD 是我们最感兴趣的 Unix 分支。 BSD 最初只是 Unix 中的实用程序和附加组件的集合,但它最终成为了一个完整的操作系统。直到第四版 BSD人称 4BSD为一大堆新标志添加了支持之前BSD 似乎还是依赖于最初的 `cat` 实现的。`cat` 的 [4BSD 实现][7] 显然是从原始实现中衍生出来的,尽管它添加了一个新函数来实现由新标志触发的行为。已经在文件中使用的 `fflg` 变量(用于标记输入是从 `stdin` 还是文件读取的)的命名约定,被新添加的 `nflg`、`bflg`、`vflg`、`sflg`、`eflg` 和 `tflg` 沿袭了下来,这些变量记录了在调用程序时是否使用了这些新标志。这些是最后一批添加到 `cat` 的命令行标志。如今 `cat` 的手册页列出了这些标志,没有其他的标志了,至少在 Mac OS 上是如此。 4BSD 于 1980 年发布,因此这套标志已有 38 年历史。
`cat` 最后一次被完全重写是在 BSD NET/2 上,其目的是通过替换 AT&T 发布的全部 Unix 源代码来规避许可证问题。BSD Net/2 在 1991 年发布。这一版本的 `cat` 是由 Kevin Fall 重写的。 Kevin Fall 于 1988 年毕业于加州大学伯克利分校并在下一年成为<ruby>计算机系统研究组<rt>Computer Systems Research Group</rt></ruby>CSRG的组员Fall 和我说当时使用 AT&T 代码的 Unix 工具被列在了 CSRG 的墙上,组员需要从中选出他们想要重写的工具; Fall 选了 `cat` 以及 `mknod`。 MacOS 系统内自带的 `cat` 实现源码的最上面还有着他的名字。他的这一版 `cat`,尽管平淡无奇,在今天还是被无数人使用着。
[Fall 的原始 cat 实现][8] 比我们迄今为止看到的版本都要长。 除了支持 `-?` 帮助标志外,它没有增加任何新功能。 从概念上讲,它与 4BSD 的实现非常相似。 它长是因为 Fall 将实现分为 “原始” 模式和 “加工” 模式。 “原始” 模式是 `cat` 的经典实现;它一个字符一个字符的打印文件。 “加工” 模式是带有所有 4BSD 命令行选项的 `cat`。 如此区别不无道理,但这么办也扩充了实现规模,因此乍一看其源码似乎比实际上更复杂。文件末尾还有一个奇特的错误处理函数,进一步地增加了实现的长度。
### MacOS
在 2001 年,苹果发布了 MacOS X。这一发布对苹果意义重大。因为苹果用了多年的时间尝试以取代其现有的老旧操作系统经典的 Mac OS但是都失败了。 在 Mac OS X 之前苹果两次尝试在内部创建一个新的操作系统,但两者都无疾而终。 最后,苹果收购了史蒂夫·乔布斯的 NeXT 公司,后者开发了一个名为 NeXTSTEP 的操作系统和面向对象编程框架。 苹果将 NeXTSTEP 作为 Mac OS X 的基础。因为 NeXTSTEP 部分基于 BSD使以 NeXTSTEP 为基础的 Mac OS X 的自然就把 BSD 系的代码直接带入苹果宇宙的中心。
因此Mac OS X 的非常早期的第一个版本包含了从 NetBSD 项目中提取的 `cat` 的[实现][9]。如今仍保持开发的 NetBSD 最初是 386BSD 的分支,而后者又直接基于 BSD Net/2。所以 Mac OS X 里面的第一个 `cat` 的实现就是 Kevin Fall 的 `cat`。唯一改变的是Fall 的错误处理函数 `err()``err.h` 提供的 `err()` 函数取代了。 `err.h` 是 C 标准库的 BSD 扩展。
之后不久,这里的 `cat` 的 NetBSD 实现被换成了 FreeBSD 中的 `cat` 实现。 [根据维基百科][10],苹果在 Mac OS X 10.3Panther中开始使用 FreeBSD 的实现而不是 NetBSD 的实现。但根据苹果自己开源的版本,`cat` 的 Mac OS X 实现在 2007 年发布的 Mac OS X 10.5Leopard之前没有被替换。苹果为 Leopard 替换的的 [FreeBSD 实现][11]与今天苹果计算机上的实现相同。截至 2018 年2007 年以来的这个实现仍未被更新或修改。
所以 Mac OS 上的 `cat` 已经很老了。实际上,这一实现在 2007 年在 MacOS X 上露面两年前就被发布了。 [这个 2005 年的修改][12] 在 FreeBSD 的 Github 镜像中可见,是在苹果将其合并入 Mac OS X 前对 FreeBSD 的 `cat` 实现进行的最后一次更改。所以 Mac OS X 中的实现没有与 FreeBSD 的 `cat` 实现保持同步,它如今已经 13 岁了。对于软件修改了多少代码才能仍是算是同一软件这一话题有着旷日持久的争论。不过,在这种情况下,源文件自 2005 年以来根本没有变化。
现在 Mac OS 使用的 `cat` 实现与 Fall 1991 年为 BSD Net/2 版本编写的实现没有什么不同。最大的区别是添加了一个全新的功能来提供 Unix 域套接字支持。FreeBSD 开发人员似乎将 Fall 的 `raw_args()` 函数和 `cook_args()` 函数组合成一个名为`scanfiles()` 的函数。否则,程序的核心就仍是 Fall 的代码。
我问过 Fall 对编写了如今被数以百万计的苹果用户(直接或者间接通过依赖 `cat` 的某些程序)使用的 `cat` 实现有何感想。Fall如今是一位顾问也是最新版《TCP/IP 详解》的合著者,他说,当人们从了解他对 `cat` 所做的工作中收获颇丰时,他感到很惊讶。 Fall 在计算机领域有着悠久的职业生涯,曾参与许多备受瞩目的项目,但似乎很多人仍对他在 1989 年重写 `cat` 的那六个月的工作感到最为兴奋。
### 百年老程序
在宏伟的发明史中,计算机并不是一项古老的发明。我们已经习惯了百年的照片甚至是百年的视频短片。但是计算机程序不一样 —— 它们代表着高科技和新技术。至少,他们是现代的技术造出来的。随着计算行业的成熟,我们有朝一日会发现自己正在使用有着接近百年历史的程序吗?
计算机硬件可能会发生较大的变化,使得我们也许无法让现在编译的可执行文件在一个世纪后的硬件上运行。也许编程语言设计的进步让未来没有人能理解 C 语言,`cat` 将来也可能也被别的语言重写很久了。 (尽管 C 已经存在了五十年了,而且它似乎不会很快就被替换掉。)但除此之外,为什么不永远使用我们现在的 `cat`
我认为 `cat` 的历史表明,计算机科学中的一些想法确实非常持久。事实上,对于 `cat`,这个想法和程序本身都很古老。不准确地说,我的电脑上的 `cat` 来自 1969 年。但我也可以说我的计算机上的 `cat` 来自1989 年,当时 Fall 写了他的 `cat` 实现。许多其他软件也同样古老。因此,也许我们不应该把计算机科学和软件开发视为不断破坏现状和发明新事物的领域。我们的计算机系统是由诸多历史文物构建的。有时,我们可能会花费更多时间在理解和维护这些历史文物上,而不是花在编写新代码上。
如果你喜欢本文,你可能更喜欢两周来一篇更新!在推特上关注 [@TwoBitHistory][13] 或者订阅这个 [RSS 源][14] 以保证接受到新的文章。
--------------------------------------------------------------------------------
via: https://twobithistory.org/2018/11/12/cat.html
作者:[Two-Bit History][a]
选题:[lujun9972][b]
译者:[name1e5s](https://github.com/name1e5s)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://twobithistory.org
[b]: https://github.com/lujun9972
[1]: https://github.com/dspinellis/unix-history-repo
[2]: https://www.bell-labs.com/usr/dmr/www/man11.pdf
[3]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-1-cat-pdp7-s
[4]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-2-cat-pdp11-s
[5]: https://en.wikipedia.org/wiki/PDP-11_architecture#Addressing_modes
[6]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-3-cat-v7-c
[7]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-4-cat-bsd4-c
[8]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-5-cat-net2-c
[9]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-6-cat-macosx-c
[10]: https://en.wikipedia.org/wiki/Darwin_(operating_system)
[11]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-7-cat-macos-10-13-c
[12]: https://github.com/freebsd/freebsd/commit/a76898b84970888a6fd015e15721f65815ea119a#diff-6e405d5ab5b47ca2a131ac7955e5a16b
[13]: https://twitter.com/TwoBitHistory
[14]: https://twobithistory.org/feed.xml
[15]: https://twitter.com/TwoBitHistory/status/1051826516844322821?ref_src=twsrc%5Etfw

View File

@ -0,0 +1,75 @@
给写作者们的 7 个命令行工具
======
> 扔掉你的文字编辑器,然后使用这些开源工具在命令行上写作吧。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/terminal_command_linux_desktop_code.jpg?itok=p5sQ6ODE)
对于大多数人(尤其是非技术人员),写作意味着在 LibreOffice Writer 或者其他带图形界面的文字处理应用上编辑文本。但是还有许多可行的方法可以让任何人通过文本传递他们的信息,尤其是越来越多的作者选择[拥抱纯文本][1]。
在使用图形界面写作的世界同样有命令行工具的一席之地。这些命令行工具可以帮助他们进行写作,检查他们的拼写等等 —— 无论是在写一篇文章、博客或者故事;写一个 README 文件;或者准备一份技术文档的时候。
下面是一些在任何写作情况下都有用的命令行工具。
### 编辑器
没错,你可以在命令行进行真正的写作。我知道一些写作者会使用 [Nano][2]、[Vim][3]、[Emacs][4]、以及 [Jove][5] 等编辑器在终端窗口中进行工作。而这些编辑器[并非屈指可数][6]。文本编辑器的优势在于它们简单易用以及更专注于文本。非常适合用于编辑任何文本的初稿甚至完成一个漫长而复杂的写作项目。
如果你想在命令行中获得更像文字编辑器的体验,不妨了解一下 [WordGrinder][7]。它是一款简单但拥有足够的编写和发布功能的文字编辑器。它支持基本的格式和样式,并且你可以将你的文字以 Markdown、ODT、LaTeX 或者 HTML 等格式导出。
### 拼写检查
每个写作者在完成他们的工作前至少要(或者说应该要)进行一次拼写检查。为什么呢?在写作的世界里有个永恒的定律,无论你检查了多少次手稿,拼写错误和错字依然会存在。
我曾经详细[介绍][9]过我最喜欢的命令行拼写检查工具 [GNU Aspell][8]。交互式检测文本文档的 Aspell 不仅能够高亮显示拼写错误还能在拼写错误的上方提供正确的拼写建议。Aspell 在进行拼写检查时同样能够忽略许多语法标记。
另一个够老但仍然有用的代替品是 [Ispell][10]。虽然它比 Aspell 稍慢一点但它们都以相同的方式工作。当你在你的文本文件上工作时Ispell 将提供正确的建议。Ispell 同样也对英语以外的语言提供了良好的支持。
### 文章 linter
软件开发人员使用 [linter][11] 来检查他们的代码是否存在错误或者 bug。同样也有用于检查文本样式或语法错误的 linter而该命令行工具会认为这些错误是样式元素。任何写作者都可以也应该使用它一个文章 linter 对于要求文档风格和样式一致的文档团队项目而言尤其有用。
[Proselint][12] 是一款全能的实时检查工具。它会找出行话、大话、不正确日期和时间格式、滥用的术语[等等][13]。它也很容易运行并忽略文本中的标记。
[Alex][14] 是一个简单但有用的文章 linter。 对明文文本或者格式为 Markdown 或 HTML 的文档使用它。Alex 会对“性别偏好、极端主义、种族相关、宗教,或者文章中其他不平等的措辞”产生警告。如果你想要试试看 Alex这里有一个在线 [demo][15]。
### 其他工具
有时候你找不到一个单词的恰当的同义词。但你不需要去呆板的词库中抓取或者去专门的网站完善你的单词完整。仅仅需要对你想要替换的单词运行 [Aiksaurus][16],然后它就会为你完成这个工作。但是,这个程序最大的缺点是它只支持英语。
即使是只会很少(甚至只有一项)技术技能的写作者都能接受 [Markdown][17] 来快速而简单地格式化他们的作品。但是,有时候你也需要将使用 Markdown 格式的文件转换成其他格式。这就是 [Pandoc][18] 的用武之地。你可以用它来将你的文档转换成 HTML、Word、LibreOffice Writer、LaTeX、EPUB 以及其他格式。你甚至可以用 Pandoc 来生成书籍和[研究论文][19]。
你有最喜欢的命令行写作工具吗?在社区发表评论分享它吧。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/11/command-line-tools-writers
作者:[Scott Nesbitt][a]
选题:[lujun9972][b]
译者:[LazyWolfLin](https://github.com/LazyWolfLin)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/scottnesbitt
[b]: https://github.com/lujun9972
[1]: https://plaintextproject.online
[2]: https://www.nano-editor.org/
[3]: https://www.vim.org
[4]: https://www.gnu.org/software/emacs/
[5]: https://opensource.com/article/17/1/jove-lightweight-alternative-vim
[6]: https://en.wikipedia.org/wiki/List_of_text_editors#Text_user_interface
[7]: https://cowlark.com/wordgrinder/
[8]: http://aspell.net/
[9]: https://opensource.com/article/18/2/how-check-spelling-linux-command-line-aspell
[10]: https://www.cs.hmc.edu/~geoff/ispell.html
[11]: https://en.wikipedia.org/wiki/Lint_(software)
[12]: http://proselint.com/
[13]: http://proselint.com/checks/
[14]: https://github.com/get-alex/alex
[15]: https://alexjs.com/#demo
[16]: http://aiksaurus.sourceforge.net/
[17]: https://en.wikipedia.org/wiki/Markdown
[18]: https://pandoc.org
[19]: https://opensource.com/article/18/9/pandoc-research-paper

View File

@ -0,0 +1,60 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: subject: (10 ways to give thanks to open source and free software maintainers)
[#]: via: (https://opensource.com/article/18/11/ways-give-thanks-open-source)
[#]: author: (Moshe Zadka https://opensource.com/users/moshez)
[#]: url: (https://linux.cn/article-10333-1.html)
感谢开源和自由软件维护者的 10 种方法
=======
> 如何表达你的感激之情。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/world_hands_diversity.png?itok=zm4EDxgE)
每天,我使用的那些高质量的软件 —— 开发和维护这些软件的人不需要我为之付款,他们尊重我的自由,并且慷慨地付出时间和精力。
在这个感恩的季节,我鼓励那些也使用和欣赏开源和自由软件维护者工作的人表达你的感激之情。以下是十种方法:
### 容易做到的
1、发送电子邮件感谢开发人员。具体点说告诉他们你使用他们的什么软件以及它是如何帮助了你。
2、使用你最喜爱的社交媒体平台宣传它。
3、写一篇关于你最喜欢的软件的博客文章。
### 捐款
4、如果你最喜欢的开源项目接受捐款请汇款。
5、如果你受雇于使用开源软件的公司看你是否可以说服管理层赞助某些项目。
6、尽你所能地捐款。社交动机能做的不可思议
### 花费时间
7、帮助审查补丁。
8、帮助分类 bug。
9、回答 IRC、邮件列表或 [Stack Overflow][1] 中的问题。
**10、额外的**如果你像我一样,你在某个时候对开源社区的其他人说了一些严厉的话。承诺做得更好:用善良和开放沟通。感谢的最好方式是让开源社区成为人们能舒适沟通的地方。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/11/ways-give-thanks-open-source
作者:[Moshe Zadka][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/moshez
[b]: https://github.com/lujun9972
[1]: https://meta.stackoverflow.com/

View File

@ -1,10 +1,11 @@
Bash 中使用控制运算符连接命令
======
在命令行中,使用控制运算符为复合命令添加逻辑。
> 在命令行中,使用控制运算符为复合命令添加逻辑。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc-lead-yearbook-best-couple.png?itok=a_99oCdE)
一些简单的复合指令——比如说在一个命令行中连接几个命令——是经常使用的。这些命令使用分号分隔,表示一个命令结束。为了在一个命令行中创建一系列简单的 shell 命令,只需要使用分号把每一条命令分隔开,就像下面这样:
经常会使用一些简单的复合指令,比如说在一个命令行中连接几个命令。这些命令使用分号分隔,表示一个命令结束。为了在一个命令行中创建一系列简单的 shell 命令,只需要使用分号把每一条命令分隔开,就像下面这样:
```
command1 ; command2 ; command3 ; command4 ;
@ -12,7 +13,7 @@ command1 ; command2 ; command3 ; command4 ;
最后一个分号你可以不用添加,因为当你按下回车键时就表示一个命令的结束,但是为了和其它的保持一致,还是建议加上比较好。
所有的命令执行都没有什么问题——只要没有什么意外发生。但是当出问题时到底发生了什么呢?我们可以预测,并且通过 Bash 中内置的 `&&``||` 运算符跟踪这些错误。这两个控制运算符提供了一些流控制,可以让我们改变代码执行队列的顺序。分号和 **换行符** 也被认为是 Bash 的控制运算符。
所有的命令执行都没有什么问题 —— 只要没有什么意外发生。但是当出问题时到底发生了什么呢?我们可以预测,并且通过 Bash 中内置的 `&&``||` 运算符跟踪这些错误。这两个控制运算符提供了一些流控制,可以让我们改变代码执行队列的顺序。分号和换行符也被认为是 Bash 的控制运算符。
`&&` 运算符意义简单来说就是“如果 `command1` 执行成功,就接着执行 `command2`。”如果 `command1` 因为任何原因执行失败,那么 `command2` 将不执行。这个语法看下来像这样:
@ -20,9 +21,9 @@ command1 ; command2 ; command3 ; command4 ;
command1 && command2
```
这样写是允许的,因为每一个命令都会返回一个值给 shell 来表示这个命令在执行的过程中是否执行成功或者失败。通常,返回值是 0 表示成功,而一个正数值表示不同种类的错误。有一些系统管理工具仅仅返回一个 1 来表示所有的错误,但是也有很多工具使用其它的正数的返回值来表示各种类型错误。
这样写是允许的,因为每一个命令都会返回一个值RC给 shell 来表示这个命令在执行的过程中是否执行成功或者失败。通常,返回值是 `0` 表示成功,而一个正数值表示不同种类的错误。有一些系统管理工具仅仅返回一个 `1` 来表示所有的错误,但是也有很多工具使用其它的正数的返回值来表示各种类型错误。
我们可以很容易的使用脚本 命令列表中的下一个命令,或者可以直接使用系统管理工具检查 shell 变量 `$?` 。我们一起来看这些返回值。运行一个简单的命令然后立即检查它的返回值,这个返回值始终是属于最后一个运行的命令。
我们可以很容易的使用脚本来检查 shell 变量 `$?`,可以通过命令列表中的下一个命令,或者可以直接使用系统管理工具检查。我们一起来看这些返回值。运行一个简单的命令然后立即检查它的返回值,这个返回值始终是属于最后一个运行的命令。
```
[student@studentvm1 ~]$ ll ; echo "RC = $?"
@ -35,7 +36,7 @@ RC = 0
[student@studentvm1 ~]$
```
这个返回值是 0表示这个命令执行成功了。现在尝试使用同样的命令在一些我们没有权限的目录上。
这个返回值是 `0`,表示这个命令执行成功了。现在尝试使用同样的命令在一些我们没有权限的目录上。
```
[student@studentvm1 ~]$ ll /root ; echo "RC = $?"
@ -44,7 +45,7 @@ RC = 2
[student@studentvm1 ~]$
```
这个返回值的含义可以在 [`ls` 命令的 man 页面][1] 中找到。
这个返回值的含义可以在 [ls 命令的 man 页面][1] 中找到。
现在我们来试试 `&&` 这个控制运算符,因为它也可能会被用在一个命令行程序中。我们将从一个简单的示例开始:创建一个新目录,如果创建成功就在这个目录中创建一个文件。
@ -54,7 +55,7 @@ RC = 2
[student@studentvm1 ~]$ cd ; mkdir testdir
```
`~/testdir` 中新建一个目录,这也应该是一个空目录,因为是你刚刚创建的,然后创建一个新的空文件在这个新目录中。下面的命令可以做这些事情。
`~/testdir` 中新建一个目录,这也应该是一个空目录,因为是你刚刚创建的,然后创建一个新的空文件在这个新目录中。下面的命令可以做这些事情。
```
[student@studentvm1 ~]$ mkdir ~/testdir/testdir2 && touch ~/testdir/testdir2/testfile1
@ -64,7 +65,7 @@ total 0
[student@studentvm1 ~]$
```
我们看到一切都运行得很好,因为 `testdir` 目录是访问且可写的。然后我们改变 `testdir` 目录的权限,让用户 **student** 不再具有访问的权限。操作如下:
我们看到一切都运行得很好,因为 `testdir` 目录是访问且可写的。然后我们改变 `testdir` 目录的权限,让用户 `student` 不再具有访问的权限。操作如下:
```
[student@studentvm1 ~]$ chmod 076 testdir ; ll | grep testdir
@ -116,7 +117,7 @@ via: https://opensource.com/article/18/11/control-operators-bash-shell
作者:[David Both][a]
选题:[lujun9972][b]
译者:[Jamskr](https://github.com/Jamskr)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,13 +1,13 @@
[#]: collector: "lujun9972"
[#]: translator: "qhwdw"
[#]: reviewer: " "
[#]: publisher: " "
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: subject: "OpenSnitch an Application Firewall for Linux [Review]"
[#]: via: "https://itsfoss.com/opensnitch-firewall-linux/"
[#]: author: "[John Paul](https://itsfoss.com/author/john/)"
[#]: url: " "
[#]: author: "John Paul https://itsfoss.com/author/john/"
[#]: url: "https://linux.cn/article-10337-1.html"
OpenSnitch 一个 Linux 上的应用程序防火墙
OpenSnitch一个 Linux 上的应用程序防火墙
======
不能因为 Linux 比 Windows 更安全,就可以在 Linux 上放松警惕。Linux 上可以使用的防火墙很多,它们可以让你的 Linux 系统更安全。今天,我们将带你了解一个这样的防火墙工具,它就是 OpenSnitch。
@ -20,9 +20,11 @@ OpenSnitch 一个 Linux 上的应用程序防火墙
OpenSnitch 所做的主要事情就是跟踪你机器上安装的应用程序所发起的互联网请求。OpenSnitch 允许你去创建规则以同意或阻止那个应用程序发起的互联网访问。当一个应用程序尝试去访问互联网而没有相应的访问规则存在时,就会出现一个对话框,这个对话框让你去选择允许还是阻止那个连接。
你也可以决定这个新规则是应用到进程上、精确的 URL 上、域名上、单个实例上,以及本次会话还是永久有效。
你也可以决定这个新规则是应用到进程上、具体的 URL 上、域名上、单个实例上,以及本次会话还是永久有效。
![OpenSnitch firewall app in Linux][5]OpenSnatch 规则请求
![OpenSnitch firewall app in Linux][5]
*OpenSnatch 规则请求*
你创建的所有规则都保存为 [JSON 文件][6],如果以后需要修改它,就可以去修改这个文件。比如说,你错误地阻止了一个应用程序。
@ -33,17 +35,17 @@ OpenSnitch 也有一个漂亮的、一目了然的图形用户界面:
* 属主用户是谁
* 使用哪个端口
如果你愿意,也可以将这些信息导出到一个 CSV 文件中。
OpenSnitch 遵循 GPL v3 许可证使用。
![OpenSnitch firewall interface][7]OpenSnitch 进程标签页
![OpenSnitch firewall interface][7]
*OpenSnitch 进程标签页*
### 在 Linux 中安装 OpenSnitch
[OpenSnitch GitHub 页面][8] 上的安装介绍是针对 Ubuntu 用户的。如果你使用的是其它发行版,你需要调整一下相关的命令。据我所知,这个应用程序仅打包到 [Arch User Repository][9] 中
[OpenSnitch GitHub 页面][8] 上的安装介绍是针对 Ubuntu 用户的。如果你使用的是其它发行版,你需要调整一下相关的命令。据我所知,这个应用程序仅在 [Arch User Repository][9] 中打包了
在你开始之前,你必须正确安装了 Go并且已经定义好了 `$GOPATH` 环境变量。
@ -67,7 +69,7 @@ go get github.com/evilsocket/opensnitch
cd $GOPATH/src/github.com/evilsocket/opensnitch
```
如果没有正确设置 `$GOPATH` 环境变量,运行上面的命令时将会出现一个 “no such folder found” 的错误信息。只需要进入到你刚才克隆仓库位置的 “evilsocket/opensnitch” 文件夹中即可。
如果没有正确设置 `$GOPATH` 环境变量,运行上面的命令时将会出现一个 “no such folder found” 的错误信息。只需要进入到你刚才克隆仓库位置的 `evilsocket/opensnitch` 文件夹中即可。
现在,我们构建并安装它。
@ -77,7 +79,7 @@ make
sudo make install
```
如果出现 “`dep` command could not be found” 的错误信息,在 `PATH` 中添加 `GOPATH/bin` 即可。
如果出现 “dep command could not be found” 的错误信息,在 `$PATH` 中添加 `$GOPATH/bin` 即可。
安装完成后,我们将要启动它的守护程序和图形用户界面。
@ -90,7 +92,8 @@ opensnitch-ui
```
![OpenSnitch firewall interface][10]
运行在 Manjaro 上的 OpenSnitch
*运行在 Manjaro 上的 OpenSnitch*
### 使用体验
@ -98,7 +101,7 @@ opensnitch-ui
不幸的是,我安装之后,不能启动图形用户界面。因此,我手动去运行最后三个步骤。一切似乎很顺利。如果我想让 Firefox 去访问 Manjaro 的网站,对话框就会弹出来询问我。
有趣的是,当我运行一个 [AUR 工具][11] `yay` 去更新我的系统时,弹出对话框要求了 `yay`、`pacman`、`pamac`、和 `git` 的访问规则。后来,我关闭并重启动 GUI因为它是活的。当我重启动它时,它不再要求我去创建规则了。我安装了 Falkon而 OpenSnitch 并没有询问我去授予它任何权限。它甚至在 OpenSnitch 的 GUI 中没有列出 Falkon。我重新安装了 OpenSnitch 后,这个问题依旧存在。
有趣的是,当我运行一个 [AUR 工具][11] `yay` 去更新我的系统时,弹出对话框要求了 `yay`、`pacman`、`pamac`、和 `git` 的访问规则。后来,我关闭并重启动 GUI因为它当前活的。当我重启动它时,它不再要求我去创建规则了。我安装了 Falkon而 OpenSnitch 并没有询问我去授予它任何权限。它甚至在 OpenSnitch 的 GUI 中没有列出 Falkon。我重新安装了 OpenSnitch 后,这个问题依旧存在。
然后,我转到 Ubuntu Mate 上安装 OpenSnitch因为安装介绍就是针对 Ubuntu 所写的,进展很顺利。但是,我遇到了几个问题。我调整了一下上面介绍的安装过程以解决我遇到的问题。
@ -106,7 +109,9 @@ opensnitch-ui
GUI 也有一点需要去改进。由于某些原因,每次窗口都被放在顶部。而且不能通过设置来修改这个问题。如果能够从 GUI 中改变规则将是一个不错的选择。
![][12]OpenSnitch 的 hosts 标签
![][12]
*OpenSnitch 的 hosts 标签*
### 对 OpenSnitch 的最后意见
@ -125,7 +130,7 @@ via: https://itsfoss.com/opensnitch-firewall-linux/
作者:[John Paul][a]
选题:[lujun9972][b]
译者:[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/) 荣誉推出

View File

@ -1,31 +1,30 @@
无服务器架构的三个意义
======
对于<ruby>无服务器<rt>Serverless</rt></ruby>架构,什么时候该用,什么时候不该用呢?
> 以及,对于<ruby>无服务器<rt>Serverless</rt></ruby>架构,什么时候该用,什么时候不该用呢?
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003499_01_linux11x_cc.png?itok=XMDOouJR)
如果将如今互联网体验中最方便实用的那一部分去掉,那么留下来的基本就是<ruby>客户端-服务端<rt>client-server</rt></ruby>模式了。这一个模式在互联网建立初期就已经在使用了,直到目前都没有太大的变化,也就是说,这个模式仍然在为我们服务。
那么,当人们谈论无服务器架构的时候,到底是指什么呢?其实,无服务器架构并不是说不使用服务器了。恰恰相反,客户端-服务端模式仍然在其中发挥着重要的作用。
那么,当人们谈论<ruby>无服务器<rt>Serverless</rt></ruby>架构的时候,到底是指什么呢?其实,无服务器架构并不是说不使用服务器了。恰恰相反,客户端-服务端模式仍然在其中发挥着重要的作用。
无服务器架构实际上指的是能够让开发者在不需要关心服务器上架、为操作系统打补丁、创建容器镜像这些工作的情况下,就能够完成编码、部署和创建应用这一整套流程的架构。
### 无服务器架构的三个重要意义
1. 一些缺乏开发经验的人员现在要参与到开发工作中来了。无服务器架构能够让他们尽量只学习必要的工作内容,把更多的时间放在更具创造性的开发工作中。
2. 开发者不再需要重复造轮子。运行和维护服务器、为操作系统打补丁、创建容器等这一系列工作,都可以由更专业的无服务器架构提供商来完成。
3. 最现实的一点是,如果不使用无服务器架构,那么在服务器管理方面,总需要有一个作最终决策的人。当服务器发生崩溃时,或是需要在服务器上执行某些操作时,总是需要这样一个统领全局的人来作出决策。因此最佳的方案是使用无服务器架构。
1. 一些缺乏开发经验的人员现在要参与到开发工作中来了。无服务器架构能够让他们尽量只学习必要的工作内容,把更多的时间放在更具创造性的开发工作中。
2. 开发者不再需要重复造轮子。运行和维护服务器、为操作系统打补丁、创建容器等这一系列工作,都可以由更专业的无服务器架构提供商来完成。
3. 最现实的一点是,如果不使用无服务器架构,那么在服务器管理方面,总需要有一个作最终决策的人。当服务器发生崩溃时,或是需要在服务器上执行某些操作时,总是需要这样一个统领全局的人来作出决策。因此最佳的方案是使用无服务器架构。
### 什么时候该用或者不该用无服务器架构?
听起来无服务器架构是个好东西。但事实上,无服务器架构并不是万能的,在使用之前还需要考虑以下这些因素:
1. 成本
2. 使用范围
3. 时间
4. 控制方式
1. 成本
2. 使用范围
3. 时间
4. 控制方式
其中值得注意的是控制方式。现在已经有一些项目为开发者提供了操作和控制无服务器架构计算环境的工具了,[Apache OpenWhisk][1] 就是其中之一。
@ -40,7 +39,7 @@ via: https://opensource.com/article/18/12/serverless-podcast-command-line-heros
作者:[Jen Wike Huger][a]
选题:[lujun9972][b]
译者:[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/) 荣誉推出

View File

@ -1,32 +1,35 @@
[#]: collector: (lujun9972)
[#]: translator: (heguangzhi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: subject: (Have a cow at the Linux command line)
[#]: via: (https://opensource.com/article/18/12/linux-toy-cowsay)
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
[#]: url: ( )
[#]: url: (https://linux.cn/article-10346-1.html)
Have a cow at the Linux command line
在 Linux 命令行上拥有一头奶牛
======
Bring a bovine voice to your terminal output with the cowsay utility.
> 使用 cowsay 实用程序将牛的话语带到你的终端输出。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/uploads/linux-toy-cowsay.png?itok=RA4NDbrY)
Welcome to the fourth day of the Linux command-line toys advent calendar. If this is your first visit to the series, you might be asking yourself, whats a command-line toy. Were figuring that out as we go, but generally, it could be a game, or any simple diversion that helps you have fun at the terminal.
欢迎来到 Linux 命令行玩具第四天。如果这是你第一次访问这个系列,你可能会问自己,什么是命令行玩具。我们也在考虑这一点,但是一般来说,这可能是一个游戏,或者任何简单的娱乐,可以帮助你在终端玩得开心。
Some of you will have seen various selections from our calendar before, but we hope theres at least one new thing for everyone. Because just about everyone who Ive mentioned this series to has asked me about it already, todays selection is an obligatory one.
你们中的一些人会见过我们之前的选中的各种玩具,但是我们希望至少有一个对每个人来说都是新的。因为几乎所有我告诉他这个系列的人都已经问过它了,所以今天的选中的玩具是必须提及的。
You didnt think wed make it through this series without mentioning cowsay, did you?
你也不会认为我们会在不提及 `cowsay` 的情况下完成这个系列,对吧?
Cowsay is an udderly fantastic utility that takes text and outputs it as the spoken text of an ASCII-art bovine.
`cowsay` 是一个神奇的实用程序,它将文本作为 ASCII 艺术牛的讲话文本输出。
Youll likely find cowsay packaged in your default repositories, and perhaps even already installed. For me, in Fedora, all it took to install was:
你可能会发现 `cowsey` 打包在你的默认存储库中,甚至可能已经安装了。对我来说,在 Fedora像这样安装:
```
$ sudo dnf install -y cowsay
```
Then, invoke it with cowsay followed by your message. Perhaps youd like to pipe in the [fortune][1] [utility][1] we talked about yesterday.
然后,用 `cowsey` 调用它,然后是你的消息。也许你想到昨天我们谈到的 [fortune 应用][1] 连接起来。
```
$ fortune | cowsay
@ -41,7 +44,7 @@ $ fortune | cowsay
                ||     ||
```
Thats it! **Cowsay** ships with few variations, called cow files, that can usually be found in **/usr/share/cowsay.** To see the cow file options available on your system, use **-l** flag after cowsay. Then, use the **-f** flag to try one out.
就这样!`cowsay` 还有点小变体,称为 cow 文件,通常可以在 `/usr/share/cowsay` 找到 ,要查看系统上可用的 cow 文件,请在 `cowsay` 之后使用 `-l` 。然后,用 `-f` 试试其中之一。
```
$ cowsay -f dragon "Run for cover, I feel a sneeze coming on."
@ -67,9 +70,9 @@ $ cowsay -f dragon "Run for cover, I feel a sneeze coming on."
                                                                  /.-~
```
My real beef with **cowsay** is that I dont have enough time today to really milk the cow puns for all they are worth. The steaks are just too high, and I might butcher the joke.
我对 `cowsay` 的真正不满是,我今天没有足够的时间来为牛的挤奶 —— 一语双关。牛排价格太高了,我只是开个玩笑。
On a more serious note, I had completely forgotten about **cowsay** until I re-encountered it when learning Ansible playbooks. If you happen to have **cowsay** installed, when you run a playbook, youll get your output from a series of cows. For example, running this playbook:
更严重的是,我已经完全忘记了 `cowsay` 直到我在学习 Ansible 的剧本时再次遇到它。如果你碰巧安装了 `cowyay`当你运行Ansible 的剧本时,你会从一队奶牛那里获得输出。例如,运行这个剧本:
```
- hosts:
@ -78,7 +81,7 @@ On a more serious note, I had completely forgotten about **cowsay** until I re-e
    - action: ping
```
Might give you the following:
可能会给你以下信息:
```
$ ansible-playbook playbook.yml
@ -123,13 +126,13 @@ ok: [localhost]
localhost                  : ok=2    changed=0    unreachable=0    failed=0  
```
**Cowsay** is available under a GPLv3 license, and you can find the Perl [source code][2] on GitHub. Ive also seen versions floating around in other languages, so take a look around for other variants; heres [one in R][3], for example. Implementing your own version in your language of choice might even be a fun programming learning task.
`cowsay` 在 GPLv3 许可证下可用,您可以在 GitHub 上找到 它的 Perl [源代码][2]。我也见过其他语言的版本,所以可以看看其他变体;例如,这是 [R 语言版][3]。用你选择的语言实现你自己的版本可能是一项有趣的编程学习任务。
Now that **cowsay** is out of the way, we can move on to greener pastures.
既然讲完了 `cowsay`,我们可以去更绿色的牧场了。
Do you have a favorite command-line toy that you think I ought to profile? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.
你有希望我来介绍的喜欢的命令行玩具吗?这个系列的排期大部分都填好了,但我还有一些空位方。在下面的评论中让我知道,我会来看看。如果有空间,我会尝试把它包括进去。如果没有,但是我收到了一些好的意见,我在结尾提及。
Check out yesterday's toy, [How to bring good fortune to your Linux terminal][1], and check back tomorrow for another!
看看昨天的玩具,[如何给你的 Linux 终端带来好运][1],明天再来看看另一个!
--------------------------------------------------------------------------------
@ -137,8 +140,8 @@ via: https://opensource.com/article/18/12/linux-toy-cowsay
作者:[Jason Baker][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
译者:[heguangzhi](https://github.com/heguangzhi)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -0,0 +1,98 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: subject: (Easily Convert Audio File Formats with SoundConverter in Linux)
[#]: via: (https://itsfoss.com/sound-converter-linux/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
[#]: url: (https://linux.cn/article-10350-1.html)
在 Linux 中使用 SoundConverter 轻松转换音频文件格式
======
> 如果你正在寻找将音频文件格式转换为 wav、mp3、ogg 或任何其他格式SoundConverter 是你在 Linux 中需要的工具。
![Audio Converter in Linux][1]
最近我购买了一些没有 DRM 的音乐。我是从 [SaReGaMa][2] 那里买的,这是一家印度历史最悠久,规模最大的音乐品牌。下载的文件采用高清质量的 WAV 格式。
不幸的是Rhythmbox 无法播放 WAV。最重要的是单个文件大小约为 70MB。想象一下将这么大的音乐传输到智能手机。它会不必要地占用大量空间。
所以我认为是时候将 WAV 文件转换为 MP3 —— 这个长青且最流行的音乐文件格式。
为此,我需要一个在 Linux 中的音频转换器。在这个教程中,我将向你展示如何使用名为 SoundCoverter 的 GUI 工具轻松地将音频文件从一种格式转换为另一种格式。
### 在 Linux 中安装 SoundConverter
[SoundConverter][3] 是一款流行的自由开源软件。它应该可以在大多数 Linux 发行版的官方仓库中找到。
Ubuntu/Linux Mint 用户只需在软件中心搜索 SoundConverter 并从那里安装即可。
![SoundConverter application in Software Center of Ubuntu][4]
*SoundConverter 可以从软件中心安装*
或者,你可以使用命令行方式。在基于 Debian 和 Ubuntu 的系统中,你可以使用以下命令:
```
sudo apt install soundconverter
```
在 Arch、Fedora 和其他非基于 Debian 的发行版中,你可以使用你的发行版的软件中心或软件包管理器。
### 在 Linux 中使用 SoundConverter 转换音频文件格式
安装完 SoundConverter 后,在菜单中搜索并启动它。
默认界面看起来像这样,它不能比这简单:
![SoundConverter application interface in Linux][5]
*简单的界面*
转换音频文件格式只要选择文件并单击转换。
但是,我建议你至少在第一次运行时检查下默认设置。默认情况下,它会将音频文件转换为 OGG 文件格式,你可能不希望这样。
![Preferences in SoundConverter][6]
*可以在“首选项”中更改默认输出设置*
要更改默认输出设置,请单击界面上的“首选项”图标。你会在这里看到很多可更改的选择。
你可以更改默认输出格式、比特率、质量等。你还可以选择是否要将转换后的文件保存在与原始文件相同的文件夹中。
转换后还可以选择自动删除原始文件。我不认为你应该使用那个选项。
你还可以更改输出文件名。默认情况下,它只会更改后缀,但你也可以选择根据曲目编号、标题、艺术家等进行命名。为此,原始文件中应包含适当的元数据。
说到元数据,你听说过 [MusicBrainz Picard][7] 吗?此工具可帮助你自动更新本地音乐文件的元数据。
### 总结
我之前用讨论过用一个小程序 [在 Linux 中录制音频][8]。这些很棒的工具通过专注某个特定的任务使得生活更轻松。你可以使用成熟和更好的音频编辑工具,如 [Audacity][9],但对于较小的任务,如转换音频文件格式,它可能用起来很复杂。
我希望你喜欢 SoundConverter。如果你使用其他工具请在评论中提及我会在 FOSS 中提及。使用开心!
--------------------------------------------------------------------------------
via: https://itsfoss.com/sound-converter-linux/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/Convert-audio-file-format-linux.png?resize=800%2C450&ssl=1
[2]: https://en.wikipedia.org/wiki/Saregama
[3]: http://soundconverter.org/
[4]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/sound-converter-software-center.png?ssl=1
[5]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2018/12/sound-converter-app-linux.jpeg?ssl=1
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/sound-converter-app-linux-preferences.jpeg?resize=800%2C431&ssl=1
[7]: https://itsfoss.com/musicbrainz-picard/
[8]: https://itsfoss.com/record-streaming-audio/
[9]: https://www.audacityteam.org/

View File

@ -1,3 +1,5 @@
translating by valoniakim
Person with diabetes finds open source and builds her own medical device
======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/health_heartbeat.png?itok=P-GXea-p)

View File

@ -1,3 +1,6 @@
Translating by wwhio
The IBM 029 Card Punch
======
Lines of code longer than 80 characters drive me crazy. I appreciate that this is pedantic. Ive seen people on the internet make good arguments for why the 80-character limit ought to be respected even on our modern Retina-display screens, but those arguments hardly justify the visceral hatred I feel for even that one protruding 81st character.

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (alim0x)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (DevOps is for everyone)

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (seriouszyx)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (What the open source community means to me)

View File

@ -0,0 +1,78 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (5 reasons to give Linux for the holidays)
[#]: via: (https://opensource.com/article/18/12/reasons-give-linux-holidays)
[#]: author: (Don Watkins https://opensource.com/users/don-watkins)
[#]: url: ( )
5 reasons to give Linux for the holidays
======
If a computer is on your gift-giving list, here's why it should be Linux.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/tux_linux_penguin_code_binary.jpg?itok=TxGxW0KY)
Every year around this time, people ask me about the best computer to give (or get) for the holidays. I always give the same answer: Linux. After all, if you want your recipients to be happy, why wouldn't you give them the best operating system on the planet?
Many people don't realize they have options when it comes to computer operating systems. Just recently, two friends (who didn't do their research) fell for the clever marketing and bought brand-new systems at premium prices. I'm willing to bet that within six months they'll be dissatisfied with those expensive computers.
In contrast, I recently purchased a four-year-old computer with an i5 processor, 4GB of RAM, and a 128GB SSD drive, and I love it. It's fast and has all the applications I need to be successful and happy. That's because I'm running Linux. Whether I'm using Firefox or Chrome, all my websites load quickly and the video is great. In fact, the web is faster on Linux than it is on MacOS or Windows.
So, if you're in the mood to give a computer for the holidays, here are five good reasons it should be Linux.
### 1\. Linux is easy to use
Linux distributions like [Fedora][1], [Ubuntu][2], [PopOS][3], [Linux Mint][4], and [Raspbian][5] come with loads of documentation and access to a user community eager to help. And desktop environments such as [GNOME][6], [KDE][7], and [LXDE][8] mean the Linux operating system is just plain easy. If you have a problem with a Linux operating system, you won't have to wait in a long telephone queue for an answer—you can tap into the community's knowledge.
### 2\. Free applications for practically anything you need
There are hundreds of high-quality, free software packages available for Linux. My favorites are [LibreOffice][9] and [GnuCash][10]. I cannot imagine any writing task that is beyond the scope of LibreOffice. I use it and recommend it to everyone I know. Why spend money on a name-brand productivity suite when LibreOffice, the best one out there, is free? (If you agree and you're able, you really ought to consider contributing to the project.)
### 3\. Security
Linux is secure, an important fact in an age when security tops most people's essential features list. On Linux, viruses and malware are minimal. I spend many days each year helping friends recover their Windows systems that have been hacked or infected with malware. That's rare on Linux, and if you want to be doubly sure no one gains improper access to your computer, there are plenty of open source solutions that can help prevent it. My favorites are [ClamAV][11] and [Rootkit Hunter][12]. Linux respects your privacy. It does not upload user data to Redmond or Cupertino.
### 4\. Freedom
Linux gives me the freedom to use my operating system however I choose, whether that is as a standalone workstation for personal productivity, a content server, a firewall for my home network, or something else. Unlike proprietary desktop operating systems, you don't have to purchase an upgrade or extension to expand your system's capabilities. There are no limitations. Best of all, I can give all of this knowledge away and encourage others to do the same. Isn't giving to others the spirit of holiday traditions?
### 5\. Stability
Linux is reliable and stable. The operating system does not crash. When you get updates, they don't require you to reboot while you're in the middle of doing something else. If you're using an older version of Fedora, Ubuntu, or Linux Mint and are happy with the status quo, you don't have to upgrade. Linux also offers more support for drivers of legacy printers and other peripherals than other operating systems.
### How to give Linux
Linux could be the best present your friends ever receive. Instead of buying holiday gifts from your favorite retailer, buy some 8GB or 16GB USB drives, download your favorite distribution, and [make some bootable USB][13] drives to give away. Volunteer your time (or include instructions) to help your friends to explore the "live" editions of these distributions before they install the operating system. Or, if you have an old, unused laptop or desktop, consider installing Linux and loaning it out for training purposes. Most of your friends will have no idea what a wonderful gift you are giving them—in the process, you will discover the joy of giving yourself to others.
If you really want to buy a new computer, this year I recommend you look at [System 76][14] or Dell's [XPS Developer][15] edition. If you don't want a new model, there are plenty of great offerings on [eBay][16], [DellRefurbished.com][17], and other sites that sell good-quality older laptops that are great candidates for an easy Linux install.
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/reasons-give-linux-holidays
作者:[Don Watkins][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/don-watkins
[b]: https://github.com/lujun9972
[1]: https://getfedora.org/
[2]: https://www.ubuntu.com/
[3]: https://system76.com/pop
[4]: https://linuxmint.com/
[5]: https://www.raspbian.org/
[6]: https://www.gnome.org/
[7]: https://www.kde.org/
[8]: https://lxde.org/
[9]: https://www.libreoffice.org/
[10]: https://www.gnucash.org/
[11]: https://www.clamav.net/
[12]: http://rkhunter.sourceforge.net/
[13]: https://opensource.com/article/18/7/getting-started-etcherio
[14]: https://system76.com/
[15]: https://www.dell.com/en-us/work/shop/dell-laptops-and-notebooks/xps-13-developer-edition/spd/xps-13-9370-laptop?appliedRefinements=302
[16]: https://www.ebay.com/b/Computers-Tablets-Network-Hardware/58058/bn_1865247
[17]: http://DellRefurbished.com

View File

@ -0,0 +1,81 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (F-Words in Linux Kernel Code Replaced with "Hug"?)
[#]: via: (https://itsfoss.com/swear-words-linux-kernel/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
[#]: url: ( )
F-Words in Linux Kernel Code Replaced with "Hug"?
======
**Brief: To comply with the new code of conduct, a developer from Intel proposes to replace F-words in the Linux kernel code with “hug”.**
![Polite Linus Torvalds after Code of Conduct][1]
Change is in air for the Linux Kernel Community.
Ever since the introduction of the [Linux code of conduct][2], things are going in a polite direction.
To refresh your memory, a few months back a new code of conduct was introduced for the Linux kernel developers. This code of conduct asks the developers to be nice and welcoming to other developers and be more open to diversity.
The new code of conduct caused a huge controversy as many Linux users and developers saw it as a conspiracy by Social Justice Warriors (SJW) to infiltrate Linux. The rumors were especially boosted by the [controversial past of the Contributor Covenant creator Coraline Ada Ehmke][2]. The Linux code of conduct is based on the same Contributor Covenant.
Right after signing the new code of conduct, Linux creator [Linus Torvalds took a month-long break to improve his behavior][3].
Torvalds who is known for being ruthless against poor code is a changed man now. After [coming back from the break][4], Torvalds controlled his rage and instead of lashing out against a developer, he replied nicely and pointed his mistake in a polite way.
### No more F-words in the Linux Kernel code?
There have been F-words in the Linux kernel code. To be clear, these F-words are in the code comments, not in the actual code.
You might expect that there will be way too many F-words in the 15+ millions of lines of Linux kernel code but thats not the case.
Jarkko Sakkinen from Intel pushed [these patches][5] that replace the F-words 33 times in the 3.3 million lines of code comments.
Interestingly, the patch email is titled “ **Zero ****s, hugload of hugs <3**“:
> In order to comply with the CoC, replace 选题模板.txt 中文排版指北.md core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LCTT翻译规范.md LICENSE published README.md scripts sources translated with a hug.
So now comments have become:
* Only Sun can take such nice parts and **hug** up the programming interface like this
* IOC3 is **hugging** **hugged** beyond belief
* **Hug** , we are miserable poor guys…
### Do you give a hug about these changes?
At this point, its not clear if this hugging patch has been accepted or not. Its more of an attempt to bring attention to profanity inside the kernel code.
So, we have to wait and watch if this patch sets a trend for removing offensive words from the Linux kernel code.
What do you think of it? Is using hug a good choice or do you have a better word for replacing the F-words?
And what do you think of these changes altogether. Do you think all these are unnecessary and futile exercises?
And when you comment, please replace your F-words with hugs :)
Story source: [Phoronix][6]
--------------------------------------------------------------------------------
via: https://itsfoss.com/swear-words-linux-kernel/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2018/12/hug-you-linus-torvalds.jpeg?resize=800%2C450&ssl=1
[2]: https://itsfoss.com/linux-code-of-conduct/
[3]: https://itsfoss.com/torvalds-takes-a-break-from-linux/
[4]: https://itsfoss.com/torvalds-is-back/
[5]: https://lists.freedesktop.org/archives/dri-devel/2018-November/198581.html
[6]: https://www.phoronix.com/scan.php?page=news_item&px=Linux-Kernel-Hugs

View File

@ -0,0 +1,94 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (6 steps to optimize software delivery with value stream mapping)
[#]: via: (https://opensource.com/article/18/12/optimizing-delivery-value-stream-mapping)
[#]: author: (Dominika Bula https://opensource.com/users/dominika)
6 steps to optimize software delivery with value stream mapping
======
Learn how VSM can help you streamline processes, boost efficiency, and better meet customer expectations.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/checklist_hands_team_collaboration.png?itok=u82QepPk)
Do your efforts to improve software development fall short due to confusion and too much debate? Does your organization have a clear picture of what is achievable, and are you sure youre moving in the right direction? Can you determine how much business value you've delivered so far? Are the bottlenecks in your process known? Do you know how to optimize your current process?
If you are looking for a tool that will help you answer these questions, consider integrating [value stream mapping][1] and [lean concepts][2] into the way you deliver software.
### What is value stream mapping (VSM)?
Popularized in the 90s by James Womack and Daniel Jones, value stream mapping is a lean enterprise technique that is currently used by many organizations. In short, the value stream is the sequence of activities that are performed by the organization to deliver customer requests. Value stream mapping helps determine what is valuable and what doesnt bring value by identifying activities that matter to your customer. The ultimate benefit of using VSM is a better understanding of how to improve your current development process to generate more value and impact.
### 6 steps to optimizing software delivery
1. **Select the process**
Any process can be modeled as a sequence of activities. For example, a [system development life cycle][3] is a value stream consisting of product specification, design, development, deployment, operation and maintenance, and finally, disposition. In this example, product design can be viewed as a value stream segment.
2. **Identify the parties involved in the project**
Select a project sponsor and team. Keep in mind that each area of the process should be represented. Holistic thinking helps identify and set expectations, which in turn reduces resistance to change.
3. **Create the current state map**
Creating the current state map helps establish a better understanding of how work is currently done. Documenting your current process is key to success at this stage. The goal is to identify the specific items that flow through your value stream.
4. **Challenge the current thinking**
Make sure that what you are doing adds value—if there are actions in your process that do not add value, stop doing them. Look at the [software development waste types][2] for ideas. Mary Poppendieck and Tom Poppendieck identify these and transfer them from manufacturing to software engineering in their book, [Lean Software Development: An Agile Toolkit][4]. The waste types are:
* Partially done work
* Extra processes
* Extra features
* Task switching
* Waiting
* Motion
* Defects
* Management activities
5. **Generate the future state map and execute improvements**
Think of what can be done to reduce or ideally eliminate the identified wastes.
While working on the future state map, follow the principle that humans should do only what they can do best, and the rest should be [automated][5]. The future state design should aim to eliminate hands-on work and deliver completed software projects in less time with higher quality.
Talk about the changes, let people ask questions—this will help reduce resistance to change. As you start executing improvements, remember that value stream mapping is an evolutionary process, and you might need to adjust the original plan. The value stream should be continuously improved; it will not be perfect the first time.
6. ****Measure benefits****
Karen Martin and Mike Osterling identify key performance metrics for software delivery in their book, [Value Stream Mapping][6]:
* Total lead time: the total time it takes to deliver on a customer request
* Total process time: the total work effort required by all functions on the timeline critical path of the value stream
* Activity ratio: the degree of flow in the value stream
* Compounded effect: the quality of output across the value stream
Well-executed value stream mapping not only improves the way work gets delivered, but it also provides a transformational opportunity for your organization and a tool to facilitate a shift in mindsets and behaviors.
### What to read next
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/optimizing-delivery-value-stream-mapping
作者:[Dominika Bula][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/dominika
[b]: https://github.com/lujun9972
[1]: https://en.wikipedia.org/wiki/Value_stream_mapping
[2]: https://en.wikipedia.org/wiki/Lean_software_development
[3]: https://en.wikipedia.org/wiki/Systems_development_life_cycle
[4]: https://www.oreilly.com/library/view/lean-software-development/0321150783/
[5]: https://xkcd.com/1205/
[6]: https://mhebooklibrary.com/doi/book/10.1036/9780071828949

View File

@ -0,0 +1,62 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Open source DIY ethics)
[#]: via: (https://arp242.net/weblog/diy.html)
[#]: author: (Martin Tournoij https://arp242.net/)
Open source DIY ethics
======
I moved to New Zealand last week, and as a proper Dutch person one of the first things I did after arriving was getting a bicycle.
I was recommended [a great place][1] where they collect old bikes and provide people with the parts and tools to fix up the bikes. Want a bike? Choose one, fix it, and its yours. There are helpful and knowledgable volunteers who will gladly help you and explain how things work, but in the end youll have to fix your own bike; theyre not going to do it for you.
I like this DIY attitude; I built my own fixie (which I unfortunately couldnt bring) years ago and had been maintaining it myself ever since, but there are many different aspects I never touched on (different brake systems, gears, etc.) and fixing my bike with some help and explanation was a useful experience which taught me a thing or two that Ill be sure to use in the future.
My attitude to open source projects tends to be similar: Ill gladly assist you or explain things, but you will have to do the work. This is especially true when it comes to feature requests or very specific scenarios.
Open source software is fundamentally a [DIY ethic][2] for many though not all people who participate in it. It certainly is for me. I just fix stuff I want myself. Since I take some amount of pride in my work and want things to work well for others Ill also gladly fix most bugs that are reported, but sometimes people will post an enhancement or feature request and just expect me to implement it. Its sometimes even combined with a “but project X does it!”-comment. Well, feck off and use project X then (I dont actually say this, just think it).
Ive seen more than a few people get frustrated by this attitude especially — though hardly exclusively — in the OpenBSD and suckless communities ([recent example that prompted this post][3]), partly because its not infrequently communicated in a somewhat unhelpful fashion (the OpenBSD saying is “shut up and hack”), but also because some people seem to misunderstand what it means to be a maintainer of an open source project. Open source software isnt a service I provide to the world; its something I DIYd myself and make available to the world because why not?
Some open source software is supported by companies. Only about [14% of the contributions to the Linux kernel are not affiliated with a company][4]. I dont think this matters: these are companies who are DIY-ing as well.
Are there people who contribute to open source for other reasons? Sure. Some do because they really believe in [Free Software][5], or because they like programming as a hobby. But those are not the majority.
Not all contributions that arent code are useless. Sometimes someone will have a great idea for an enhancement or feature that I hadnt thought of myself and this can be a very valuable contribution. But those types of constructive contributions are usually easy to recognize: they consist of more than just a single paragraph, are respectful, show a clear understanding of what the project is supposed to do, if they dont understand a certain aspect theyll ask instead of bombastically claiming that its “broken”, and perhaps most importantly, they show a willingness to constructively contribute, rather than just trying to tell you how to run your project.
This attitude isnt limited to open source; to quote Neil Gaiman when talking about A Song of Ice and Fire fans demanding George R.R. Martin work harder on the next instalment of the series: “[George R.R. Martin is not your bitch][6]”.
I cant help George with his next book, but I can help with software projects, which is really neat. Not everyone is a computer programmer, but the vast majority of projects Ive worked on are used exclusively by programmers.
In the two months that it took me to finish this post (cleaning up drafts always takes forever) there have been a number of incidents in various communities that touched upon a mismatch in expectations between open source authors/maintainers and the users. “Its not fun anymore, you get nothing from maintaining a popular package”, to quote one maintainer, or “Im frustrated because I cant handle the volume of emails” to quote another.
The situation would be vastly improved if more people start seeing and treating open source more like the DIY that it is and assume responsibility for that bug youve encountered or enhancement you want, rather than offloading all responsibility to the maintainer. This wont fix everything, but its a good start. Note that plenty of people — including myself — already do this.
Both authors and users will benefit; authors will be frustrated less with “entitled” users, and users will be frustrated less by “rude” authors, and in the end the software will work better as users will be more willing to spend some time fixing stuff themselves, rather than just expecting other people to do it for them.
--------------------------------------------------------------------------------
via: https://arp242.net/weblog/diy.html
作者:[Martin Tournoij][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://arp242.net/
[b]: https://github.com/lujun9972
[1]: https://www.facebook.com/TheCrookedSpoke
[2]: https://en.wikipedia.org/wiki/DIY_ethic
[3]: https://www.reddit.com/r/suckless/comments/9mhwg8/why_does_sts_latency_suck_so_bad/e7fu9sj/
[4]: https://www.linux.com/publications/linux-kernel-development-how-fast-it-going-who-doing-it-what-they-are-doing-and-who-0
[5]: https://www.gnu.org/philosophy/free-sw.html
[6]: http://journal.neilgaiman.com/2009/05/entitlement-issues.html
[7]: mailto:martin@arp242.net
[8]: https://github.com/Carpetsmoker/arp242.net/issues/new

View File

@ -0,0 +1,316 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (YAML: probably not so great after all)
[#]: via: (https://arp242.net/weblog/yaml_probably_not_so_great_after_all.html)
[#]: author: (Martin Tournoij https://arp242.net/)
YAML: probably not so great after all
======
I previously wrote [why using JSON for human-editable configuration files is a bad idea][1]. Today were going to look at some general problems with the YAML format.
### Insecure by default
YAML is insecure by default. Loading a user-provided (untrusted) YAML string needs careful consideration.
```
!!python/object/apply:os.system
args: ['ls /']
```
Running it with `print(yaml.load(open('a.yaml')))` should give you something like:
```
bin etc lib lost+found opt root sbin tmp var sys
boot dev efi home lib64 mnt proc run srv usr
0
```
Many other languages (including Ruby and PHP) are also unsafe by default. [Searching for `yaml.load` on GitHub][2] gives a whopping 2.8 million results. [`yaml.safe_load`][3] only gives 26,000 results.
Mind you, many of those `yaml.load()`s are fine loading in a config file with `yaml.load()` is often okay since its usually (though not always!) from a trusted source, and many are from test files with static YAML. But still, one cant help but wonder how many exploits are hidden in those 2.8 million results.
This is not a theoretical problem. In 2013 [every Ruby on Rails application ever written was found to be vulnerable][4] to remote code execution due to exactly this problem.
One might argue this is not really the fault of the YAML format as such, but rather the fault of the libraries implementing it wrong, but it seems to be the case that the majority of libraries are unsafe by default (especially the dynamic languages), so de-facto it is a problem with YAML.
One might also argue that fixing it is as easy as replacing `load()` with `safe_load()`, but many people are unaware of the problem, and even if youre aware of it, its one of those things that can be easy to forget. Its pretty bad API design.
### Can be hard to edit, especially for large files
YAML files can be hard to edit, and this difficulty grows fast as the file gets larger.
A good example of this are Ruby on Rails translation files; for example:
```
en:
formtastic:
labels:
title: "Title" # Default global value
article:
body: "Article content"
post:
new:
title: "Choose a title..."
body: "Write something..."
edit:
title: "Edit title"
body: "Edit body"
```
This still looks okay, right? But what if this file has 100 lines? Or 1,000 lines? It is difficult to see “where” in the file you are because it may be off the screen. Youll need to scroll up, but then you need to keep track of the indentation, which can be pretty hard even with indentation guides, especially since 2-space indentation is the norm and [tab indentation is forbidden][5].
And accidentally getting the indentation wrong often isnt an error; it will often just deserialize to something you didnt intend. Happy debugging!
Ive been happily programming Python for over a decade, so Im used to significant whitespace, but sometimes Im still struggling with YAML. In Python the drawbacks and loss of clarity are contained by not having functions that are several pages long, but data or configuration files have no such natural limits to their length.
For small files this is not a problem; but it really doesnt scale well to larger files, especially not if you want to edit them later on.
### Its pretty complex
YAML may seem simple and obvious when glancing at a basic example, but turns out its not. The [YAML spec][6] is 23,449 words; for comparison, [TOML][7] is 3,339 words, [JSON][8] is 1,969 words, and [XML][9] is 20,603 words.
Who among us have read all that? Who among us have read and understood all of that? Who among of have read, understood, and **remembered** all of that?
For example did you know there are [nine ways to write a multi-line string in YAML][10] with subtly different behaviour?
Yeah :-/
That post gets even more interesting if you look at [its revision history][11], as the author of the post discovers more and more ways to do this and more of the subtleties involved.
Its telling that the YAML spec starts with a preview, which states (emphases mine):
> This section provides a quick glimpse into the expressive power of YAML. **It is not expected that the first-time reader grok all of the examples**. Rather, these selections are used as motivation for the remainder of the specification.
#### Surprising behaviour
What does this parse to (examples courtesy of [Colm OConnor][12]):
```
- Don Corleone: Do you have faith in my judgment?
- Clemenza: Yes
- Don Corleone: Do I have your loyalty?
```
Yup!
```
[
{'Don Corleone': 'Do you have faith in my judgment?'},
{'Clemenza': True},
{'Don Corleone': 'Do I have your loyalty?'}
]
```
Or what about:
```
python: 3.5.3
postgres: 9.3
```
`3.5.3` gets recognized as as string, but `9.3` gets recognized as a number instead of a string:
```
{'python': '3.5.3', 'postgres': 9.3}
```
Or what about:
```
Effenaar: Eindhoven
013: Tilburg
```
013 is a popular music Venue in Tilburg, but YAML will send you the wrong way since its parsed as an octal number:
```
{11: 'Tilburg', 'Effenaar': 'Eindhoven'}
```
All of this and more is why many experienced YAMLers will often quote all strings, even when its not strictly required. Many people dont use quotes, and it can be easy to forget especially if the rest of the file possibly written by other people doesnt use quotes.
#### Its not portable
Because its so complex, its claims of portability have been greatly exaggerated. For example consider this example taken from the YAML spec:
```
? - Detroit Tigers
- Chicago cubs
:
- 2001-07-23
? [ New York Yankees,
Atlanta Braves ]
: [ 2001-07-02, 2001-08-12,
2001-08-14 ]
```
Aside from the fact that most readers of this probably wont even know what this does, try parsing it in Python with PyYAML:
```
yaml.constructor.ConstructorError: while constructing a mapping
in "a.yaml", line 1, column 1
found unhashable key
in "a.yaml", line 1, column 3
```
In Ruby it works:
```
{
["Detroit Tigers", "Chicago cubs"] => [
#<Date: 2001-07-23 ((2452114j,0s,0n),+0s,2299161j)>
],
["New York Yankees", "Atlanta Braves"] => [
#<Date: 2001-07-02 ((2452093j,0s,0n),+0s,2299161j)>,
#<Date: 2001-08-12 ((2452134j,0s,0n),+0s,2299161j)>,
#<Date: 2001-08-14 ((2452136j,0s,0n),+0s,2299161j)>
]
}
```
The reason for this is because you cant use a list as a dict key in Python:
```
>>> {['a']: 'zxc'}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
```
And this restriction is not unique to Python; common languages such as PHP, JavaScript, and Go all share this restriction.
So use this in a YAML file, and you wont be able to read it in most languages.
Heres another example again taken from the examples section of the YAML spec:
```
# Ranking of 1998 home runs
---
- Mark McGwire
- Sammy Sosa
- Ken Griffey
# Team ranking
---
- Chicago Cubs
- St Louis Cardinals
```
Python says:
```
yaml.composer.ComposerError: expected a single document in the stream
in "a.yaml", line 3, column 1
but found another document
in "a.yaml", line 8, column 1
```
While Ruby outputs:
```
["Mark McGwire", "Sammy Sosa", "Ken Griffey"]
```
The reason for this is that there are multiple YAML documents in a single file (`---` start the document). In Python there is the `load_all()` function to parse all documents. Rubys `load()` just loads the first document, and as near as I can tell, doesnt have a way to load multiple documents.
There are [many more incompatibilities between implementations][13].
### Goals achieved?
The spec states:
> The design goals for YAML are, in decreasing priority:
>
> 1. YAML is easily readable by humans.
> 2. YAML data is portable between programming languages.
> 3. YAML matches the native data structures of agile languages.
> 4. YAML has a consistent model to support generic tools.
> 5. YAML supports one-pass processing.
> 6. YAML is expressive and extensible.
> 7. YAML is easy to implement and use.
>
So how well does it do?
> YAML is easily readable by humans.
True only if you stick to a small subset. The full set is complex much more so than XML or JSON.
> YAML data is portable between programming languages.
Not really true, as its too easy to create constructs that are not supported by common languages.
> YAML matches the native data structures of agile languages.
See above. Plus, why only support agile (or dynamic) languages? What about other languages?
> YAML has a consistent model to support generic tools.
I am not even sure what this means and I cant find any elaboration.
> YAML supports one-pass processing.
Ill take their word for it.
> YAML is expressive and extensible.
Well, it is, but its too expressive (e.g. too complex).
> YAML is easy to implement and use.
```
$ cat `ls -1 ~/gocode/src/github.com/go-yaml/yaml/*.go | grep -v _test` | wc -l
9247
$ cat /usr/lib/python3.5/site-packages/yaml/*.py | wc -l
5713
```
### Conclusion
Dont get me wrong, its not like YAML is absolutely terrible its certainly not as [problematic as using JSON][1] but its not exactly great either. There are some drawbacks and surprises that are not at all obvious at first, and there are a number of better alternatives such as [TOML][7] and other more specialized formats.
Personally, Im not likely to use it again when Ive got a choice.
If you must use YAML then I recommend you use [StrictYAML][14], which removes some (though not all) of the more hairy parts.
### Feedback
You can mail me at [martin@arp242.net][15] or [create a GitHub issue][16] for feedback, questions, etc.
--------------------------------------------------------------------------------
via: https://arp242.net/weblog/yaml_probably_not_so_great_after_all.html
作者:[Martin Tournoij][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://arp242.net/
[b]: https://github.com/lujun9972
[1]: http://arp242.net/weblog/JSON_as_configuration_files-_please_dont.html
[2]: https://github.com/search?q=yaml.load&type=Code&utf8=%E2%9C%93
[3]: https://github.com/search?q=yaml.safe_load&type=Code&utf8=%E2%9C%93
[4]: https://www.sitepoint.com/anatomy-of-an-exploit-an-in-depth-look-at-the-rails-yaml-vulnerability/
[5]: http://www.yaml.org/faq.html
[6]: http://yaml.org/spec/1.2/spec.pdf
[7]: https://github.com/toml-lang/toml
[8]: http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf
[9]: https://www.w3.org/TR/REC-xml/
[10]: http://stackoverflow.com/a/21699210/660921
[11]: http://stackoverflow.com/posts/21699210/revisions
[12]: https://github.com/crdoconnor/strictyaml/blob/master/FAQ.rst#what-is-wrong-with-implicit-typing
[13]: https://github.com/cblp/yaml-sucks
[14]: https://github.com/crdoconnor/strictyaml
[15]: mailto:martin@arp242.net
[16]: https://github.com/Carpetsmoker/arp242.net/issues/new

View File

@ -1,236 +0,0 @@
Manage your workstation with Ansible: Automating configuration Translating By FelixYFZ
======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/robot_arm_artificial_ai.png?itok=8CUU3U_7)
Ansible is an amazing automation and configuration management tool. It is mainly used for servers and cloud deployments, and it gets far less attention for its use in workstations, both desktops and laptops, which is the focus of this series.
In the [first part][1] of this series, I showed you basic usage of the `ansible-pull` command, and we created a playbook that installs a handful of packages. That wasn't extremely useful by itself, but it set the stage for further automation.
In this article, everything comes together full circle, and by the end we will have a fully working solution for automating workstation configuration. This time, we'll set up our Ansible configuration such that future changes we make will automatically be applied to our workstations. At this point, I'm assuming you already worked through part one. If you haven't, feel free to do that now and then return to this article when you're done. You should already have a GitHub repository with the code from the first article inside it. We're going to build directly on what we did before.
First, we need to do some reorganization because we're going to do more than just install packages. At this point, we currently have a playbook named `local.yml` with the following content:
```
- hosts: localhost
  become: true
  tasks:
  - name: Install packages
    apt: name={{item}}
    with_items:
      - htop
      - mc
      - tmux
```
That's all well and good if we only want to perform one task. As we add new things to our configuration, this file will become quite large and get very cluttered. It's better to organize our plays into individual files with each responsible for a different type of configuration. To achieve this, create what's called a taskbook, which is very much like a playbook but the contents are more streamlined. Let's create a directory for our taskbooks inside our Git repository:
```
mkdir tasks
```
The code inside our current `local.yml` playbook lends itself well to become a taskbook for installing packages. Let's move this file into the `tasks` directory we just created with a new name:
```
mv local.yml tasks/packages.yml
```
Now, we can edit our `packages.yml` taskbook and strip it down quite a bit. In fact, we can strip everything except for the individual task itself. Let's make `packages.yml` look like this:
```
- name: Install packages
  apt: name={{item}}
  with_items:
    - htop
    - mc
    - tmux
```
As you can see, it uses the same syntax, but we stripped out everything that isn't necessary to the task it's performing. Now we have a dedicated taskbook for installing packages. However, we still need a file named `local.yml`, since `ansible-pull` still expects to find a file with that name. So we'll create a fresh one with this content in the root of our repository (not in the `tasks` directory):
```
- hosts: localhost
  become: true
  pre_tasks:
    - name: update repositories
      apt: update_cache=yes
      changed_when: False
  tasks:
    - include: tasks/packages.yml
```
This new `local.yml` acts as an index that will import all our taskbooks. I've added a few new things to this file that you haven't seen yet in this series. First, at the beginning of the file, I added `pre_tasks`, which allows us to have Ansible perform a task before all the other tasks run. In this case, we're telling Ansible to update our distribution's repository index. This line does that for us:
```
apt: update_cache=yes
```
Normally the `apt` module allows us to install packages, but we can also tell it to update our repository index. The idea is that we want all our individual plays to work with a fresh index each time Ansible runs. This will help ensure we don't have an issue with a stale index while attempting to install a package. Note that the `apt` module works only with Debian, Ubuntu, and their derivatives. If you're running a different distribution, you'll want to use a module specific to your distribution rather than `apt`. See the documentation for Ansible if you need to use a different module.
The following line is also worth further explanation:
```
changed_when: False
```
This line on an individual task stops Ansible from reporting the results of the play as changed even when it results in a change in the system. In this case, we don't care if the repository index contains new data; it almost always will, since repositories are always changing. We don't care about changes to `apt` repositories, as index changes are par for the course. If we omit this line, we'll see the summary at the end of the process report that something has changed, even if it was merely about the repository being updated. It's better to ignore these types of changes.
Next is our normal tasks section, and we import the taskbook we created. Each time we add another taskbook, we add another line here:
```
tasks:
  - include: tasks/packages.yml
```
If you were to run the `ansible-pull` command here, it should essentially do the same thing as it did in the last article. The difference is that we have improved our organization and we can more efficiently expand on it. The `ansible-pull` command syntax, to save you from finding the previous article, is this:
```
sudo ansible-pull -U https://github.com/<github_user>/ansible.git
```
If you recall, the `ansible-pull` command pulls down a Git repository and applies the configuration it contains.
Now that our foundation is in place, we can expand upon our Ansible config and add features. Specifically, we'll add configuration to automate the deployment of future changes to our workstations. To support this goal, the first thing we should do is to create a user specifically to apply our Ansible configuration. This isn't required—we can continue to run our Ansible configuration under our own user. But using a separate user segregates this to a system process that will run in the background, without our involvement.
We could create this user with the normal method, but since we're using Ansible, we should shy away from manual changes. Instead, we'll create a taskbook to handle user creation. This taskbook will create just one user for now, but you can always add additional plays to this taskbook to add additional users. I'll call this user `ansible`, but you can name it something else if you wish (if you do, make sure to update all occurrences). Let's create a taskbook named `users.yml` and place this code inside of it:
```
- name: create ansible user
  user: name=ansible uid=900
```
Next, we need to edit our `local.yml` file and append this new taskbook to the file, so it will look like this:
```
- hosts: localhost
  become: true
  pre_tasks:
    - name: update repositories
      apt: update_cache=yes
      changed_when: False
  tasks:
    - include: tasks/users.yml
    - include: tasks/packages.yml
```
Now when we run our `ansible-pull` command, a user named `ansible` will be created on the system. Note that I specifically declared `User ID 900` for this user by using the `UID` option. This isn't required, but it's recommended. The reason is that UIDs under 1,000 are typically not shown on the login screen, which is great because there's no reason we would need to log into a desktop session as our `ansible` user. UID 900 is arbitrary; it should be any number under 1,000 that's not already in use. You can find out if UID 900 is in use on your system with the following command:
```
cat /etc/passwd |grep 900
```
However, you shouldn't run into a problem with this UID because I've never seen it used by default in any distribution I've used so far.
Now, we have an `ansible` user that will later be used to apply our Ansible configuration automatically. Next, we can create the actual cron job that will be used to automate this. Rather than place this in the `users.yml` taskbook we just created, we should separate this into its own file. Create a taskbook named `cron.yml` in the tasks directory and place the following code inside:
```
- name: install cron job (ansible-pull)
  cron: user="ansible" name="ansible provision" minute="*/10" job="/usr/bin/ansible-pull -o -U https://github.com/<github_user>/ansible.git > /dev/null"
```
The syntax for the cron module should be fairly self-explanatory. With this play, we're creating a cron job to be run as the `ansible` user. The job will execute every 10 minutes, and the command it will execute is this:
```
/usr/bin/ansible-pull -o -U https://github.com/<github_user>/ansible.git > /dev/null
```
Also, we can put additional cron jobs we want all our workstations to have into this one file. We just need to add additional plays to add new cron jobs. However, simply adding a new taskbook for cron isn't enough—we'll also need to add it to our `local.yml` file so it will be called. Place the following line with the other includes:
```
- include: tasks/cron.yml
```
Now when `ansible-pull` is run, it will set up a new cron job that will be run as the `ansible` user every 10 minutes. But, having an Ansible job running every 10 minutes isn't ideal because it will take considerable CPU power. It really doesn't make sense for Ansible to run every 10 minutes unless we've changed something in the Git repository.
However, we've already solved this problem. Notice the `-o` option I added to the `ansible-pull` command in the cron job that we've never used before. This option tells Ansible to run only if the repository has changed since the last time `ansible-pull` was called. If the repository hasn't changed, it won't do anything. This way, you're not wasting valuable CPU for no reason. Sure, some CPU will be used when it pulls down the repository, but not nearly as much as it would use if it were applying your entire configuration all over again. When `ansible-pull` does run, it will go through all the tasks in the Playbook and taskbooks, but at least it won't run for no purpose.
Although we've added all the required components to automate `ansible-pull`, it actually won't work properly yet. The `ansible-pull` command will run with `sudo`, which would give it access to perform system-level commands. However, our `ansible` user is not set up to perform tasks as `sudo`. Therefore, when the cron job triggers, it will fail. Normally we could just use `visudo` and manually set the `ansible` user up to have this access. However, we should do things the Ansible way from now on, and this is a great opportunity to show you how the `copy` module works. The `copy` module allows you to copy a file from your Ansible repository to somewhere else in the filesystem. In our case, we'll copy a config file for `sudo` to `/etc/sudoers.d/` so that the `ansible` user can perform administrative tasks.
Open up the `users.yml` taskbook, and add the following play to the bottom:
```
- name: copy sudoers_ansible
  copy: src=files/sudoers_ansible dest=/etc/sudoers.d/ansible owner=root group=root mode=0440
```
The `copy` module, as we can see, copies a file from our repository to somewhere else. In this case, we're grabbing a file named `sudoers_ansible` (which we will create shortly) and copying it to `/etc/sudoers.d/ansible` with `root` as the owner.
Next, we need to create the file that we'll be copying. In the root of your Ansible repository, create a `files` directory:
```
mkdir files
```
Then, in the `files` directory we just created, create the `sudoers_ansible` file with the following content:
```
ansible ALL=(ALL) NOPASSWD: ALL
```
Creating a file in `/etc/sudoers.d`, like we're doing here, allows us to configure `sudo` for a specific user. Here we're allowing the `ansible` user full access to the system via `sudo` without a password prompt. This will allow `ansible-pull` to run as a background task without us needing to run it manually.
Now, you can run `ansible-pull` again to pull down the latest changes:
```
sudo ansible-pull -U https://github.com/<github_user>/ansible.git
```
From this point forward, the cron job for `ansible-pull` will run every 10 minutes in the background and check your repository for changes. If it finds changes, it will run your playbook and apply your taskbooks.
So now we have a fully working solution. When you first set up a new laptop or desktop, you'll run the `ansible-pull` command manually, but only the first time. From that point forward, the `ansible` user will take care of subsequent runs in the background. When you want to make a change to your workstation machines, you simply pull down your Git repository, make the changes, then push those changes back to the repository. Then, the next time the cron job fires on each machine, it will pull down those changes and apply them. You now only have to make changes once, and all your workstations will follow suit. This method may be a bit unconventional though. Normally, you'd have an `inventory` file with your machines listed and several roles each machine could be a member of. However, the `ansible-pull` method, as described in this article, is a very efficient way of managing workstation configuration.
I have updated the code in my [GitHub repository][2] for this article, so feel free to browse the code there and check your syntax against mine. Also, I moved the code from the previous article into its own directory in that repository.
In part 3, we'll close out the series by using Ansible to configure GNOME desktop settings. I'll show you how to set your wallpaper and lock screen, apply a desktop theme, and more.
In the meantime, it's time for a little homework assignment. Most of us have configuration files we like to maintain for various applications we use. This could be configuration files for Bash, Vim, or whatever tools you use. I challenge you now to automate copying these configuration files to your machines via the Ansible repository we've been working on. In this article, I've shown you how to copy a file, so take a look at that and see if you can apply that knowledge to your personal files.
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/3/manage-your-workstation-configuration-ansible-part-2
作者:[Jay LaCroix][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
选题:[lujun9972](https://github.com/lujun9972)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://opensource.com/users/jlacroix
[1]:https://opensource.com/article/18/3/manage-workstation-ansible
[2]:https://github.com/jlacroix82/ansible_article.git

View File

@ -1,526 +0,0 @@
GraveAccent翻译中 Command Line Tricks For Data Scientists • kade killary
======
![](https://i.imgur.com/0mzQMcB.png)
For many data scientists, data manipulation begins and ends with Pandas or the Tidyverse. In theory, there is nothing wrong with this notion. It is, after all, why these tools exist in the first place. Yet, these options can often be overkill for simple tasks like delimiter conversion.
Aspiring to master the command line should be on every developers list, especially data scientists. Learning the ins and outs of your shell will undeniably make you more productive. Beyond that, the command line serves as a great history lesson in computing. For instance, awk - a data-driven scripting language. Awk first appeared in 1977 with the help of [Brian Kernighan][1], the K in the legendary [K&R book][2]. Today, some near 50 years later, awk remains relevant with [new books][3] still appearing every year! Thus, its safe to assume that an investment in command line wizardry wont depreciate any time soon.
### What Well Cover
* ICONV
* HEAD
* TR
* WC
* SPLIT
* SORT & UNIQ
* CUT
* PASTE
* JOIN
* GREP
* SED
* AWK
### ICONV
File encodings can be tricky. For the most part files these days are all UTF-8 encoded. To understand some of the magic behind UTF-8, check out this [excellent video][4]. Nonetheless, there are times where we receive a file that isnt in this format. This can lead to some wonky attempts at swapping the encoding schema. Here, `iconv` is a life saver. Iconv is a simple program that will take text in one encoding and output the text in another.
```
# Converting -f (from) latin1 (ISO-8859-1)
# -t (to) standard UTF_8
iconv -f ISO-8859-1 -t UTF-8 < input.txt > output.txt
```
* Useful options:
* `iconv -l` list all known encodings
* `iconv -c` silently discard characters that cannot be converted
### HEAD
If you are a frequent Pandas user then `head` will be familiar. Often when dealing with new data the first thing we want to do is get a sense of what exists. This leads to firing up Pandas, reading in the data and then calling `df.head()` \- strenuous, to say the least. Head, without any flags, will print out the first 10 lines of a file. The true power of `head` lies in testing out cleaning operations. For instance, if we wanted to change the delimiter of a file from commas to pipes. One quick test would be: `head mydata.csv | sed 's/,/|/g'`.
```
# Prints out first 10 lines
head filename.csv
# Print first 3 lines
head -n 3 filename.csv
```
* Useful options:
* `head -n` print a specific number of lines
* `head -c` print a specific number of bytes
### TR
Tr is analogous to translate. This powerful utility is a workhorse for basic file cleaning. An ideal use case is for swapping out the delimiters within a file.
```
# Converting a tab delimited file into commas
cat tab_delimited.txt | tr "\t" "," comma_delimited.csv
```
Another feature of `tr` is all the built in `[:class:]` variables at your disposal. These include:
```
[:alnum:] all letters and digits
[:alpha:] all letters
[:blank:] all horizontal whitespace
[:cntrl:] all control characters
[:digit:] all digits
[:graph:] all printable characters, not including space
[:lower:] all lower case letters
[:print:] all printable characters, including space
[:punct:] all punctuation characters
[:space:] all horizontal or vertical whitespace
[:upper:] all upper case letters
[:xdigit:] all hexadecimal digits
```
You can chain a variety of these together to compose powerful programs. The following is a basic word count program you could use to check your READMEs for overuse.
```
cat README.md | tr "[:punct:][:space:]" "\n" | tr "[:upper:]" "[:lower:]" | grep . | sort | uniq -c | sort -nr
```
Another example using basic regex:
```
# Converting all upper case letters to lower case
cat filename.csv | tr '[A-Z]' '[a-z]'
```
* Useful options:
* `tr -d` delete characters
* `tr -s` squeeze characters
* `\b` backspace
* `\f` form feed
* `\v` vertical tab
* `\NNN` character with octal value NNN
### WC
Word count. Its value is primarily derived from the `-l` flag, which will give you the line count.
```
# Will return number of lines in CSV
wc -l gigantic_comma.csv
```
This tool comes in handy to confirm the output of various commands. So, if we were to convert the delimiters within a file and then run `wc -l` we would expect the total lines to be the same. If not, then we know something went wrong.
* Useful options:
* `wc -c` print the byte counts
* `wc -m` print the character counts
* `wc -L` print length of longest line
* `wc -w` print word counts
### SPLIT
File sizes can range dramatically. And depending on the job, it could be beneficial to split up the file - thus `split`. The basic syntax for split is:
```
# We will split our CSV into new_filename every 500 lines
split -l 500 filename.csv new_filename_
# filename.csv
# ls output
# new_filename_aaa
# new_filename_aab
# new_filename_aac
```
Two quirks are the naming convention and lack of file extensions. The suffix convention can be numeric via the `-d` flag. To add file extensions, youll need to run the following `find` command. It will change the names of ALL files within the current directory by appending `.csv`, so be careful.
```
find . -type f -exec mv '{}' '{}'.csv \;
# ls output
# filename.csv.csv
# new_filename_aaa.csv
# new_filename_aab.csv
# new_filename_aac.csv
```
* Useful options:
* `split -b` split by certain byte size
* `split -a` generate suffixes of length N
* `split -x` split using hex suffixes
### SORT & UNIQ
The preceding commands are obvious: they do what they say they do. These two provide the most punch in tandem (i.e. unique word counts). This is due to `uniq`, which only operates on duplicate adjacent lines. Thus, the reason to `sort` before piping the output through. One interesting note is that `sort -u` will achieve the same results as the typical `sort file.txt | uniq` pattern.
Sort does have a sneakily useful ability for data scientists: the ability to sort an entire CSV based on a particular column.
```
# Sorting a CSV file by the second column alphabetically
sort -t"," -k2,2 filename.csv
# Numerically
sort -t"," -k2n,2 filename.csv
# Reverse order
sort -t"," -k2nr,2 filename.csv
```
The `-t` option here is to specify the comma as our delimiter. More often than not spaces or tabs are assumed. Furthermore, the `-k` flag is for specifying our key. The syntax for this is `-km,n`, with `m` being the starting field and `n` being the last.
* Useful options:
* `sort -f` ignore case
* `sort -r` reverse sort order
* `sort -R` scramble order
* `uniq -c` count number of occurrences
* `uniq -d` only print duplicate lines
### CUT
Cut is for removing columns. To illustrate, if we only wanted the first and third columns.
```
cut -d, -f 1,3 filename.csv
```
To select every column other than the first.
```
cut -d, -f 2- filename.csv
```
In combination with other commands, `cut` serves as a filter.
```
# Print first 10 lines of column 1 and 3, where "some_string_value" is present
head filename.csv | grep "some_string_value" | cut -d, -f 1,3
```
Finding out the number of unique values within the second column.
```
cat filename.csv | cut -d, -f 2 | sort | uniq | wc -l
# Count occurences of unique values, limiting to first 10 results
cat filename.csv | cut -d, -f 2 | sort | uniq -c | head
```
### PASTE
Paste is a niche command with an interesting function. If you have two files that you need merged, and they are already sorted, `paste` has you covered.
```
# names.txt
adam
john
zach
# jobs.txt
lawyer
youtuber
developer
# Join the two into a CSV
paste -d ',' names.txt jobs.txt > person_data.txt
# Output
adam,lawyer
john,youtuber
zach,developer
```
For a more SQL_-esque variant, see below.
### JOIN
Join is a simplistic, quasi-tangential, SQL. The largest differences being that `join` will return all columns and matches can only be on one field. By default, `join` will try and use the first column as the match key. For a different result, the following syntax is necessary:
```
# Join the first file (-1) by the second column
# and the second file (-2) by the first
join -t"," -1 2 -2 1 first_file.txt second_file.txt
```
The standard join is an inner join. However, an outer join is also viable through the `-a` flag. Another noteworthy quirk is the `-e` flag, which can be used to substitute a value if a missing field is found.
```
# Outer join, replace blanks with NULL in columns 1 and 2
# -o which fields to substitute - 0 is key, 1.1 is first column, etc...
join -t"," -1 2 -a 1 -a2 -e ' NULL' -o '0,1.1,2.2' first_file.txt second_file.txt
```
Not the most user-friendly command, but desperate times, desperate measures.
* Useful options:
* `join -a` print unpairable lines
* `join -e` replace missing input fields
* `join -j` equivalent to `-1 FIELD -2 FIELD`
### GREP
Global search for a regular expression and print, or `grep`; likely, the most well known command, and with good reason. Grep has a lot of power, especially for finding your way around large codebases. Within the realm of data science, it acts as a refining mechanism for other commands. Although its standard usage is valuable as well.
```
# Recursively search and list all files in directory containing 'word'
grep -lr 'word' .
# List number of files containing word
grep -lr 'word' . | wc -l
```
Count total number of lines containing word / pattern.
```
grep -c 'some_value' filename.csv
# Same thing, but in all files in current directory by file name
grep -c 'some_value' *
```
Grep for multiple values using the or operator - `\|`.
```
grep "first_value\|second_value" filename.csv
```
* Useful options
* `alias grep="grep --color=auto"` make grep colorful
* `grep -E` use extended regexps
* `grep -w` only match whole words
* `grep -l` print name of files with match
* `grep -v` inverted matching
### THE BIG GUNS
Sed and Awk are the two most powerful commands in this article. For brevity, Im not going to go into exhausting detail about either. Instead, I will cover a variety of commands that prove their impressive might. If you want to know more, [there is a book][5] just for that.
### SED
At its core `sed` is a stream editor. It excels at substitutions, but can also be leveraged for all out refactoring.
The most basic `sed` command consists of `s/old/new/g`. This translates to search for old value, replace with new globally. Without the `/g` our command would terminate after the first occurrence.
To get a quick taste of the power lets dive into an example. In this scenario youve been given the following file:
```
balance,name
$1,000,john
$2,000,jack
```
The first thing we may want to do is remove the dollar signs. The `-i` flag indicates in-place. The `''` is to indicate a zero-length file extension, thus overwriting our initial file. Ideally, you would test each of these individually and then output to a new file.
```
sed -i '' 's/\$//g' data.txt
# balance,name
# 1,000,john
# 2,000,jack
```
Next up, the commas in our `balance` column values.
```
sed -i '' 's/\([0-9]\),\([0-9]\)/\1\2/g' data.txt
# balance,name
# 1000,john
# 2000,jack
```
Lastly, Jack up and decided to quit one day. So, au revoir, mon ami.
```
sed -i '' '/jack/d' data.txt
# balance,name
# 1000,john
```
As you can see, `sed` packs quite a punch, but the fun doesnt stop there.
### AWK
The best for last. Awk is much more than a simple command: it is a full-blown language. Of everything covered in this article, `awk` is by far the coolest. If you find yourself impressed there are loads of great resources - see [here][6], [here][7] and [here][8].
Common use cases for `awk` include:
* Text processing
* Formatted text reports
* Performing arithmetic operations
* Performing string operations
Awk can parallel `grep` in its most nascent form.
```
awk '/word/' filename.csv
```
Or with a little more magic the combination of `grep` and `cut`. Here, `awk` prints the third and fourth column, tab separated, for all lines with our word. `-F,` merely changes our delimiter to a comma.
```
awk -F, '/word/ { print $3 "\t" $4 }' filename.csv
```
Awk comes with a lot of nifty variables built-in. For instance, `NF` \- number of fields - and `NR` \- number of records. To get the fifty-third record in a file:
```
awk -F, 'NR == 53' filename.csv
```
An added wrinkle is the ability to filter based off of one or more values. The first example, below, will print the line number and columns for records where the first column equals string.
```
awk -F, ' $1 == "string" { print NR, $0 } ' filename.csv
# Filter based off of numerical value in second column
awk -F, ' $2 == 1000 { print NR, $0 } ' filename.csv
```
Multiple numerical expressions:
```
# Print line number and columns where column three greater
# than 2005 and column five less than one thousand
awk -F, ' $3 >= 2005 && $5 <= 1000 { print NR, $0 } ' filename.csv
```
Sum the third column:
```
awk -F, '{ x+=$3 } END { print x }' filename.csv
```
The sum of the third column, for values where the first column equals “something”.
```
awk -F, '$1 == "something" { x+=$3 } END { print x }' filename.csv
```
Get the dimensions of a file:
```
awk -F, 'END { print NF, NR }' filename.csv
# Prettier version
awk -F, 'BEGIN { print "COLUMNS", "ROWS" }; END { print NF, NR }' filename.csv
```
Print lines appearing twice:
```
awk -F, '++seen[$0] == 2' filename.csv
```
Remove duplicate lines:
```
# Consecutive lines
awk 'a !~ $0; {a=$0}']
# Nonconsecutive lines
awk '! a[$0]++' filename.csv
# More efficient
awk '!($0 in a) {a[$0];print}
```
Substitute multiple values using built-in function `gsub()`.
```
awk '{gsub(/scarlet|ruby|puce/, "red"); print}'
```
This `awk` command will combine multiple CSV files, ignoring the header and then append it at the end.
```
awk 'FNR==1 && NR!=1{next;}{print}' *.csv > final_file.csv
```
Need to downsize a massive file? Welp, `awk` can handle that with help from `sed`. Specifically, this command breaks one big file into multiple smaller ones based on a line count. This one-liner will also add an extension.
```
sed '1d;$d' filename.csv | awk 'NR%NUMBER_OF_LINES==1{x="filename-"++i".csv";}{print > x}'
# Example: splitting big_data.csv into data_(n).csv every 100,000 lines
sed '1d;$d' big_data.csv | awk 'NR%100000==1{x="data_"++i".csv";}{print > x}'
```
### CLOSING
The command line boasts endless power. The commands covered in this article are enough to elevate you from zero to hero in no time. Beyond those covered, there are many utilities to consider for daily data operations. [Csvkit][9], [xsv][10] and [q][11] are three of note. If youre looking to take an even deeper dive into command line data science, then look no further than [this book][12]. Its also available online [for free][13]!
--------------------------------------------------------------------------------
via: http://kadekillary.work/post/cli-4-ds/
作者:[Kade Killary][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]:http://kadekillary.work/authors/kadekillary
[1]:https://en.wikipedia.org/wiki/Brian_Kernighan
[2]:https://en.wikipedia.org/wiki/The_C_Programming_Language
[3]:https://www.amazon.com/Learning-AWK-Programming-cutting-edge-text-processing-ebook/dp/B07BT98HDS
[4]:https://www.youtube.com/watch?v=MijmeoH9LT4
[5]:https://www.amazon.com/sed-awk-Dale-Dougherty/dp/1565922255/ref=sr_1_1?ie=UTF8&qid=1524381457&sr=8-1&keywords=sed+and+awk
[6]:https://www.amazon.com/AWK-Programming-Language-Alfred-Aho/dp/020107981X/ref=sr_1_1?ie=UTF8&qid=1524388936&sr=8-1&keywords=awk
[7]:http://www.grymoire.com/Unix/Awk.html
[8]:https://www.tutorialspoint.com/awk/index.htm
[9]:http://csvkit.readthedocs.io/en/1.0.3/
[10]:https://github.com/BurntSushi/xsv
[11]:https://github.com/harelba/q
[12]:https://www.amazon.com/Data-Science-Command-Line-Time-Tested/dp/1491947853/ref=sr_1_1?ie=UTF8&qid=1524390894&sr=8-1&keywords=data+science+at+the+command+line
[13]:https://www.datascienceatthecommandline.com/

View File

@ -1,3 +1,5 @@
Translating by MjSeven
Users, Groups, and Other Linux Beasts
======

View File

@ -1,228 +0,0 @@
An Introduction to Quantum Computing with Open Source Cirq Framework
======
As the title suggests what we are about to begin discussing, this article is an effort to understand how far we have come in Quantum Computing and where we are headed in the field in order to accelerate scientific and technological research, through an Open Source perspective with Cirq.
First, we will introduce you to the world of Quantum Computing. We will try our best to explain the basic idea behind the same before we look into how Cirq would be playing a significant role in the future of Quantum Computing. Cirq, as you might have heard of recently, has been breaking news in the field and in this Open Science article, we will try to find out why.
<https://www.youtube.com/embed/WVv5OAR4Nik?enablejsapi=1&autoplay=0&cc_load_policy=0&iv_load_policy=1&loop=0&modestbranding=1&rel=0&showinfo=0&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=2&>
Before we start with what Quantum Computing is, it is essential to get to know about the term Quantum, that is, a [subatomic particle][1] referring to the smallest known entity. The word [Quantum][2] is based on the Latin word Quantus, meaning, “how little”, as described in this short video:
<https://www.youtube.com/embed/-pUOxVsxu3o?enablejsapi=1&autoplay=0&cc_load_policy=0&iv_load_policy=1&loop=0&modestbranding=1&rel=0&showinfo=0&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=2&>
It will be easier for us to understand Quantum Computing by comparing it first to Classical Computing. Classical Computing refers to how todays conventional computers are designed to work. The device with which you are reading this article right now, can also be referred to as a Classical Computing Device.
### Classical Computing
Classical Computing is just another way to describe how a conventional computer works. They work via a binary system, i.e, information is stored using either 1 or 0. Our Classical computers cannot understand any other form.
In literal terms inside the computer, a transistor can be either on (1) or off (0). Whatever information we provide input to, is translated into 0s and 1s, so that the computer can understand and store that information. Everything is represented only with the help of a combination of 0s and 1s.
<https://www.youtube.com/embed/Xpk67YzOn5w?enablejsapi=1&autoplay=0&cc_load_policy=0&iv_load_policy=1&loop=0&modestbranding=1&rel=0&showinfo=0&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=2&>
### Quantum Computing
Quantum Computing, on the other hand, does not follow an “on or off” model like Classical Computing. Instead, it can simultaneously handle multiple states of information with help of two phenomena called [superimposition and entanglement][3], thus accelerating computing at a much faster rate and also facilitating greater productivity in information storage.
Please note that superposition and entanglement are [not the same phenomena][4].
<https://www.youtube.com/embed/jiXuVIEg10Q?enablejsapi=1&autoplay=0&cc_load_policy=0&iv_load_policy=1&loop=0&modestbranding=1&rel=0&showinfo=0&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=2&>
![][5]
So, if we have bits in Classical Computing, then in the case of Quantum Computing, we would have qubits (or Quantum bits) instead. To know more about the vast difference between the two, check this [page][6] from where the above pic was obtained for explanation.
Quantum Computers are not going to replace our Classical Computers. But, there are certain humongous tasks that our Classical Computers will never be able to accomplish and that is when Quantum Computers would prove extremely resourceful. The following video describes the same in detail while also describing how Quantum Computers work:
<https://www.youtube.com/embed/JhHMJCUmq28?enablejsapi=1&autoplay=0&cc_load_policy=0&iv_load_policy=1&loop=0&modestbranding=1&rel=0&showinfo=0&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=2&>
A comprehensive video on the progress in Quantum Computing so far:
<https://www.youtube.com/embed/CeuIop_j2bI?enablejsapi=1&autoplay=0&cc_load_policy=0&iv_load_policy=1&loop=0&modestbranding=1&rel=0&showinfo=0&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=2&>
### Noisy Intermediate Scale Quantum
According to the very recently updated research paper (31st July 2018), the term “Noisy” refers to inaccuracy because of producing an incorrect value caused by imperfect control over qubits. This inaccuracy is why there will be serious limitations on what Quantum devices can achieve in the near term.
“Intermediate Scale” refers to the size of Quantum Computers which will be available in the next few years, where the number of qubits can range from 50 to a few hundred. 50 qubits is a significant milestone because thats beyond what can be simulated by [brute force][7] using the most powerful existing digital [supercomputers][8]. Read more in the paper [here][9].
With the advent of Cirq, a lot is about to change.
### What is Cirq?
Cirq is a python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits that we just talked about. In other words, Cirq can address challenges to improve accuracy and reduce noise in Quantum Computing.
Cirq does not necessarily require an actual Quantum Computer for execution. Cirq can also use a simulator-like interface to perform Quantum circuit simulations.
Cirq is gradually grabbing a lot of pace, with one of its first users being [Zapata][10], formed last year by a [group of scientists][11] from Harvard University focused on Quantum Computing.
### Getting started with Cirq on Linux
The developers of the Open Source [Cirq library][12] recommend the installation in a [virtual python environment][13] like [virtualenv][14]. The developers installation guide for Linux can be found [here][15].
However, we successfully installed and tested Cirq directly for Python3 on an Ubuntu 16.04 system via the following steps:
#### Installing Cirq on Ubuntu
![Cirq Framework for Quantum Computing in Linux][16]
First, we would require pip or pip3 to install Cirq. [Pip][17] is a tool recommended for installing and managing Python packages.
For Python 3.x versions, Pip can be installed with:
```
sudo apt-get install python3-pip
```
Python3 packages can be installed via:
```
pip3 install <package-name>
```
We went ahead and installed the Cirq library with Pip3 for Python3:
```
pip3 install cirq
```
#### Enabling Plot and PDF generation (optional)
Optional system dependencies not install-able with pip can be installed with:
```
sudo apt-get install python3-tk texlive-latex-base latexmk
```
* python3-tk is Pythons own graphic library which enables plotting functionality.
* texlive-latex-base and latexmk enable PDF writing functionality.
Later, we successfully tested Cirq with the following command and code:
```
python3 -c 'import cirq; print(cirq.google.Foxtail)'
```
We got the resulting output as:
![][18]
#### Configuring Pycharm IDE for Cirq
We also configured a Python IDE [PyCharm on Ubuntu][19] to test the same results:
Since we installed Cirq for Python3 on our Linux system, we set the path to the project interpreter in the IDE settings to be:
```
/usr/bin/python3
```
![][20]
In the output above, you can note that the path to the project interpreter that we just set, is shown along with the path to the test program file (test.py). An exit code of 0 shows that the program has finished executing successfully without errors.
So, thats a ready-to-use IDE environment where you can import the Cirq library to start programming with Python and simulate Quantum circuits.
#### Get started with Cirq
A good place to start are the [examples][21] that have been made available on Cirqs Github page.
The developers have included this [tutorial][22] on GitHub to get started with learning Cirq. If you are serious about learning Quantum Computing, they recommend an excellent book called [“Quantum Computation and Quantum Information” by Nielsen and Chuang][23].
#### OpenFermion-Cirq
[OpenFermion][24] is an open source library for obtaining and manipulating representations of fermionic systems (including Quantum Chemistry) for simulation on Quantum Computers. Fermionic systems are related to the generation of [fermions][25], which according to [particle physics][26], follow [Fermi-Dirac statistics][27].
OpenFermion has been hailed as [a great practice tool][28] for chemists and researchers involved with [Quantum Chemistry][29]. The main focus of Quantum Chemistry is the application of [Quantum Mechanics][30] in physical models and experiments of chemical systems. Quantum Chemistry is also referred to as [Molecular Quantum Mechanics][31].
The advent of Cirq has now made it possible for OpenFermion to extend its functionality by providing routines and tools for using Cirq to compile and compose circuits for Quantum simulation algorithms.
#### Google Bristlecone
On March 5, 2018, Google presented [Bristlecone][32], their new Quantum processor, at the annual [American Physical Society meeting][33] in Los Angeles. The [gate-based superconducting system][34] provides a test platform for research into [system error rates][35] and [scalability][36] of Googles [qubit technology][37], along-with applications in Quantum [simulation][38], [optimization][39], and [machine learning.][40]
In the near future, Google wants to make its 72 qubit Bristlecone Quantum processor [cloud accessible][41]. Bristlecone will gradually become quite capable to perform a task that a Classical Supercomputer would not be able to complete in a reasonable amount of time.
Cirq would make it easier for researchers to directly write programs for Bristlecone on the cloud, serving as a very convenient interface for real-time Quantum programming and testing.
Cirq will allow us to:
* Fine tune control over Quantum circuits,
* Specify [gate][42] behavior using native gates,
* Place gates appropriately on the device &
* Schedule the timing of these gates.
### The Open Science Perspective on Cirq
As we all know Cirq is Open Source on GitHub, its addition to the Open Source Scientific Communities, especially those which are focused on Quantum Research, can now efficiently collaborate to solve the current challenges in Quantum Computing today by developing new ways to reduce error rates and improve accuracy in the existing Quantum models.
Had Cirq not followed an Open Source model, things would have definitely been a lot more challenging. A great initiative would have been missed out and we would not have been one step closer in the field of Quantum Computing.
### Summary
To summarize in the end, we first introduced you to the concept of Quantum Computing by comparing it to existing Classical Computing techniques followed by a very important video on recent developmental updates in Quantum Computing since last year. We then briefly discussed Noisy Intermediate Scale Quantum, which is what Cirq is specifically built for.
We saw how we can install and test Cirq on an Ubuntu system. We also tested the installation for usability on an IDE environment with some resources to get started to learn the concept.
Finally, we also saw two examples of how Cirq would be an essential advantage in the development of research in Quantum Computing, namely OpenFermion and Bristlecone. We concluded the discussion by highlighting some thoughts on Cirq with an Open Science Perspective.
We hope we were able to introduce you to Quantum Computing with Cirq in an easy to understand manner. If you have any feedback related to the same, please let us know in the comments section. Thank you for reading and we look forward to see you in our next Open Science article.
--------------------------------------------------------------------------------
via: https://itsfoss.com/qunatum-computing-cirq-framework/
作者:[Avimanyu Bandyopadhyay][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/avimanyu/
[1]:https://en.wikipedia.org/wiki/Subatomic_particle
[2]:https://en.wikipedia.org/wiki/Quantum
[3]:https://www.clerro.com/guide/491/quantum-superposition-and-entanglement-explained
[4]:https://physics.stackexchange.com/questions/148131/can-quantum-entanglement-and-quantum-superposition-be-considered-the-same-phenom
[5]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/bit-vs-qubit.jpg
[6]:http://www.rfwireless-world.com/Terminology/Difference-between-Bit-and-Qubit.html
[7]:https://en.wikipedia.org/wiki/Proof_by_exhaustion
[8]:https://www.explainthatstuff.com/how-supercomputers-work.html
[9]:https://arxiv.org/abs/1801.00862
[10]:https://www.xconomy.com/san-francisco/2018/07/19/google-partners-with-zapata-on-open-source-quantum-computing-effort/
[11]:https://www.zapatacomputing.com/about/
[12]:https://github.com/quantumlib/Cirq
[13]:https://itsfoss.com/python-setup-linux/
[14]:https://virtualenv.pypa.io
[15]:https://cirq.readthedocs.io/en/latest/install.html#installing-on-linux
[16]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/cirq-framework-linux.jpeg
[17]:https://pypi.org/project/pip/
[18]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/cirq-test-output.jpg
[19]:https://itsfoss.com/install-pycharm-ubuntu/
[20]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/cirq-tested-on-pycharm.jpg
[21]:https://github.com/quantumlib/Cirq/tree/master/examples
[22]:https://github.com/quantumlib/Cirq/blob/master/docs/tutorial.md
[23]:http://mmrc.amss.cas.cn/tlb/201702/W020170224608149940643.pdf
[24]:http://openfermion.org
[25]:https://en.wikipedia.org/wiki/Fermion
[26]:https://en.wikipedia.org/wiki/Particle_physics
[27]:https://en.wikipedia.org/wiki/Fermi-Dirac_statistics
[28]:https://phys.org/news/2018-03-openfermion-tool-quantum-coding.html
[29]:https://en.wikipedia.org/wiki/Quantum_chemistry
[30]:https://en.wikipedia.org/wiki/Quantum_mechanics
[31]:https://ocw.mit.edu/courses/chemical-engineering/10-675j-computational-quantum-mechanics-of-molecular-and-extended-systems-fall-2004/lecture-notes/
[32]:https://techcrunch.com/2018/03/05/googles-new-bristlecone-processor-brings-it-one-step-closer-to-quantum-supremacy/
[33]:http://meetings.aps.org/Meeting/MAR18/Content/3475
[34]:https://en.wikipedia.org/wiki/Superconducting_quantum_computing
[35]:https://en.wikipedia.org/wiki/Quantum_error_correction
[36]:https://en.wikipedia.org/wiki/Scalability
[37]:https://research.googleblog.com/2015/03/a-step-closer-to-quantum-computation.html
[38]:https://research.googleblog.com/2017/10/announcing-openfermion-open-source.html
[39]:https://research.googleblog.com/2016/06/quantum-annealing-with-digital-twist.html
[40]:https://arxiv.org/abs/1802.06002
[41]:https://www.computerworld.com.au/article/644051/google-launches-quantum-framework-cirq-plans-bristlecone-cloud-move/
[42]:https://en.wikipedia.org/wiki/Logic_gate

View File

@ -1,62 +0,0 @@
Know Your Storage: Block, File & Object
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/block2_1920.jpg?itok=s1y6RLhT)
Dealing with the tremendous amount of data generated today presents a big challenge for companies who create or consume such data. Its a challenge for tech companies that are dealing with related storage issues.
“Data is growing exponentially each year, and we find that the majority of data growth is due to increased consumption and industries adopting transformational projects to expand value. Certainly, the Internet of Things (IoT) has contributed greatly to data growth, but the key challenge for software-defined storage is how to address the use cases associated with data growth,” said Michael St. Jean, principal product marketing manager, Red Hat Storage.
Every challenge is an opportunity. “The deluge of data being generated by old and new sources today is certainly presenting us with opportunities to meet our customers escalating needs in the areas of scale, performance, resiliency, and governance,” said Tad Brockway, General Manager for Azure Storage, Media and Edge.
### Trinity of modern software-defined storage
There are three different kinds of storage solutions -- block, file, and object -- each serving a different purpose while working with the others.
Block storage is the oldest form of data storage, where data is stored in fixed-length blocks or chunks of data. Block storage is used in enterprise storage environments and usually is accessed using Fibre Channel or iSCSI interface. “Block storage requires an application to map where the data is stored on the storage device,” according to SUSEs Larry Morris, Sr. Product Manager, Software Defined Storage.
Block storage is virtualized in storage area network and software defined storage systems, which are abstracted logical devices that reside on a shared hardware infrastructure and are created and presented to the host operating system of a server, virtual server, or hypervisor via protocols like SCSI, SATA, SAS, FCP, FCoE, or iSCSI.
“Block storage splits a single storage volume (like a virtual or cloud storage node, or a good old fashioned hard disk) into individual instances known as blocks,” said St. Jean.
Each block exists independently and can be formatted with its own data transfer protocol and operating system — giving users complete configuration autonomy. Because block storage systems arent burdened with the same investigative file-finding duties as the file storage systems, block storage is a faster storage system. Pairing that speed with configuration flexibility makes block storage ideal for raw server storage or rich media databases.
Block storage can be used to host operating systems, applications, databases, entire virtual machines and containers. Traditionally, block storage can only be accessed by individual machine, or machines in a cluster, to which it has been presented.
### File-based storage
File-based storage uses a filesystem to map where the data is stored on the storage device. Its a dominant technology used on direct- and networked-attached storage system, and it takes care of two things: organizing data and representing it to users. “With file storage, data is arranged on the server side in the exact same format as the clients see it. This allows the user to request a file by some unique identifier — like a name, location, or URL — which is communicated to the storage system using specific data transfer protocols,” said St. Jean.
The result is a type of hierarchical file structure that can be navigated from top to bottom. File storage is layered on top of block storage, allowing users to see and access data as files and folders, but restricting access to the blocks that stand up those files and folders.
“File storage is typically represented by shared filesystems like NFS and CIFS/SMB that can be accessed by many servers over an IP network. Access can be controlled at a file, directory, and export level via user and group permissions. File storage can be used to store files needed by multiple users and machines, application binaries, databases, virtual machines, and can be used by containers,” explained Brockway.
### Object storage
Object storage is the newest form of data storage, and it provides a repository for unstructured data which separates the content from the indexing and allows the concatenation of multiple files into an object. An object is a piece of data paired with any associated metadata that provides context about the bytes contained within the object (things like how old or big the data is). Those two things together — the data and metadata — make an object.
One advantage of object storage is the unique identifier associated with each piece of data. Accessing the data involves using the unique identifier and does not require the application or user to know where the data is actually stored. Object data is accessed through APIs.
“The data stored in objects is uncompressed and unencrypted, and the objects themselves are arranged in object stores (a central repository filled with many other objects) or containers (a package that contains all of the files an application needs to run). Objects, object stores, and containers are very flat in nature — compared to the hierarchical structure of file storage systems — which allow them to be accessed very quickly at huge scale,” explained St. Jean.
Object stores can scale to many petabytes to accommodate the largest datasets and are a great choice for images, audio, video, logs, backups, and data used by analytics services.
### Conclusion
Now you know about the various types of storage and how they are used. Stay tuned to learn more about software-defined storage as we examine the topic in the future.
Join us at [Open Source Summit + Embedded Linux Conference Europe][1] in Edinburgh, UK on October 22-24, 2018, for 100+ sessions on Linux, Cloud, Containers, AI, Community, and more.
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/2018/9/know-your-storage-block-file-object
作者:[Swapnil Bhartiya][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/arnieswap
[1]: https://events.linuxfoundation.org/events/elc-openiot-europe-2018/

View File

@ -0,0 +1,291 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Manage NTP with Chrony)
[#]: via: (https://opensource.com/article/18/12/manage-ntp-chrony)
[#]: author: (David Both https://opensource.com/users/dboth)
Manage NTP with Chrony
======
Chronyd is a better choice for most networks than ntpd for keeping computers synchronized with the Network Time Protocol.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/clocks_time.png?itok=_ID09GDk)
> "Does anybody really know what time it is? Does anybody really care?"
> [Chicago][1], 1969
Perhaps that rock group didn't care what time it was, but our computers do need to know the exact time. Timekeeping is very important to computer networks. In banking, stock markets, and other financial businesses, transactions must be maintained in the proper order, and exact time sequences are critical for that. For sysadmins and DevOps professionals, it's easier to follow the trail of email through a series of servers or to determine the exact sequence of events using log files on geographically dispersed hosts when exact times are kept on the computers in question.
I used to work at an organization that received over 20 million emails per day and had four servers just to accept and do a basic filter on the incoming flood of email. From there, emails were sent to one of four other servers to perform more complex anti-spam assessments, then they were delivered to one of several additional servers where the emails were placed in the correct inboxes. At each layer, the emails would be sent to one of the next-level servers, selected only by the randomness of round-robin DNS. Sometimes we had to trace a new message through the system until we could determine where it "got lost," according to the pointy-haired bosses. We had to do this with frightening regularity.
Most of that email turned out to be spam. Some people actually complained that their [joke, cat pic, recipe, inspirational saying, or other-strange-email]-of-the-day was missing and asked us to find it. We did reject those opportunities.
Our email and other transactional searches were aided by log entries with timestamps that—today—can resolve down to the nanosecond in even the slowest of modern Linux computers. In very high-volume transaction environments, even a few microseconds of difference in the system clocks can mean sorting thousands of transactions to find the correct one(s).
### The NTP server hierarchy
Computers worldwide use the [Network Time Protocol][2] (NTP) to synchronize their times with internet standard reference clocks via a hierarchy of NTP servers. The primary servers are at stratum 1, and they are connected directly to various national time services at stratum 0 via satellite, radio, or even modems over phone lines. The time service at stratum 0 may be an atomic clock, a radio receiver tuned to the signals broadcast by an atomic clock, or a GPS receiver using the highly accurate clock signals broadcast by GPS satellites.
To prevent time requests from time servers lower in the hierarchy (i.e., with a higher stratum number) from overwhelming the primary reference servers, there are several thousand public NTP stratum 2 servers that are open and available for anyone to use. Many organizations with large numbers of hosts that need an NTP server will set up their own time servers so that only one local host accesses the stratum 2 time servers, then they configure the remaining network hosts to use the local time server which, in my case, is a stratum 3 server.
### NTP choices
The original NTP daemon, **ntpd** , has been joined by a newer one, **chronyd**. Both keep the local host's time synchronized with the time server. Both services are available, and I have seen nothing to indicate that this will change anytime soon.
Chrony has features that make it the better choice for most environments for the following reasons:
* Chrony can synchronize to the time server much faster than NTP. This is good for laptops or desktops that don't run constantly.
* It can compensate for fluctuating clock frequencies, such as when a host hibernates or enters sleep mode, or when the clock speed varies due to frequency stepping that slows clock speeds when loads are low.
* It handles intermittent network connections and bandwidth saturation.
* It adjusts for network delays and latency.
* After the initial time sync, Chrony never steps the clock. This ensures stable and consistent time intervals for system services and applications.
* Chrony can work even without a network connection. In this case, the local host or server can be updated manually.
The NTP and Chrony RPM packages are available from standard Fedora repositories. You can install both and switch between them, but modern Fedora, CentOS, and RHEL releases have moved from NTP to Chrony as their default time-keeping implementation. I have found that Chrony works well, provides a better interface for the sysadmin, presents much more information, and increases control.
Just to make it clear, NTP is a protocol that is implemented with either NTP or Chrony. If you'd like to know more, read this [comparison between NTP and Chrony][3] as implementations of the NTP protocol.
This article explains how to configure Chrony clients and servers on a Fedora host, but the configuration for CentOS and RHEL current releases works the same.
### Chrony structure
The Chrony daemon, **chronyd** , runs in the background and monitors the time and status of the time server specified in the **chrony.conf** file. If the local time needs to be adjusted, **chronyd** does it smoothly without the programmatic trauma that would occur if the clock were instantly reset to a new time.
Chrony's **chronyc** tool allows someone to monitor the current status of Chrony and make changes if necessary. The **chronyc** utility can be used as a command that accepts subcommands, or it can be used as an interactive text-mode program. This article will explain both uses.
### Client configuration
The NTP client configuration is simple and requires little or no intervention. The NTP server can be defined during the Linux installation or provided by the DHCP server at boot time. The default **/etc/chrony.conf** file (shown below in its entirety) requires no intervention to work properly as a client. For Fedora, Chrony uses the Fedora NTP pool, and CentOS and RHEL have their own NTP server pools. Like many Red Hat-based distributions, the configuration file is well commented.
```
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
pool 2.fedora.pool.ntp.org iburst
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3
# Enable kernel synchronization of the real-time clock (RTC).
# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *
# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2
# Allow NTP client access from local network.
#allow 192.168.0.0/16
# Serve time even if not synchronized to a time source.
#local stratum 10
# Specify file containing keys for NTP authentication.
keyfile /etc/chrony.keys
# Get TAI-UTC offset and leap seconds from the system tz database.
leapsectz right/UTC
# Specify directory for log files.
logdir /var/log/chrony
# Select which information is logged.
#log measurements statistics tracking
```
Let's look at the current status of NTP on a virtual machine I use for testing. The **chronyc** command, when used with the **tracking** subcommand, provides statistics that report how far off the local system is from the reference server.
```
[root@studentvm1 ~]# chronyc tracking
Reference ID    : 23ABED4D (ec2-35-171-237-77.compute-1.amazonaws.com)
Stratum         : 3
Ref time (UTC)  : Fri Nov 16 16:21:30 2018
System time     : 0.000645622 seconds slow of NTP time
Last offset     : -0.000308577 seconds
RMS offset      : 0.000786140 seconds
Frequency       : 0.147 ppm slow
Residual freq   : -0.073 ppm
Skew            : 0.062 ppm
Root delay      : 0.041452706 seconds
Root dispersion : 0.022665167 seconds
Update interval : 1044.2 seconds
Leap status     : Normal
[root@studentvm1 ~]#
```
The Reference ID in the first line of the result is the server the host is synchronized to—in this case, a stratum 3 reference server that was last contacted by the host at 16:21:30 2018. The other lines are described in the [chronyc(1) man page][4].
The **sources** subcommand is also useful because it provides information about the time source configured in **chrony.conf**.
```
[root@studentvm1 ~]# chronyc sources
210 Number of sources = 5
MS Name/IP address         Stratum Poll Reach LastRx Last sample              
===============================================================================
^+ 192.168.0.51                  3   6   377     0  -2613us[-2613us] +/-   63ms
^+ dev.smatwebdesign.com         3  10   377   28m  -2961us[-3534us] +/-  113ms
^+ propjet.latt.net              2  10   377   465  -1097us[-1085us] +/-   77ms
^* ec2-35-171-237-77.comput>     2  10   377    83  +2388us[+2395us] +/-   95ms
^+ PBX.cytranet.net              3  10   377   507  -1602us[-1589us] +/-   96ms
[root@studentvm1 ~]#
```
The first source in the list is the time server I set up for my personal network. The others were provided by the pool. Even though my NTP server doesn't appear in the Chrony configuration file above, my DHCP server provides its IP address for the NTP server. The "S" column—Source State—indicates with an asterisk ( ***** ) the server our host is synced to. This is consistent with the data from the **tracking** subcommand.
The **-v** option provides a nice description of the fields in this output.
```
[root@studentvm1 ~]# chronyc sources -v
210 Number of sources = 5
  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample              
===============================================================================
^+ 192.168.0.51                  3   7   377    28  -2156us[-2156us] +/-   63ms
^+ triton.ellipse.net            2  10   377    24  +5716us[+5716us] +/-   62ms
^+ lithium.constant.com          2  10   377   351   -820us[ -820us] +/-   64ms
^* t2.time.bf1.yahoo.com         2  10   377   453   -992us[ -965us] +/-   46ms
^- ntp.idealab.com               2  10   377   799  +3653us[+3674us] +/-   87ms
[root@studentvm1 ~]#
```
If I wanted my server to be the preferred reference time source for this host, I would add the line below to the **/etc/chrony.conf** file.
```
server 192.168.0.51 iburst prefer
```
I usually place this line just above the first pool server statement near the top of the file. There is no special reason for this, except I like to keep the server statements together. It would work just as well at the bottom of the file, and I have done that on several hosts. This configuration file is not sequence-sensitive.
The **prefer** option marks this as the preferred reference source. As such, this host will always be synchronized with this reference source (as long as it is available). We can also use the fully qualified hostname for a remote reference server or the hostname only (without the domain name) for a local reference time source as long as the search statement is set in the **/etc/resolv.conf** file. I prefer the IP address to ensure that the time source is accessible even if DNS is not working. In most environments, the server name is probably the better option, because NTP will continue to work even if the server's IP address changes.
If you don't have a specific reference source you want to synchronize to, it is fine to use the defaults.
### Configuring an NTP server with Chrony
The nice thing about the Chrony configuration file is that this single file configures the host as both a client and a server. To add a server function to our host—it will always be a client, obtaining its time from a reference server—we just need to make a couple of changes to the Chrony configuration, then configure the host's firewall to accept NTP requests.
Open the **/etc/ ** **chrony****.conf** file in your favorite text editor and uncomment the **local stratum 10** line. This enables the Chrony NTP server to continue to act as if it were connected to a remote reference server if the internet connection fails; this enables the host to continue to be an NTP server to other hosts on the local network.
Let's restart **chronyd** and track how the service is working for a few minutes. Before we enable our host as an NTP server, we want to test a bit.
```
[root@studentvm1 ~]# systemctl restart chronyd ; watch chronyc tracking
```
The results should look like this. The **watch** command runs the **chronyc tracking** command every two seconds so we can watch changes occur over time.
```
Every 2.0s: chronyc tracking                                           studentvm1: Fri Nov 16 20:59:31 2018
Reference ID    : C0A80033 (192.168.0.51)
Stratum         : 4
Ref time (UTC)  : Sat Nov 17 01:58:51 2018
System time     : 0.001598277 seconds fast of NTP time
Last offset     : +0.001791533 seconds
RMS offset      : 0.001791533 seconds
Frequency       : 0.546 ppm slow
Residual freq   : -0.175 ppm
Skew            : 0.168 ppm
Root delay      : 0.094823152 seconds
Root dispersion : 0.021242738 seconds
Update interval : 65.0 seconds
Leap status     : Normal
```
Notice that my NTP server, the **studentvm1** host, synchronizes to the host at 192.168.0.51, which is my internal network NTP server, at stratum 4. Synchronizing directly to the Fedora pool machines would result in synchronization at stratum 3. Notice also that the amount of error decreases over time. Eventually, it should stabilize with a tiny variation around a fairly small range of error. The size of the error depends upon the stratum and other network factors. After a few minutes, use Ctrl+C to break out of the watch loop.
To turn our host into an NTP server, we need to allow it to listen on the local network. Uncomment the following line to allow hosts on the local network to access our NTP server.
```
# Allow NTP client access from local network.
allow 192.168.0.0/16
```
Note that the server can listen for requests on any local network it's attached to. The IP address in the "allow" line is just intended for illustrative purposes. Be sure to change the IP network and subnet mask in that line to match your local network's.
Restart **chronyd**.
```
[root@studentvm1 ~]# systemctl restart chronyd
```
To allow other hosts on your network to access this server, configure the firewall to allow inbound UDP packets on port 123. Check your firewall's documentation to find out how to do that.
### Testing
Your host is now an NTP server. You can test it with another host or a VM that has access to the network on which the NTP server is listening. Configure the client to use the new NTP server as the preferred server in the **/etc/chrony.conf** file, then monitor that client using the **chronyc** tools we used above.
### Chronyc as an interactive tool
As I mentioned earlier, **chronyc** can be used as an interactive command tool. Simply run the command without a subcommand and you get a **chronyc** command prompt.
```
[root@studentvm1 ~]# chronyc
chrony version 3.4
Copyright (C) 1997-2003, 2007, 2009-2018 Richard P. Curnow and others
chrony comes with ABSOLUTELY NO WARRANTY.  This is free software, and
you are welcome to redistribute it under certain conditions.  See the
GNU General Public License version 2 for details.
chronyc>
```
You can enter just the subcommands at this prompt. Try using the **tracking** , **ntpdata** , and **sources** commands. The **chronyc** command line allows command recall and editing for **chronyc** subcommands. You can use the **help** subcommand to get a list of possible commands and their syntax.
### Conclusion
Chrony is a powerful tool for synchronizing the times of client hosts, whether they are all on the local network or scattered around the globe. It's easy to configure because, despite the large number of options available, only a few configurations are required for most circumstances.
After my client computers have synchronized with the NTP server, I like to set the system hardware clock from the system (OS) time by using the following command:
```
/sbin/hwclock --systohc
```
This command can be added as a cron job or a script in **cron.daily** to keep the hardware clock synced with the system time.
Chrony and NTP (the service) both use the same configuration, and the files' contents are interchangeable. The man pages for [chronyd][5], [chronyc][4], and [chrony.conf][6] contain an amazing amount of information that can help you get started or learn about esoteric configuration options.
Do you run your own NTP server? Let us know in the comments and be sure to tell us which implementation you are using, NTP or Chrony.
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/manage-ntp-chrony
作者:[David Both][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/dboth
[b]: https://github.com/lujun9972
[1]: https://en.wikipedia.org/wiki/Does_Anybody_Really_Know_What_Time_It_Is%3F
[2]: https://en.wikipedia.org/wiki/Network_Time_Protocol
[3]: https://chrony.tuxfamily.org/comparison.html
[4]: https://linux.die.net/man/1/chronyc
[5]: https://linux.die.net/man/8/chronyd
[6]: https://linux.die.net/man/5/chrony.conf

View File

@ -1,3 +1,5 @@
translating by hopefully2333
Improve login security with challenge-response authentication
======

View File

@ -0,0 +1,191 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (My Google-free Android life)
[#]: via: (https://lushka.al/my-android-setup/)
[#]: author: (Anxhelo Lushka https://lushka.al/)
My Google-free Android life
======
People have been asking me a lot lately about my phone, my Android setup and how I manage to use my smartphone without Google Services. Well, this is a post that aims to address precisely that. I would like to make this article really beginner-friendly so Ill try to go slow, going through things one by one and including screenshots so you can have a better view on how things happen and work like.
At first Ill start with why Google Services are (imo) bad for your device. I could cut it short and guide you to this [post][1] by [Richard Stallman][2], but Im grabbing a few main points from it and adding them here.
* Nonfree software required
* In general, most Google services require running nonfree Javascript code. Nowadays, nothing whatsoever appears if Javascript is disabled, even making a Google account requires running nonfree software (Javascript sent by the site), same thing for logging in.
* Surveillance
* Google quietly combines its ad-tracking profiles with its browsing profiles and stores a huge amount of data on each user.
* Terms of Service
* Google cuts off accounts for users that resell Pixel phones. They lose access to all of their mail and documents stored in Google servers under that account.
* Censorship
* Amazon and Google have cut off domain-fronting, a feature used to enable people in tyrannical countries to reach communication systems that are banned there.
* Google has agreed to perform special censorship of Youtube for the government of Pakistan, deleting views that the state opposes. This will help the illiberal Pakistani state suppress dissent.
* Youtubes “content ID” automatically deletes posted videos in a way copyright law does not require.
These are just a few reasons, but you can read the post by RMS I linked above in which he tries to explain these points in detail. Although it may look like a tinfoil hat reaction to you, all these actions already happen everyday in real life.
### Next on the list, my setup and a tutorial on how I achieved it
I own a **[Xiaomi Redmi Note 5 Pro][3]** smartphone (codename **whyred** ), produced in China by [Xiaomi][4], which I bought for around 185 EUR 4 months ago (from the time of writing this post).
Now you might be thinking, but why did you buy a Chinese brand, they are not reliable. Yes, it is not made from the usuals as you would expect, such as Samsung (which people often associate with Android, which is plain wrong), OnePlus, Nokia etc, but you should know almost every phone is produced in China.
There were a few reasons I chose this phone, first one of course being the price. It is a quite **budget-friendly** device, so most people are able to afford it. Next one would be the specs, which on paper (not only) are pretty decents for the price tag. With a 6 inch screen (Full HD resolution), a **4000 mAh battery** (superb battery life), 4GB of RAM, 64GB of storage, dual back cameras (12MP + 5MP), a front camera with flash (13MP) and a decent efficient Snapdragon 636, it was probably the best choice at that moment.
The issue with it was that it came with [MIUI][5], the Android skin that Xiaomi ships with most of its devices (except the Android One project devices). Yes, it is not that horrible, it has some extra features, but the problems lie deeper within. One of the reasons these devices from Xiaomi are so cheap (afaik they only have 5-10% win margin from sales) is that **they include data mining and ads in the system altogether with MIUI**. In this way, the system apps requires extra unnecessary permissions that mine your data and bombard you with ads, from which Xiaomi earns money.
Funnily enough, the Weather app included wanted access to my contacts and to make calls, why would it need that if it would just show the weather? Another case was with the Recorder app, it also required contacts and internet permissions, probably to send those recordings back to Xiaomi.
To fix this, Id have to format the phone and get rid of MIUI. This has become increasingly difficult with the latest phones in the market.
The concept of formatting a phone is simple, you remove the existing system and install a new one of your preference (Android-only in this case). To do that, you have to have your [bootloader][6] unlocked.
> A bootloader is a computer program that loads an operating system (OS) or runtime environment for the computer after completion of the self-tests. — [Wikipedia][7]
The problem here is that Xiaomi has a specific policy about the bootloader unlocking. A few months ago, the process was like this. You would have to [make a request][8] to Xiaomi to obtain an unlock code for your phone, by giving a valid reason, but this would not always work, as they could just refuse your request without reason and explanation.
Now, that process has changed. Youll have to download a specific software from Xiaomi, called [Mi Unlock][9], install it in your Windows PC, [activate Debugging Settings in Developer Options][10] on your phone, reboot to the bootloader mode (by holding the Volume Down + Power button while the phone is off) and connect the phone to your computer to start a process called “Approval”. This process starts a timer on the Xiaomi servers that will allow you to **unlock the phone only after a period of 15 days** (or a month in some rare cases, totally random) goes by.
![Mi Unlock app][11]
After this period of 15 days has passed, you have to re-connect your phone and do the same procedure as above, then by pressing the Unlock button your bootloader will be unlocked and this will allow you to install other ROM-s (systems). **Careful, make sure to backup your data because unlocking the bootloader deletes everything in the phone**.
The next step would be finding a system ([ROM][12]) that works for your device. I searched through the [XDA Developers Forum][13], which is a place where Android developers and users exchange ideas, apps etc. Fortunately, my phone is quite popular so it had [its own forum category][14]. There, I skimmed through some popular ROM-s for my device and decided to use the [AOSiP ROM][15] (AOSiP standing for Android Open Source illusion Project).
**EDIT** : Someone emailed me to say that my article is exactly what [/e/][16] does and is targeted to. I wanted to say thank you for reaching out but that is not true at all. The reasoning behind my opinion about /e/ can also be found in this [website][17], but Ill list a few of the reasons here.
eelo is a “foundation” that got over 200K € in funding from Kickstarter and IndieGoGo, promising to create a mobile OS and web services that are open and secure and protect your privacy.
1. Their OS is based on LineageOS 14.1 (Android 7.1) with microG and other open source apps with it, which already exists for a long time now and its called [Lineage for microG][18].
2. Instead of building all apps from the source code, they download the APKs from [APKPure][19] and put them in the ROM, without knowing if those APKs contain proprietary code/malware in them.
3. At one point, they were literally just removing the Lineage copyright header from their code and adding theirs.
4. They love to delete negative feedback and censor their users opinions in their Telegram group chat.
In conclusion, I **dont recommend using /e/** ROM-s (at least until now).
Another thing you would likely want to do is have [root access][20] to your phone, to make it truly yours and modify files in the system, such as use a system-wide adblocker etc. To do this, I decided to use [Magisk][21], a godsend app developed by a student to help you gain root access on your device and install what are called [modules][22], basically software.
After downloading the ROM and Magisk, I had to install them on my phone. To do that, I moved the files to my SD card on the phone. Now, to install the system, I had to use something called a [recovery system][23]. The one I use is called [TWRP][24] (standing for TeamWin Recovery Project), a popular solution.
To install the recovery system (sounds hard, I know), I had to [flash][20] the file on the phone. To do that, I connected my phone with the computer (Fedora Linux system) and with something called [ADB Tools][25] I issued a command that overwrites the system recovery with the custom one I had.
> fastboot flash recovery twrp.img
After this was done, I turned off the phone and kept Volume Up + Power button pressed until I saw the TWRP screen show up. That meant I was good to go and it was ready to receive my commands.
![TWRP screen][26]
Next step was to **issue a Wipe command** , necessary when you first install a custom ROM on your phone. As you can see from the image above, the Wipe command clears the Data, Cache and Dalvik (there is also an advanced option that allows us to tick a box to delete the System one too, as we dont need the old one anymore).
This takes a few moments and after that, your phone is basically clean. Now its time to **install the system**. By pressing the Install button on the main screen, we select the zip file we added there before (the ROM file) and swipe the screen to install it. Next, we have to install Magisk, which gives us root access to the device.
**EDIT** : As some more experienced/power Android users might have noticed until now, there is no [GApps][27] (Google Apps) included. This is what we call GApps-less in the Android world, not having those packages installed at all.
Note that one of the downsides of not having Google Services installed is that some of your apps might not work, for example their notifications might take longer to arrive or might not even work at all (this is what happens with Mattermost app for me). This happens because these apps use [Google Cloud Messaging][28] (now called [Firebase][29]) to wake the phone and push notifications to your phone.
You can solve this (partially) by installing and using [microG][30] which provides some features of Google Services but allows for more control on your side. I dont recommend using this because it still helps Google Services and you dont really give up on them, but its a good start if you want to quit Google slowly and not go cold turkey on it.
After successfully installing both, now we reboot the phone and **tada** 🎉, we are in the main screen.
### Next part, installing the apps and configuring everything
This is where things start to get easier. To install the apps, I use [F-Droid][31], an alternative app store that includes **only free and open source apps**. If you need apps that are not available there, you can use [Aurora Store][32], a client to download apps from the Play Store without using your Google account or getting tracked.
F-Droid has what are called repos, a “storehouse” that contains apps you can install. I use the default ones and have added another one from [IzzyOnDroid][33], that contains some more apps not available from the default F-Droid repo and is updated more often.
![My repos][34]
Below you will find a list of the apps I have installed, what they replace and their use.
This is pretty much **my list of the most useful F-Droid apps** I use, but unfortunately these are NOT the only apps I use. The proprietary apps I use (I know, I might sound a hypocrite, but not everything is replaceable, not yet at least) are as below:
* AliExpress
* Boost for Reddit
* Google Camera (coupled with Camera API 2, this app allows me to take wonderful pictures with a 185 EUR phone, its just too impressive)
* Instagram
* MediaBox HD (allows me to stream movies)
* Mi Fit (an app that pairs with my Mi Band 2)
* MyVodafoneAL (the carrier app)
* ProtonMail (email app)
* Shazam Encore (to find those songs you usually listen in coffee shops)
* Snapseed (photo editing app, really simple, powerful and quite good)
* Spotify (music streaming)
* Titanium Backup (to backup my app data, wifi passwords, calls log etc.)
* ViPER4Android FX (music equalizer)
* VSCO (photo editing, never use it really)
* WhatsApp (E2E proprietary messaging app, almost everyone I know has it)
* WiFi Map (mapped hotspots that are available, handy when abroad)
This is pretty much it, all the apps I use on my phone. **The configs are then pretty simple and straightforward and I can give a few tips**.
1. Read and check the permissions of apps carefully, dont click Install mindlessly.
2. Try to use as many open source apps as possible, they both respect your privacy and are free (as in both free beer and freedom).
3. Use a VPN as much as you can, find a reputable one and dont use free ones, otherwise you get to be the product and youll get your data harvested.
4. Dont keep your WiFi/mobile data/location on all the time, it might be a security risk.
5. Try not to rely on fingerprint unlock only, or better yet use only PIN/password/pattern unlock, as biometric data can be cloned and used against you, for example to unlock your phone and steal your data.
And as a bonus for reading far down here, **a screenshot of my home screen** right now.
![Screenshot][35]
--------------------------------------------------------------------------------
via: https://lushka.al/my-android-setup/
作者:[Anxhelo Lushka][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://lushka.al/
[b]: https://github.com/lujun9972
[1]: https://stallman.org/google.html
[2]: https://en.wikipedia.org/wiki/Richard_Stallman
[3]: https://www.gsmarena.com/xiaomi_redmi_note_5_pro-8893.php
[4]: https://en.wikipedia.org/wiki/Xiaomi
[5]: https://en.wikipedia.org/wiki/MIUI
[6]: https://forum.xda-developers.com/wiki/Bootloader
[7]: https://en.wikipedia.org/wiki/Booting
[8]: https://en.miui.com/unlock/
[9]: http://www.miui.com/unlock/apply.php
[10]: https://www.youtube.com/watch?v=7zhEsJlivFA
[11]: https://lushka.al//assets/img/posts/mi-unlock.png
[12]: https://www.xda-developers.com/what-is-custom-rom-android/
[13]: https://forum.xda-developers.com/
[14]: https://forum.xda-developers.com/redmi-note-5-pro
[15]: https://forum.xda-developers.com/redmi-note-5-pro/development/rom-aosip-8-1-t3804473
[16]: https://e.foundation
[17]: https://ewwlo.xyz/evil
[18]: https://lineage.microg.org/
[19]: https://apkpure.com/
[20]: https://lifehacker.com/5789397/the-always-up-to-date-guide-to-rooting-any-android-phone
[21]: https://forum.xda-developers.com/apps/magisk/official-magisk-v7-universal-systemless-t3473445
[22]: https://forum.xda-developers.com/apps/magisk
[23]: http://www.smartmobilephonesolutions.com/content/android-system-recovery
[24]: https://dl.twrp.me/whyred/
[25]: https://developer.android.com/studio/command-line/adb
[26]: https://lushka.al//assets/img/posts/android-twrp.png
[27]: https://opengapps.org/
[28]: https://developers.google.com/cloud-messaging/
[29]: https://firebase.google.com/docs/cloud-messaging/
[30]: https://microg.org/
[31]: https://f-droid.org/
[32]: https://f-droid.org/en/packages/com.dragons.aurora/
[33]: https://android.izzysoft.de/repo
[34]: https://lushka.al//assets/img/posts/android-fdroid-repos.jpg
[35]: https://lushka.al//assets/img/posts/android-screenshot.jpg
[36]: https://creativecommons.org/licenses/by-nc-sa/4.0/

View File

@ -1,75 +0,0 @@
Translating by LazyWolfLin
7 command-line tools for writers | Opensource.com
======
Put away your word processor and start writing from the command line using these open source tools.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/terminal_command_linux_desktop_code.jpg?itok=p5sQ6ODE)
For most people (especially non-techies), the act of writing means tapping out words using LibreOffice Writer or another GUI word processing application. But there are many other options available to help anyone communicate their message in writing, especially for the growing number of writers [embracing plaintext][1].
There's also room in a GUI writer's world for command line tools that can help them write, check their writing, and more—regardless of whether they're banging out an article, blog post, or story; writing a README; or prepping technical documentation.
Here's a look at some command-line tools that any writer will find useful.
### Editors
Yes, you _can_ do actual writing at the command line. I know writers who do their work using editors like [Nano][2], [Vim][3], [Emacs][4], and [Jove][5] in a terminal window. And those editors [aren't the only games in town][6]. Text editors are great because they (at a basic level, anyway) are easy to use and distraction free. They're perfect for tapping out a first draft of anything or even completing a long and complicated writing project.
If you want a more word processor-like experience at the command line, take a look at [WordGrinder][7] . WordGrinder is a bare-bones word processor, but it has more than enough features for writing and publishing your work. It supports basic formatting and styles, and you can export your writing to formats like Markdown, ODT, LaTeX, and HTML.
### Spell checkers
Every writer does (or at least should do) a spelling check on their work at least once. Why? An immutable law of the writing universe states that, no matter how many times you look over your manuscript, a spelling mistake or typo will creep in.
My favorite command-line spelling checker is [GNU Aspell][8], which I previously [looked at][9] in detail. Aspell checks plaintext documents interactively and not only highlights errors but often puts the best correction at the top of its list of suggestions. Aspell also ignores many markup languages while doing its thing.
A much older but still useful alternative is [Ispell][10]. It's a bit slower than Aspell, but both utilities work the same way. As you interact with your text file, Ispell suggests corrections. Ispell also has good support for foreign languages.
### Prose linters
Software developers use [linters][11] to check their code for errors or bugs. There are also linters for prose that check for style and syntax errors; think of them as the _Elements of Style_ for the command line. While any writer can (and probably should) use one, a prose linter is especially useful for team documentation projects that require a consistent voice and style.
[Proselint][12] is a comprehensive tool for checking what you're writing. It looks for jargon, hyperbole, incorrect date and time format, misused terms, and [much more][13]. It's also easy to run and ignores markup in a plaintext file.
[Alex][14] is a simple yet powerful prose linter. Run it against a plaintext document or one formatted with Markdown or HTML. Alex pumps out warnings of "gender favouring, polarising, race related, religion inconsiderate, or other unequal phrasing in text." If you want to give Alex a test drive, there's an [online demo][15].
### Other tools
Sometimes you just can't find the right synonym for a word. But you don't need to grab a "dead tree" thesaurus or go to a dedicated website to perfect your word choice. Just run [Aiksaurus][16] against the word you want to replace, and it does the work for you. This utility's main drawback, though, is that it supports English only.
Even writers with few (if any) technical skills are embracing [Markdown][17] to quickly and easily format their work. Sometimes, though, you need to convert files formatted with Markdown to something else. That's where [Pandoc][18] comes in. You can use it to convert your documents to HTML, Word, LibreOffice Writer, LaTeX, EPUB, and other formats. You can even use Pandoc to produce books and [research papers][19].
Do you have a favorite command-line tool for writing? Share it with the Opensource.com community by leaving a comment.
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/11/command-line-tools-writers
作者:[Scott Nesbitt][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/scottnesbitt
[b]: https://github.com/lujun9972
[1]: https://plaintextproject.online
[2]: https://www.nano-editor.org/
[3]: https://www.vim.org
[4]: https://www.gnu.org/software/emacs/
[5]: https://opensource.com/article/17/1/jove-lightweight-alternative-vim
[6]: https://en.wikipedia.org/wiki/List_of_text_editors#Text_user_interface
[7]: https://cowlark.com/wordgrinder/
[8]: http://aspell.net/
[9]: https://opensource.com/article/18/2/how-check-spelling-linux-command-line-aspell
[10]: https://www.cs.hmc.edu/~geoff/ispell.html
[11]: https://en.wikipedia.org/wiki/Lint_(software)
[12]: http://proselint.com/
[13]: http://proselint.com/checks/
[14]: https://github.com/get-alex/alex
[15]: https://alexjs.com/#demo
[16]: http://aiksaurus.sourceforge.net/
[17]: https://en.wikipedia.org/wiki/Markdown
[18]: https://pandoc.org
[19]: https://opensource.com/article/18/9/pandoc-research-paper

View File

@ -1,113 +0,0 @@
Translating by jlztan
How to swap Ctrl and Caps Lock keys in Linux
======
Linux desktop environments make it easy to set up your keyboard as you want it. Here's how.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/keyboard_numbers_letters_type_game.jpg?itok=fLlWGw1K)
For many people who've been computer users for (let's just say) "quite some time now," the Ctrl and Caps Lock keys have been in the wrong place since shortly after the first PC keyboards rolled off the production line. For me, the correct positioning appears in this image of a vintage 1995 Sun Workstation keyboard. (Forgive me for the blurriness of the image; it was taken with a Minox spy camera in low light.)
If you're interested, you can read about the [history of the Ctrl key location][1]. I'm not going to discuss the various rationales for placing the Ctrl key next to the "a" key versus below the Shift key; I'm not going to comment on the overall uselessness of the Caps Lock key (whoops); and I'm not going to argue with those who advocate using the heel of the hand to activate the Ctrl key, even though it's impossible to do on some laptop keyboards where the keys are inset below the level of the wrist rest (whoops).
Rather, I'm going to assume I'm not the only one who prefers the Ctrl key next to the "a" and describe how to use the wonderful flexibility that comes with Linux to swap the Ctrl and Caps Lock keys on various desktop environments. Note that this kind of advice seems to have a limited shelf life, as tools for tweaking desktop settings change fairly often. But I hope this offers a good place for you to start.
### With GNOME 3
[GNOME 3][2] desktop environment users can use the [Tweaks][3] tool to swap their Caps Lock and Ctrl keys, as you can see below.
![](https://opensource.com/sites/default/files/uploads/tweaks-tool.png)
Here's how to do it:
1. Install the Tweaks tool from your distribution's repositories.
2. Start the Tweaks application.
3. Select "Keyboard & Mouse" from the left-hand menu.
4. Click "Additional Layout Options".
5. Click "Ctrl position" on the window that opens and choose "Swap Ctrl and Caps Lock."
That's it! By the way, you can do lots of cool stuff with the Tweaks tool. For example, I set my right Ctrl key to be a Compose key, which allows me to type all sorts of characters with keyboard shortcuts—such as ç, é, ô, and ñ and with the keystrokes Compose+c+Comma; Compose+e+Right quote; Compose+o+Circumflex; and Compose+n+Tilde.
### With KDE
I don't use [KDE][4], but item 5 in this article about [KDE tweaks that will change your life][5] by my colleague Seth Kenlon will show you how to remap your keys.
### With Xfce
As far as I can tell, the [Xfce][6] desktop environment doesn't have a handy tool for managing these kinds of settings. However, the **ctrl:swapcaps** option to the **setxkbmap** command will help you make these changes. This type of modification has two parts:
1. Figuring out the command's usage;
2. Figuring out where to invoke the command so it is activated as the desktop comes up.
The first part is pretty straightforward: the command is:
```
/usr/bin/setxkbmap -option "ctrl:nocaps"
```
It's worth executing this in a terminal window to make sure the results are what you expect.
Assuming it works, where should you invoke the command? That requires some experimentation; one possibility is in the file **.profile** in the user's home directory. Another option is to add the command to the autostart facility in Xfce (look for "Session and Startup" in the Settings Manager).
Another possibility is to use the same option in the file / **etc/default/keyboard** , which might end up looking like this:
```
# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) manual page.
XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS="ctrl:swapcaps"
BACKSPACE="guess"
```
Note that this kind of change will affect all users, so if you share your computer, be prepared to do some explaining. Also, system updates may overwrite this file, so you'll need to edit it again if your setup stops working. Putting the same information in the file **.keyboard** in the user's home directory might accomplish the same task on the user's behalf.
Finally, note that these kinds of changes require you to restart Xfce (except when running the command on the command line in the terminal window, but that won't stick past the end of the session).
### With LXQt and other desktop environments
I haven't tried [LXQt][7], but if my memory serves from [LXDE][8], I would try the same recipe used above for Xfce. I'd also expect that the Xfce recipe could work for other Linux desktop environments, but, of course, your favorite search engine is always your friend.
### The console
I haven't tried this, as I have very few opportunities to interact with the console (what you see on a server or when your window system doesn't come up properly). The recipes presented above affect the terminal window in the way one would hope, i.e., consistently with other applications.
However, if the file **/etc/default/keyboard** or **~/.keyboard** has already been edited (as described above), the utility **setupcon** is intended to change the console keyboard setup so it functions the same way.** **This [StackExchange article][9], [this other one][10], and [this third one][11] give some ideas on how to effect these changes from both of these files. The third article also talks about using **dumpkeys** and **loadkeys**. It's also worthwhile to read [the setupcon man page][12] — it's short and to the point, and combined with the comments from the StackExchange articles, should be enough to get a solution in place.
Finally, it's worth emphasizing here the point mentioned in the StackExchange articles - configuring the console IS NOT THE SAME as configuring terminal windows; the latter are configured through the desktop manager as described previously.
### When all else fails
The manual pages for **setxkbmap** , **xkeyboard-config** , **keyboard** , **console-setup** , and **setupcon** are all useful references. Or, if you don't like reading manual pages, there's [this great article][13].
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/11/how-swap-ctrl-and-caps-lock-your-keyboard
作者:[Chris Hermansen][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/clhermansen
[b]: https://github.com/lujun9972
[1]: https://en.wikipedia.org/wiki/Control_key
[2]: https://www.gnome.org/gnome-3/
[3]: https://wiki.gnome.org/Apps/Tweaks
[4]: https://www.kde.org/
[5]: https://opensource.com/article/17/5/7-cool-kde-tweaks-will-improve-your-life
[6]: https://www.xfce.org/
[7]: https://lxqt.org/
[8]: https://lxde.org/
[9]: https://askubuntu.com/questions/485454/how-to-remap-keys-on-a-user-level-both-with-and-without-x
[10]: https://unix.stackexchange.com/questions/198791/how-do-i-permanently-change-the-console-tty-font-type-so-it-holds-after-reboot
[11]: https://superuser.com/questions/290115/how-to-change-console-keymap-in-linux
[12]: http://man.he.net/man1/setupcon
[13]: http://www.noah.org/wiki/CapsLock_Remap_Howto

View File

@ -0,0 +1,192 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (The Top Command Tutorial With Examples For Beginners)
[#]: via: (https://www.ostechnix.com/the-top-command-tutorial-with-examples-for-beginners/)
[#]: author: ([SK](https://www.ostechnix.com/author/sk/))
[#]: url: ( )
The Top Command Tutorial With Examples For Beginners
======
![](https://www.ostechnix.com/wp-content/uploads/2018/11/top-command-720x340.png)
As a Linux administrator, you may need to need to know some basic details of your Linux system, such as the currently running processes, average system load, cpu and memory usage etc., at some point. Thankfully, we have a command line utility called **“top”** to get such details. The top command is a well-known and most widely used utility to display dynamic real-time information about running processes in Unix-like operating systems. In this brief tutorial, we are going to see some common use cases of top command.
### Top Command Examples
**Monitor all processes**
To start monitoring the running processes, simply run the top command without any options:
```
$ top
```
Sample output:
![](https://www.ostechnix.com/wp-content/uploads/2018/11/top-command-1.png)
As you see in the above screenshot, top command displays the list of processes in multiple columns. Each column displays details such as pid, user, cpu usage, memory usage. Apart from the list of processes, you will also see the brief stats about average system load, number of tasks, cpu usage, memory usage and swap usage on the top.
Here is the explanation of the parameters mentioned above.
* **PID** Process id of the task.
* **USER** Username of the the tasks owner.
* **PR** Priority of the task.
* **NI** Nice value of the task. If the nice value is negative, the process gets higher priority. If the nice value is positive, the priority is low. Refer [**this guide**][1] to know more about nice.
* **VIRT** Total amount of virtual memory used by the task.
* **RES** Resident Memory Size, the non-swapped physical memory a task is currently using.
* **SHR** Shared Memory Size. The amount of shared memory used by a task.
* **S** The status of the process (S=sleep R=running Z=zombie).
* **%CPU** CPU usage. The tasks share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time.
* **%MEM** Memory Usage. A tasks currently resident share of available physical memory.
* **TIME+** Total CPU time used by the task since it has started, precise to the hundredths of a second.
* **COMMAND** Name of the running program.
**Display path of processes**
If you want to see the absolute path of the running processes, just press **c**. Now you will see the actual path of the programs under the COMMAND column in the below screenshot.
![][3]
**Monitor processes owned by a specific user**
If you run top command without any options, it will list all running processes owned by all users. How about displaying processes owned by a specific user? It is easy! To show the processes owned by a given user, for example **sk** , simply run:
```
$ top -u sk
```
![](https://www.ostechnix.com/wp-content/uploads/2018/11/top-command-3.png)
**Do not show idle/zombie processes**
Instead of viewing all processes, you can simply ignore the idle or zombie processes. The following command will not show any idle or zombie processes:
```
$ top -i
```
**Monitor processes with PID**
If you know the PID of any processes, for example 21180, you can monitor that process using **-p** flag.
```
$ top -p 21180
```
You can specify multiple PIDs with comma-separated values.
**Monitor processes with process name**
I dont know PID, but know only the process name. How to monitor it? Simple!
```
$ top -p $(pgrep -d ',' firefox)
```
Here, **firefox** is the process name and **pgrep -d** picks the respective PID from the process name.
**Display processes by CPU usage**
Sometimes, you might want to display processes sorted by CPU usage. If so, use the following command:
```
$ top -o %CPU
```
![][4]
The processes with higher CPU usage will be displayed on the top. Alternatively, you sort the processes by CPU usage by pressing **SHIFT+p**.
**Display processes by Memory usage**
Similarly, to order processes by memory usage, the command would be:
```
$ top -o %MEM
```
**Renice processes**
You can change the priority of a process at any time using the option **r**. Run the top command and press **r** and type the PID of a process to change its priority.
![][5]
Here, **r** refers renice.
**Set update interval**
Top program has an option to specify the delay between screen updates. If want to change the delay-time, say 5 seconds, run:
```
$ top -d 5
```
The default value is **3.0** seconds.
If you already started the top command, just press **d** and type delay-time and hit ENTER key.
![][6]
**Set number of iterations (repetition)**
By default, top command will keep running until you press **q** to exit. However, you can set the number of iterations after which top will end. For instance, to exit top command automatically after 5 iterations, run:
```
$ top -n 5
```
**Kill running processes**
To kill a running process, simply press **k** and type its PID and hit ENTER key.
![][7]
Top command supports few other options as well. For example, press **z** to switch between mono and color output. It will help you to easily highlight running processes.
![][8]
Press **h** to view all available keyboard shortcuts and help section.
To quit top, just press **q**.
At this stage, you will have a basic understanding of top command. For more details, refer man pages.
```
$ man top
```
As you can see, using Top command to monitor the running processes isnt that hard. Top command is easy to learn and use!
And, thats all for now. More good stuffs to come. Stay tuned!
Cheers!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/the-top-command-tutorial-with-examples-for-beginners/
作者:[SK][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.ostechnix.com/author/sk/
[b]: https://github.com/lujun9972
[1]: https://www.ostechnix.com/change-priority-process-linux/
[2]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
[3]: http://www.ostechnix.com/wp-content/uploads/2018/11/top-command-2.png
[4]: http://www.ostechnix.com/wp-content/uploads/2018/11/top-command-4.png
[5]: http://www.ostechnix.com/wp-content/uploads/2018/11/top-command-8.png
[6]: http://www.ostechnix.com/wp-content/uploads/2018/11/top-command-7.png
[7]: http://www.ostechnix.com/wp-content/uploads/2018/11/top-command-5.png
[8]: http://www.ostechnix.com/wp-content/uploads/2018/11/top-command-6.png

View File

@ -1,86 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (SMPlayer in Linux: Features, Download and Installation)
[#]: via: (https://itsfoss.com/smplayer/)
[#]: author: (Aquil Roshan;Abhishek Prakash https://itsfoss.com/author/aquil/)
[#]: url: ( )
SMPlayer in Linux: Features, Download and Installation
======
One of the [things youll notice after a fresh install of Ubuntu][1], or pretty much any other Linux distribution, is this message when you try to play certain video files.
![][2]
Default media player is not good with codecs
It means that the [codecs needed][3] to play the media are not installed on the system. Now, due to some copyright issues, some Linux based operating systems cannot pre-pack the codecs in the installation media. But they do allow you to download and install the codecs with just a click, or you could just install a media player which has all the multimedia codecs, to begin with. Checkout [SMPlayer][4].
### Meet SMPlayer: A Better Media Player for Linux
SMPlayer is a free and open-source media player built on the powerful [MPlayer][5] media engine. SMPlayer is capable of playing avi, mp4, mkv, mpeg, mov, divx, h.264 and pretty much any other major media format out there. And the cherry on top is, it can play [YouTube][6] videos too, ad-free.
![SMPlayer default interface][7]
SMPlayer is a complete media solution. It is cross-platform, so available on all the operating systems. If you have a dual boot, you can install it on your Windows and Linux OS to get a uniform experience on both the systems. It also supports convertible laptops with touch support.
You can play YouTube on SMPlayer too. I know its impractical to copy-paste the video URL and play on an external player every time. But SMPlayer is particularly useful when you are watching comparatively lengthy videos. SMPlayer plays YouTube videos in a very good quality and I felt the videos play out much better than the in-browser videos. And by playing the lengthier videos on SMPlayer, you can stay clear of the mid-roll ads that pop up on the lengthier videos.
If youre watching a movie which doesnt have subtitles, You can directly download the subtitles through SMPlayer. It comes with [opensubtitles.org][8] integration. So none of that, open the browser, search for subtitles, download the appropriate ones, unzip, place them in the video folder and connect the subtitles to the movie. No Sir! SMPlayer at your service.
![Automatic subtitle download in SMPlayer][9]
SMPlayer is available in more than 30 languages and it is highly customizable. It has both applications theming and a ton of icon sets in it.
If you feel that the default interface of SMPlayer doesnt look good, in a few clicks you can make it look like this:
![SMPlayer skin change][10]
SMPlayer comes with a lot of tools and features for the power users. It has an equalizer, video speed controls, aspect ratio and zoom controls, video filters, screenshot ripping and lot more.
All in all, I really liked SMPlayer. It has a lot to offer in a small and lightweight package. I think it is a must have video player on your Linux PC. Along with playing all the media formats easily it also provides a ton of power controls.
### Installing SMPlayer on Linux
SMPlayer should be available in the software center of all major Linux distributions. You can search for it and install it from there itself.
On Ubuntu/ Linux Mint/ Elementary OS, you can also install SMPlayer by running the following command in the terminal
```
sudo apt install smplayer
```
Alternatively, you can download the package for Fedora, Arch Linux, OpenSUSE and Debian [here.][11]
### Wrapping Up
There are a good number of full-fledged media players out there like the VLC media player. SMPlayer is one of the best ones with a full functionality and great add-on benefits. Ill consider it one of the [must-have applications for Linux][12].
Do give it a try and share your thoughts with us in the comments section below.
--------------------------------------------------------------------------------
via: https://itsfoss.com/smplayer/
作者:[Aquil Roshan;Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/aquil/
[b]: https://github.com/lujun9972
[1]: https://itsfoss.com/things-to-do-after-installing-ubuntu-18-04/
[2]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-warning.jpg?fit=800%2C450&ssl=1
[3]: https://packages.ubuntu.com/trusty/ubuntu-restricted-extras
[4]: https://www.smplayer.info/
[5]: http://www.mplayerhq.hu/design7/news.html
[6]: https://www.youtube.com/
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-coco.jpg?fit=800%2C450&ssl=1
[8]: https://www.opensubtitles.org/en/search
[9]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-icon-packs.jpg?fit=800%2C450&ssl=1
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-theme.jpg?fit=800%2C450&ssl=1
[11]: https://software.opensuse.org/download.html?project=home%3Asmplayerdev&package=smplayer
[12]: https://itsfoss.com/essential-linux-applications/

View File

@ -0,0 +1,108 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (ANGRYsearch Quick Search GUI Tool for Linux)
[#]: via: (https://itsfoss.com/angrysearch/)
[#]: author: (John Paul https://itsfoss.com/author/john/)
[#]: url: ( )
ANGRYsearch Quick Search GUI Tool for Linux
======
A search application is one of the most important tools you can have on your computer. Most are slow to indexes your system and find results. However, today we will be looking at an application that can display results as you type. Today, we will be looking at ANGRYsearch.
### What is ANGRYsearch?
![][1]
Newly installed ANGRYsearch
[ANGRYsearch][2] is a Python-based application that delivers results as you type your search query. The overall idea and design of the application are both inspired by [Everything][3] a search tool for Windows. (I discovered Everything ad couple of years ago and install it wherever I use Windows.)
ANGRYsearch is able to display the search results so quickly because it only indexes filenames. After you install ANGRYsearch, you create a database of filenames by indexing your system. ANGRYsearch then quickly filters filenames as you type your query.
Even though there is not much to ANGRYsearch, there are several things you can do to customize the experience. First, ANGRYsearch has two different display modes: lite and full. Lite mode only shows the filename and path. Full mode displays filename, path, size, and date of the last modification. Full mode, obviously, takes longer to display. The default is lite mode. In order to switch to full mode, you need to edit the config file at `~/.config/angrysearch/angrysearch.conf`. In that file change the `angrysearch_lite` value to false.
ANGRYsearch also has three different search modes: fast, slow, and regex. Fast mode displays filenames that start with your search term. For example, if you had a folder full of the latest releases of a bunch of Linux distros and you searched “Ubuntu”, ANGRYsearch would display Ubuntu, Ubuntu Mate, Ubuntu Budgie, but not Kubuntu, Xubuntu, or Lubuntu. Fast mode is on by default and can be turned off by unchecking the checkbox next to the “update” button. Slow mode is slightly slower (obviously), but it will display files that have your search term anywhere in their name. In the previous example, ANGRYsearch would show all Ubuntu distros. Regex mode is the slowest and most precise. It uses [regular expressions][4] and is case insensitive. Regex mode is activated by pressing F8.
You can also tell ANGRYsearch to ignore certain folders when it indexes your system. Just click the “update” button and enter the names of the folders you want to be ignored in the space provided. You can also choose from several icon themes, though it doesnt make that much difference.
![][5]Fast mode results
### Installing ANGRYsearch on Linux
ANGRYsearch is available in the [Arch User Repository][6]. It has also been packaged for [Fedora and openSUSE][7].
To install on other distros, follow these instructions. Instructions are written for a Debian or Ubuntu based system.
ANGRYsearch depends on `python3-pyqt5` and`xdg-utils` so you will need to install them first. Most distros have `xdg-utils`already installed.
`sudo apt install python3-pyqt5`
Next. download the latest version (1.0.1).
`wget https://github.com/DoTheEvo/ANGRYsearch/archive/v1.0.1.zip`
Now, unzip the archive file.
`unzip v1.0.1.zip`
Next, we will navigate to the new folder (ANGRYsearch-1.0.1) and run the installer.
`cd ANGRYsearch-1.0.1`
`chmod +x install.sh`
`sudo ./install.sh`
The installation process is very quick, so dont be surprised when a new command line is displayed as soon as you hit `Enter`.
The first time that you start ANGRYsearch, you will need to index your system. ANGRYsearch does not automatically keep its database updated. You can use `crontab` to schedule a system scan.
To open a text editor to create a new cronjob, use `crontab -e`. To make sure that the ANGRYsearch database is updated every 6 hours, use this command `0 */6 选题模板.txt 中文排版指北.md core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LCTT翻译规范.md LICENSE published README.md scripts sources translated 选题模板.txt 中文排版指北.md core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LCTT翻译规范.md LICENSE published README.md scripts sources translated 选题模板.txt 中文排版指北.md core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LCTT翻译规范.md LICENSE published README.md scripts sources translated /usr/share/angrysearch/angrysearch_update_database.py`. `crontab` does not run the job if it is powered off when the timer does off. In some case, you may need to manually update the database, but it should not take long.
![][8]ANGRYsearch update/options menu
### Experience
In the past, I was always frustrated by how painfully slow it was to search my computer. I knew that Windows had the Everything app, but I thought Linux out of luck. It didnt even occur to me to look for something similar on Linux. Im glad I accidentally stumbled upon ANGRYsearch.
I know there will be quite a few people complaining that ANGRYsearch only searches filenames, but most of the time that is all I need. Thankfully, most of the time I only need to remember part of the name to find what I am looking for.
The only thing that annoys me about ANGRYsearch is that fact that it does not automatically update its database. Youd think there would be a way for the installer to create a cron job when you install it.
![][9]Slow mode results
### Final Thoughts
Since ANGRYsearch is basically a Linux port of one of my favorite Windows apps, Im pretty happy with it. I plan to install it on all my systems going forward.
I know that I have ragged on other Linux apps for not being packaged for easy install, but I cant do the same for ANGRYsearch. The installation process is pretty easy. I would definitely recommend it for Linux noobs.
Have you ever used [ANGRYsearch][2]? If not, what is your favorite Linux search application? Let us know in the comments below.
If you found this article interesting, please take a minute to share it on social media, Hacker News or [Reddit][10].
--------------------------------------------------------------------------------
via: https://itsfoss.com/angrysearch/
作者:[John Paul][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/john/
[b]: https://github.com/lujun9972
[1]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2018/11/angrysearch3.jpg?resize=800%2C627&ssl=1
[2]: https://github.com/dotheevo/angrysearch/
[3]: https://www.voidtools.com/
[4]: http://www.aivosto.com/articles/regex.html
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2018/11/angrysearch1.jpg?resize=800%2C627&ssl=1
[6]: https://aur.archlinux.org/packages/angrysearch/
[7]: https://software.opensuse.org/package/angrysearch
[8]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2018/11/angrysearch2.jpg?resize=800%2C626&ssl=1
[9]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/11/angrysearch4.jpg?resize=800%2C627&ssl=1
[10]: http://reddit.com/r/linuxusersgroup

View File

@ -0,0 +1,153 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Four Easy Ways to Search Or Find Files And Folders in Linux)
[#]: via: (https://www.2daygeek.com/four-easy-ways-to-search-or-find-files-and-folders-in-linux/)
[#]: author: (Prakash Subramanian https://www.2daygeek.com/author/prakash/)
Four Easy Ways to Search Or Find Files And Folders in Linux
======
Linux admins cant able to leave a day without performing a file search as this one of the activity for their routine.
Its good to know all the file search stuffs because it would help you in many ways when you are working on headless server.
These commands are not complicate to remember because these are using a standard syntax.
This can be performed through Four Linux commands and each command has their own unique feature.
### Method-1: Search Files And Folders in Linux Using find Command
Find command is widely used and very famous command to search files and folders in Linux. It searches given files in the current directory and recursively through its sub-directories based on the search criteria.
It allow users to perform all kind of file searches based on the criteria lie by size, name, owner, group, type, permissions, date, and other criteria.
Run the following command to find a given file in system.
```
# find / -iname "sshd_config"
/etc/ssh/sshd_config
```
Run the following command to find a given folder in system. To search a folder in Linux we need to use `-type` parameter.
```
# find / -type d -iname "ssh"
/usr/lib/ssh
/usr/lib/go/src/cmd/vendor/golang.org/x/crypto/ssh
/usr/lib/go/pkg/linux_amd64/cmd/vendor/golang.org/x/crypto/ssh
/etc/ssh
```
Use wildcard option to search set of files on your system. We are going to search all files available in the system with `.config` extension.
```
# find / -name "*.config"
/usr/lib/mono/gac/avahi-sharp/1.0.0.0__4d116c78973743f5/avahi-sharp.dll.config
/usr/lib/mono/gac/avahi-ui-sharp/0.0.0.0__4d116c78973743f5/avahi-ui-sharp.dll.config
/usr/lib/python2.7/config/Setup.config
/usr/share/git/mw-to-git/t/test.config
/var/lib/lightdm/.config
/home/daygeek/.config
/root/.config
/etc/skel/.config
```
Use the following command format to find an empty files and folders in system.
```
# find / -empty
```
Use the following command combination to find all files containing specific text on Linux.
```
# find / -type f -exec grep "Port 22" '{}' \; -print
# find / -type f -print | xargs grep "Port 22"
# find / -type f | xargs grep 'Port 22'
# find / -type f -exec grep -H 'Port 22' {} \;
```
### Method-2: Search Files And Folders in Linux Using locate command
locate command works faster than the find command because it uses updatedb database, whereas the find command searches in the real system.
It uses a database rather than hunting individual directory paths to get a given file.
locate command doesnt pre-installed in most of the distributions so, use your distribution package manager to install it.
The database is updated regularly through cron, however we can manually update it by running the following command.
```
$ sudo updatedb
```
Simply run the following command to list the given file or folder. There is no specific options need to be specified in locate command to print file or folder.
To search `ssh` folder in system.
```
# locate --basename '\ssh'
/etc/ssh
/usr/bin/ssh
/usr/lib/ssh
/usr/lib/go/pkg/linux_amd64/cmd/vendor/golang.org/x/crypto/ssh
/usr/lib/go/src/cmd/go/testdata/failssh/ssh
/usr/lib/go/src/cmd/vendor/golang.org/x/crypto/ssh
```
To search `ssh_config` file in system.
```
# locate --basename '\sshd_config'
/etc/ssh/sshd_config
```
### Method-3: Search Files in Linux Using which command
TThe which command returns the full path of the executable that would have been executed when the command had been entered in terminal.
Its very useful when you want to create a desktop shortcut or symbolic link for executable files.
Which command searches the directories listed in the current users PATH environment variable not for all the users. I mean, when you are logged in your own account and you cant able to search for root user file or directory.
Run the following command to print the full path of the vim executable file location.
```
# which vi
/usr/bin/vi
```
Alternatively, its allowing user to perform multiple file search in one shot.
```
# which -a vi sudo
/usr/bin/vi
/bin/vi
/usr/bin/sudo
/bin/sudo
```
### Method-4: Search Files in Linux Using whereis command
The whereis command used to search the binary, source, and man page files for a given command.
```
# whereis vi
vi: /usr/bin/vi /usr/share/man/man1/vi.1p.gz /usr/share/man/man1/vi.1.gz
```
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/four-easy-ways-to-search-or-find-files-and-folders-in-linux/
作者:[Prakash Subramanian][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.2daygeek.com/author/prakash/
[b]: https://github.com/lujun9972

View File

@ -0,0 +1,86 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (How to bring good fortune to your Linux terminal)
[#]: via: (https://opensource.com/article/18/12/linux-toy-fortune)
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
[#]: url: ( )
How to bring good fortune to your Linux terminal
======
Bring quotes and quips to the command line with the fortune utility.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/uploads/linux-toy-fortune.png?itok=5PVVZVer)
It's December, and if you haven't found a [tech advent calendar][1] that sparks your fancy yet, well, maybe this one will do the trick. Every day, from now to the 24th, we're bringing you a different Linux command-line toy. What's a command-line toy, you ask? It could be a game or any simple diversion to bring a little happiness to your terminal.
You may have seen some of these before. We hope you'll find something new, too. Either way, we hope you have fun following along.
Today's toy, **fortune** , is an old one. Versions of it date back to the 1980s when it was included with Unix. The version I installed in Fedora was available under a BSD license, and I grabbed it with the following.
```
$ sudo dnf install fortune-mod -y
```
Your distribution may be different. On some, you may need to install the fortunes separately from **fortune** itself (try searching your package manager for "fortunes*"). You can also check out the source code on [GitHub][2]. Then, just run **fortune** to get, well, a fortune.
```
$ fortune
"Time is an illusion.  Lunchtime doubly so."
-- Ford Prefect, _Hitchhiker's Guide to the Galaxy_
```
So why do you need fortunes at the terminal? For fun, of course. Perhaps you'd like to add them to the message of the day on your system?
Personally, I like using the **fortune** command as a built-in piece of dummy data when I'm using the terminal to parse text, particularly with [regular expressions][3], and want something simple to try it out on.
For example, let's say I was testing our a transformation with the **tr** command to replace letter the letter e with a numeral 3.
```
$ fortune | tr 'eE' '3'
Unix 3xpr3ss:
All pass3ng3r bring a pi3c3 of th3 a3roplan3 and a box of tools with th3m to
th3 airport. Th3y gath3r on th3 tarmac, arguing constantly about what kind
of plan3 th3y want to build and how to put it tog3th3r. 3v3ntually, th3
pass3ng3rs split into groups and build s3v3ral diff3r3nt aircraft, but giv3
th3m all th3 sam3 nam3. Som3 pass3ng3rs actually r3ach th3ir d3stinations.
All pass3ng3rs b3li3v3 th3y got th3r3.
```
So what fortunes come with your distribution? Take a look in your **/usr/share/games/fortune** directory to find them all. Here are a few of my favorites.
```
Never laugh at live dragons.
                -- Bilbo Baggins [J.R.R. Tolkien, "The Hobbit"]
I dunno, I dream in Perl sometimes...
             -- Larry Wall in  <8538@jpl-devvax.JPL.NASA.GOV>
I have an existential map.  It has "You are here" written all over it.
                -- Steven Wright
```
Looking for more on **fortune**? You can, of course, always check out the man page to learn more about the options, or read a little bit more about the history of the command on [Wikipedia][4].
Do you have a favorite command-line toy that you think I ought to profile? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.
Check out yesterday's toy, [Drive a locomotive through your Linux terminal][5], and check back tomorrow for another!
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/linux-toy-fortune
作者:[Jason Baker][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/jason-baker
[b]: https://github.com/lujun9972
[1]: https://opensource.com/article/16/11/7-tech-advent-calendars-holiday-season
[2]: https://github.com/shlomif/fortune-mod
[3]: https://opensource.com/article/18/5/getting-started-regular-expressions
[4]: https://en.wikipedia.org/wiki/Fortune_%28Unix%29
[5]: https://opensource.com/article/18/12/linux-toy-sl

View File

@ -1,92 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (Easily Convert Audio File Formats with SoundConverter in Linux)
[#]: via: (https://itsfoss.com/sound-converter-linux/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
[#]: url: ( )
Easily Convert Audio File Formats with SoundConverter in Linux
======
**If you are looking for converting audio file formats to wav, mp3, ogg or any other format, SoundConverter is the tool you need in Linux.**
![Audio Converter in Linux][1]
So recently I purchased some DRM-free music. I got it from [SaReGaMa][2], the oldest and the largest music labels in India. The downloaded files were in HD quality and in WAV format.
Unfortunately, Rhythmbox doesnt play the WAV files. On top of that, a single file was around 70 MB in size. Imagine transferring such large music files to smartphones. It would eat up a lot of space unnecessarily.
So I thought it was time to convert the WAV files to MP3, the evergreen and the most popular music file format.
And for this task, I needed an audio converter in Linux. In this quick tutorial, Ill show you how can you convert your audio files from one format to another easily with a GUI tool called SoundCoverter.
### Installing SoundConverter in Linux
[SoundConverter][3] is a popular free and open source software. It should be available in the official repository of most Linux distributions.
Ubuntu/Linux Mint users can simply search for SoundConverter in the software center and install it from there.
![SoundConverter application in Software Center of Ubuntu][4]SoundConverter can be installed from Software Center
Alternatively, you can use the command line way. In Debian and Ubuntu based systems, you can use the following command:
```
sudo apt install soundconverter
```
For Arch, Fedora and other non-Debian based distributions, you can use the software center or the package manager of your distribution.
### Using SoundConverter to convert audio file formats in Linux
Once you have installed SoundConverter, search for it in the menu and start it.
The default interface looks like this and it cannot be more simple than this:
![SoundConverter application interface in Linux][5]Simple Interface
Converting audio file format is as easy as selecting the file and clicking on convert.
However, I would advise you to check the default settings at least on the first run. By default it converts the audio file to OGG file format and you may not want that.
![Preferences in SoundConverter][6]Default output settings can be changed in Preferences
To change the default output settings, click on the Preferences icon visible on the interface. Youll see plenty of options to change here.
You can change the default output format, bitrate, quality etc. You can also choose if you want to keep the converted files in the same folder as the original or not.
There is also an option of automatically deleting the original file after conversion. I dont think you should use that option.
You can also change the output file name. By default, it will just change the suffix but you can also choose to name it based on track number, title, artist etc. For that to happen, you should have proper metadata on the original file.
Speaking of metadata, have you heard of [MusicBrainz Picard][7]? This tool helps you automatically updates the metadata of your local music files.
### Conclusion
I have discussed [recording audio in Linux][8] previously with a similar tiny application. Such nifty tools actually make life easier with their focused aim of completing a certain task. You may use full-fledged and a lot better audio editing tool like [Audacity][9] but that may be complicated to use for smaller tasks like converting audio file formats.
I hope you like SoundConverter. If you use some other tool, do mention that in the comments and I may cover it here on Its FOSS. Enjoy!
--------------------------------------------------------------------------------
via: https://itsfoss.com/sound-converter-linux/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/Convert-audio-file-format-linux.png?resize=800%2C450&ssl=1
[2]: https://en.wikipedia.org/wiki/Saregama
[3]: http://soundconverter.org/
[4]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/sound-converter-software-center.png?ssl=1
[5]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2018/12/sound-converter-app-linux.jpeg?ssl=1
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/sound-converter-app-linux-preferences.jpeg?resize=800%2C431&ssl=1
[7]: https://itsfoss.com/musicbrainz-picard/
[8]: https://itsfoss.com/record-streaming-audio/
[9]: https://www.audacityteam.org/

View File

@ -0,0 +1,78 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (How To Fix Broken Ubuntu OS Without Reinstalling It)
[#]: via: (https://www.ostechnix.com/how-to-fix-broken-ubuntu-os-without-reinstalling-it/)
[#]: author: (SK https://www.ostechnix.com/author/sk/)
[#]: url: ( )
How To Fix Broken Ubuntu OS Without Reinstalling It
======
![](https://www.ostechnix.com/wp-content/uploads/2018/12/Fix-Broken-Ubuntu-OS-720x340.jpg)
Today, I was upgrading my Ubuntu 18.04 LTS system. Unfortunately, the power has gone in mid-way and the system powered off while updating Ubuntu OS. When the power is back, I boot the system again. Right after entering the password at the login screen, its gone blank and didnt respond. Keyboard and mouse also didnt work. All I see is just a blank screen! Thankfully, Its just a test machine and there were no important data in it. I can simply wipe off the entire OS and install it again. But, I dont want to do that. Since I have nothing to lose, I just wanted to repair my broken Ubuntu system without reinstalling it completely and it worked!!! If you ever find yourself in a situation like mine, dont panic. This brief tutorial describes how to easily fix broken Ubuntu OS without losing data and without reinstalling it completely.
### Fix Broken Ubuntu OS
First of all, try to login with live cd and **backup your data** in an external drive. Just in case, if this method didnt work, you can still have your data and reinstall everything!
At the login screen, press **CTRL+ALT+F1** to switch to **tty1**. You can learn more about switching between TTYs [**here**][1].
Now, type the following commands one by one to fix the broken Ubuntu Linux.
```
$ sudo rm /var/lib/apt/lists/lock
$ sudo rm /var/lib/dpkg/lock
$ sudo rm /var/lib/dpkg/lock-frontend
$ sudo dpkg --configure -a
$ sudo apt clean
$ sudo apt update --fix-missing
$ sudo apt install -f
$ sudo dpkg --configure -a
$ sudo apt upgrade
$ sudo apt dist-upgrade
```
Finally, reboot the system using command:
```
$ sudo reboot
```
You can now be able to login to your Ubuntu system as usual.
After I followed these steps, all of my data in Ubuntu 18.04 test system was there and everything is the same as I left it. This method may not work for everyone. However, this small tip worked for me and saved a couple minutes from reinstalling. If you know any other better way, please let me know in the comment section. I will add them in this guide as well.
And, thats all for now. Hope this was useful.
More good stuffs to come. Stay tuned!
Cheers!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/how-to-fix-broken-ubuntu-os-without-reinstalling-it/
作者:[SK][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.ostechnix.com/author/sk/
[b]: https://github.com/lujun9972
[1]: https://www.ostechnix.com/how-to-switch-between-ttys-without-using-function-keys-in-linux/

View File

@ -0,0 +1,106 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How To Boot Into Rescue Mode Or Emergency Mode In Ubuntu 18.04)
[#]: via: (https://www.ostechnix.com/how-to-boot-into-rescue-mode-or-emergency-mode-in-ubuntu-18-04/)
[#]: author: (SK https://www.ostechnix.com/author/sk/)
How To Boot Into Rescue Mode Or Emergency Mode In Ubuntu 18.04
======
![](https://www.ostechnix.com/wp-content/uploads/2018/12/Boot-Into-Rescue-Mode-Or-Emergency-Mode-720x340.png)
As you might already know, **Runlevels** are replaced with **Systemd targets** in many recent Linux distributions like RHEL 7 and Ubuntu 16.04 LTS. For more details about runlevels and systemd target, refer [**this guide**][1]. In this brief tutorial, we are going to see how to boot into **rescue mode** and/or **emergency mode**. This guide is tested in Ubuntu 18.04 LTS, however the steps given below would work on most Linux distributions that uses Systemd as default service manager. Before going further, let me clarify what is rescue mode and emergency mode and what is the purpose of the both modes.
### What is Rescue mode?
The **rescue mode** is equivalent to **single user mode** in Linux distributions that uses **SysV** as the default service manager. In rescue mode, all local filesystems will be mounted, only some important services will be started. However, no normal services (E.g network services) wont be started. The rescue mode is helpful in situations where the system cant boot normally. Also, we can perform some important rescue operations, such as [**reset root password**][2], in rescue mode.
### What is Emergency mode?
In contrast to the rescue mode, nothing is started in the **emergency mode**. No services are started, no mount points mounted, no sockets established, nothing. All you will have is just a **raw shell**. Emergency mode is suitable for debugging purposes.
### Boot Into Rescue Mode In Ubuntu 18.04 LTS
Boot your Ubuntu system. When Grub menu appears, choose the first entry and press **e** to edit.
![](https://www.ostechnix.com/wp-content/uploads/2018/12/Grub-menu.png)
If you dont see the Grub menu, just hit ESC key right after the BIOS logo disappears.
Find the line that starts with word **“linux”** and add the following line at the end of that line (To reach the end, just press **CTRL+e** or use END key or LEFT/RIGHT arrows in your keyboard):
```
systemd.unit=rescue.target
```
![](https://www.ostechnix.com/wp-content/uploads/2018/12/Edit-grub-menu.png)
Once you added the above line, just press **CTRL+x** or **F10** to continue to boot into rescue mode. After a few seconds, you will be ended up in the rescue mode (single user mode) as root user. Here is how rescue mode looks like in Ubuntu 18.04 LTS server:
![](https://www.ostechnix.com/wp-content/uploads/2018/12/Ubuntu-rescue-mode.png)
Next, type the following command to mount root (/) file system into read/write mode.
```
mount -n -o remount,rw /
```
### Boot Into Emergency Mode
Booting your Ubuntu into emergency is as same as above method. All you have to do is replace “systemd.unit=rescue.target” with “systemd.unit=emergency.target” when editing grub menu.
[![emergency mode][3]][4]
Once you added “systemd.unit=emergency.target”, press **Ctrl+x** or **F10** to continue booting into emergency mode.
![](https://www.ostechnix.com/wp-content/uploads/2018/12/emergency-mode-1.png)
Finally, you can mount root filesystem into read/write mode with command:
```
mount -n -o remount,rw /
```
### Switch between Rescue to Emergency mode and vice versa
If you are in rescue mode, you dont have to edit the grub boot entry as I mentioned above. Instead, just type the following command to switch to emergency mode instantly:
```
systemctl emergency
```
Similarly, to switch from emergency to rescue mode, type:
```
systemctl rescue
```
You know now what is rescue and emergency modes and how to boot into those modes in Ubuntu 18.04. Like I already mentioned, the steps provided here will work on many recent Linux versions that uses Systemd.
And, thats all for now. Hope this was useful.
More good stuffs to come. Stay tuned!
Cheers!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/how-to-boot-into-rescue-mode-or-emergency-mode-in-ubuntu-18-04/
作者:[SK][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.ostechnix.com/author/sk/
[b]: https://github.com/lujun9972
[1]: https://www.ostechnix.com/check-runlevel-linux/
[2]: https://www.ostechnix.com/how-to-reset-or-recover-root-user-password-in-linux/
[3]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
[4]: http://www.ostechnix.com/wp-content/uploads/2018/12/emergency-mode.png

View File

@ -0,0 +1,109 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to view XML files in a web browser)
[#]: via: (https://opensource.com/article/18/12/xml-browser)
[#]: author: (Greg Pittman https://opensource.com/users/greg-p)
How to view XML files in a web browser
======
Turn XML files into something more useful.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/web_browser_desktop_devlopment_design_system_computer.jpg?itok=pfqRrJgh)
Once you learn that HTML is a form of XML, you might wonder what would happen if you tried to view an XML file in a browser. The results are quite disappointing—Firefox shows you a banner at the top of the page that says, "This XML file does not appear to have any style information associated with it. The document tree is shown below." The document tree looks like the file would look in an editor:
![](https://opensource.com/sites/default/files/uploads/xml_menu.png)
This is the beginning of the **menu.xml** file for the online manual that comes with [Scribus][1], to which I'm a contributor. Although you see blue text, they are not clickable links. I wanted to be able to view this in a regular browser, since sometimes I need to go back and forth from the canvas in Scribus to the manual to figure out how to do something (maybe to see if I need to edit the manual to straighten out some misinformation or to add some missing information).
The way to help a browser know what to do with these XML tags is by using XSLT—Extensible Stylesheet Language Transformations. In a broad sense, you could use XSLT to transform XML to a variety of outputs, or even HTML to XML. Here I want to use it to present the XML tags to a browser as suitable HTML.
One slight modification needs to happen to the XML file:
![](https://opensource.com/sites/default/files/uploads/xml_modified-menu.png)
Adding this second line to the file tells the browser to look for a file named **scribus-manual.xsl** for the style information. The more important part is to create this XSL file. Here is the complete listing of **scribus-manual.xsl** for the Scribus manual:
```
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
    <title>Scribus Online Manual</title>
<style type="text/css">
h2,h3,h4 { text-indent: 50px;}
ul { margin-left: 100px;}
</style>
<table border="0" cellspacing="0" cellpadding="0" width="100%"
bgcolor="#183867" >
        <tr>
                <td align="left"><img src="images/docheader1.png" width="222"
height="87"/></td>
                <td align="right"><img src="images/docheader2.png" width="318"
height="87"/></td>
        </tr>
</table>
    <body bgcolor="#ffffff">
      <xsl:for-each select="menu">
        <xsl:for-each select="area">
          <h3><a href="{@file}" ><xsl:value-of select = "@text" /></a></h3>
          <xsl:for-each select="submenuitem">
            <h4><a href="{@file}" ><xsl:value-of select = "@text" /></a></h4>
                <xsl:for-each select="submenuitem">
                  <p><ul>
                    <li><a href="{@file}" ><xsl:value-of select = "@text" /></a></li>
                  </ul></p>
                </xsl:for-each>
          </xsl:for-each>
        <xsl:for-each select="area">
          <h3><a href="{@file}" ><xsl:value-of select = "@text" /></a></h3>
        </xsl:for-each>
        </xsl:for-each>
      </xsl:for-each>
    </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
```
This looks a lot more like HTML, and you can see it contains a number of HTML tags. After some preliminary tags and some particulars about displaying H2, H3, and H4 tags, you see a Table tag. This adds a graphical heading at the top of the page and uses some images already in the documentation files.
After this, you get into the process of dissecting the various **submenuitem** tags, trying to create the nested listing structure as it appears in Scribus when you view the manual. One feature I did not try to duplicate is the ability to collapse and expand **submenuitem** areas. As you can imagine, it takes some time to sort through the number of nested lists you need to create, but when I finished, here is how it looked:
![](https://opensource.com/sites/default/files/uploads/xml_scribusmenuinbrowser.png)
This minimal editing to **menu.xml** does not interfere with Scribus' ability to show the manual in its own browser. I put this modified **menu.xml** file and the **scribus-manual.xsl** in the English documentation folder for 1.5.x versions of Scribus, so anyone using these versions can simply point their browser to the **menu.xml** file and it should show up just like you see above.
A much bigger chore I took on a few years ago was to create a version of the ICD10 (International Classification of Diseases, version 10) when it came out. Many changes were made from the previous version (ICD9) to 10. These are important since these codes must be used for diagnostic purposes in medical practice. You can easily download XML files from the US [Centers for Medicare and Medicaid][2] website since it is public information, but—just as with the Scribus manual—these files are hard to use.
Here is the beginning of the tabular listing of diseases:
![](https://opensource.com/sites/default/files/uploads/xml_tabular_begin.png)
One of the features I created was the color coding used in the listing shown here:
![](https://opensource.com/sites/default/files/uploads/xml_tabular_body.png)
As with **menu.xml** , the only editing I did in this **Tabular.xml** file was to add **<?xml-stylesheet type="text/xsl" href="tabular.xsl"? >** as the second line of the file. I started this project with the 2014 version, and I was quite pleased to find that the original **tabular.xsl** stylesheet worked perfectly when the 2016 version came out, which is the last one I worked on. The** Tabular.xml** file is 8.4MB, quite large for a plaintext file. It takes a few seconds to load into a browser, but once it's loaded, navigation is fast.
While you may not often have to deal with an XML file in this way, if you do, I hope this article shows that your file can easily be turned into something much more usable.
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/xml-browser
作者:[Greg Pittman][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/greg-p
[b]: https://github.com/lujun9972
[1]: https://www.scribus.net/
[2]: https://www.cms.gov/

View File

@ -0,0 +1,61 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (Take a break at the Linux command line with Nyan Cat)
[#]: via: (https://opensource.com/article/18/12/linux-toy-nyancat)
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
[#]: url: ( )
Take a break at the Linux command line with Nyan Cat
======
Rainbows, Pop-Tarts, and cats in space: What more could you want at your terminal?
![](https://opensource.com/sites/default/files/styles/image-full-size/public/uploads/linux-toy-nyancat.png?itok=eg1aEmBw)
We're now on day six of the Linux command-line toys advent calendar, where we explore some of the fun, entertaining, and in some cases, utterly useless toys available for your Linux terminal. All are available under an open source license.
Will they all be unique? Yes. Will they all be unique to you? I don't know, but, chances are you'll find at least one new toy to play with by the time our advent calendar is done.
Today's selection is a continuation on the [theme][1] we started yesterday: cats and rainbows. Wait, there's more cat-related rainbow fun to be had at the Linux command line? You bet there is.
So let's make a throwback all the way to 2011's [Nyan Cat][2] with a command-line toy call, not surprisingly, **nyancat**. Did you miss the cultural phenomenon that was Nyan Cat? Watch the embed below, I'll wait.
<https://www.youtube.com/embed/QH2-TGUlwu4>
Now, let's recreate that amazing experience in your terminal. **Nyancat** is packaged for many distributions (Arch, Debian, Gentoo, Ubuntu, etc.) but not for mine (Fedora), but compiling from source was simple. In fact, I grabbed the source, built it, and launched it in one line:
```
git clone https://github.com/klange/nyancat.git && cd nyancat && make && cd src && ./nyancat
```
This launched straight into a **nyancat** experience complete with a counter of how long I had been enjoying the **nyancat** magic for.
![](https://opensource.com/sites/default/files/uploads/linux-toy-nyancat-animated.gif)
You can find the source for **nyancat** [on GitHub][3] under an [NCSA open source license][4].
The command-line version of Nyan Cat used to be [accessible by a public Telnet server][5] (or, for even more pun, with [netcat][6]) so that you didn't even have to install it, but sadly was shut down due to bandwidth limitations. Nevertheless, the [gallery][5] from the old Telnet server running Nyan Cat on a variety of old devices is well-worth checking out, and maybe you'd like to do the community a favor by launching your own public mirror and letting the author know so that they may share it with the public yet again?
Do you have a favorite command-line toy that you think I ought to profile? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.
Check out yesterday's toy, [Bring some color to your Linux terminal with lolcat][1], and check back tomorrow for another!
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/linux-toy-nyancat
作者:[Jason Baker][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/jason-baker
[b]: https://github.com/lujun9972
[1]: https://opensource.com/article/18/12/linux-toy-lolcat
[2]: https://en.wikipedia.org/wiki/Nyan_Cat
[3]: https://github.com/klange/nyancat
[4]: http://en.wikipedia.org/wiki/University_of_Illinois/NCSA_Open_Source_License
[5]: http://nyancat.dakko.us/
[6]: http://netcat.sourceforge.net/

View File

@ -0,0 +1,177 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (5 Screen Recorders for the Linux Desktop)
[#]: via: (https://www.linux.com/blog/intro-to-linux/2018/12/5-screen-recorders-linux-desktop)
[#]: author: (Jack Wallen https://www.linux.com/users/jlwallen)
5 Screen Recorders for the Linux Desktop
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/screen-record.png?itok=tKWx29k8)
There are so many reasons why you might need to record your Linux desktop. The two most important are for training and for support. If you are training users, a video recording of the desktop can go a long way to help them understand what you are trying to impart. Conversely, if youre having trouble with one aspect of your Linux desktop, recording a video of the shenanigans could mean the difference between solving the problem and not. But what tools are available for the task? Fortunately, for every Linux user (regardless of desktop), there are options available. I want to highlight five of my favorite screen recorders for the Linux desktop. Among these five, you are certain to find one that perfectly meets your needs. I will only be focusing on those screen recorders that save as video. What video format you prefer may or may not dictate which tool you select.
And, without further ado, lets get on with the list.
### Simple Screen Recorder
Im starting out with my go-to screen recorder. I use [Simple Screen Recorder][1] on a daily basis, and it never lets me down. This particular take on the screen recorder is available for nearly every flavor of Linux and is, as the name implies, very simple to use. With Simple Screen Recorder you can select a single window, a portion of the screen, or the entire screen to record. One of the best features of Simple Screen Recorder is the ability to save profiles (Figure 1), which allows you to configure the input for a recording (including scaling, frame rate, width, height, left edge and top edge spacing, and more). By saving profiles, you can easily use a specific profile to meet a unique need, without having to go through the customization every time. This is handy for those who do a lot of screen recording, with different input variables for specific jobs.
![Simple Screen Recorder ][3]
Figure 1: Simple Screen Recorder input profile window.
[Used with permission][4]
Simple screen recorder also:
* Records audio input
* Allows you to pause and resume recording
* Offers a preview during recording
* Allows for the selection of video containers and codecs
* Adds timestamp to file name (optional)
* Includes hotkey recording and sound notifications
* Works well on slower machines
* And much more
Simple Screen Recorder is one of the most reliable screen recording tools I have found for the Linux desktop. Simple Screen Recorder can be installed from the standard repositories on many desktops, or via easy to follow instructions on the [application download page][5].
### Gtk-recordmydesktop
The next entry, [gtk-recordmydesktop][6], doesnt give you nearly the options found in Simple Screen Recorder, but it does offer a command line component (for those who prefer not working with a GUI). The simplicity that comes along with this tool also means you are limited to a specific video output format (.ogv). That doesnt mean gtk-recordmydesktop isnt without appeal. In fact, there are a few features that make this option in the genre fairly appealing. First and foremost, its very simple to use. Second, the record window automatically gets out of your way while you record (as opposed to Simple Screen Recorder, where you need to minimize the recording window when recording full screen). Another feature found in gtk-recordmydesktop is the ability to have the recording follow the mouse (Figure 2).
![gtk-recordmydesktop][8]
Figure 2: Some of the options for gtk-recordmydesktop.
[Used with permission][4]
Unfortunately, the follow the mouse feature doesnt always work as expected, so chances are youll be using the tool without this interesting option. In fact, if you opt to go the gtk-recordmydesktop route, you should understand the GUI frontend isnt nearly as reliable as is the command line version of the tool. From the command line, you could record a specific position of the screen like so:
```
recordmydesktop -x X_POS -y Y_POS --width WIDTH --height HEIGHT -o FILENAME.ogv
```
where:
* X_POS is the offset on the X axis
* Y_POS is the offset on the Y axis
* WIDTH is the width of the screen to be recorded
* HEIGHT is the height of the screen to be recorded
* FILENAME is the name of the file to be saved
To find out more about the command line options, issue the command man recordmydesktop and read through the manual page.
### Kazam
If youre looking for a bit more than just a recorded screencast, you might want to give Kazam a go. Not only can you record a standard screen video (with the usual—albeit limited amount of—bells and whistles), you can also take screenshots and even broadcast video to YouTube Live (Figure 3).
![Kazam][10]
Figure 3: Setting up YouTube Live broadcasting in Kazam.
[Used with permission][4]
Kazam falls in line with gtk-recordmydesktop, when it comes to features. In other words, its slightly limited in what it can do. However, that doesnt mean you shouldnt give Kazam a go. In fact, Kazam might be one of the best screen recorders out there for new Linux users, as this app is pretty much point and click all the way. But if youre looking for serious bells and whistles, look away.
The version of Kazam, with broadcast goodness, can be found in the following repository:
```
ppa:sylvain-pineau/kazam
```
For Ubuntu (and Ubuntu-based distributions), install with the following commands:
```
sudo apt-add-repository ppa:sylvain-pineau/kazam
sudo apt-get update
sudo apt-get install kazam -y
```
### Vokoscreen
The [Vokoscreen][11] recording app is for new-ish users who need more options. Not only can you configure the output format and the video/audio codecs, you can also configure it to work with a webcam (Figure 4).
![Vokoscreen][13]
Figure 4: Configuring a web cam for a Vokoscreen screen recording.
[Used with permission][4]
As with most every screen recording tool, Vokoscreen allows you to specify what on your screen to record. You can record the full screen (even selecting which display on multi-display setups), window, or area. Vokoscreen also allows you to select a magnification level (200x200, 400x200, or 600x200). The magnification level makes for a great tool to highlight a specific section of the screen (the magnification window follows your mouse).
Like all the other tools, Vokoscreen can be installed from the standard repositories or cloned from its [GitHub repository][14].
### OBS Studio
For many, [OBS Studio][15] will be considered the mack daddy of all screen recording tools. Why? Because OBS Studio is as much a broadcasting tool as it is a desktop recording tool. With OBS Studio, you can broadcast to YouTube, Smashcast, Mixer.com, DailyMotion, Facebook Live, Restream.io, LiveEdu.tv, Twitter, and more. In fact, OBS Studio should seriously be considered the de facto standard for live broadcasting the Linux desktop.
Upon installation (the software is only officially supported for Ubuntu Linux 14.04 and newer), you will be asked to walk through an auto-configuration wizard, where you setup your streaming service (Figure 5). This is, of course, optional; however, if youre using OBS Studio, chances are this is exactly why, so you wont want to skip out on configuring your default stream.
![OBS Studio][17]
Figure 5: Configuring your streaming service for OBS Studio.
[Used with permission][4]
I will warn you: OBS Studio isnt exactly for the faint of heart. Plan on spending a good amount of time getting the streaming service up and running and getting up to speed with the tool. But for anyone needing such a solution for the Linux desktop, OBS Studio is what you want. Oh … it can also record your desktop screencast and save it locally.
### Theres More Where That Came From
This is a short list of screen recording solutions for Linux. Although there are plenty more where this came from, you should be able to fill all your desktop recording needs with one of these five apps.
Learn more about Linux through the free ["Introduction to Linux" ][18]course from The Linux Foundation and edX.
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/intro-to-linux/2018/12/5-screen-recorders-linux-desktop
作者:[Jack Wallen][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.linux.com/users/jlwallen
[b]: https://github.com/lujun9972
[1]: http://www.maartenbaert.be/simplescreenrecorder/
[2]: /files/images/screenrecorder1jpg
[3]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/screenrecorder_1.jpg?itok=hZJ5xugI (Simple Screen Recorder )
[4]: /licenses/category/used-permission
[5]: http://www.maartenbaert.be/simplescreenrecorder/#download
[6]: http://recordmydesktop.sourceforge.net/about.php
[7]: /files/images/screenrecorder2jpg
[8]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/screenrecorder_2.jpg?itok=TEGXaVYI (gtk-recordmydesktop)
[9]: /files/images/screenrecorder3jpg
[10]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/screenrecorder_3.jpg?itok=cvtFjxen (Kazam)
[11]: https://github.com/vkohaupt/vokoscreen
[12]: /files/images/screenrecorder4jpg
[13]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/screenrecorder_4.jpg?itok=c3KVS954 (Vokoscreen)
[14]: https://github.com/vkohaupt/vokoscreen.git
[15]: https://obsproject.com/
[16]: /files/images/desktoprecorder5jpg
[17]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/desktoprecorder_5.jpg?itok=xyM-dCa7 (OBS Studio)
[18]: https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux

View File

@ -0,0 +1,102 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Automatic continuous development and delivery of a hybrid mobile app)
[#]: via: (https://opensource.com/article/18/12/hybrid-mobile-app-development)
[#]: author: (Angelo Manganiello https://opensource.com/users/amanganiello90)
Automatic continuous development and delivery of a hybrid mobile app
======
Hybrid apps are a good middle ground between native and web apps.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/idea_innovation_mobile_phone.png?itok=RqVtvxkd)
Offering a mobile app is essentially a business requirement for organizations today. One of the first steps in developing an app is to understand the different types—native, hybrid (or cross-platform), and web—so you can decide which one will best meet your needs.
### Native is better, right?
**Native apps** represent the vast majority of applications that people download every day. Native applications are developed specifically for an operating system. Thus, a native iOS application will not work on an Android system and vice versa. To develop a native app, you need to know two things:
1. How to develop in a specific programming language (e.g., Swift for Apple devices; Java for Android)
2. The app will not work for other platforms
Even though native apps will work only on the platform they're developed for, they have several notable advantages over hybrid and web apps:
* Increased speed, reliability, and responsiveness and higher resolution, all of which provide a better user experience
* May work offline/without internet service
* Easier access to all phone features (e.g., accelerometer, camera, microphone)
### But my business is still linked to the web…
Most companies have focused their resources on web development and now want to enter the mobile market. But many don't have the right technical resources to develop a native app for each platform. For these companies, **hybrid** development is the right choice. In this model, developers can use their existing frontend skills to develop a single, cross-platform mobile app.
![Hybrid mobile apps][2]
Hybrid apps are a good middle ground: they're faster and less expensive to develop than native apps, and they offer more possibilities than web apps. The tradeoffs are they don't perform as well as native apps and developers can't maintain their existing tight focus on web development (as they could with web apps).
If you already are a fan of the [Angular][3] cross-platform development framework, I recommend trying the [Ionic][4] framework, which "lets web developers build, test, and deploy cross-platform hybrid mobile apps." I see Ionic as an extension of the [Apache Cordova][5] framework, which enables a normal web app (JS, HTML, or CSS) to run as a mobile app in a container. Ionic uses the base Cordova features that support the Angular development for its user interface.
The advantage of this approach is simple: the Angular paradigm is maintained, so developers can continue writing [TypeScript][6] files but target a build for Android, iOS, and Windows by properly configuring the development environment. It also provides two important tools:
* An appealing design and widget that are very similar to a native app's, so your hybrid app will look less "web"
* Cordova Plugins allow the app to communicate with all phone features
### What about the Node.js backend?
The programming world likes to standardize, which is why hybrid apps are so popular. Frontend developers' common skills are useful in the mobile world. But if we have a technology stack for the user interface, why not focus on a single backend with the same programming paradigm?
This makes [Node.js][7] an appealing option. Node.js is a JavaScript runtime built on the Chrome V8 JavaScript engine. It can make the API development backend very fast and easy, and it integrates fully with web technologies. You can develop a Cordova plugin, using your Node.js backend, internally in your hybrid app, as I did with the [nodejs-cordova-plugin][8]. This plugin, following the Cordova guidelines, integrates a mobile-compatible version of the Node.js platform to provide a full-stack mobile app.
If you need a simple CRUD Node.js backend, you can use my [API][9] [node generator][9] that generates an app using a [MongoDB][10] embedded database.
![Cordova Full Stack application][12]
### Deploying your app
Open source offers everything you need to deploy your app in the best way. You just need a GitHub repository and a good continuous integration tool. I recommend [Travis-ci][13], an excellent tool that allows you to build and deploy your product for every commit.
Travis-ci is a fork of the better known [Jenkins][14]. Like with Jenkins, you have to configure your pipeline through a configuration file (in this case a **.travis.yml** file) in your GitHub repo. See the [.travis.yml file][15] in my repository as an example.
![](https://opensource.com/sites/default/files/uploads/3-travis-ci-process.png)
In addition, this pipeline automatically delivers and installs your app on [Appetize.io][16], a web-based iOS simulator and Android emulator, for testing.
You can learn more in the [Cordova Android][17] section of my GitHub repository.
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/hybrid-mobile-app-development
作者:[Angelo Manganiello][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/amanganiello90
[b]: https://github.com/lujun9972
[1]: /file/416441
[2]: https://opensource.com/sites/default/files/uploads/1-title.png (Hybrid mobile apps)
[3]: https://angular.io/
[4]: https://ionicframework.com/
[5]: https://cordova.apache.org/
[6]: https://www.typescriptlang.org/
[7]: https://nodejs.org/
[8]: https://github.com/fullStackApp/nodejs-cordova-plugin
[9]: https://github.com/fullStackApp/generator-full-stack-api
[10]: https://www.mongodb.com/
[11]: /file/416351
[12]: https://opensource.com/sites/default/files/uploads/2-cordova-full-stack-app.png (Cordova Full Stack application)
[13]: https://travis-ci.org/
[14]: https://jenkins.io/
[15]: https://github.com/amanganiello90/java-angular-web-app/blob/master/.travis.yml
[16]: https://appetize.io/
[17]: https://github.com/amanganiello90/java-angular-web-app#cordova-android

View File

@ -0,0 +1,132 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Plan your own holiday calendar at the Linux command line)
[#]: via: (https://opensource.com/article/18/12/linux-toy-cal)
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
Plan your own holiday calendar at the Linux command line
======
Link commands together to build a colorful calendar, and then whisk it away in a snowstorm.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/uploads/linux-toy-cal.png?itok=S0F8RY9k)
Welcome to today's installment of the Linux command-line toys advent calendar. If this is your first visit to the series, you might be asking yourself, whats a command-line toy. Even I'm not quite sure, but generally, it could be a game or any simple diversion that helps you have fun at the terminal.
It's quite possible that some of you will have seen various selections from our calendar before, but we hope theres at least one new thing for everyone.
We've somehow made it to the seventh day of our series without creating an actual calendar to celebrate with, so let's use a command-line tool to do that today: **cal**. By itself, **cal** is perhaps not the most amazing of tools, but we can use a few other utilities to spice it up a bit.
Chances are, **cal** is installed on your system already. To use it in this instance, just type **cal**.
```
$ cal
    December 2018  
Su Mo Tu We Th Fr Sa
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
```
We aren't going to go into advanced usage in this article, so if you want to learn more about **cal** , go check out Opensource.com Community Moderator Don Watkin's excellent [overview of the date and cal commands][1].
Now, let's spice it up with a pretty box, as we covered in our previous Linux toy article. I'll use the diamonds box, and use a little bit of padding to get it nicely aligned.
```
$ cal | boxes -d diamonds -p a1l4t2 
       /\          /\          /\
    /\//\\/\    /\//\\/\    /\//\\/\
 /\//\\\///\\/\//\\\///\\/\//\\\///\\/\
//\\\//\/\\///\\\//\/\\///\\\//\/\\///\\
\\//\/                            \/\\//
 \/                                  \/
 /\           December 2018          /\
//\\      Su Mo Tu We Th Fr Sa      //\\
\\//                         1      \\//
 \/        2  3  4  5  6  7  8       \/
 /\        9 10 11 12 13 14 15       /\
//\\      16 17 18 19 20 21 22      //\\
\\//      23 24 25 26 27 28 29      \\//
 \/       30 31                      \/
 /\                                  /\
//\\/\                            /\//\\
\\///\\/\//\\\///\\/\//\\\///\\/\//\\\//
 \/\\///\\\//\/\\///\\\//\/\\///\\\//\/
    \/\\//\/    \/\\//\/    \/\\//\/
       \/          \/          \/
```
That looks nice, but for good measure, let's put the whole thing in a second box, just for fun. We'll use the scoll design this time.
```
cal | boxes -d diamonds -p a1t2l3 | boxes -a c -d scroll        
 / ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \
|  /~~\                                              /~~\  |
|\ \   |         /\          /\          /\         |   / /|
| \   /|      /\//\\/\    /\//\\/\    /\//\\/\      |\   / |
|  ~~  |   /\//\\\///\\/\//\\\///\\/\//\\\///\\/\   |  ~~  |
|      |  //\\\//\/\\///\\\//\/\\///\\\//\/\\///\\  |      |
|      |  \\//\/                            \/\\//  |      |
|      |   \/                                  \/   |      |
|      |   /\          December 2018           /\   |      |
|      |  //\\     Su Mo Tu We Th Fr Sa       //\\  |      |
|      |  \\//                        1       \\//  |      |
|      |   \/       2  3  4  5  6  7  8        \/   |      |
|      |   /\       9 10 11 12 13 14 15        /\   |      |
|      |  //\\     16 17 18 19 20 21 22       //\\  |      |
|      |  \\//     23 24 25 26 27 28 29       \\//  |      |
|      |   \/      30 31                       \/   |      |
|      |   /\                                  /\   |      |
|      |  //\\/\                            /\//\\  |      |
|      |  \\///\\/\//\\\///\\/\//\\\///\\/\//\\\//  |      |
|      |   \/\\///\\\//\/\\///\\\//\/\\///\\\//\/   |      |
|      |      \/\\//\/    \/\\//\/    \/\\//\/      |      |
|      |         \/          \/          \/         |      |
|      |                                            |      |
 \     |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|     /
  \   /                                              \   /
   ~~~                                                ~~~
```
Perfect. Now, here's where things get a little crazy. I like our design, but, I'd like to go all out. So I'm going to colorize it. But here in the Raleigh, NC office where Opensource.com's staff are based, there's a good chance for snow this weekend. So let's enjoy our colorized advent calendar, and then wipe it out with snow.
For the snow, I'm grabbing a nifty [snippet][2] of Bash and Gawk goodness I found over on CLIMagic. If you're not familiar with CLIMagic, go check out their [website][3] and follow them on [Twitter][4]. You'll be glad you did.
So here we go. Let's clear the screen, throw up our boxy calendar, colorize it, wait a few seconds, then snowstorm it away. All here at the terminal, in one line.
```
$ clear;cal|boxes -d diamonds -p a1t2l3|boxes -a c -d scroll|lolcat;sleep 3;while :;do echo $LINES $COLUMNS $(($RANDOM%$COLUMNS)) $(printf "\u2744\n");sleep 0.1;done|gawk '{a[$3]=0;for(x in a) {o=a[x];a[x]=a[x]+1;printf "\033[%s;%sH ",o,x;printf "\033[%s;%sH%s \033[0;0H",a[x],x,$4;}}'
```
And there we go.
![](https://opensource.com/sites/default/files/uploads/linux-toy-cal-animated.gif)
For this to work on your system, you'll need all of the referenced utilities (boxes, lolcat, cal, gawk, etc.), and you'll need to use a terminal emulator that supports Unicode.
Do you have a favorite command-line toy that you think I ought to profile? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.
Check out yesterday's toy, [Take a break at the Linux command line with Nyan Cat][5], and check back tomorrow for another!
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/linux-toy-cal
作者:[Jason Baker][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/jason-baker
[b]: https://github.com/lujun9972
[1]: https://opensource.com/article/16/12/using-calendar-function-linux
[2]: http://climagic.org/coolstuff/let-it-snow.html
[3]: http://climagic.org/
[4]: https://twitter.com/climagic
[5]: https://opensource.com/article/18/12/linux-toy-nyancat

View File

@ -0,0 +1,57 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Play Tetris at your Linux terminal)
[#]: via: (https://opensource.com/article/18/12/linux-toy-tetris)
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
Play Tetris at your Linux terminal
======
Recreate the magic of the 1980s with everyone's favorite tile-matching game, Tetris.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/uploads/linux-toy-tetris.png?itok=_UXtpgzN)
Thanks for joining us for today's installment of the Linux command-line toys advent calendar. If this is your first visit to the series, you might be asking yourself, whats a command-line toy. Even I'm not quite sure, but generally, it could be a game or any simple diversion that helps you have fun at the terminal.
It's quite possible that some of you will have seen various selections from our calendar before, but we hope theres at least one new thing for everyone.
I promised when I started this series I'd be including games, but so far I've neglected to, so let's fix that with today's selection: Tetris.
Tetris and I are almost exactly the same age, having first come into the world in the summer of 1984. Instead of rural North Carolina, though, Tetris originated in Moscow in what was at the time the Soviet Union.
After taking the world by storm, Tetris was cloned many, many times. I would suspect you could find a Tetris clone for just about any operating system in any language you looked for. Seriously, go look. There are some fun ones out there.
The [version][1] I'm bringing you for today's command-line toy is [written in Haskell,][1] and it's one of the better-done versions I've seen, with on-screen preview, score, help, and a clean look.
If you're willing to run a compiled binary from an untrusted source (I wouldn't recommend it), you can grab that directly, but for a safer approach, it's also easy to use a containerized version with [dex][2], or to install from source with [stack][3].
This particular Tetris clone is by Sam Tay and available under a BSD license. [Check it out][1]!
![](https://opensource.com/sites/default/files/uploads/linux-toy-tetris-animated.gif)
If you've got your own favorite Tetris clone (or maybe you've written your own?), let us know!
Do you have a favorite command-line toy that you think I ought to profile? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.
Check out yesterday's toy, [Plan your own holiday calendar at the Linux command line][4], and check back tomorrow for another!
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/linux-toy-tetris
作者:[Jason Baker][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/jason-baker
[b]: https://github.com/lujun9972
[1]: https://github.com/samtay/tetris
[2]: https://github.com/dockerland/dex
[3]: https://docs.haskellstack.org/en/stable/README/#how-to-install
[4]: https://opensource.com/article/18/12/linux-toy-cal

View File

@ -0,0 +1,52 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Powers of two, powers of Linux: 2048 at the command line)
[#]: via: (https://opensource.com/article/18/12/linux-toy-2048)
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
Powers of two, powers of Linux: 2048 at the command line
======
Looking for a terminal-based game to pass the time? Look no further than 2048-cli.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/uploads/linux-toy-2048.png?itok=3M6S-n1a)
Hello and welcome to today's installment of the Linux command-line toys advent calendar. Every day, we look at a different toy for your terminal: it could be a game or any simple diversion that helps you have fun.
Maybe you have seen various selections from our calendar before, but we hope theres at least one new thing for everyone.
Today's toy is a [command-line version][1] of one of my all-time favorite casual games, [2048][2] (which itself is a clone of another clone).
To play, you just slide blocks up, down, left, and right to combine matching pairs and increment numbers, until you've made a block that is 2048 in size. The catch (and the challenge), is that you can't just move one block; instead, you move every block on the screen.
It's simple, fun, and easy to get lost in it for hours. This 2048 clone, [2048-][1][cli][1], is by Marc Tiehuis and written in C, and made available as open source under an MIT license. You can find the source code [on GitHub][1], where you can also get installation instructions for your platform. Since it was packaged for Fedora, for me, installing it was as simple as:
```
$ sudo dnf install 2048-cli
```
That's it, have fun!
![](https://opensource.com/sites/default/files/uploads/linux-toy-2048-animated_0.gif)
Do you have a favorite command-line toy that you think I ought to profile? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.
Check out yesterday's toy, [Play Tetris at your Linux terminal][3], and check back tomorrow for another!
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/linux-toy-2048
作者:[Jason Baker][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/jason-baker
[b]: https://github.com/lujun9972
[1]: https://github.com/tiehuis/2048-cli
[2]: https://github.com/gabrielecirulli/2048
[3]: https://opensource.com/article/18/12/linux-toy-tetris

View File

@ -0,0 +1,257 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (5 Ways To Check Laptop Battery Status And Level From Linux Terminal)
[#]: via: (https://www.2daygeek.com/check-laptop-battery-status-and-charging-state-in-linux-terminal/)
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
5 Ways To Check Laptop Battery Status And Level From Linux Terminal
======
We can easily check the battery status through GUI such as current battery percentage, whether its charging or not charging and how long it will be usable without charging, but we cant able to check the battery health and other related information.
In this scenario what will be the solutions.
Yes, we have few utilities available for this in Linux and it can be achieved through command line.
We are going to discuss about this topic today through this article and i will try to cover possible information i can.
Checking your battery health monthly once is something good. It will help you to identify whether we are facing any battery or charge related issues.
Also, we can see battery model name, power source, vendor and battery technology, etc,.
Power management is a feature that turns off the power or switches systems components to a low-power state when inactive.
### Following Utilities are available in Linux to Check Battery Status.
* `upower`: upower is a command line tool which provides an interface to enumerate power sources on the system.
* `acpi`: acpi Shows information from the /proc or the /sys filesystem, such as battery status or thermal information.
* `batstat`: batstat is a command line tool to print battery status for linux.
* `tlp`: TLP brings you the benefits of advanced power management for Linux without changing any configuration.
* `class file`: The sysfs filesystem is a pseudo-filesystem which provides an interface to kernel data structures.
### How to Check Laptop Battery Status Using upower Command?
[upower][1] is a command line tool that provides an interface to enumerate power sources on the system. It control the latency of different operations on your computer, which enables you to save significant amounts of power.
Just run the following command to get the battery and its related information on Linux.
```
$ upower -i /org/freedesktop/UPower/devices/battery_BAT0
native-path: BAT0
vendor: SMP
model: L14M4P23
serial: 756
power supply: yes
updated: Monday 03 December 2018 07:56:18 PM IST (95 seconds ago)
has history: yes
has statistics: yes
battery
present: yes
rechargeable: yes
state: discharging
warning-level: none
energy: 28.23 Wh
energy-empty: 0 Wh
energy-full: 52.26 Wh
energy-full-design: 60 Wh
energy-rate: 10.714 W
voltage: 14.819 V
time to empty: 2.6 hours
percentage: 54%
capacity: 87.1%
technology: lithium-ion
icon-name: 'battery-good-symbolic'
History (charge):
1543847178 54.000 discharging
History (rate):
1543847178 10.714 discharging
```
To check the specific information about battery, use the following format.
```
$ upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -i "state\|percentage\|time to empty"
state: discharging
time to empty: 2.1 hours
percentage: 43%
```
Its same as above, but its taken after power cable plugged in, thats why the state showing charging.
```
$ upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -i "state\|percentage\|time to empty"
state: charging
percentage: 41%
```
### How to Check Laptop Battery Status Using TLP Command?
TLP is a free opensource feature-rich command line tool which optimize laptop battery without making any configuration change.
TLP brings you the benefits of advanced power management for Linux without the need to understand every technical detail. TLP comes with a default configuration already optimized for battery life, so you may just install and forget it. Nevertheless TLP is highly customizable to fulfil your specific requirements.
TLP package is available in most of the Linux distribution official repository such as Arch, Debian, Fedora, Gentoo, openSUSE, etc. Use your distribution Package Manager to install the TLP utility.
Just run the following command to get the battery and its related information on Linux.
```
$ sudo tlp-stat -b
--- TLP 1.1 --------------------------------------------
+++ Battery Status
/sys/class/power_supply/BAT0/manufacturer = SMP
/sys/class/power_supply/BAT0/model_name = L14M4P23
/sys/class/power_supply/BAT0/cycle_count = (not supported)
/sys/class/power_supply/BAT0/energy_full_design = 60000 [mWh]
/sys/class/power_supply/BAT0/energy_full = 52260 [mWh]
/sys/class/power_supply/BAT0/energy_now = 21950 [mWh]
/sys/class/power_supply/BAT0/power_now = 10923 [mW]
/sys/class/power_supply/BAT0/status = Discharging
Charge = 42.0 [%]
Capacity = 87.1 [%]
```
To see other information as well.
```
$ sudo tlp-stat -s
--- TLP 1.1 --------------------------------------------
+++ System Info
System = LENOVO Lenovo ideapad Y700-15ISK 80NV
BIOS = CDCN35WW
Release = "Manjaro Linux"
Kernel = 4.19.6-1-MANJARO #1 SMP PREEMPT Sat Dec 1 12:21:26 UTC 2018 x86_64
/proc/cmdline = BOOT_IMAGE=/boot/vmlinuz-4.19-x86_64 root=UUID=69d9dd18-36be-4631-9ebb-78f05fe3217f rw quiet resume=UUID=a2092b92-af29-4760-8e68-7a201922573b
Init system = systemd
Boot mode = BIOS (CSM, Legacy)
+++ TLP Status
State = enabled
Last run = 07:16:12 IST, 4362 sec(s) ago
Mode = battery
Power source = battery
```
### How to Check Laptop Battery Status Using ACPI Command?
ACPI stands for Advanced Configuration and Power Interface modules are kernel modules for different ACPI parts. They enable special ACPI functions or add information to /proc or /sys. These information can be parsed by acpid for events or other monitoring applications.
```
$ acpi
Battery 0: Charging, 43%, 01:05:11 until charged
```
To see battery capacity.
```
$ acpi -i
Battery 0: Charging, 43%, 01:05:07 until charged
Battery 0: design capacity 3817 mAh, last full capacity 3324 mAh = 87%
```
To see more details about battery and related information.
```
$ acpi -V
Battery 0: Charging, 43%, 01:05:07 until charged
Battery 0: design capacity 3815 mAh, last full capacity 3323 mAh = 87%
Adapter 0: on-line
Cooling 0: Processor 0 of 10
Cooling 1: Processor 0 of 10
Cooling 2: Processor 0 of 10
Cooling 3: iwlwifi 0 of 19
Cooling 4: Processor 0 of 10
Cooling 5: iwlwifi no state information available
Cooling 6: Processor 0 of 10
Cooling 7: Processor 0 of 10
Cooling 8: Processor 0 of 10
Cooling 9: intel_powerclamp no state information available
Cooling 10: x86_pkg_temp no state information available
Cooling 11: Processor 0 of 10
```
### How to Check Laptop Battery Status Using Batstat Command?
batstat is a command line tool to print battery status in linux terminal.
```
Status: Charging
Max energy: 50.00 Wh
Energy left: 24.50 Wh
Power Consumption: 26.40 W
Percentage left: 49.00%
Average power Consumption: 0.00 W
Time elapsed: 0: 0:12 since 49.00%
= Time ======== Percent ============================================
0: 0: 0 49.00%
```
### How to Check Laptop Battery Status Using sysfs filesystem?
The sysfs filesystem is a pseudo-filesystem which provides an interface to kernel data structures. The files under sysfs provide information about devices, kernel modules, filesystems, and other kernel components.
The sysfs filesystem is commonly mounted at /sys. Typically, it is mounted automatically by the system, but it can also be mounted manually using a command such as `mount -t sysfs sysfs /sys`
Many of the files in the sysfs filesystem are read-only, but some files are writable, allowing kernel variables to be changed. To avoid redundancy, symbolic links are heavily used to connect entries across the filesystem tree.
```
$ cat /sys/class/power_supply/BAT0/*
0
51
Normal
0
cat: /sys/class/power_supply/BAT0/device: Is a directory
52260000
60000000
26660000
SMP
L14M4P23
cat: /sys/class/power_supply/BAT0/power: Is a directory
27656000
1
756
Charging
cat: /sys/class/power_supply/BAT0/subsystem: Is a directory
Li-ion
Battery
POWER_SUPPLY_NAME=BAT0
POWER_SUPPLY_STATUS=Charging
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_TECHNOLOGY=Li-ion
POWER_SUPPLY_CYCLE_COUNT=0
POWER_SUPPLY_VOLTAGE_MIN_DESIGN=14800000
POWER_SUPPLY_VOLTAGE_NOW=15840000
POWER_SUPPLY_POWER_NOW=27656000
POWER_SUPPLY_ENERGY_FULL_DESIGN=60000000
POWER_SUPPLY_ENERGY_FULL=52260000
POWER_SUPPLY_ENERGY_NOW=26660000
POWER_SUPPLY_CAPACITY=51
POWER_SUPPLY_CAPACITY_LEVEL=Normal
POWER_SUPPLY_MODEL_NAME=L14M4P23
POWER_SUPPLY_MANUFACTURER=SMP
POWER_SUPPLY_SERIAL_NUMBER= 756
14800000
15840000
```
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/check-laptop-battery-status-and-charging-state-in-linux-terminal/
作者:[Magesh Maruthamuthu][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.2daygeek.com/author/magesh/
[b]: https://github.com/lujun9972
[1]: https://upower.freedesktop.org/

View File

@ -0,0 +1,175 @@
[#]: collector: (lujun9972)
[#]: translator: (LazyWolfLin)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to Update Ubuntu [Terminal & GUI Methods] It's FOSS)
[#]: via: (https://itsfoss.com/update-ubuntu/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
Translating by LazyWolfLin
How to Update Ubuntu [Terminal & GUI Methods] It's FOSS
======
**This tutorial shows you how to update Ubuntu for both server and desktop versions. It also explains the difference between update and upgrade along with a few other things you should know about updates in Ubuntu Linux.**
If you are a new user and have been using Ubuntu for a few days or weeks, you might be wondering how to update your [Ubuntu][1] system for security patches, bug fixes and application upgrades.
Updating Ubuntu is absolutely simple. I am not exaggerating. Its as simple as running two commands. Let me give you more details on it.
Please note that the tutorial is valid for Ubuntu 18.04, 16.04 or any other version. The command line way is also valid for Ubuntu-based distributions like Linux Mint, Linux Lite, elementary OS etc.
### Update Ubuntu via Command Line
![How to Update Ubuntu][2]
On the desktop, open the terminal. You can find it in the menu or use the Ctrl+Alt+T [keyboard shortcut][3]. If you are logged on to an [Ubuntu server][4], you already have access to a terminal.
In the terminal, you just have to use the following command:
```
sudo apt update && sudo apt upgrade -y
```
It will ask for password and you can use your accounts password. You wont see the anything on the screen while typing so keep on typing your password and hit enter.
Now let me explain the above command.
Actually, its not a single command. Its a combination of two commands. The && is a way to combine two commands in a way that the second command runs only when the previous command ran successfully.
The -y in the end automatically enters yes when the command apt upgrade ask for your confirmation before installing the updates.
Note that you can also use the two commands separately, one by one:
```
sudo apt update
sudo apt upgrade
```
It will take a little longer because you have to wait for one command to finish and then enter the second command.
#### Explanation: sudo apt update
This command updates the local database of available packages. If you wont run this command, the local database wont be updated and your system will not know if there are any new versions available.
This is why when you run the sudo apt update, youll see lots of URLs in the output. The command fetches the package information from the respective repositories (the URLs you see in the output).
![Updating Ubuntu Linux][5]
At the end of the command, it tells you how many packages can be upgraded. You can see these packages by running the following command:
```
apt list --upgradable
```
**Additional Reading:** Read this article to learn [what is Ign, Hit and Get in the apt update command output][6].
#### Explanation: sudo apt upgrade
This command matches the versions of installed packages with the local database. It collects all of them and then it will list all of the packages that have a newer version available. At this point, it will ask if you want to upgrade (the installed packages to the newer version).
![Update Ubuntu Linux via Command Line][7]
You can type yes, y or just press enter to confirm the installation of updates.
So the bottom line is that the sudo apt update checks for the availability of new versions while as the sudo apt upgrade actually performs the update.
The term update might be confusing as you might expect the apt update command to update the system by installing the updates but that doesnt happen.
### Update Ubuntu via GUI [For Desktop Users]
If you are using Ubuntu as a desktop, you dont have to go to terminal just for updating the system. You can still use the command line but its optional for you.
In the menu, look for Software Updater and run it.
![Run Software Updater in Ubuntu][8]
It will check if there are updates available for your system.
![Checking if updates are available for Ubuntu][9]
If there are updates available, it will give provide you with options to install the updates.
![Install Updates via Update Manager in Ubuntu][10]
Click on Install Now, it may ask for your password.
![Installing Updates in Ubuntu Linux via GUI][11]
Once you enter your password, it will start installing the updates.
![Updating Ubuntu via GUI][12]
In some cases, you may need to reboot the system for the installed updates to work properly. Youll be notified at the end of the update if you need to restart the system.
![Updating Ubuntu via GUI][12]
You can choose to restart later if you dont want to reboot your system straightaway.
![Installing updates via GUI in Ubuntu][13]
Tip: If the software updater returns an error, you should use the command sudo apt update in the terminal. The last few lines of the output will contain the actual error message. You can search on the internet for that error and fix the problem.
### Few things to keep in mind abou updating Ubuntu
You just learned how to update your Ubuntu system. If you are interested, you should also know these few things around Ubuntu updates.
#### Clean up after an update
Your system will have some unnecessary packages that wont be required after the updates. You can remove such packages and [free up some space][14] using this command:
```
sudo apt autoremove
```
#### Live patching kernel in Ubuntu Server to avoid rebooting
In case of a Linux kernel updates, youll have to restart the system after the update. This is an issue when you dont want downtime for your server.
[Live patching][15] feature allows the patching of Linux kernel while the kernel is still running. In other words, you dont have to reboot your system.
If you manage servers, you may want to [enable live patching in Ubuntu][16].
#### Version upgrades are different
The updates discussed here is to keep your Ubuntu install fresh and updated. It doesnt cover the [version upgrades][17] (for example upgrading Ubuntu 16.04 to 18.04).
[Ubuntu version][18] upgrades are entirely a different thing. It updates the entire operating system core. You need to make proper backups before starting this lengthy process.
### Conclusion
I hope you liked this tutorial on updating the Ubuntu system and you learned a few new things.
If you have any questions, please fee free to ask. If you are an experienced Linux users and have some tip that can make this tutorial more useful, please share it with the rest of us.
--------------------------------------------------------------------------------
via: https://itsfoss.com/update-ubuntu/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://www.ubuntu.com/
[2]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2018/12/how-to-update-ubuntu.png?resize=800%2C450&ssl=1
[3]: https://itsfoss.com/ubuntu-shortcuts/
[4]: https://www.ubuntu.com/download/server
[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/update-ubunt-1.jpeg?resize=800%2C357&ssl=1
[6]: https://itsfoss.com/apt-get-linux-guide/
[7]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2018/12/update-ubunt-2.jpeg?ssl=1
[8]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/update-ubuntu-via-GUI-1.jpeg?resize=800%2C250&ssl=1
[9]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2018/12/update-ubuntu-via-GUI-2.jpeg?resize=800%2C250&ssl=1
[10]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/update-ubuntu-GUI-3.jpeg?resize=800%2C365&ssl=1
[11]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2018/12/install-update-ubuntu-1.jpg?resize=800%2C450&ssl=1
[12]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/installing-updates-ubuntu.jpg?ssl=1
[13]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2018/12/installing-updates-ubuntu-2.jpeg?ssl=1
[14]: https://itsfoss.com/free-up-space-ubuntu-linux/
[15]: https://www.ubuntu.com/livepatch
[16]: https://www.cyberciti.biz/faq/howto-live-patch-ubuntu-linux-server-kernel-without-rebooting/
[17]: https://itsfoss.com/upgrade-ubuntu-version/
[18]: https://itsfoss.com/how-to-know-ubuntu-unity-version/

View File

@ -0,0 +1,113 @@
[#]: collector: (lujun9972)
[#]: translator: (qhwdw)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to get started in AI)
[#]: via: (https://opensource.com/article/18/12/how-get-started-ai)
[#]: author: (Gordon Haff https://opensource.com/users/ghaff)
How to get started in AI
======
Before you can begin working in artificial intelligence, you need to acquire some human intelligence.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/brain-think-ai-intelligence-ccby.png?itok=C-gK01E_)
I've both asked and been asked about the best way to learn more about artificial intelligence (AI). What should I read? What should I watch? I'll get to that. But, first, it's useful to break down this question, given that AI covers a lot of territory.
One important distinction to draw is between the research side of AI and the applied side. Cassie Kozyrkov of Google [drew this distinction][1] in a talk at the recent O'Reilly Artificial Intelligence Conference in London, and it's a good one.
Research AI is rather academic in nature and requires a heavy dose of math across a variety of disciplines before you even get to those parts that are specific to AI. This aspect of AI focuses on the algorithms and tools that drive the state of AI forward. For example, what neural network structures might improve vision recognition results? How might we make unsupervised learning a more generally useful approach? Can we find ways to understand better how deep learning pipelines come up with the answers they do?
Applied AI, on the other hand, is more about using existing tools to obtain useful results. Open source has played a big role here in providing free and often easy-to-use software in a variety of languages. Public cloud providers have also devoted a lot of attention to providing machine learning services, models, and datasets that make the onramp to getting started with AI much simpler than it would be otherwise.
I'll add at this point that applied AI practitioners shouldn't treat their tools as some sort of black box that spits out answers for mysterious reasons. At a minimum, they need to understand the limits and potential biases of different techniques, models, and data collection approaches. It's just that they don't necessarily need to delve deeply into all the theory underpinning every part of their toolchain.
Although it's probably less important for working in AI on a day-to-day basis, it's also useful to understand the broader context of AI. It goes beyond the narrow scope of deep learning on neural networks that have been so important to the gains made in reinforcement learning and supervised learning to date. For example, AI is often viewed as a way to augment (rather than replace) human judgment and decisions. But the handoff between machine and human has its own pitfalls.
With that background, here are some study areas and resources you may find useful.
### Research AI
In a lot of respects, a list of resources for research AI mirror those in an undergraduate (or even graduate) computer science program that's focused on AI. The main difference is that the syllabus you draw up may be more interdisciplinary than more traditionally focused university curricula.
Where you start will depend on your computer science and math background.
If it's minimal or rusty, but you still want to develop a deep understanding of AI fundamentals, you'll benefit from taking some math courses to start. There are many options on massive online open courses (MOOCs) like the nonprofit [edX][2] platform and [Coursera][3]. (Both platforms charge for certifications, but edX makes all the content available for free to people just auditing the course.)
Typical foundational courses could include:
+ [MIT's Calculus courses][22], starting with differentiation
+ [Linear Algebra][23] (University of Texas)
+ Probability and statistics, such as MIT's [Probability—The Science of Uncertainty and Data][24]
To get deeper into AI from a research perspective, you'll probably want to get into all these areas of mathematics and more. But the above should give you an idea of the general branches of study that are probably most important before delving into machine learning and AI proper.
In addition to MOOCs, resources such as [MIT OpenCourseWare][4] provide the syllabus and various supporting materials for a wide range of mathematics and computer science courses.
With the foundations in place, you can move onto more specialized courses in AI proper. Andrew Ng's AI MOOC, from when he was teaching at Stanford, was one of the early courses to popularize the whole online course space. Today, his [Neural Networks and Deep Learning][5] is part of the Deep Learning specialization at Coursera. There are corresponding programs on edX. For example, Columbia offers an [Artificial Intelligence MicroMasters][6].
In addition to courses, a variety of textbooks and other learning material are also available online. These include:
* [Neural Networks and Deep Learning][7]
* [Deep Learning][8] from MIT Press by Ian Goodfellow and Yoshua Bengio and Aaron Courville
### Applied AI
Applied AI is much more focused on using available tools than building new ones. Some appreciation of the mathematical underpinnings, especially statistics, is still useful—arguably even necessary—but you won't be majoring in that aspect of AI to the same degree you would in a research mode.
Programming is a core skill here. While different programming languages can come into play, a lot of libraries and toolsets—such as [PyTorch][9]—rely on Python, so that's a good skill to have. Especially if you have some level of programming background, MIT's [Introduction to Computer Science and Programming Using Python][10], based on its on-campus 6.001 course, is a good primer. If you're truly new to programming, Charles Severance's [Programming for Everybody (Getting Started with Python)][11] from the University of Michigan doesn't toss you into the deep end of the pool the way the MIT course does.
[The R programming language][12] is also a useful skill to add to your toolbox. While it's less used in machine learning (ML) per se, it's common for a variety of other data science tasks, and applied AI/ML and data science often blend in practice. For example, many tasks associated with organizing and cleaning data apply equally whatever analysis techniques you'll eventually use. A MOOC sequence like Harvard's [Data Science certificate][13] is an example of a set of courses that provide a good introduction to working with data.
Another open source software library you're likely to encounter if you do any work with AI is [TensorFlow][14]. It was originally developed by researchers and engineers from the Google Brain team within Google's AI organization. [Google offers a variety of tutorials][15] to get started with TensorFlow using the high-level Keras API. You can run TensorFlow locally as well as online in Google Cloud.
In general, all of the big public cloud providers offer online datasets and ML services that can be an easy way to get started. However, especially as you move beyond "play" datasets and applications, you need to start thinking seriously about the degree to which you want to be locked into a single provider.
Datasets for your exploratory learning projects are available from many different sources. In addition to the public cloud providers, [Kaggle][16] is another popular source and also a good learning resource more broadly. Government data is also increasingly available in digital form. The US Federal Government's [Data.gov][17] claims over 300,000 datasets. State and local governments also publish data on everything from restaurant health ratings to dogs' names.
### Miscellany
I'll close by noting that AI is a broad topic that isn't just about math, programming, and data. AI as a whole touches many other fields, including cognitive psychology, linguistics, game theory, operations research, and control systems. Indeed, a concern among at least some AI researchers today is that the field has become too fixated on a small number of techniques that have become powerful and interesting only quite recently because of the intersection of processing power and big data. Many longstanding problems in understanding how humans learn and reason remain largely unsolved. Developing at least some appreciation for these broader problem spaces will better enable you to place AI within a broader context.
One of my favorite examples is the [Humans and Autonomy Lab][18] at Duke. The work in this lab touches on all the challenges of humans working with machines, such as how autopilots can create ["Children of the Magenta"][19] who are unable to take control quickly if the automation fails. A basic brain-science course, such as MIT's [Introduction to Psychology][20], provides some useful context for the relationship between human intelligence and machine intelligence. Another course in a similar vein, but taught by the late Marvin Minsky from MIT's Electrical Engineering and Computer Science department, is [The Society of Mind][21].
If there's one key challenge to learning about AI, it's not that raw materials and tools aren't readily available. It's that there are so many of them. My objective hasn't been to give you a comprehensive set of pointers. Rather, it's been to both point out the different paths you can take and provide you with some possible starting points. Happy learning!
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/how-get-started-ai
作者:[Gordon Haff][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/ghaff
[b]: https://github.com/lujun9972
[1]: https://www.youtube.com/watch?v=RLtI7r3QUyY
[2]: https://www.edx.org/
[3]: https://www.coursera.org/
[4]: https://ocw.mit.edu/index.htm
[5]: https://www.coursera.org/learn/neural-networks-deep-learning
[6]: https://www.edx.org/micromasters/columbiax-artificial-intelligence
[7]: http://neuralnetworksanddeeplearning.com/
[8]: http://www.deeplearningbook.org/
[9]: https://pytorch.org/
[10]: https://www.edx.org/course/introduction-to-computer-science-and-programming-using-python
[11]: https://www.coursera.org/learn/python
[12]: https://www.r-project.org/about.html
[13]: https://www.edx.org/professional-certificate/harvardx-data-science
[14]: https://www.tensorflow.org/
[15]: https://www.tensorflow.org/tutorials/
[16]: https://www.kaggle.com/
[17]: https://www.data.gov/
[18]: https://hal.pratt.duke.edu/
[19]: https://99percentinvisible.org/episode/children-of-the-magenta-automation-paradox-pt-1/
[20]: https://ocw.mit.edu/courses/brain-and-cognitive-sciences/9-00sc-introduction-to-psychology-fall-2011/
[21]: https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-868j-the-society-of-mind-fall-2011/
[22]: https://www.edx.org/course/calculus-1a-differentiation
[23]: https://www.edx.org/course/linear-algebra-foundations-to-frontiers
[24]: https://courses.edx.org/courses/course-v1:MITx+6.431x+3T2018/course/

View File

@ -0,0 +1,160 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (McFly A Replacement To Ctrl+R Bash History Search Feature)
[#]: via: (https://www.ostechnix.com/mcfly-a-replacement-to-ctrlr-bash-history-search-feature/)
[#]: author: (SK https://www.ostechnix.com/author/sk/)
McFly A Replacement To Ctrl+R Bash History Search Feature
======
![](https://www.ostechnix.com/wp-content/uploads/2018/12/mcfly-720x340.png)
If you spend a lot of time on CLI mode, you should definitely used or heard about **reverse search** function in BASH. The keyboard shortcut to do reverse search in Bash is **Ctrl+r**. Using bash reverse search, we can bring up all commands which we used previously executed without having to re-type them every time. You can, of course, use UP/DOWN arrows to search your bash history. However, Ctrl+r will make this process much easier and faster. Today, I Stumbled upon a replacement to Ctrl+r Bash history search feature. Meet **“McFly”** , a simple tool written in **Rust** programming language that replaces the default Ctrl+r Bash history search with an intelligent search engine. All command suggestions made by McFly are prioritized in real time with a small **neural network**.
McFly rebinds Ctrl+r functionality to bring up all recently executed commands from your Bash history. It augments your shell history by tracking the following:
* Command exit status,
* timestamp (When you run the command),
* and execution directory (Where you run the command).
It saves all tracking details in a SQLite database. Since it tracks the commands historical exit status, you can simply ignore the old failed commands. Cool, yeah?
When suggesting a command, McFly considers the following facts:
* On which directory you ran the command. Youre likely to repeat that command in the same directory in future.
* What commands you typed before the command.
* How often you run the command.
* When you last ran the command.
* If youve selected the command in McFly before.
* The commands historical exit status. Because, you probably dont want to run old failed commands, right?
McFly maintains your default Bash history file, so you can stop using McFly at any time. McFly is not just for BASH, it is also extendable for other shells as well.
### Installing McFly
McFly can be installed using Linuxbrew on Linux. If you havent installed Linuxbrew yet, refer the following link.
[Linuxbrew A Common Package Manager For Linux And Mac OS X][1]
Once Linuxbrew installed, run the following commands to install McFly:
```
$ brew tap cantino/mcfly https://github.com/cantino/mcfly
$ brew install mcfly
```
After the installation is completed, you will see the following output.
```
==> Installing mcfly from cantino/mcfly
==> Downloading https://github.com/cantino/mcfly/releases/download/v0.2.5/mcfly-v0
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.c
######################################################################## 100.0%
==> ONE MORE STEP! Edit ~/.bashrc and add the following:
if [ -f $(brew --prefix)/opt/mcfly/mcfly.bash ]; then
. $(brew --prefix)/opt/mcfly/mcfly.bash
fi
🍺 /home/linuxbrew/.linuxbrew/Cellar/mcfly/v0.2.5: 4 files, 3.5MB, built in 33 seconds
```
![](https://www.ostechnix.com/wp-content/uploads/2018/12/install-mcfly.png)
As you can see, we need to do one more step before start using McFly.
Add the following lines to your **~/.bashrc** file:
```
if [ -f $(brew --prefix)/opt/mcfly/mcfly.bash ]; then
. $(brew --prefix)/opt/mcfly/mcfly.bash
fi
```
Finally, run the following command to take effects changes:
```
$ source ~/.bashrc
```
Your BASH history will be imported to McFly database when you run this command for the first time. It will take a few moments depending upon size of your bash history file. Once the import is done, you will see the following message.
```
McFly: Importing Bash history for the first time. This may take a minute or two...done.
```
You can now start using McFly.
### Usage
To search through your command history, just type mcfly search followed by the part of the command name and hit ENTER key. Mcfly will display the command suggestions based on the search query you just type.
```
$ mcfly search <part-of-the-command>
```
For instance, I type the following command:
```
$ mcfly search mk
```
Here is the sample output from my Ubuntu machine:
![](https://www.ostechnix.com/wp-content/uploads/2018/12/mcfly-command-1.png)
As you can see, I have used mkdir command two times. If you want to run a command from the list of suggestions, just use **UP/DOWN** arrows to select it and hit ENTER to run it immediately. If you want to edit a command, choose it and hit **TAB** key to bring it back to your Terminal and then edit before running it. To delete the selected command from the history, just press **F2**.
Alternatively, type the following command to open the history search and then type any command or part of the command to view the suggestions from your history.
```
$ mcfly search
```
McFly will display the command suggestions as you type.
Here is a short video demonstration of McFly:
![](https://www.ostechnix.com/wp-content/uploads/2018/12/mcfly-demo.gif)
View help:
```
$ mcfly --help
```
### Remove McFly
Dont like McFly, no problem! Remove it using the following commands:
```
$ brew uninstall mcfly
$ brew untap cantino/mcfly
```
Finally, remove the lines which we added earlier from **~/.bashrc** file.
And, thats all for now. More good stuffs to come. Stay tuned!
Cheers!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/mcfly-a-replacement-to-ctrlr-bash-history-search-feature/
作者:[SK][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.ostechnix.com/author/sk/
[b]: https://github.com/lujun9972
[1]: https://www.ostechnix.com/linuxbrew-common-package-manager-linux-mac-os-x/

View File

@ -0,0 +1,52 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Snake your way across your Linux terminal)
[#]: via: (https://opensource.com/article/18/12/linux-toy-snake)
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
Snake your way across your Linux terminal
======
Python isn't the only snake you'll find at the Linux command line with this classic 1970s game remake.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/uploads/linux-toy-snake.png?itok=oNhqUTDu)
Welcome back to the Linux command-line toys advent calendar. If this is your first visit to the series, you might be asking yourself what a command-line toy even is. It's hard to say exactly, but my definition is anything that helps you have fun at the terminal.
We've been on a roll with games over the weekend, and it was fun, so let's look at one more game today, Snake!
Snake is an oldie but goodie; versions of it have been around seemingly forever. The first version I remember playing was one called [Nibbles][1] that came packaged with [QBasic][2] in the 1990s, and was probably pretty important to my understanding of what a programming language even was. Here I had the source code to a game that I could modify and just see what happens, and maybe learn something about what all of those funny little words that made up a programming language were all about.
Today's [Snake][3] is written in Go, and while it's simple, it's just as much fun as the original. Like most simple old games, there are a ton of versions to choose from. In Snake's case, there's even a version in the classic [bsdgames][4] package that's almost certainly packaged for your distribution.
But what I like about this version of Snake is that it's packaged for Docker so I can easily run it in one line from my terminal without worrying about anything disto-specific. That, and it makes use of 15 randomized food emojis for the snake to eat. I'm a sucker for food emojis. Anyway, give it a try using:
```
$ docker run -ti dyego/snake-game
```
This Snake is licensed as open source under an MIT license, and you can check out the source code [on GitHub][3].
![](https://opensource.com/sites/default/files/uploads/linux-toy-snake-animated.gif)
Do you have a favorite command-line toy that you think I ought to profile? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.
Check out yesterday's toy, [Powers of two, powers of Linux: 2048 at the command line][5], and check back tomorrow for another!
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/linux-toy-snake
作者:[Jason Baker][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/jason-baker
[b]: https://github.com/lujun9972
[1]: https://en.wikipedia.org/wiki/Nibbles_(video_game)
[2]: https://en.wikipedia.org/wiki/QBasic
[3]: https://github.com/DyegoCosta/snake-game
[4]: https://github.com/vattam/BSDGames
[5]: https://opensource.com/article/18/12/linux-toy-2048

View File

@ -0,0 +1,265 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How To Benchmark Linux Commands And Programs From Commandline)
[#]: via: (https://www.ostechnix.com/how-to-benchmark-linux-commands-and-programs-from-commandline/)
[#]: author: (SK https://www.ostechnix.com/author/sk/)
How To Benchmark Linux Commands And Programs From Commandline
======
![](https://www.ostechnix.com/wp-content/uploads/2018/12/benchmark-720x340.png)
A while ago, I have written a guide about the [**alternatives to top, the command line utility**][1]. Some of the users asked me which one among those tools is best and on what basis (like features, contributors, years active, page requests etc.) I compared those tools. They also asked me to share the bench-marking results If I have any. Unfortunately, I didnt even know how to benchmark programs at that time. While searching for some simple and easy to use bench-marking tools to compare the Linux programs, I stumbled upon two utilities named **Bench** and **Hyperfine**. These are simple and easy-to-use command line tools to benchmark Linux commands and programs on Unix-like systems.
### 1\. Bench Tool
The **Bench** utility benchmarks one or more given commands/programs using **Haskells criterion** library and displays the output statistics in an easy-to-understandable format. This tool can be helpful where you need to compare similar programs based on the bench-marking result. We can also export the results to HTML format or CSV or templated output.
#### Installing Bench Utility
The bench utility can be installed in three methods.
**1\. Using Linuxbrew**
We can install Bench utility using Linuxbrew package manager. If you havent installed Linuxbrew yet, refer the following link.
After installing Linuxbrew, run the following command to install Bench:
```
$ brew install bench
```
**2\. Using Haskells stack tool**
First, install Haskell as described in the following link.
And then, run the following commands to install Bench.
```
$ stack setup
$ stack install bench
```
The stack will install bench to **~/.local/bin** or something similar. Make sure that the installation directory is on your executable search path before using bench tool. You will be reminded to do this even if you forgot.
**3\. Using Nix package manager**
Another way to install Bench is using **Nix** package manager. Install Nix as shown in the below link.
After installing Nix, install Bench tool using command:
```
$ nix-env -i bench
```
#### Benchmark Linux Commands And Programs Using Bench
It is time to start benchmarking the programs.
For instance, let me show you the benchmark result of ls -al command.
```
$ bench 'ls -al'
```
**Sample output:**
![](https://www.ostechnix.com/wp-content/uploads/2018/12/Benchmark-commands-1.png)
You must quote the commands when you use flags/options with them.
Similarly, you can benchmark any programs installed in your system. The following commands shows the benchmarking result of htop and ptop programs.
```
$ bench htop
$ bench ptop
```
![](https://www.ostechnix.com/wp-content/uploads/2018/12/Benchmark-commands-2-1.png)
Bench tool can benchmark multiple programs at once as well. Here is the benchmarking result of ls, htop, ptop programs.
```
$ bench ls htop ptop
```
Sample output:
![](https://www.ostechnix.com/wp-content/uploads/2018/12/Benchmark-commands-3.png)
We can also export the benchmark result to a HTML like below.
```
$ bench htop --output example.html
```
To export the result to CSV, just run:
```
$ bench htop --csv FILE
```
View help section:
```
$ bench --help
```
### **2. Hyperfine Benchmark Tool
**
**Hyperfine** is yet another command line benchmarking tool inspired by the Bench tool which we just discussed above. It is free, open source, cross-platform benchmarking program and written in **Rust** programming language. It has few additional features compared to the Bench tool as listed below.
* Statistical analysis across multiple runs.
* Support for arbitrary shell commands.
* Constant feedback about the benchmark progress and current estimates.
* Perform warmup runs before the actual benchmark.
* Cache-clearing commands can be set up before each timing run.
* Statistical outlier detection.
* Export benchmark results to various formats, such as CSV, JSON, Markdown.
* Parameterized benchmarks.
#### Installing Hyperfine
We can install Hyperfine using any one of the following methods.
**1\. Using Linuxbrew**
```
$ brew install hyperfine
```
**2\. Using Cargo**
Make sure you have installed Rust as described in the following link.
After installing Rust, run the following command to install Hyperfine via Cargo:
```
$ cargo install hyperfine
```
**3\. Using AUR helper programs**
Hyperfine is available in [**AUR**][2]. So, you can install it on Arch-based systems using any helper programs, such as [**YaY**][3], like below.
```
$ yay -S hyperfine
```
**4\. Download and install the binaries**
Hyperfine is available in binaries for Debian-based systems. Download the latest .deb binary file from the [**releases page**][4] and install it using dpkg package manager. As of writing this guide, the latest version was **1.4.0**.
```
$ wget https://github.com/sharkdp/hyperfine/releases/download/v1.4.0/hyperfine_1.4.0_amd64.deb
$ sudo dpkg -i hyperfine_1.4.0_amd64.deb
$ sudo apt install -f
```
#### Benchmark Linux Commands And Programs Using Hyperfine
To run a benchmark using Hyperfine, simply run it along with the program/command as shown below.
```
$ hyperfine 'ls -al'
```
![](https://www.ostechnix.com/wp-content/uploads/2018/12/hyperfine-1.png)
Benchmark multiple commands/programs:
```
$ hyperfine htop ptop
```
Sample output:
![](https://www.ostechnix.com/wp-content/uploads/2018/12/hyperfine-2.png)
As you can see at the end of the output, Hyperfine mentiones **htop ran 1.96 times faster than ptop** , so we can immediately conclude htop performs better than Ptop. This will help you to quickly find which program performs better when benchmarking multiple programs. We dont get this detailed output in Bench utility though.
Hyperfine will automatically determine the number of runs to perform for each command. By default, it will perform at least **10 benchmarking runs**. If you want to set the **minimum number of runs** (E.g 5 runs), use the `-m` **/`--min-runs`** option like below:
```
$ hyperfine --min-runs 5 htop ptop
```
Or,
```
$ hyperfine -m 5 htop ptop
```
Similarly, to perform **maximum number of runs** for each command, the command would be:
```
$ hyperfine --max-runs 5 htop ptop
```
Or,
```
$ hyperfine -M 5 htop ptop
```
We can even perform **exact number of runs** for each command using the following command:
```
$ hyperfine -r 5 htop ptop
```
As you may know, if the program execution time is limited by disk I/O, the benchmarking results can be heavily influenced by disk caches and whether they are cold or warm. Luckily, Hyperfine has the options to perform a certain number of program executions before performing the actual benchmark.
To perform NUM warmup runs (E.g 3) before the actual benchmark, use the **`-w`/**`--warmup` option like below:
```
$ hyperfine --warmup 3 htop
```
Just like Bench utility, Hyperfine also allows us to export the benchmark results to a given file. We can export the results to CSV, JSON, and Markdown formats.
For instance, to export the results in Markdown format, use the following command:
```
$ hyperfine htop ptop --export-markdown <FILE-NAME>
```
For more options and usage details, refer the help secion:
```
$ hyperfine --help
```
And, thats all for now. If you ever be in a situation where you need to benchmark similar and alternative programs, these tools might help to compare how they performs and share the details with your peers and colleagues.
More good stuffs to come. Stay tuned!
Cheers!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/how-to-benchmark-linux-commands-and-programs-from-commandline/
作者:[SK][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.ostechnix.com/author/sk/
[b]: https://github.com/lujun9972
[1]: https://www.ostechnix.com/some-alternatives-to-top-command-line-utility-you-might-want-to-know/
[2]: https://aur.archlinux.org/packages/hyperfine
[3]: https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/
[4]: https://github.com/sharkdp/hyperfine/releases

View File

@ -0,0 +1,111 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to Install Putty on Ubuntu and Other Linux Distributions)
[#]: via: (https://itsfoss.com/putty-linux/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
How to Install Putty on Ubuntu and Other Linux Distributions
======
If I am not wrong, [Putty][1] is perhaps the most popular SSH client for Windows.
In IT companies, the development environment is usually on a remote Linux system while the developers use Windows as their local system. Putty is used for connecting to the remote Linux system from the Windows machine.
Putty is not limited to Windows only. You can also use this open source software on Linux and macOS.
But wait! Why would you use a separate SSH client on Linux when you already have the real Linux terminal with you? There are several reasons why you would want to use Putty on Linux.
* You have used Putty for so long on Windows that you are more comfortable with it.
* You find it difficult to manually edit SSH config file to save the various SSH sessions. You prefer Puttys graphical way of storing SSH connection.
* You want to debug by connecting to raw sockets and serial ports.
Whatever may be the reason, if you want to use Putty on Ubuntu or any other Linux, you can certainly do so. Let me show you how to do that.
### Installing Putty on Ubuntu Linux
![Installing Putty on Linux][2]
The good news for the Ubuntu users is that Putty is available in the universe repository of Ubuntu.
To install Putty on Ubuntu, you should first make sure that the universe repository is enabled.
```
sudo add-apt-repository universe
```
Once you have the universe repository enabled, you should update Ubuntu with this command:
```
sudo apt update
```
After this, you can install Putty with this command:
```
sudo apt install putty
```
Once installed, you can start Putty by finding it in the menu.
As you can see in the screenshot below, the Linux version of Putty looks the same as the Windows version. Thats a relief because you wont have to fiddle around trying to find your way through a new and changed settings.
![Putty in Linux][3]
When you enter the remote systems [hostname][4] or IP address and connect to it, Putty will utilize the already saved SSH keys in your home directory.
![Using Putty in Ubuntu Linux][5]
### Installing Putty on other Linux distributions
[Putty is available for Debian][6] so you just need to use apt-get or aptitude for installing it.
```
sudo apt-get install putty
```
Putty is also available for Fedora/Red Hat and can be installed using the default package manager.
```
sudo dnf install putty
```
You can also easily install Putty in Arch Linux based distributions.
```
sudo pacman -S putty
```
Remember that Putty is an open source software. You can also install it via source code if you really want to. You can get the source code of Putty from the link below.
[Download Putty Source Code][8]
I would always prefer the native Linux terminal over an SSH client like Putty. I feel more at home with the GNOME terminal or [Terminator][7]. However, its up to an individuals choice to use the default terminal or Putty in Linux
What do you use for managing multiple SSH connections on Linux?
--------------------------------------------------------------------------------
via: https://itsfoss.com/putty-linux/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://www.putty.org/
[2]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/Putty-linux.png?resize=800%2C450&ssl=1
[3]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/putty-interface-ubuntu.jpeg?resize=800%2C503&ssl=1
[4]: https://itsfoss.com/change-hostname-ubuntu/
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2018/12/putty-interface-ubuntu-1.jpeg?resize=800%2C430&ssl=1
[6]: https://packages.debian.org/jessie/putty
[7]: https://launchpad.net/terminator
[8]: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

View File

@ -0,0 +1,85 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Winterize your Bash prompt in Linux)
[#]: via: (https://opensource.com/article/18/12/linux-toy-bash-prompt)
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
Winterize your Bash prompt in Linux
======
Your Linux terminal probably supports Unicode, so why not take advantage of that and add a seasonal touch to your prompt?
![](https://opensource.com/sites/default/files/styles/image-full-size/public/uploads/linux-toy-bash-prompt.png?itok=HK_kVn37)
Hello once again for another installment of the Linux command-line toys advent calendar. If this is your first visit to the series, you might be asking yourself what a command-line toy even is? Really, we're keeping it pretty open-ended: It's anything that's a fun diversion at the terminal, and we're giving bonus points for anything holiday-themed.
Maybe you've seen some of these before, maybe you haven't. Either way, we hope you have fun.
Today's toy is super-simple: It's your Bash prompt. Your Bash prompt? Yep! We've got a few more weeks of the holiday season left to stare at it, and even more weeks of winter here in the northern hemisphere, so why not have some fun with it.
Your Bash prompt currently might be a simple dollar sign ( **$** ), or more likely, it's something a little longer. If you're not sure what makes up your Bash prompt right now, you can find it in an environment variable called $PS1. To see it, type:
```
echo $PS1
```
For me, this returns:
```
[\u@\h \W]\$
```
The **\u** , **\h** , and **\W** are special characters for username, hostname, and working directory. There are others you can use as well; for help building out your Bash prompt, you can use [EzPrompt][1], an online generator of PS1 configurations that includes lots of options including date and time, Git status, and more.
You may have other variables that make up your Bash prompt set as well; **$PS2** for me contains the closing brace of my command prompt. See [this article][2] for more information.
To change your prompt, simply set the environment variable in your terminal like this:
```
$ PS1='\u is cold: '
jehb is cold:
```
To set it permanently, add the same code to your **/etc/bashrc **using your favorite text editor.
So what does this have to do with winterization? Well, chances are on a modern machine, your terminal support Unicode, so you're not limited to the standard ASCII character set. You can use any emoji that's a part of the Unicode specification, including a snowflake ❄, a snowman ☃, or a pair of skis 🎿. You've got plenty of wintery options to choose from.
```
🎄 Christmas Tree
🧥 Coat
🦌 Deer
🧤 Gloves
🤶 Mrs. Claus
🎅 Santa Claus
🧣 Scarf
🎿 Skis
🏂 Snowboarder
❄ Snowflake
☃ Snowman
⛄ Snowman Without Snow
🎁 Wrapped Gift
```
Pick your favorite, and enjoy some winter cheer. Fun fact: modern filesystems also support Unicode characters in their filenames, meaning you can technically name your next program **"❄❄❄❄❄.py"**. That said, please don't.
Do you have a favorite command-line toy that you think I ought to include? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.
Check out yesterday's toy, [Snake your way across your Linux terminal][3], and check back tomorrow for another!
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/linux-toy-bash-prompt
作者:[Jason Baker][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/jason-baker
[b]: https://github.com/lujun9972
[1]: http://ezprompt.net/
[2]: https://access.redhat.com/solutions/505983
[3]: https://opensource.com/article/18/12/linux-toy-snake

View File

@ -0,0 +1,133 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Aliases: DIY Shell Commands)
[#]: via: (https://www.linux.com/blog/learn/2018/12/aliases-diy-shell-commands)
[#]: author: (Paul Brown https://www.linux.com/users/bro66)
Aliases: DIY Shell Commands
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/jodi-mucha-540841-unsplash.jpg?itok=n1d1VDUV)
Aliases, in the context of the Linux shell, are **commands you build yourself** by packing them with combinations of other instructions that are too long or too hard to remember.
You create an alias by using the word `alias`, then the name of the command you want to create, an equal sign (`=`), and then the Bash command(s) you want your alias to run. For example, `ls` in its base form does not colorize its output, making it difficult to distinguish between directories, files, and links. You can build a new command that shows colors by making an alias like this:
```
alias lc='ls --color=auto'
```
where `lc` is the name you have picked for your new command. When creating aliases, be sure to check that the name you picked isn't already in use, or you may override an existing command. In this case, `lc` stands for "list (with) color". Notice there is no space in front of or behind the `=`. Finally, you have the regular Bash command(s) you want to run when `lc` is executed. In this case, the `ls` command with the `--color` option.
After defining your alias, every time you type `lc`, the contents of the current directory will be shown in color.
But, you may think, "my `ls` command already lists files in different colors!" That is because most Linux distros come with some aliases already set up for you.
### Aliases you (probably) already have
Indeed, you can use the `alias` instruction without any options to see what aliases you already have. These will vary by distro, but some typical preset aliases are:
* `alias ls='ls --color=auto'`: You already saw this one above. The `auto` modifier of the `--color` option tells `ls` to use color when standard output is connected to a terminal. That is, the output of `ls` is going to show up in a terminal window or a text screen, instead of, say, being piped to a file. Other alternatives for `--color` are `always` and `never`.
* `alias cp='cp -i'`: The `-i` option stands for _interactive_. Sometimes, when you use `cp` you may inadvertently overwrite an existing file. By using the `-i`, `cp` will ask you before clobbering anything.
* `alias free='free -m'`: Using `-m` with `free`you can see how much free memory you have and how much your applications are using in megabytes instead of the default bytes. This makes the output of `free` easier to read for a human.
There may be more (or less, or even none), but regardless of what your distribution comes with, you can always use the base form (vs. the aliased form) of a command with the `\` modifier. For example:
```
\free
```
will execute `free` without the `-m` option, and
```
\ls
```
will execute `ls` without the `--color=auto` option.
If you want to get rid or modify the preset aliases forever, note that they live in the global _.bashrc_ file which hangs out in [our old haunt, the _/etc/skel_ directory][1].
### Aliases for muscle memory
Distro designers try their best to predict which aliases are going to be useful for you. But every user is different and comes from a different background. If you are new to GNU+Linux, it may be because you are coming from another system, and the basic commands vary from shell to shell. If you come from a Windows/MS-DOS background, you may want to define an alias like
```
alias dir='ls'
```
to list files or directories.
Likewise,
```
alias copy='cp'
alias move='mv'
```
may also come in handy, at least until you get used to Linux's new lexicon.
The other problem occurs when mistakes become ingrained in your muscle memory, so you always mistype some words the same way. I, for instance, have great difficulty typing _admnis-_... _adminsi-_... _A-D-M-I-N-I-S-T-R-A-T-I-ON_ ( _phew!_ ) at speed. That is why some users create aliases like
```
alias sl='ls'
```
and
```
alias gerp='echo "You did it *again*!"; grep'
```
Although we haven't formally introduced `grep` yet, in its most basic form, it looks for a string of characters in a file or a set of files. It's one of those commands that you will tend to use A LOT once you get to grips with it, as those ingrained mistyping habits that force you to type the instruction twice every time get annoying really quickly.
Another thing to note in the `gerp` example is that it is not a single instruction, but two. The first one (`echo "You did it *again*!"`) prints out a message reminding you that you misspelled the grep command, then there is a semicolon (`;`) that separates one instruction from the other. Finally, you've got the second command (`grep`) that does the actual grepping.
Using `gerp` on my system to search for the lines containing the word " _alias_ " in _/etc/skel/.bashrc_ , the output looks like this:
```
$ gerp -R alias /etc/skel/.bashrc
You did it *again*!
alias ls='ls --color=auto'
alias grep='grep --colour=auto'
alias egrep='egrep --colour=auto'
alias fgrep='fgrep --colour=auto'
alias cp="cp -i"
alias df='df -h'
alias free='free -m'
alias np='nano -w PKGBUILD'
alias more=less
shopt -s expand_aliases
```
Running commands sequentially as part of an alias, or, even better, chaining commands so that one command can use the results coughed up by another, is getting us perilously close to Bash scripting. This has been in the making of this series for quite some time, and we'll start covering it in the very next article.
For the time being, if you want to get rid of an alias you temporarily set up in a running terminal, use the `unalias` command:
```
unalias gerp
```
If you want to make your aliases permanent, you can drop them into the _.bashrc_ file you have in your home directory. This is the same thing we did with custom environment variables in [last week's article][2].
See you next time!
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/learn/2018/12/aliases-diy-shell-commands
作者:[Paul Brown][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.linux.com/users/bro66
[b]: https://github.com/lujun9972
[1]: https://www.linux.com/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts
[2]: https://www.linux.com/blog/learn/2018/12/bash-variables-environmental-and-otherwise

View File

@ -0,0 +1,454 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to Build a Netboot Server, Part 2)
[#]: via: (https://fedoramagazine.org/how-to-build-a-netboot-server-part-2/)
[#]: author: (Gregory Bartholomew https://fedoramagazine.org/author/glb/)
How to Build a Netboot Server, Part 2
======
![](https://fedoramagazine.org/wp-content/uploads/2018/12/netboot2-816x345.jpg)
The article [How to Build a Netboot Server, Part 1][1] showed you how to create a netboot image with a “liveuser” account whose home directory lives in volatile memory. Most users probably want to preserve files and settings across reboots, though. So this second part of the netboot series shows how to reconfigure the netboot image from part one so that [Active Directory][2] user accounts can log in and their home directories can be automatically mounted from a NFS server.
Part 3 of this series will show how to make an interactive and centrally-configurable iPXE boot menu for the netboot clients.
### Setup NFS4 Home Directories with KRB5 Authentication
Follow the directions from the previous post “[Share NFS Home Directories Securely with Kerberos][3],” then return here.
### Remove the Liveuser Account
Remove the “liveuser” account created in part one of this series:
```
$ sudo -i
# sed -i '/automaticlogin/Id' /fc28/etc/gdm/custom.conf
# rm -f /fc28/etc/sudoers.d/liveuser
# for i in passwd shadow group gshadow; do sed -i '/^liveuser:/d' /fc28/etc/$i; done
```
### Configure NTP, KRB5 and SSSD
Next, we will need to duplicate the NTP, KRB5, and SSSD configuration that we set up on the server in the client image so that the same accounts will be available:
```
# MY_HOSTNAME=$(</etc/hostname)
# MY_DOMAIN=${MY_HOSTNAME#*.}
# dnf -y --installroot=/fc28 install ntp krb5-workstation sssd
# cp /etc/ntp.conf /fc28/etc
# chroot /fc28 systemctl enable ntpd.service
# cp /etc/krb5.conf.d/${MY_DOMAIN%%.*} /fc28/etc/krb5.conf.d
# cp /etc/sssd/sssd.conf /fc28/etc/sssd
```
Reconfigure sssd to provide authentication services, in addition to the identification service already configured:
```
# sed -i '/services =/s/$/, pam/' /fc28/etc/sssd/sssd.conf
```
Also, ensure none of the clients attempt to update the computer account password:
```
# sed -i '/id_provider/a \ \ ad_maximum_machine_account_password_age = 0' /fc28/etc/sssd/sssd.conf
```
Also, copy the nfsnobody definitions:
```
# for i in passwd shadow group gshadow; do grep "^nfsnobody:" /etc/$i >> /fc28/etc/$i; done
```
### Join Active Directory
Next, youll perform a chroot to join the client image to Active Directory. Begin by deleting any pre-existing computer account with the same name your netboot image will use:
```
# MY_USERNAME=jsmith
# MY_CLIENT_HOSTNAME=$(</fc28/etc/hostname)
# adcli delete-computer "${MY_CLIENT_HOSTNAME%%.*}" -U "$MY_USERNAME"
```
Also delete the krb5.keytab file from the netboot image if it exists:
```
# rm -f /fc28/etc/krb5.keytab
```
Perform a chroot into the netboot image:
```
# for i in dev dev/pts dev/shm proc sys run; do mount -o bind /$i /fc28/$i; done
# chroot /fc28 /usr/bin/bash --login
```
Perform the join:
```
# MY_USERNAME=jsmith
# MY_HOSTNAME=$(</etc/hostname)
# MY_DOMAIN=${MY_HOSTNAME#*.}
# MY_REALM=${MY_DOMAIN^^}
# MY_OU="cn=computers,dc=${MY_DOMAIN//./,dc=}"
# adcli join $MY_DOMAIN --login-user="$MY_USERNAME" --computer-name="${MY_HOSTNAME%%.*}" --host-fqdn="$MY_HOSTNAME" --user-principal="host/$MY_HOSTNAME@$MY_REALM" --domain-ou="$MY_OU"
```
Now log out of the chroot and clear the root users command history:
```
# logout
# for i in run sys proc dev/shm dev/pts dev; do umount /fc28/$i; done
# > /fc28/root/.bash_history
```
### Install and Configure PAM Mount
We want our clients to automatically mount the users home directory when they log in. To accomplish this, well use the “pam_mount” module. Install and configure pam_mount:
```
# dnf install -y --installroot=/fc28 pam_mount
# cat << END > /fc28/etc/security/pam_mount.conf.xml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE pam_mount SYSTEM "pam_mount.conf.xml.dtd">
<pam_mount>
<debug enable="0" />
<volume uid="1400000000-1499999999" fstype="nfs4" server="$MY_HOSTNAME" path="/home/%(USER)" mountpoint="/home/%(USER)" options="sec=krb5" />
<mkmountpoint enable="1" remove="0" />
<msg-authpw>Password:</msg-authpw>
</pam_mount>
END
```
Reconfigure PAM to use pam_mount:
```
# dnf install -y patch
# cp -r /fc28/usr/share/authselect/default/sssd /fc28/etc/authselect/custom
# echo 'initgroups: files' >> /fc28/etc/authselect/custom/sssd/nsswitch.conf
# patch /fc28/etc/authselect/custom/sssd/system-auth << END
@@ -12 +12,2 @@
-auth sufficient pam_sss.so forward_pass
+auth requisite pam_mount.so {include if "with-pammount"}
+auth sufficient pam_sss.so {if "with-pammount":use_first_pass|forward_pass}
@@ -35,2 +36,3 @@
session required pam_unix.so
+session optional pam_mount.so {include if "with-pammount"}
session optional pam_sss.so
END
# patch /fc28/etc/authselect/custom/sssd/password-auth << END
@@ -9 +9,2 @@
-auth sufficient pam_sss.so forward_pass
+auth requisite pam_mount.so {include if "with-pammount"}
+auth sufficient pam_sss.so {if "with-pammount":use_first_pass|forward_pass}
@@ -32,2 +33,3 @@
session required pam_unix.so
+session optional pam_mount.so {include if "with-pammount"}
session optional pam_sss.so
END
# chroot /fc28 authselect select custom/sssd with-pammount --force
```
Also ensure the NFS servers hostname is always resolvable from the client:
```
# MY_IP=$(host -t A $MY_HOSTNAME | awk '{print $4}')
# echo "$MY_IP $MY_HOSTNAME ${MY_HOSTNAME%%.*}" >> /fc28/etc/hosts
```
Optionally, allow all users to run sudo:
```
# echo '%users ALL=(ALL) NOPASSWD: ALL' > /fc28/etc/sudoers.d/users
```
### Convert the NFS Root to an iSCSI Backing-Store
Current versions of nfs-utils may have difficulty establishing a second connection from the client back to the NFS server for home directories when an nfsroot connection is already established. The client hangs when attempting to access the home directory. So, we will work around the problem by using a different protocol (iSCSI) for sharing our netboot image.
First chroot into the image to reconfigure its initramfs for booting from an iSCSI root:
```
# for i in dev dev/pts dev/shm proc sys run; do mount -o bind /$i /fc28/$i; done
# chroot /fc28 /usr/bin/bash --login
# dnf install -y iscsi-initiator-utils
# sed -i 's/nfs/iscsi/' /etc/dracut.conf.d/netboot.conf
# echo 'omit_drivers+=" qedi "' > /etc/dracut.conf.d/omit-qedi.conf
# echo 'blacklist qedi' > /etc/modprobe.d/blacklist-qedi.conf
# KERNEL=$(ls -c /lib/modules | head -n 1)
# INITRD=$(find /boot -name 'init*' | grep -m 1 $KERNEL)
# dracut -f $INITRD $KERNEL
# logout
# for i in run sys proc dev/shm dev/pts dev; do umount /fc28/$i; done
# > /fc28/root/.bash_history
```
The qedi driver broke iscsi during testing, so its been disabled here.
Next, create a fc28.img [sparse file][4]. This file serves as the iSCSI targets backing store:
```
# FC28_SIZE=$(du -ms /fc28 | cut -f 1)
# dd if=/dev/zero of=/fc28.img bs=1MiB count=0 seek=$(($FC28_SIZE*2))
```
(If you have one available, a separate partition or disk drive can be used instead of creating a file.)
Next, format the image with a filesystem, mount it, and copy the netboot image into it:
```
# mkfs -t xfs -L NETROOT /fc28.img
# TEMP_MNT=$(mktemp -d)
# mount /fc28.img $TEMP_MNT
# cp -a /fc28/* $TEMP_MNT
# umount $TEMP_MNT
```
During testing using SquashFS, the client would occasionally stutter. It seems that SquashFS does not perform well when doing random I/O from a multiprocessor client. (See also [The curious case of stalled squashfs reads][5].) If you want to improve throughput performance with filesystem compression, [ZFS][6] is probably a better option.
If you need extremely high throughput from the iSCSI server (say, for hundreds of clients), it might be possible to [load balance][7] a [Ceph][8] cluster. For more information, see [Load Balancing Ceph Object Gateway Servers with HAProxy and Keepalived][9].
### Install and Configure iSCSI
Install the scsi-target-utils package which will provide the iSCSI daemon for serving our image out to our clients:
```
# dnf install -y scsi-target-utils
```
Configure the iSCSI daemon to serve the fc28.img file:
```
# MY_REVERSE_HOSTNAME=$(echo $MY_HOSTNAME | tr '.' "\n" | tac | tr "\n" '.' | cut -b -${#MY_HOSTNAME})
# cat << END > /etc/tgt/conf.d/fc28.conf
<target iqn.$MY_REVERSE_HOSTNAME:fc28>
backing-store /fc28.img
readonly 1
</target>
END
```
The leading iqn. is expected by /usr/lib/dracut/modules.d/40network/net-lib.sh.
Add an exception to the firewall and enable and start the service:
```
# firewall-cmd --add-service=iscsi-target
# firewall-cmd --runtime-to-permanent
# systemctl enable tgtd.service
# systemctl start tgtd.service
```
You should now be able to see the image being shared with the tgtadm command:
```
# tgtadm --mode target --op show
```
The above command should output something similar to the following:
```
Target 1: iqn.edu.example.server-01:fc28
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: null
Backing store path: None
Backing store flags:
  LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 10488 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: Yes
SWP: No
Thin-provisioning: No
Backing store type: rdwr
Backing store path: /fc28.img
Backing store flags:
Account information:
ACL information:
ALL
```
We can now remove the NFS share that we created in part one of this series:
```
# rm -f /etc/exports.d/fc28.exports
# exportfs -rv
# umount /export/fc28
# rmdir /export/fc28
# sed -i '/^\/fc28 /d' /etc/fstab
```
You can also delete the /fc28 filesystem, but you may want to keep it for performing future updates.
### Update the ESP to use the iSCSI Kernel
Ipdate the ESP to contain the iSCSI-enabled initramfs:
```
$ rm -vf $HOME/esp/linux/*.fc28.*
$ MY_KRNL=$(ls -c /fc28/lib/modules | head -n 1)
$ cp $(find /fc28/lib/modules -maxdepth 2 -name 'vmlinuz' | grep -m 1 $MY_KRNL) $HOME/esp/linux/vmlinuz-$MY_KRNL
$ cp $(find /fc28/boot -name 'init*' | grep -m 1 $MY_KRNL) $HOME/esp/linux/initramfs-$MY_KRNL.img
```
Update the boot.cfg file to pass the new root and netroot parameters:
```
$ MY_NAME=server-01.example.edu
$ MY_EMAN=$(echo $MY_NAME | tr '.' "\n" | tac | tr "\n" '.' | cut -b -${#MY_NAME})
$ MY_ADDR=$(host -t A $MY_NAME | awk '{print $4}')
$ sed -i "s! root=[^ ]*! root=/dev/disk/by-path/ip-$MY_ADDR:3260-iscsi-iqn.$MY_EMAN:fc28-lun-1 netroot=iscsi:$MY_ADDR::::iqn.$MY_EMAN:fc28!" $HOME/esp/linux/boot.cfg
```
Now you just need to copy the updated files from your $HOME/esp/linux directory out to the ESPs of all your client systems. You should see results similar to what is shown in the below screenshot:
![][10]
### Upgrading the Image
First, make a copy of the current image:
```
# cp -a /fc28 /fc29
```
Chroot into the new copy of the image:
```
# for i in dev dev/pts dev/shm proc sys run; do mount -o bind /$i /fc29/$i; done
# chroot /fc29 /usr/bin/bash --login
```
Allow updating the kernel:
```
# sed -i 's/^exclude=kernel-\*$/#exclude=kernel-*/' /etc/dnf/dnf.conf
```
Perform the upgrade:
```
# dnf distro-sync -y --releasever=29
```
Prevent the kernel from being updated:
```
# sed -i 's/^#exclude=kernel-\*$/exclude=kernel-*/' /etc/dnf/dnf.conf
```
The above command is optional, but saves you from having to copy a new kernel out to the clients if you add or update a few packages in the image at some future time.
Clean up dnfs package cache:
```
# dnf clean all
```
Exit the chroot and clear roots command history:
```
# logout
# for i in run sys proc dev/shm dev/pts dev; do umount /fc29/$i; done
# > /fc29/root/.bash_history
```
Create the iSCSI image:
```
# FC29_SIZE=$(du -ms /fc29 | cut -f 1)
# dd if=/dev/zero of=/fc29.img bs=1MiB count=0 seek=$(($FC29_SIZE*2))
# mkfs -t xfs -L NETROOT /fc29.img
# TEMP_MNT=$(mktemp -d)
# mount /fc29.img $TEMP_MNT
# cp -a /fc29/* $TEMP_MNT
# umount $TEMP_MNT
```
Define a new iSCSI target that points to our new image and export it:
```
# MY_HOSTNAME=$(</etc/hostname)
# MY_REVERSE_HOSTNAME=$(echo $MY_HOSTNAME | tr '.' "\n" | tac | tr "\n" '.' | cut -b -${#MY_HOSTNAME})
# cat << END > /etc/tgt/conf.d/fc29.conf
<target iqn.$MY_REVERSE_HOSTNAME:fc29>
backing-store /fc29.img
readonly 1
</target>
END
# tgt-admin --update ALL
```
Add the new kernel and initramfs to the ESP:
```
$ MY_KRNL=$(ls -c /fc29/lib/modules | head -n 1)
$ cp $(find /fc29/lib/modules -maxdepth 2 -name 'vmlinuz' | grep -m 1 $MY_KRNL) $HOME/esp/linux/vmlinuz-$MY_KRNL
$ cp $(find /fc29/boot -name 'init*' | grep -m 1 $MY_KRNL) $HOME/esp/linux/initramfs-$MY_KRNL.img
```
Update the boot.cfg in the ESP:
```
$ MY_DNS1=192.0.2.91
$ MY_DNS2=192.0.2.92
$ MY_NAME=server-01.example.edu
$ MY_EMAN=$(echo $MY_NAME | tr '.' "\n" | tac | tr "\n" '.' | cut -b -${#MY_NAME})
$ MY_ADDR=$(host -t A $MY_NAME | awk '{print $4}')
$ cat << END > $HOME/esp/linux/boot.cfg
#!ipxe
kernel --name kernel.efi \${prefix}/vmlinuz-$MY_KRNL initrd=initrd.img ro ip=dhcp rd.peerdns=0 nameserver=$MY_DNS1 nameserver=$MY_DNS2 root=/dev/disk/by-path/ip-$MY_ADDR:3260-iscsi-iqn.$MY_EMAN:fc29-lun-1 netroot=iscsi:$MY_ADDR::::iqn.$MY_EMAN:fc29 console=tty0 console=ttyS0,115200n8 audit=0 selinux=0 quiet
initrd --name initrd.img \${prefix}/initramfs-$MY_KRNL.img
boot || exit
END
```
Finally, copy the files from your $HOME/esp/linux directory out to the ESPs of all your client systems and enjoy!
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/how-to-build-a-netboot-server-part-2/
作者:[Gregory Bartholomew][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://fedoramagazine.org/author/glb/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/how-to-build-a-netboot-server-part-1/
[2]: https://en.wikipedia.org/wiki/Active_Directory
[3]: https://fedoramagazine.org/secure-nfs-home-directories-kerberos
[4]: https://en.wikipedia.org/wiki/Sparse_file
[5]: https://chrisdown.name/2018/04/17/kernel-adventures-the-curious-case-of-squashfs-stalls.html
[6]: https://en.wikipedia.org/wiki/ZFS
[7]: https://en.wikipedia.org/wiki/Load_balancing_(computing)
[8]: http://docs.ceph.com/docs/mimic/rbd/iscsi-overview/
[9]: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/load_balancer_administration/ceph_example
[10]: https://fedoramagazine.org/wp-content/uploads/2018/12/netboot-screenshot-1024x819.png

View File

@ -0,0 +1,54 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Patch into The Matrix at the Linux command line)
[#]: via: (https://opensource.com/article/18/12/linux-toy-cmatrix)
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
Patch into The Matrix at the Linux command line
======
Recreate the classic look and feel of everyone's favorite 1990s sci-fi movie code scroller with cmatrix.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/uploads/linux-toy-cmatrix.png?itok=YlmbHVPr)
You've found your way to today's entry from the Linux command-line toys advent calendar. If this is your first visit to the series, you might be wondering what a command-line toy even is? It's anything that's an entertaining diversion at the terminal, be it a game, a fun utility, or a simple distraction.
Some of these are classics, and some are completely new (at least to me), but I hope all of you find something you enjoy in this series.
As we come to the close of another year, it's a good time for looking back, and looking forward. What will 2019 hold for you? What does it mean to be 2019?
I'm reminded that 2019 will mark the twentieth anniversary of one of my favorite science fiction movies from my teenage years, that at the time had me thinking a lot about what the future would hold: [The Matrix][1]. For a computer nerd kid like me, it was the ultimate story of a computer programmer rising up and becoming an action hero in a virtual universe by tapping into the power of his mind.
At the time, there was no movie that seemed more futuristic to me; both in the story itself, and in the mesmerizing special effects. Realizing that it was filmed over twenty years ago doesn't change that in my mind.
Bringing it back to our command-line toy for today, let's recreate the downward flowing code of the Matrix at our terminal with **cmatrix**. **cmatrix** was an easy install for me, packaged for Fedora, so installing it took simply:
```
$ dnf install cmatrix
```
Then, just type **cmatrix **at your terminal to run.
![](https://opensource.com/sites/default/files/uploads/linux-toy-cmatrix-animated.gif)
You can find the source code for **** **cmatrix** [on GitHub][2] under a GPL license.
Do you have a favorite command-line toy that you think I ought to include? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.
Check out yesterday's toy, [Winterize your Bash prompt in Linux][3], and check back tomorrow for another!
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/linux-toy-cmatrix
作者:[Jason Baker][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/jason-baker
[b]: https://github.com/lujun9972
[1]: https://en.wikipedia.org/wiki/The_Matrix
[2]: https://github.com/abishekvashok/cmatrix
[3]: https://opensource.com/article/18/12/linux-toy-bash-prompt

View File

@ -0,0 +1,122 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Top 5 configuration management tools)
[#]: via: (https://opensource.com/article/18/12/configuration-management-tools)
[#]: author: (Marco Bravo https://opensource.com/users/marcobravo)
Top 5 configuration management tools
======
Learn about configuration management tools and figure out which will work best for your DevOps organization.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/innovation_lightbulb_gears_devops_ansible.png?itok=TSbmp3_M)
DevOps is evolving and gaining traction as organizations discover how it enables them to produce better applications and reduce their software products' time to market.
[DevOps' core values][1] are Culture, Automation, Measurement, and Sharing (CAMS), and an organization's adherence to them influences how successful it is.
* **Culture** brings people and processes together;
* **Automation** creates a fabric for DevOps;
* **Measurement** permits improvements; and
* **Sharing** enables the feedback loop in the CAMS cycle.
Another DevOps concept is the idea that almost everything can be managed in code: servers, databases, networks, log files, application configurations, documentation, automated tests, deployment processes, and more.
In this article, I'll focus on one aspect of automation: Configuration management. As part of [Infrastructure as Code][2] (IaC), configuration management tools enable the use of tested and proven software development practices for managing and provisioning data centers through plaintext definition files.
By manipulating simple configuration files, a DevOps team can use application development best practices, such as version control, testing, small deployments, and design patterns. In short, this means code can be written to provision and manage an infrastructure as well as automate processes.
### Why use configuration management tools?
Configuration management tools enable changes and deployments to be faster, repeatable, scalable, predictable, and able to maintain the desired state, which brings controlled assets into an expected state.
Some advantages of using configuration management tools include:
* Adherence to coding conventions that make it easier to navigate code
* Idempotency, which means that the end state remains the same, no matter how many times the code is executed
* Distribution design to improve managing large numbers of remote servers
Some configuration management tools use a pull model, in which an agent installed on the servers runs periodically to pull the latest definitions from a central repository and apply them to the server. Other tools use a push model, where a central server triggers updates to managed servers.
### Top 5 configuration management tools
There are a variety of configuration management tools available, and each has specific features that make it better for some situations than others. Yet the top five configuration management tools, presented below in alphabetical order, have several things in common that I believe are essential for DevOps success: all have an open source license, use externalized configuration definition files, run unattended, and are scriptable. All of the descriptions are based on information from the tools' software repositories and websites.
#### Ansible
"Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications—automate in a language that approaches plain English, using SSH, with no agents to install on remote systems." —[GitHub repository][3]
Ansible is one of my favorite tools; I started using it several years ago and fell in love with it. You can use Ansible to execute the same command for a list of servers from the command line. You can also use it to automate tasks using "playbooks" written into a YAML file, which facilitate communication between teams and non-technical people. Its main advantages are that it is simple, agentless, and easy to read (especially for non-programmers).
Because agents are not required, there is less overhead on servers. An SSH connection is necessary when running in push mode (which is the default), but pull mode is available if needed. [Playbooks][4] can be written with a minimal set of commands or they can be scaled for more elaborate automation tasks that could include roles, variables, and modules written by other people.
You can combine Ansible with other tools to create a central console to control processes. Those tools include Ansible Works (AWX), Jenkins, RunDeck, and [ARA][5], which offers [traceability when running playbooks][6].
### CFEngine
"CFEngine 3 is a popular open source configuration management system. Its primary function is to provide automated configuration and maintenance of large-scale computer systems." —[GitHub repository][7]
CFEngine was introduced by Mark Burgess in 1993 as a scientific approach to automated configuration management. The goal was to deal with the entropy in computer systems' configuration and resolve it with end-state "convergence." Convergence means a desired end-state and elaborates on idempotence as a capacity to reach the desired end-state. Burgess' research evolved in 2004 when he proposed the [Promise theory][8] as a model of voluntary cooperation between agents.
The current version of CFEngine incorporates Promise theory and uses agents running on each server that pull the configuration from a central repository. It requires some expert knowledge to deal with configurations, so it's best suited for technical people.
### Chef
"A systems integration framework, built to bring the benefits of configuration management to your entire infrastructure." —[GitHub repository][9]
Chef uses "recipes" written in Ruby to keep your infrastructure running up-to-date and compliant. The recipes describe a series of resources that should be in a particular state. Chef can run in client/server mode or in a standalone configuration named [chef-solo][10]. It has good integration with the major cloud providers to automatically provision and configure new machines.
Chef has a solid user base and provides a full toolset to allow people with different technical backgrounds and skills to interact around the recipes. But, at its base, it is more technically oriented tool.
### Puppet
"Puppet, an automated administrative engine for your Linux, Unix, and Windows systems, performs administrative tasks (such as adding users, installing packages, and updating server configurations) based on a centralized specification." —[GitHub repository][11]
Conceived as a tool oriented toward operations and sysadmins, Puppet has consolidated as a configuration management tool. It usually works in a client-server architecture, and an agent communicates with the server to fetch configuration instructions.
Puppet uses a declarative language or Ruby to describe the system configuration. It is organized in modules, and manifest files contain the desired-state goals to keep everything as required. Puppet uses the push model by default, and the pull model can be configured.
### Salt
"Software to automate the management and configuration of any infrastructure or application at scale." — [GitHub repository][12]
Salt was created for high-speed data collection and scale beyond tens of thousands of servers. It uses Python modules to handle configuration details and specific actions. These modules manage all of Salt's remote execution and state management behavior. Some level of technical skills are required to configure the modules.
Salt uses a client-server topology (with the Salt master as server and Salt minions as clients). Configurations are kept in Salt state files, which describe everything required to keep a system in the desired state.
### Conclusion
The landscape of DevOps tools is evolving all the time, and it is important to keep an eye on the changes. I hope this article will encourage you to explore these concepts and tools further. If so, the Cloud Native Computing Foundation (CNCF) maintains a good reference in the [Cloud Native Landscape Project][13].
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/configuration-management-tools
作者:[Marco Bravo][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/marcobravo
[b]: https://github.com/lujun9972
[1]: https://www.oreilly.com/learning/why-use-terraform
[2]: https://www.oreilly.com/library/view/infrastructure-as-code/9781491924334/ch04.html
[3]: https://github.com/ansible/ansible
[4]: https://opensource.com/article/18/8/ansible-playbooks-you-should-try
[5]: https://github.com/openstack/ara
[6]: https://opensource.com/article/18/5/analyzing-ansible-runs-using-ara
[7]: https://github.com/cfengine/core
[8]: https://en.wikipedia.org/wiki/Promise_theory
[9]: https://github.com/chef/chef
[10]: https://docs.chef.io/chef_solo.html
[11]: https://github.com/puppetlabs/puppet
[12]: https://github.com/saltstack/salt
[13]: https://github.com/cncf/landscape

View File

@ -0,0 +1,315 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (What is PPA? Everything You Need to Know About PPA in Linux)
[#]: via: (https://itsfoss.com/ppa-guide/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
What is PPA? Everything You Need to Know About PPA in Linux
======
**Brief: An in-depth article that covers almost all the questions around using PPA in Ubuntu and other Linux distributions.**
If you have been using Ubuntu or some other Linux distribution based on Ubuntu such as Linux Mint, Linux Lite, Zorin OS etc, you may have come across three magical lines of this sort:
```
sudo add-apt-repository ppa:dr-akulavich/lighttable
sudo apt-get update
sudo apt-get install lighttable-installer
```
A number of websites suggest these kind of lines to [install applications in Ubuntu][1]. This is what is called installing an application using PPA.
But what is PPA? Why is it used? Is it safe to use PPA? How to properly use PPA? How to delete a PPA?
Ill answer all of the above questions in this detailed guide. Even if you already know a few things about PPAs, I am sure this article will still add to your knowledge.
Do note that I am writing this article using Ubuntu. Therefore Ill use the term Ubuntu almost everywhere but the explanations and steps are also applicable to other Debian/Ubuntu based distributions.
### What is PPA? Why is it used?
![Everything you need to know about PPA in Ubuntu Linux][2]
PPA stands for Personal Package Archive.
Does that make sense? Probably not.
Before you understand PPA, you should know the concept of repositories in Linux. I wont go into details here though.
#### Concept of repositories and package management
A repository is a collection of files that has information about various software, their versions and some other details like the checksum. Each Ubuntu version has its own official set of four repositories:
* **Main** Canonical-supported free and open-source software.
* **Universe** Community-maintained free and open-source software.
* **Restricted** Proprietary drivers for devices.
* **Multiverse** Software restricted by copyright or legal issues.
You can see such repositories for all Ubuntu versions [here][3]. You can browse through them and also go to the individual repositories. For example, Ubuntu 16.04 main repository can be found [here][4].
So basically its a web URL that has information about the software. How does your system know where are these repositories?
This information is stored in the sources.list file in the directory /etc/apt. If you look at its content, youll see that it has the URL of the repositories. The lines with # at the beginning are ignored.
Now when you run the command sudo apt update, your system uses [APT tool][5] to check against the repo and stores the information about the software and their version in a cache. When you use the command sudo apt install package_name, it uses the information to get that package from the URL where the actual software is stored.
If the repository doesnt have the information about a certain package, youll see an error like:
```
E: Unable to locate package
```
At this point, I recommend reading my [guide to using apt commands][6]. This will give you a much better understanding of apt commands, update etc.
So this was about repositories. But what is PPA? How does it enter into the picture?
#### Why is PPA used?
As you can see, Ubuntu controls what software and more importantly which version of a software you get on your system. But imagine if a software developer releases a new version of the software.
Ubuntu wont make it available immediately. There is a procedure to check if the new version of the software is compatible with the system or not. This ensures the stability of the system.
But this also means that it will be some weeks or in some cases, some months before it is made available by Ubuntu. Not everyone would want to wait that long to get their hands on the new version of their favorite software.
Similarly, suppose someone develops a software and wants Ubuntu to include that software in the official repositories. It again will take months before Ubuntu makes a decision and includes it in the official repositories.
Another case would be during beta testing. Even if a stable version of the software is available in the official repositories, a software developer may want some end users to test their upcoming release. How do they enable the end user to beta test the upcoming release?
Enter PPA!
### How to use PPA? How does PPA work?
[PPA][7], as I already told you, means Personal Package Archive. Mind the word Personal here. That gives the hint that this is something exclusive to a developer and is not officially endorsed by the distribution.
Ubuntu provides a platform called Launchpad that enables software developers to create their own repositories. An end user i.e. you can add the PPA repository to your sources.list and when you update your system, your system would know about the availability of this new software and you can install it using the standard sudo apt install command like this.
`sudo add-apt-repository ppa:dr-akulavich/lighttable`
`sudo apt-get update`
`sudo apt-get install lighttable-installer`
To summarize:
* sudo add-apt-repository <PPA_info> < This command adds the PPA repository to the list.
* sudo apt-get update < This command updates the list of the packages that can be installed on the system.
* sudo apt-get install <package_in_PPA> < This command installs the package.
You see that it is important to use the command sudo apt update or else your system will not know when a new package is available.
Now lets take a look at the first command in a bit more detail.
```
sudo add-apt-repository ppa:dr-akulavich/lighttable
```
You would notice that this command doesnt have a URL to the repository. This is because the tool has been designed to abstract the information about URL from you.
Just a small note. If you add ppa:dr-akulavich/lighttable, you get Light Table. But if you add ppa:dr-akulavich, youll get all the repository or packages mentioned in the upper repository. Its hierarchical.
Basically, when you add a PPA using add-apt-repository, it will do the same action as if you manually run these commands:
```
deb http://ppa.launchpad.net/dr-akulavich/lighttable/ubuntu YOUR_UBUNTU_VERSION_HERE main
deb-src http://ppa.launchpad.net/dr-akulavich/lighttable/ubuntu YOUR_UBUNTU_VERSION_HERE main
```
The above two lines are the traditional way to add any repositories to your sources.list. But PPA does it automatically for you, without wondering about the exact repository URL and operating system version.
One important thing to not here is that when you use PPA, it doesnt change your original sources.list. Instead, it creates two files in /etc/apt/sources.d directory, a list and a back up file with suffix save.
![Using a PPA in Ubuntu][8]PPA create separate sources.list
The files with suffix list has the command that adds the information about the repository.
![PPA add repository information][9]Content of source.list of a PPA
This is a safety measure to ensure that adding PPAs dont mess with the original sources.list. It also helps in removing the PPA.
#### Why PPA? Why not DEB packages?
You may ask why should you use PPA when it involves using command line which might not be preferred by everyone. Why not just distribute a DEB package that can be installed graphically?
The answer lies in the update procedure. If you install a software using a DEB package, there is no guarantee that the installed software will be updated to a newer version when you run sudo apt update && sudo apt upgrade.
Its because the apt upgrade procedure relies on the sources.list. If there is no entry for a software, it doesnt get the update via the standard software updater.
So does it mean software installed using DEB never gets an update? No, not really. It depends on how the package was created.
Some developers automatically add an entry to the sources.list and then it is updated like a regular software. Google Chrome is one such example.
Some software would notify you of availability of a new version when you try to run it. Youll have to download the new DEB package and run it again to update the current software to a newer version. Oracle Virtual Box is an example in this case.
For the rest of the DEB packages, youll have to manually look for an update and this is not convenient, especially if your software is meant for beta testers. You need to add more updates frequently. This is where PPA come to the rescue.
#### Offical PPA vs unofficial PPA
You may also hear the term official PPA or unofficial PPA. Whats the difference?
When developers create PPA for their software, it is called the official PPA. Quite obviously because it is coming from none other than the project developers.
But at times, individuals create PPA of projects that were created by other developers.
Why would someone do that? Because many developers just provide the source code of the software and you know that [installing software from source code in Linux][10] is a pain and not everyone could or would do that.
This is why volunteers take it upon themselves to create a PPA from those source code so that other users can install the software easily. After all, using those 3 lines is a lot easier than battling the source code installation.
#### Make sure that a PPA is available for your distribution version
When it comes to using PPA in Ubuntu or any other Debian based distribution, there are a few things you should keep in mind.
Not every PPA is available for your particular version. You should know [which Ubuntu version][11] you are using. The codename of the release is important because when you go to the webpage of a certain PPA, you can see which Ubuntu versions are supported by the PPA.
For other Ubuntu-based distributions, you can check the content of /etc/os-release to [find out the Ubuntu version][11] information.
![Verify PPA availability for Ubuntu version][12]Check if PPA is available for your Ubuntu version
How to know the PPA url? Simply search on the internet with the PPA name like ppa:dr-akulavich/lighttable and youll get the first result from [Launchpad][13], the official platform for hosting PPA. You can also go to Launchpad and search for the required PPA directly there.
If you dont verify and add the PPA, you may see an error like this when you try to install a software not available for your version.
```
E: Unable to locate package
```
Whats worse is that since it has been added to your source.list, each time you run software updater, youll see an error “[Failed to download repository information][14]“.
![Failed to download repository information Ubuntu 13.04][15]
If you run sudo apt update in the terminal, the error will have more details about which repository is causing the trouble. You can see something like this in the end of the output of sudo apt update:
```
W: Failed to fetch http://ppa.launchpad.net/venerix/pkg/ubuntu/dists/raring/main/binary-i386/Packages  404  Not Found
E: Some index files failed to download. They have been ignored, or old ones used instead.
```
Which is self-explanatory because the system cannot find the repository for your version. Remember what we saw earlier about repository structure? APT will try to look for software information in the place <http://ppa.launchpad.net/\><PPA_NAME>/ubuntu/dists/Ubuntu_Version
And if the PPA for the specific version is not available, it will never be able to open the URL and you get the famous 404 error.
#### Why are PPAs not available for all the Ubuntu release versions?
It is because someone has to compile the software and create a PPA out of it on the specific versions. Considering that a new Ubuntu version is released every six months, its a tiresome task to update the PPA for every Ubuntu release. Not all developers have time to do that.
#### How to install the application if PPA is not available for your version?
It is possible that though the PPA is not available for your Ubuntu version, you could still download the DEB file and install the application
Lets say that you go to the Light Table PPA. Using the knowledge about PPA you just learned, you realize that the PPA is not available for your specific Ubuntu release.
What you can do is to click on the View package details.
![Get DEB file from PPA][16]
And in here, you can click on a package to reveal more details. Youll also find the source code and the DEB file of the package here.
![Download DEB file from PPA][17]
I advise [using Gdebi to install these DEB files][18] instead of the Software Center because Gdebi is a lot better at handling dependencies.
Do note that the package installed this way might not get any future updates.
I think you have read enough about adding PPAs. How about removing a PPA and the software installed by it?
### How to delete PPA?
I have written about [deleting PPA][19] in the past. I am going to describe the same methods here as well.
I advise deleting the software that you installed from a PPA before removing the PPA. If you just remove the PPA, the installed software remains in the system but it wont get any updates. You wouldnt want that, would you?
So, the question comes, how to know which application was installed by which PPA?
#### Find packages installed by a PPA and remove them
Ubuntu Software Center doesnt help here. Youll have to use Synaptic package manager here which has more advanced features.
You can install Synaptic from Software Center or use the command below:
```
sudo apt install synaptic
```
Once installed, start Synaptic package manager and select Origin. Youll see various repositories added to the system. PPA entries will be labeled with prefix PPA. Click on them to see the packages that are available by the PPA. Installed software will have appropriate symbol before it.
![Managing PPA with Synaptic package manager][20]Find packages installed via a PPA
Once you have found the packages, you can delete them from Synaptic itself. Otherwise, you always have the option to use the command line:
```
sudo apt remove package_name
```
Once you have removed the packages installed by a PPA, you can continue to remove the PPA from your sources.list.
#### Remove a PPA graphically
Go to Software & Updates and then go to tab Other Software. Look for the PPA that you want to remove:
![Delete a PPA from Software Source][21]
You have two options here. Either you deselect the PPA or you choose the Remove option.
The difference is that when you deselect a PPA entry, your system will comment out the repository entry in its ppa_name.list file in /etc/apt/sources.list.d but if you choose the Remove option, it will delete the repository entry from its ppa_name.list file in /etc/apt/sources.list.d directory.
In both the cases, the files ppa_name.list remains in the said directory, even if it is empty.
### Is it safe to use PPA?
It is a subjective question. Purists abhor PPA because most of the time PPAs are from third-party developers. But at the same time, PPAs are popular in the Debian/Ubuntu world as they provide an easier installation option.
As far as the security is concerned, its less likely that you use a PPA and your Linux system is hacked or injected with malware. I dont recall such an incident ever happened so far.
Official PPAs can be used without thinking twice. Using unofficial PPA is entirely your decision.
As a rule of thumb, you should avoid installing a program via a third party PPA if it the program requires sudo access to run.
### What do you think about using PPA?
I know its a long read but I wanted to give you a better understanding of PPA. I hope this detailed guide answered most of your questions about using PPA.
If you have more questions about PPA, please feel free to ask in the comment section.
If you notice any technical or grammatical error or if you have suggestions for improving this article, please let me know.
--------------------------------------------------------------------------------
via: https://itsfoss.com/ppa-guide/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://itsfoss.com/remove-install-software-ubuntu/
[2]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2018/12/what-is-ppa.png?resize=800%2C450&ssl=1
[3]: http://archive.ubuntu.com/ubuntu/dists/
[4]: http://archive.ubuntu.com/ubuntu/dists/xenial/main/
[5]: https://wiki.debian.org/Apt
[6]: https://itsfoss.com/apt-command-guide/
[7]: https://launchpad.net/ubuntu/+ppas
[8]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2018/01/ppa-sources-list-files.png?resize=800%2C259&ssl=1
[9]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2018/01/content-of-ppa-list.png?ssl=1
[10]: https://itsfoss.com/install-software-from-source-code/
[11]: https://itsfoss.com/how-to-know-ubuntu-unity-version/
[12]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2017/12/verify-ppa-availibility-version.jpg?resize=800%2C481&ssl=1
[13]: https://launchpad.net/
[14]: https://itsfoss.com/failed-to-download-repository-information-ubuntu-13-04/
[15]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2013/04/Failed-to-download-repository-information-Ubuntu-13.04.png?ssl=1
[16]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2018/12/deb-from-ppa.jpg?resize=800%2C483&ssl=1
[17]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2018/12/deb-from-ppa-2.jpg?resize=800%2C477&ssl=1
[18]: https://itsfoss.com/gdebi-default-ubuntu-software-center/
[19]: https://itsfoss.com/how-to-remove-or-delete-ppas-quick-tip/
[20]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2018/01/ppa-synaptic-manager.jpeg?resize=800%2C394&ssl=1
[21]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2012/08/Delete-a-PPA.jpeg?ssl=1

View File

@ -1,114 +0,0 @@
当 NASA 开始应用开放科学
======
![][1]
最近我们刚为 NASA 在它的自由开源软件上新开放了[科学][2]板块。其中发表的最新一篇文章名为:[开源手段是怎样影响科学的][3]。在这篇文章中我们主要讨论的是 [NASA][4] 在鼓励使用开源工具之后,是怎样在大量的科研机构潮流中保持自身的动态角色,实现快速发展的。
### NASA 是怎样使用开源手段促进科学研究的
NASA 将他们的整个研究库对整个公共域开放,这是一项[壮举][5]。
没错!每个人都能访问他们的研究库,并能从他们的研究中获益。
他们现已开放的资料可以大致分为一下三类:
* 开放的 NASA 资源
* 开放的应用程序编程接口
* 开放的资料
#### 1\.开放的 NASA 资源
采访 [GitHub][7] 的联合创始人之一和执行总裁 [Chris Wanstrath][6] 时,他向我们介绍道,一切都是从很多年前开始的。
NASA 的账号叫做 “[code.nasa.gov][8]“, 截至现在为止NASA 已经[通过 GitHub 开放][9]了365个科学软件对于一位热爱程序的开发者来说即使一天研究一个软件想把NASA的这些软件全部研究过来也要整整一年的时间。
即使你不是一位开发者,你也可以在入口网站浏览这些壮观软件合集的统计列表。
其中就有[阿波罗11号][10]的制导计算机的源代码。阿波罗11号空间飞行器[首次将两名人类带上月球][11],分别是 [Neil Armstrong][12] 和 [Edwin Aldrin][13] 。如果你对 Edwin Aldrin 感兴趣,可以点击[这里][14]了解更多。
##### NASA 开源代码促进会使用的开源代码许可:
这里有几种[开源代码许可][15],其分类如下:
#### 2\.开放的应用程序编程接口API
开放的[应用程序设计接口][16]或者应用程序编程接口在推行开源技术中起到了很大作用。与[开源代码促进会][17]类似,开放的应用程序编程接口有它们的[开放平台促进会][18]。下面这张示意图可以告诉你 API 是怎样将应用程序和它的开发者连接起来的。
![][19]
记得点击图片上面的链接看看。链接内的文章使用了简单易懂的方法解读 API ,文末将 API 总结为五种架构。
![][20]
这让人忍不住想象由专有 API 变成开放 API 会有多么大的不同。
![][22]
[NASA 的开放 API][23] 主要针对应用程序开发者,大大提高了包括图片内容在内的数据可及性,这是前所未有的。网站设有活动编辑器,为需要查阅[每日天文一图][24]板块 [API][16] 的用户们授权。
#### 3\.开放的资料
![][25]
在[我们发布的第一篇科学文章][3]中我们介绍了“开放科学”板块下提到的三个国家——法国印度和美国的多种开放资料形式。NASA 有着类似的想法和行为。这种意识形态已经被[多个国家][26]所接受。
[NASA 的开放数据门户][27]致力于不断扩大的可供大众使用的开放数据目录。这个数据集的内容对于任何研究活动来说都是必要且重要的。NASA 还在他们的门户网站上征集各方的数据,以一同收录在他们的数据库中。这一行为不仅是领先的,创新的,还顺应了[数据科学][28]和 [AI 深度学习][29]的趋势。
下面的视频讲的是学者和学生们是怎样通过大量研究得出对数据科学的定义的。这个过程十分的激动人心。瑞尔森大学罗杰斯商学院的 [Murtaza Haider 教授][30]在视频中提到了开源的出现对数据科学的改变,尤其让是旧有的封闭发展模式逐渐变得开放。而这也确实成为了现实。
![][31]
现在任何人都能在 NASA 上提交数据。正如视频中所说, NASA 的领先方案很大程度上与征集和分析优化数据有关。
![][32]
你只需要进行免费注册。考虑到论坛上的公开讨论走向和在任何统计分析环境下都能运行的数据集,这个方案在未来会有非常积极的影响,对数据的统计分析当然也会大幅进展。在之后的文章中我们还会具体讨论这些细节,还有他们和开源模式之间的相关性。
以上就是对 NASA 开放科学模式的一些探索成就,希望您能继续关注我们接下来的相关文章!
--------------------------------------------------------------------------------
via: https://itsfoss.com/nasa-open-science/
作者:[Avimanyu Bandyopadhyay][a]
译者:[Valoniakim](https://github.com/Valoniakim)
校对:[校对者ID](https://github.com/校对者ID)
选题:[lujun9972](https://github.com/lujun9972)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/avimanyu/
[1]:https://itsfoss.com/wp-content/uploads/2018/03/tux-in-space.jpg
[2]:https://itsfoss.com/category/science/
[3]:https://itsfoss.com/open-source-impact-on-science/
[4]:https://www.nasa.gov/
[5]:https://futurism.com/free-science-nasa-just-opened-its-entire-research-library-to-the-public/
[6]:http://chriswanstrath.com/
[7]:https://github.com/
[8]:http://code.nasa.gov
[9]:https://github.com/open-source
[10]:https://www.nasa.gov/mission_pages/apollo/missions/apollo11.html
[11]:https://www.space.com/16758-apollo-11-first-moon-landing.html
[12]:https://www.jsc.nasa.gov/Bios/htmlbios/armstrong-na.html
[13]:https://www.jsc.nasa.gov/Bios/htmlbios/aldrin-b.html
[14]:https://buzzaldrin.com/the-man/
[15]:https://itsfoss.com/open-source-licenses-explained/
[16]:https://en.wikipedia.org/wiki/Application_programming_interface
[17]:https://opensource.org/
[18]:https://www.openapis.org/
[19]:https://itsfoss.com/wp-content/uploads/2018/03/api-bridge.jpeg
[20]:https://itsfoss.com/wp-content/uploads/2018/03/open-api-diagram.jpg
[21]:http://www.apiacademy.co/resources/api-strategy-lesson-201-private-apis-vs-open-apis/
[22]:https://itsfoss.com/wp-content/uploads/2018/03/nasa-open-api-live-example.jpg
[23]:https://api.nasa.gov/
[24]:https://apod.nasa.gov/apod/astropix.html
[25]:https://itsfoss.com/wp-content/uploads/2018/03/nasa-open-data-portal.jpg
[26]:https://www.xbrl.org/the-standard/why/ten-countries-with-open-data/
[27]:https://data.nasa.gov/
[28]:https://en.wikipedia.org/wiki/Data_science
[29]:https://www.kdnuggets.com/2017/07/ai-deep-learning-explained-simply.html
[30]:https://www.ryerson.ca/tedrogersschool/bm/programs/real-estate-management/murtaza-haider/
[31]:https://itsfoss.com/wp-content/uploads/2018/03/suggest-dataset-nasa-1.jpg
[32]:https://itsfoss.com/wp-content/uploads/2018/03/suggest-dataset-nasa-2-1.jpg

View File

@ -1,94 +0,0 @@
The Source History of Cat
======
以前我和我的一些亲戚争论过计算机科学的学位值不值得读。当时我正在上大学,并要决定是不是该主修计算机。我姨和我一表姐觉得我不应该主修计算机。她们承认知道如何编程肯定是很有用且对自己有利的一件事,但是她们认为计算机科学现在发展的如此迅速以至于我学的东西几乎马上就过时了。建议我更好是把编程作为辅业,选择一个基础原理可以受用终身的领域主修,比如经济学或物理学。
我知道我姨和我表姐说的不对,并决定主修计算机科学。(对不住啊!)平常人可能会觉得像计算机科学领域和软件工程专业每隔几年就完全和之前不一样了。其原因很容易理解。我们有了个人电脑,然后有了互联网,有了手机,之后还有了机器学习…… 科技总是在更新,支撑科技发展的原理和技能当然也在改变。当然,最惊人的是其实原理的改变竟然如此之小。我敢肯定,大多数人在知道了他们电脑里一些重要的软件的历史是多么久远时他们一定会深感震惊。当然我不是说那些刷版本号的浮夸软件 —— 我电脑上的 Firefox 浏览器副本,可能是我用的最多的软件,可能才更新不到两周。如果你看了比如 `grep` 的手册页,你就会发现他在 2010 年后就没有过更新了(至少在 MacOS 上如此)。初版 `grep` 是在 1974 年写就的,那时可以算是计算机世界的侏罗纪了。直到现在,人们(还有程序)仍然依赖 `grep` 来完成日常工作。
我姨和我表姐认为计算机技术就像一系列日渐精致的沙堡,在潮水抹净沙滩后新的沙堡完全取代旧的。但事实上,在很多领域上,我们都是不断积累能够解决问题的程序。我们可能不得不偶尔修改这些程序以避免软件无法使用,但大多数情况下我们都可以不修改。 `grep` 是一个简单的程序,可以解决一个仍然存在的问题,所以它能够存活下来。 大多数应用程序编程都是在非常高的级别上完成的,他们建立在解决了旧问题的程序的金字塔上。 30年或40年前的想法和概念远非过时在很多情况下他们依然在您的笔记本电脑上软件中存在着。
我想追溯这样的老程序自第一次写就以来改变了多少回很有趣。 `cat`可能是所有 Unix 实用程序中最简单的,因此我们以它为例。 Ken Thompson于 1969 年编写了 `cat` 的原始实现。如果我告诉别人我的电脑上安了个 1969 年的程序,这准确吗?我们电脑上的程序多大了?
感谢这种[这种][1]仓库,我们可以完整的看到 `cat` 自 1969 年后是如何发展的。我会先聚焦于可以算得上是我的 MacBook 上的 `cat` 的祖先的 `cat` 实现。随着我们从 Unix 上的第一版 `cat` 追踪到现在 MacOS 上的 `cat`,你会发现,这个程序被重写的次数比你想的还要多 —— 但是直到现在它运行的方式和五十年前多少是完全一致的。
### 研究 Unix
Ken Thompson 和 Dennis Ritchie 在 PDP 7 上开始写 Unix。那还是 1969 年C 还没被发明出来,因此所有早期的 Unix 软件都是用 PDP 7 汇编实现的。他们使用的汇编种类是 Unix 特有的Ken Thompson 在 DEC也就是 PDP 7 的厂商提供的汇编器之上加了些特性实现了自己的汇编器。Thompson 的更改在[最初的 Unix 程序员手册][2]的 `as`(也就是汇编器)条目下均有所记录。
因此,[最初的][3] `cat` 也是使用 PDP 7 汇编实现的。 我添加了一些注释,试图解释每条指令的作用,但除非你理解 Thompson 在编写汇编器时加的特性,否则程序仍然很难理解。在那些特性中有两个很重要:其一是 `;` 这个字符可以在一行中用来分隔多条语句,它多出现于在使用 `sys` 指令时将系统调用的多个参数放在同一行上。其二是, Thompson 的汇编器支持使用 0 到 9 作为“临时标签”,也就是在程序内可以重用的标签。因此。就如 Unix 程序员手册中所说:“对程序员的想象力和汇编程序的符号空间的要求都降低了”。在任何给定的指令内,你都可以使用 `nf``nb` 来引用下一个或最近的临时标签 `n`。 例如,如果存在标记为 `1:` 的代码块,你就可以使用指令 `jmp 1b` 从下游代码跳回该块。 (但是你不使用 `jmp 1f` 的话就没法从上面的代码跳到这里。)
初版 `cat` 最有趣的就是它包含着我们应该认识的符号。有一块指令快标记为 `getc`,还有一个标记为 `putc`,可以看到这两个符号比 C 标准还古老。第一版的 `cat` 函数实际上已经包含了这两个函数的实现。这个 `cat` 实现做了缓存,这样他就不需要一次只读写一个字母。
`cat` 的第一个版本并没有持续多久。 Ken Thompson 和 Dennis Ritchie 说服贝尔实验室购买了 PDP 11这样他们就能够继续扩展和改进 Unix。 PDP 11 的指令集和之前不一样,因此必须重写 `cat`。 我也注释了[这个第二版][4] `cat`。 它为新的指令集使用新的汇编程序助记符,并利用了 PDP 11 的各种[寻址模式][5]。(如果你对源代码中的括号和美元符号感到困惑,那是因为这些符号用于指示不同的寻址模式。)但它也使用 `;` 字符和临时标签,和 `cat` 的第一个版本一样,这意味着当把 `as` 移植到 PDP 11 上时,必须要保留这些功能。
`cat` 的第二个版本比第一个版本简单得多。 它也更有 Unix 味儿,它不只是依靠参数列表,一旦没给参数列表,它将从 `stdin` 读取数据,这也就是今天 `cat` 仍在做的事情。 你也也可以在此版本的 `cat` 中以 `-` 为参数,以表示它应该从`stdin`读取。
在 1973 年,为了准备发布第四版 Unix大部分代码都用 C 语言重写了。但是 `cat` 似乎在之后一段时间内并没有使用 C 重写。 [`cat` 的第一个 C 语言实现][6]出现在第七版 Unix 中。 这个实现非常有趣,因为它很简单。 在所有要以后的实现中,这个实现和在 KR 的 C语言教科书中用作教学示范的理想化 `cat` 最相似。这个程序的核心就是经典的两行:
```
while ((c = getc(fi)) != EOF)
putchar(c);
```
当然实际代码要比这多一些,额外的代码主要是为了确保你没有在读/写同一个文件。另一个有趣的事情是,`cat` 的这一版实现只识别一个标志位 `-u``-u` 标志可用于避免缓冲输入和输出,否则 `cat` 将以 512 字节为块进行输入输出。
### BSD
在第七版之后Unix 出现了了各种衍生品和分支。 MacOS 建立于 Darwin 之上,而 Darwin 又源自 Berkeley Software DistributionBSD因此 BSD 是我们最感兴趣的Unix 分支。 BSD 最初只是 Unix 中的实用程序和附加组件的集合,但它最终成为了一个完整的操作系统。直到第四版 BSD人称 4BSD为一大堆新标志添加了支持之前BSD 似乎还是依赖于最初的 `cat` 实现的。`cat` 的 [4BSD 实现][7] 显然是从原始实现中衍生出来的,尽管它添加了一个新函数来实现新标志触发的行为。按照已经在文件中使用由用于标记输入是从`stdin`还是文件读取的 `fflg` 变量指定的命名约定。被新添加的 `nflg``bflg``vflg``sflg``eflg`和`tflg` 保存了下来,这些变量记录了在调用程序时是否使用了这些新标志。这些是最后一批添加到 `cat` 的命令行标志。如今 `cat` 的手册页列出了这些标志没有其他的标志了至少在Mac OS上是如此。 4BSD 于1980年发布因此这套标志已有 38 年历史。
`cat` 最后一次被完全重写是在 BSD NET/2 上,其目的是通过替换全部 AT&T 发布的 Unix 源代码来规避许可证问题。BSD Net/2 在 1991 年发布。这一版本的 `cat` 是由 Kevin Fall 重写的。 Kevin Fall 于 1988 年毕业于加州大学伯克利分校并在下一年成为计算机系统研究组CSRG的组员Fall 和我说当时使用 AT&T 代码的 Unix 工具被列在了 CSRG 的墙上,组员需要从中选出他们想要重写的工具; Fall 选了 `cat` 以及 `mknod`。 MacOS 系统内自带的 `cat` 实现源码的最上面还有着他的名字。他的这一版 `cat`,尽管平淡无奇,在今天还是被无数人使用着。
[Fall的原始 `cat `实现][8] 比我们迄今为止看到的程序都要长。 除了支持 `-?` 帮助标志外,它没有增加任何新功能。 从概念上讲,它与 4BSD 的实现非常相似。 它长是因为 Fall 将实现分为 “原始” 模式和 “熟” 模式。 “原始” 模式是 `cat ` 的经典实现; 它一个字符一个字符的打印文件。 “熟” 模式是带有所有 4BSD 命令行选项的 `cat`。 如此区别不无道理,但这么办也扩充了实现规模,因此乍一看其源码似乎比实际上更复杂。文件末尾还有一个奇特的错误处理函数,进一步地增加了实现的长度。
### MacOS
在 2001 年,苹果发布了 MacOS X。这一发布对苹果意义重大。因为苹果花了很多年时间来尝试并且取代现有的过时操作系统经典的Mac OS但是都失败了。 在 Mac OS X 之前苹果两次尝试在内部创建一个新的操作系统,但两者都无疾而终。 最后,苹果收购了史蒂夫 · 乔布斯的 NeXT 公司,后者开发了一个名为 NeXTSTEP 的操作系统和面向对象编程框架。 苹果将 NeXTSTEP 作为Mac OS X的基础。因为 NeXTSTEP 部分基于 BSD使以 NeXTSTEP 为基础的 Mac OS X的自然就把 BSD 系的代码直接带入苹果宇宙的中心。
因此Mac OS X的第一个版本包含了从 NetBSD 项目中提取的 `cat` 的[实现][9]。如今仍在开发中的 NetBSD 最初是 386BSD 的分支,而后者又直接基于 BSD Net/2。所以Mac OS X里面的第一个 `cat` 的实现就是 Kevin Fall的 `cat`。唯一改变的是Fall 的错误处理函数 `err()``err.h` 提供的`err()` 函数取代了。 `err.h` 是 C 标准库的 BSD 扩展。
之后不久,`cat` 的 NetBSD 实现被换成了 FreeBSD 中的 `cat` 实现。 [根据维基百科][10]苹果在Mac OS X 10.3(Panther) 中开始使用 FreeBSD 的实现而不是 NetBSD 的实现。但根据苹果自己开源的版本,`cat` 的Mac OS X实现在2007年发布的 Mac OS X 10.5(Leopard) 之前没有被替换。苹果为 Leopard 替换的的 [FreeBSD 实现][11]与今天苹果计算机上的实现相同。截至 2018 年,此实现仍未被更新或修改。
所以Mac OS 上的 `cat` 已经很老了。实际上,这一实现在 2007 年在 MacOS X 上露面两年前就被发布了。 [这个 2005 年的修改][12] 在 FreeBSD 的 Github 镜像中可见,是在苹果将其合并入 Mac OS X 前对 FreeBSD 的 `cat` 实现进行的最后一次更改。所以 Mac OS X 的没有与 FreeBSD 的 `cat` 实现保持同步的 `cat`实现,如今 13 岁了。对于软件修改了多少代码才能仍是算是同一软件这一话题有着旷日持久的争论。不过,在这种情况下,源文件自 2005 年以来根本没有变化。
现在 Mac OS 使用的 `cat` 实现与 Fall 1991年为 BSD Net/2 版本编写的实现没有什么不同。最大的区别是添加了一个全新的功能来提供 Unix 域套接字支持。FreeBSD 开发人员似乎将 Fall 的 `raw_args()` 函数和 `cook_args()` 函数组合成一个名为`scanfiles()`的函数。要没有的话,程序的核心就仍是 Fall 的代码。
我问过 Fall 对编写如今被数以百万计的苹果用户直接或者通过依赖 `cat` 的程序间接使用的 `cat` 实现有何感想。Fall如今是最新版 TCP/IP 详解的顾问和合著者,说,当人们从了解他对 `cat` 所做的的工作中收获颇丰时,他感到很惊讶。 Fall 在计算机领域有着悠久的职业生涯,曾参与许多备受瞩目的项目,但似乎很多人仍对他在 1989 年重写 `cat` 的那六个月的工作感到最为兴奋。
### 百年老程序
在宏伟的发明史中,计算机并不是一项古老的发明。我们已经习惯了百年的照片甚至是百年的视频短片。但是计算机程序不一样 - 它们代表着高科技和新技术。至少,他们是现代的技术造出来的。随着计算行业的成熟,我们有朝一日会发现自己正在使用有着接近百年历史的程序吗?
计算机硬件可能会发生较大的变化,使得我们也许无法让现在编译的可执行文件在一个世纪后的硬件上运行。也许编程语言设计的进步让未来没有人能理解 C 语言,`cat` 将来也可能也被别的语言重写很久了。 (尽管 C已经存在了五十年了而且它似乎不会很快就被替换掉。但除此之外为什么不永远使用我们现在的 `cat`
我认为 `cat` 的历史表明,计算机科学中的一些想法确实非常持久。事实上,对于 `cat`,这个想法和程序本身都很古老。不准确地说,我的电脑上的 `cat` 来自1969 年。但我也可以说我的计算机上的 `cat` 来自1989 年,当时 Fall 写了他的 `cat` 实现。许多其他软件也同样古老。因此,也许我们不应该把计算机科学和软件开发视为不断破坏现状和发明新事物的领域。我们的计算机系统是由诸多历史文物构建的。有时,我们可能会花费更多时间在理解和维护这些历史文物上,而不是花在编写新代码上。
如果你喜欢本文,你可能更喜欢两周来一篇更新!在推特上关注 [@TwoBitHistory][13] 或者订阅这个 [RSS 源][14] 以保证接受到新的文章。
--------------------------------------------------------------------------------
via: https://twobithistory.org/2018/11/12/cat.html
作者:[Two-Bit History][a]
选题:[lujun9972][b]
译者:[name1e5s](https://github.com/name1e5s)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://twobithistory.org
[b]: https://github.com/lujun9972
[1]: https://github.com/dspinellis/unix-history-repo
[2]: https://www.bell-labs.com/usr/dmr/www/man11.pdf
[3]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-1-cat-pdp7-s
[4]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-2-cat-pdp11-s
[5]: https://en.wikipedia.org/wiki/PDP-11_architecture#Addressing_modes
[6]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-3-cat-v7-c
[7]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-4-cat-bsd4-c
[8]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-5-cat-net2-c
[9]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-6-cat-macosx-c
[10]: https://en.wikipedia.org/wiki/Darwin_(operating_system)
[11]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-7-cat-macos-10-13-c
[12]: https://github.com/freebsd/freebsd/commit/a76898b84970888a6fd015e15721f65815ea119a#diff-6e405d5ab5b47ca2a131ac7955e5a16b
[13]: https://twitter.com/TwoBitHistory
[14]: https://twobithistory.org/feed.xml
[15]: https://twitter.com/TwoBitHistory/status/1051826516844322821?ref_src=twsrc%5Etfw

View File

@ -1,58 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (10 ways to give thanks to open source and free software maintainers)
[#]: via: (https://opensource.com/article/18/11/ways-give-thanks-open-source)
[#]: author: (Moshe Zadka https://opensource.com/users/moshez)
[#]: url: ( )
感谢开源和自由软件维护者的 10 种方法
======
如何表达你的感激之情。
![](https://opensource.com/users/moshez)
每天,我都使用高质量的软件,这些软件由没有要求付款的人开发和维护,他们尊重我的自由,并且慷慨地付出时间和精力。
在这个感恩的季节,我鼓励那些也使用和欣赏开源和自由软件维护者工作的人表达你的感激之情。以下是十种方法:
### 容易做到的
1. 发送电子邮件,感谢开发人员。具体点说,告诉他们你使用他们的什么软件以及你如何获益的。
2. 使用你最喜爱的社交媒体平台宣传它。
3. 写一篇关于你最喜欢的软件的博客文章。
### 捐款
4. 如果你最喜欢的开源项目接受捐款,请汇款。
5. 如果你受雇于使用开源软件的公司,看你是否可以说服管理层赞助某些项目。
6. 提供最高设置额度的捐款。社交动机能做的不可思议!
### 花费时间
7. 帮助查看补丁。
8. 帮助分类 bug。
9. 回答 IRC、邮件列表或 [Stack Overflow][1] 中的问题。
**10. 额外的:**如果你像我一样,你在某个时候对开源社区的其他人说了一些严厉的话。承诺做得更好:用善良和开放沟通。感谢的最好方式是让开源社区成为人们能舒适沟通的地方。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/11/ways-give-thanks-open-source
作者:[Moshe Zadka][a]
选题:[lujun9972][b]
译者:[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/moshez
[b]: https://github.com/lujun9972
[1]: https://meta.stackoverflow.com/

View File

@ -1,128 +0,0 @@
享受Linux下命令行全操作
======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc_terminals.png?itok=CfBqYBah)
很多文章讨论关于命令行下如何做事情。有多少文章要么用晦涩的方式介绍 `ls` ,要么介绍关于 Sed 和 Awk 一些有意思的正则表达式,要么就是介绍一大堆的 perl 脚本是如何解析的?这些都不是命令行操作的重点。
本文章是关于[享受命令行全操作][1]在我们不需要图形桌面网络浏览器或网络连接情况下用命令行操作能完成实际事务的跟踪。为了达到这一点我们将介绍四个途径跟踪你的待办清单纯文件文件Todo.txtTaskWarriorOrg-mode。
### 纯文本
![plaintext][3]
我喜欢用 Vim ,其实你也可以喜欢 Nano。
最直接管理管理你的待办清单的方式就是用纯文本文件来编辑。只需要打开一个空文件,每一行添加一个任务。当任务完成后,删除这一行,简单有效,不用再关心这一行之前干什么用的了。不过这个方法也有缺点,一点你删除一行并保存了文件,它就是永远消失了。如果你想知道本周或者上周都做了哪些事情,就成了问题。使用简单文本文件很方便却也容易导致混乱。
### Todo.txt: 纯文件的升级版
![todo.txt screen][5]
整洁,有条理,易用
这就是我们要说的 [Todo.txt][6] 格式文件和应用程序。安装可从 GitHub [下载][7]最新的版本解压后并执行命令 `sudo make install`
![安装 todo.txt][9]
也可以从 Git 克隆一个。
Todo.txt 可以很容易的增加新任务,并能显示任务列表和已完成任务的标记:
|||
| ------------- |:-------------|
| `todo.sh add "某任务"` | 增加 "某任务" 到你的待办列表 |
| `todo.sh ls` | 显示所有的任务 |
| `todo.sh ls due:2018-02-15` | 显示2018-02-15之前的所有任务 |
| `todo.sh do 3` | 标记任务3 为已完成任务 |
清单实际上仍然是纯文本,你可以用你喜欢的编辑器遵循[正确的格式][10]编辑它。
应用程序同时也内置了一个强大的帮助。
![在 todo.txt 中语法高亮][12]
你可以使用语法高亮的功能
此外,还有许多附加组件可供选择,以及编写自己的附件组件规范。甚至有浏览器组件,移动设备应用程序和桌面应用程序支持 Todo.txt 的格式。
![GNOME extensions in todo.txt][14]
GNOME的扩展组件
Todo.txt 最大的缺点是缺少自动或内置的同步机制。大多数(不是全部)的浏览器扩展程序和移动应用程序需要用 Dropbox 实现桌面系统和应用程序直接的数据同步。如果你想内置同步机制,我们也有……
### Taskwarrior: 现在我们用 Python 做事了
[Taskwarrior][15] 是一个与Todo.txt 有许多相同功能的 Python 工具。但不同的是它的数据保存在数据库里并具有内置的数据同步功能。它还可以跟踪即将要做的任务,可以提醒某个任务持续了多久,可以提醒你一些重要的事情应该马上去做。
[安装][16] Taskwarrior 可以通过通过发行版自带的包管理器,或通过 Python 命令 `pip`安装,或者用源码编译。用法也和 Todo.txt 的命令完全一样:
|||
| ------------- |:-------------|
| `task add "某任务"` | 增加 "某任务" 到任务清单 |
| `task list` | 列出所有任务 |
| `task list due ``:today` |列出截止今天的任务 |
| `task do 3` | 标记编号是3的任务为完成状态 |
Taskwarrior 还有漂亮的文本用户界面。
![Taskwarrior in Vit][18]
我喜欢 Vit, 它的设计灵感来自 Vim.
不同于 Todo.txtTaskwarrior 可以和本地或远程服务器同步信息。如果你希望运行自己的同步服务器可以使用名为 `taskd` 的基础服务器,如果不使用自己的服务器也有好几个可用服务器。
Taskwarriot 还拥有一个蓬勃发展的插件和扩展生态系统,这和移动和桌面系统的应用生态类似。
![GNOME in Taskwarrior ][20]
在 GNOME 下的 Taskwarrior 看起来还是很漂亮的。
Taskwarrior 有一个唯一的缺点,你是不能直接修改待办任务的,这和其他的工具不一样。你只能把任务清单按照格式导出,然后修改导出文件后,重新再导入,这样相对于编辑器直接编辑任务还是挺麻烦的。
谁能给我们带来最大的希望呢......
### Emacs Org-mode: 牛逼的任务收割机
![Org-mode][22]
Emacs 具有所有优点。
Emacs [Org-mode][23] 是目前为止最强大,最灵活的开源待办任务管理器。它支持多文件,使用纯文本,高度定制和自动识别日期,截止日期和任务计划。相对于我们这里介绍的其他工具,它的配置也更复杂一些。但是一旦配置好,她可以比其他工具完成更多功能。如果你是熟悉或者是 [Bullet Journals][24] 的粉丝Org-mode 可能是在桌面程序里最像[Bullet Journals][24]的了。
Org-mode 可以运行在任何 Emacs 运行的地方一些移动应用程序可以和它很好交互。但是不幸的是目前没有桌面程序或浏览器插件支持Org-mode。尽管如此Org-mode仍然是跟踪待办事项最好的应用程序之一因为他确实很强大。
### 选择适合自己的工具
最后,这些程序目的是帮助你跟踪待办事务并确保不会忘记做某个事情。这些程序的基础功能都大同小异,那一款适合你取决于多种因素。有的人需要自带同步功能,有的人需要一个移动客户端,有的人要必须支持插件。不管你选择什么,请记住程序本身不会让你更有调理,但是可以帮助你。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/2/getting-to-done-agile-linux-command-line
作者:[Kevin Sonney][a]
译者:[guevaraya](https://github.com/guevaraya)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://opensource.com/users/ksonney (Kevin Sonney)
[1]:https://www.scruminc.com/getting-done/
[3]:https://opensource.com/sites/default/files/u128651/plain-text.png (plaintext)
[5]:https://opensource.com/sites/default/files/u128651/todo-txt.png (todo.txt screen)
[6]:http://todotxt.org/
[7]:https://github.com/todotxt/todo.txt-cli/releases
[9]:https://opensource.com/sites/default/files/u128651/todo-txt-install.png (Installing todo.txt)
[10]:https://github.com/todotxt/todo.txt
[12]:https://opensource.com/sites/default/files/u128651/todo-txt-vim.png (Syntax highlighting in todo.txt)
[14]:https://opensource.com/sites/default/files/u128651/tod-txt-gnome.png (GNOME extensions in todo.txt)
[15]:https://taskwarrior.org/
[16]:https://taskwarrior.org/download/
[18]:https://opensource.com/sites/default/files/u128651/taskwarrior-vit.png (Taskwarrior in Vit)
[20]:https://opensource.com/sites/default/files/u128651/taskwarrior-gnome.png (Taskwarrior on GNOME)
[22]:https://opensource.com/sites/default/files/u128651/emacs-org-mode.png (Org-mode)
[23]:https://orgmode.org/
[24]:http://bulletjournal.com/

View File

@ -0,0 +1,231 @@
使用Ansible来管理你的工作站配置自动化
======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/robot_arm_artificial_ai.png?itok=8CUU3U_7)
Ansible是一个令人惊讶的自动化的配置管理工具。主要应用在服务器和云部署上但在工作站上的应用无论是台式机还是笔记本却得到了很少的关注这就是本系列所要关注的。
在这个系列的第一部分,我会向你展示'ansible-pull'命令的基本用法我们创建了一个安装了少量包的palybook.它本身是没有多大的用处的,但是它为后续的自动化做了准备。
在这篇文章中所有的事件操作都是闭环的而且在最后部分我们将会有一个针对工作站自动配置的完整的工作解决方案。现在我们将要设置Ansible的配置这样未来将要做的改变将会自动的部署应用到我们的工作站上。现阶段假设你已经完成了第一部分的工作。如果没有的话当你完成的时候回到本文。你应该已经有一个包含第一篇文章中代码的Github库。我们将直接按照之前的方式创建。
首先,因为我们要做的不仅仅是安装包文件,所以我们要做一些重新的组织工作。现在,我们已经有一个名为'local.yml'并包含以下内容的playbook:
```
- hosts: localhost
become: true
tasks:
- name: Install packages
apt: name={{item}}
with_items:
- htop
- mc
- tmux
```
如果我们仅仅想实现一个任务那么上面的配置就足够了。随着向我们的配置中不断的添加内容这个文件将会变的相当的庞大和杂乱。最好能够根据不同类型的配置将play文件分为独立的文件。为了达到这个要求创建一个名为taskbook的文件它和playbook很像但内容更加的流线型。让我们在Git库中为taskbook创建一个目录。
```
mkdir tasks
```
在'local.yml'playbook中的代码使它很好过过渡到成为安装包文件的taskbook.让我们把这个文件移动到刚刚创建好并新命名的目录中。
```
mv local.yml tasks/packages.yml
```
现在,我们编辑'packages.yml'文件将它进行大幅的瘦身,事实上,我们可以精简除了独立任务本身之外的所有内容。让我们把'packages.yml'编辑成如下的形式:
```
- name: Install packages
apt: name={{item}}
with_items:
- htop
- mc
- tmux
```
正如你所看到的它使用同样的语法但我们去掉了对这个任务无用没有必要的所有内容。现在我们有了一个专门安装包文件的taskbook.然而我们仍然需要一个名为'local.yml'的文件,因为执行'ansible-pull'命令时仍然会去发现这个文件。所以我们将在我们库的根目录下(不是在'task'目录下)创建一个包含这些内容的全新文件:
```
- hosts: localhost
become: true
pre_tasks:
- name: update repositories
apt: update_cache=yes
changed_when: False
tasks:
- include: tasks/packages.yml
```
这个新的'local.yml'扮演的是将要导入我们的taksbooks的主页的角色。我已经在这个文件中添加了一些你在这个系列中看不到的内容。首先在这个文件的开头处我添加了'pre——tasks',这个任务的作用是在其他所有任务运行之前先运行某个任务。在这种情况下我们给Ansible的命令是让它去更新我们的分布存储库主页下面的配置将执行这个任务要求
```
apt: update_cache=yes
```
通常'apt'模块是用来安装包文件的但我们也能够让它来更新库索引。这样做的目的是让我们的每个play在Ansible运行的时候能够以最新的索引工作。这将确保我们在使用一个老旧的索引安装一个包的时候不会出现问题。因为'apt'模块仅仅在DebianUbuntu和他们的衍生环境下工作。如果你运行的一个不同的环境你期望在你的环境中使用一个特殊的模块而不是'apt'。如果你需要使用一个不同的模块请查看Ansible的相关文档。
下面这行值得以后解释:
```
changed_when: False
```
在独立任务中的这行阻止了Ansible去报告play改变的结果即使是它本身在系统中导致的一个改变。在这中情况下我们不会去在意库索引是否包含新的数据它几乎总是会的因为库总是在改变的。我们不会去在意'apt'库的改变,因为索引的改变是正常的过程。如果我们删除这行,我们将在过程保告的后面看到所有的变动,即使仅仅库的更新而已。最好能够去忽略这类的改变。
接下来是常规任务的阶段我们将创建好的taskbook导入。我们每次添加另一个taskbook的时候要添加下面这一行
```
tasks:
- include: tasks/packages.yml
```
如果你将要运行'ansible-pull'命令,他应该向上一篇文章中的那样做同样重要的事情。 不同的是我们已经提高了我们的组织并且能够更有效的扩展它。'ansible-pull'命令的语法,为了节省你到上一篇文章中去寻找,参考如下:
```
sudo ansible-pull -U https://github.com/<github_user>/ansible.git
```
如果你还记得话,'ansible-pull'的命令拉取一个Git库并且应用了它所包含的配置。
既然我们的基础已经搭建好我们现在可以扩展我们的Ansible并且添加功能。更特别的是我们将添加配置来自动化的部署对工作站要做的改变。为了支撑这个要求首先我们要创建一个特殊的账户来应用我们的Ansible配置。这个不是必要的我们仍然能够在我们自己的用户下运行Ansible配置。但是使用一个隔离的用户能够将其隔离到不需要我们参与的在后台运行的一个系统进程中
我们可以使用常规的方式来创建这个用户但是既然我们正在使用Ansible,我们应该尽量避开使用手动的改变。替代的是我们将会创建一个taskbook来处理用户的创建任务。这个taskbook目前将会仅仅创建一个用户但你可以在这个taskbook中添加额外的plays来创建更多的用户。我将这个用户命名为'ansible',你可以按照自己的想法来命名(如果你做了这个改变要确保更新所有的变动)。让我们来创建一个名为'user.yml'的taskbook并且将以下代码写进去
```
- name: create ansible user
user: name=ansible uid=900
```
下一步,我们需要编辑'local.yml'文件将这个新的taskbook添加进去像如下这样写
```
- hosts: localhost
become: true
pre_tasks:
- name: update repositories
apt: update_cache=yes
changed_when: False
tasks:
- include: tasks/users.yml
- include: tasks/packages.yml
```
现在当我们运行'ansible-pull'命令的时候,一个名为'ansible'的用户将会在系统中被创建。注意我特地通过参数'UID'为这个用户声明了用户ID为900。这个不是必须的但建议直接创建好UID。因为在1000以下的UID在登陆界面是不会显示的这样是很棒的因为我们根本没有需要去使用'ansibe'账户来登陆我们的桌面。UID 900是固定的它应该是在1000以下没有被使用的任何一个数值。你可以使用以下命令在系统中去验证UID 900是否已经被使用了
```
cat /etc/passwd |grep 900
```
然而你使用这个UID应该不会遇到什么问题因为迄今为止在我使用的任何发行版中我还没遇到过它是被默认使用的。
现在,我们已经拥有了一个名为'ansible'的账户,它将会在之后的自动化配置中使用。接下来,我们可以创建实际的定时作业来自动操作它。而不是将其放置到我们刚刚创建的'users.yml'文件中,我们应该将其分开放到它自己的文件中。在任务目录中创建一个名为'cron.yml'的taskbook并且将以下的代买写进去
```
- name: install cron job (ansible-pull)
cron: user="ansible" name="ansible provision" minute="*/10" job="/usr/bin/ansible-pull -o -U https://github.com/<github_user>/ansible.git > /dev/null"
```
定时模块的语法几乎是不需加以说明的。通过这个play,我们创建了一个通过用户'ansible'运行的定时作业。这个作业将每隔10分钟执行一次下面是它将要执行的命令
```
/usr/bin/ansible-pull -o -U https://github.com/<github_user>/ansible.git > /dev/null
```
同样我们也可以添加想要我们的所有工作站部署的额外定时作业到这个文件中。我们只需要在新的定时作业中添加额外的palys即可。然而仅仅是添加一个定时的taskbook是不够的我们还需要将它添加到'local.yml'文件中以便它能够被调用。将下面的一行添加到末尾:
```
- include: tasks/cron.yml
```
现在当'ansible-pull'命令执行的时候,它将会以通过用户'ansible'每个十分钟设置一个新的定时作业。但是每个十分钟运行一个Ansible作业并不是一个好的方式因为这个将消耗很多的CPU资源。每隔十分钟来运行对于Ansible来说是毫无意义的除非欧文已经在Git库中改变一些东西。
然而,我们已经解决了这个问题。注意到我在定时作业中的命令'ansible-pill'添加的我们之前从未用到过的参数'-o'.这个参数告诉Ansible只有在从上次'ansible-pull'被调用以后库有了变化后才会运行。如果库没有任何变化他将不会做任何事情。通过这个方法你将不会无端的浪费CPU资源。当然一些CPU资源将会在下来存储库的时候被使用但不会像再一次应用整个配置的时候使用的那么多。当'ansible-pull'执行的时候它将会遍历在playbooks和taskbooks中的所有任务但至少它不会毫无目的的运行。
尽管我们已经添加了所有必须的配置要素来自动化'ansible-pull',它任然还不能正常的工作。'ansible-pull'命令需要sudo的权限来运行这将允许它执行系统级的命令。然而我们创建的用户'ansible'并没有被设置为以'sudo'的权限来执行命令,因此当定时作业触发的时候,执行将会失败。通常沃恩可以使用命令'visudo'来手动的去设置用户'ansible'的拥有这个权限。然而我们现在应该以Ansible的方式来操作而且这将会是一个向你展示'copy'模块是如何工作的机会。'copy'模块允许你从库复制一个文件到文件系统的任何位置。在这个案列中,我们将会复制'sudo'的一个配置文件到'/etc/sudoers.d/'以便用户'ansible'能够以管理员的权限执行任务。
打开'users.yml',将下面的play添加到文件末尾。
```
- name: copy sudoers_ansible
copy: src=files/sudoers_ansible dest=/etc/sudoers.d/ansible owner=root group=root mode=0440
```
'copy'模块,正如我们看到的,从库复制一个文件到其他任何位置。在这个过程中,我们正在抓取一个名为'sudoers_ansible'(我们将在后续创建)的文件并将它复制到拥有者为'root'的'/etc/sudoers/ansible'中。
接下来,我们需要创建我们将要复制的文件。在你的库的根目录下,创建一个名为'files'的目录:
```
mkdir files
```
然后,在我们刚刚创建的'files'目录里,创建包含以下内容的名为'sudoers_ansible'的文件:
```
ansible ALL=(ALL) NOPASSWD: ALL
```
在'/etc/sudoer.d'目录里创建一个文件,就像我们正在这样做的,允许我们为一个特殊的用户配置'sudo'权限。现在我们正在通过'sudo'允许用户'ansible'不需要密码拥有完全控制权限。这将允许'ansible-pull'以后台任务的形式运行而不需要手动去运行。
现在,你可以通过再次运行'ansible-pull'来拉取最新的变动:
```
sudo ansible-pull -U https://github.com/<github_user>/ansible.git
```
从这个节点开始,'ansible-pull'的定时作业将会在后台每隔十分钟运行一次来检查你的库是否有变化如果它发现有变化将会运行你的palybook并且应用你的taskbooks.
所以现在我们有了一个完整的工作方案。当你第一次设置一台新的笔记本或者台式机的时候,你要去手动的运行'ansible-pull'命令,但仅仅是在第一次的时候。从第一次之后,用户'ansible'将会在后台接手后续的运行任务。当你想对你的机器做变动的时候你只需要简单的去拉取你的Git库来做变动然后将这些变化回传到库中。接着当定时作业下次在每台机器上运行的时候它将会拉取变动的部分并应用它们。你现在只需要做一次变动你的所有工作站将会跟着一起变动。这方法尽管有一点不方便通常你会有一个你的机器列表的文件和包含不同机器的规则。不管怎样'ansible-pull'的方法,就像在文章中描述的,是管理工作站配置的非常有效的方法。
我已经在我的[Github repository]中更新了这篇文章中的代码,所以你可以随时去浏览来再一次检查你的语法。同时我将前一篇文章中的代码移到了它自己的目录中。
在第三部分我们将通过介绍使用Ansible来配置GNOME桌面设置来结束这个系列。我将会告诉你如何设置你的墙纸和锁屏壁纸应用一个桌面主题以及更多的东西。
同时到了布置一些作业的时候了大多数人有我们使用的各种应用的配置文件。可能是Bash,Vim或者其他你使用的工具的配置文件。现在你可以尝试通过我们在使用的Ansible库来自动复制这些配置到你的机器中。在这篇文章中我已将想你展示了如何去复制文件所以去尝试以下看看你是都已经能应用这些知识。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/3/manage-your-workstation-configuration-ansible-part-2
作者:[Jay LaCroix][a]
译者:[FelixYFZ](https://github.com/FelixYFZ)
校对:[校对者ID](https://github.com/校对者ID)
选题:[lujun9972](https://github.com/lujun9972)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://opensource.com/users/jlacroix
[1]:https://opensource.com/article/18/3/manage-workstation-ansible
[2]:https://github.com/jlacroix82/ansible_article.git

View File

@ -1,71 +0,0 @@
Emacs #4使用org-mode自动管理邮件及同步文档
======
这是 [Emacs 和 org-mode 系类][4]的第四篇。
至今为止,你已经见识到了 org-mode 的强大和高效,如果你像我一样,你可能会想:
“我真的很想让它在我所有的设备上同步。”
或者是说:
“我能在 org-mode 中转发邮件吗?”
答案当然是肯定的,因为这就是 Emacs。
### 同步
由于 org-mode 只使用文本文件,所以使用任意工具都可以很容易地实现同步。我使用的是 git 的 git-remote-gcrypt。由于 git-remote-gcrypt 的一些限制,每台机器都倾向于推到自己的分支,并使用命令来控制。每台机子都会先合并其他所有的 branch 然后再将合并后的结果 push 到 master 上。cron 作业可以实现将机器上的 branch push 上去,而 elisp 会协调这一切--确保在同步之前保存缓冲区,在同步之后从磁盘刷新缓冲区,等等。
这篇文章的代码有点多,所以我将把它链接到 github 上,而不是写在这里。
我有一个用来存放我所有的 org-stuff 的目录 $HOME/org在 ~/org 目录下有个 [Makefile][2] 文件来处理同步。该文件定义了一下目标:
* push 添加,提交和 push 到以主机命名的 branch 上
* fetch 一个简单的 git fetch
* sync 添加,提交和 pull 远程的修改,合并并将其 push 到以主机命名的 branch 和 master 上(假设合并成功)
现在,在我的用户 crontab 中有这个:
```
*/15 * * * * make -C $HOME/org push fetch 2>&1 | logger --tag 'orgsync'
```
[accompanying elisp code][3] 定义了一个快捷键C-c s来调用同步。多亏了 cronjob只要文件被保存 -- 即使我没有在另一个 boxen 上同步 -- 它们也会被 pull 进来。
我发现这个设置非常好用。
### 用 org-mode 发邮件
在继续下去之前,首先要问自己一下:你真的需要它吗? 我用的是带有 [mu4e][4] 的 org-mode而且它集成的也很好任何组织任务都可以通过 message-id 链接到电子邮件,这很理想 -- 它可以让一个人做一些事情,比如提醒他在一周内回复一条消息。
然而org 不仅仅只有提醒。它还是一个知识库、创作系统等,但是并不是我所有的邮件客户端都使用 mu4e。(注意:像 MobileOrg 是存在于移动设备中)。我并没有像我想的那样经常使用它,但是它有它的用途,所以我认为我也应该在这里记录它。
现在我不仅想处理纯文本电子邮件。我希望能够处理附件、HTML 邮件等。这听起来很快就有问题了 -- 但是通过使用 ripmime 和 pandoc 这样的工具,情况还不错。
第一步就是要用某些方法将获取到的邮件放入指定的文件夹下。扩展名,特殊用户等。然后我用 [fetchmail configuration][5] 来将它 pull 下来并运行我自己的 [insorgmail][6] 脚本。
这个脚本就是处理所有有趣的部分了。它从 ripmime 开始处理消息,用 pandoc 将HTML 的部分转换为 org 格式。 org 的层次结构是用来尽可能最好地表示 email 的结构。使用HTML和其他工具时email 可能会变得相当复杂,但我发现这对于我来说是可以接受的。
### 下一篇
我最后一篇关于 org-mode 的文章将讨论如何使用它来编写文档和准备幻灯片 -- 我发现自己对 org-mode 的使用非常满意,但这需要一些调整。
--------------------------------------------------------------------------------
via: http://changelog.complete.org/archives/9898-emacs-4-automated-emails-to-org-mode-and-org-mode-syncing
作者:[John Goerzen][a]
译者:[oneforalone](https://github.com/oneforalone)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://changelog.complete.org/
[1]:https://changelog.complete.org/archives/tag/emacs2018
[2]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/Makefile
[3]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/emacs-config.org
[4]:https://www.emacswiki.org/emacs/mu4e
[5]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/fetchmailrc.orgmail
[6]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/insorgmail

View File

@ -1,680 +0,0 @@
使用 gorilla/mux 进行HTTP请求路由和验证
======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/data_metrics_analytics_desktop_laptop.png?itok=9QXd7AUr)
Go 网络库包括 `http.ServeMux` 结构类型,它支持 HTTP 请求多路复用路由Web 服务器将托管资源的 HTTP 请求与诸如 sales4today 之类的 URI 路由到代码处理程序; 处理程序在发送 HTTP 响应(通常是 HTML 页面)之前执行适当的逻辑。 这是该体系的草图:
```
                 +------------+     +--------+     +---------+
HTTP 请求---->| web 服务器 |---->| 路由 |---->| 处理程序|
                 +------------+     +--------+     +---------+
```
调用 `ListenAndServe` 方法后启动 HTTP 服务器
```
http.ListenAndServe(":8888", nil) // args: port & router
```
第二个参数 `nil` 意味着 `DefaultServeMux` 用于请求路由。
`gorilla/mux` 库包含 `mux.Router` 类型,可替代 `DefaultServeMux` 或自定义请求多路复用器。 在 `ListenAndServe` 调用中,`mux.Router` 实例将代替 `nil` 作为第二个参数。 下面的示例代码很好的说明了为什么 `mux.Router`如此吸引人:
### 1\. A sample crud web app
crud web 应用程序(见下文)支持四种 CRUD创建读取更新删除操作它们分别对应四种 HTTP 请求方法POSTGETPUT 和 DELETE。 在 crud 应用程序中,托管资源是陈词滥调对的列表,每个陈词滥调都是陈词滥调和冲突的陈词滥调,例如这对:
```
Out of sight, out of mind. Absence makes the heart grow fonder.
```
可以添加新的陈词滥调对,可以编辑或删除现有的陈词滥调对。
**crud web 应用程序**
```
package main
import (
   "gorilla/mux"
   "net/http"
   "fmt"
   "strconv"
)
const GETALL string = "GETALL"
const GETONE string = "GETONE"
const POST string   = "POST"
const PUT string    = "PUT"
const DELETE string = "DELETE"
type clichePair struct {
   Id      int
   Cliche  string
   Counter string
}
// Message sent to goroutine that accesses the requested resource.
type crudRequest struct {
   verb     string
   cp       *clichePair
   id       int
   cliche   string
   counter  string
   confirm  chan string
}
var clichesList = []*clichePair{}
var masterId = 1
var crudRequests chan *crudRequest
// GET /
// GET /cliches
func ClichesAll(res http.ResponseWriter, req *http.Request) {
   cr := &crudRequest{verb: GETALL, confirm: make(chan string)}
   completeRequest(cr, res, "read all")
}
// GET /cliches/id
func ClichesOne(res http.ResponseWriter, req *http.Request) {
   id := getIdFromRequest(req)
   cr := &crudRequest{verb: GETONE, id: id, confirm: make(chan string)}
   completeRequest(cr, res, "read one")
}
// POST /cliches
func ClichesCreate(res http.ResponseWriter, req *http.Request) {
   cliche, counter := getDataFromRequest(req)
   cp := new(clichePair)
   cp.Cliche = cliche
   cp.Counter = counter
   cr := &crudRequest{verb: POST, cp: cp, confirm: make(chan string)}
   completeRequest(cr, res, "create")
}
// PUT /cliches/id
func ClichesEdit(res http.ResponseWriter, req *http.Request) {
   id := getIdFromRequest(req)
   cliche, counter := getDataFromRequest(req)
   cr := &crudRequest{verb: PUT, id: id, cliche: cliche, counter: counter, confirm: make(chan string)}
   completeRequest(cr, res, "edit")
}
// DELETE /cliches/id
func ClichesDelete(res http.ResponseWriter, req *http.Request) {
   id := getIdFromRequest(req)
   cr := &crudRequest{verb: DELETE, id: id, confirm: make(chan string)}
   completeRequest(cr, res, "delete")
}
func completeRequest(cr *crudRequest, res http.ResponseWriter, logMsg string) {
   crudRequests<-cr
   msg := <-cr.confirm
   res.Write([]byte(msg))
   logIt(logMsg)
}
func main() {
   populateClichesList()
   // From now on, this gorountine alone accesses the clichesList.
   crudRequests = make(chan *crudRequest, 8)
   go func() { // resource manager
      for {
         select {
         case req := <-crudRequests:
         if req.verb == GETALL {
            req.confirm<-readAll()
         } else if req.verb == GETONE {
            req.confirm<-readOne(req.id)
         } else if req.verb == POST {
            req.confirm<-addPair(req.cp)
         } else if req.verb == PUT {
            req.confirm<-editPair(req.id, req.cliche, req.counter)
         } else if req.verb == DELETE {
            req.confirm<-deletePair(req.id)
         }
      }
   }()
   startServer()
}
func startServer() {
   router := mux.NewRouter()
   // Dispatch map for CRUD operations.
   router.HandleFunc("/", ClichesAll).Methods("GET")
   router.HandleFunc("/cliches", ClichesAll).Methods("GET")
   router.HandleFunc("/cliches/{id:[0-9]+}", ClichesOne).Methods("GET")
   router.HandleFunc("/cliches", ClichesCreate).Methods("POST")
   router.HandleFunc("/cliches/{id:[0-9]+}", ClichesEdit).Methods("PUT")
   router.HandleFunc("/cliches/{id:[0-9]+}", ClichesDelete).Methods("DELETE")
   http.Handle("/", router) // enable the router
   // Start the server.
   port := ":8888"
   fmt.Println("\nListening on port " + port)
   http.ListenAndServe(port, router); // mux.Router now in play
}
// Return entire list to requester.
func readAll() string {
   msg := "\n"
   for _, cliche := range clichesList {
      next := strconv.Itoa(cliche.Id) + ": " + cliche.Cliche + "  " + cliche.Counter + "\n"
      msg += next
   }
   return msg
}
// Return specified clichePair to requester.
func readOne(id int) string {
   msg := "\n" + "Bad Id: " + strconv.Itoa(id) + "\n"
   index := findCliche(id)
   if index >= 0 {
      cliche := clichesList[index]
      msg = "\n" + strconv.Itoa(id) + ": " + cliche.Cliche + "  " + cliche.Counter + "\n"
   }
   return msg
}
// Create a new clichePair and add to list
func addPair(cp *clichePair) string {
   cp.Id = masterId
   masterId++
   clichesList = append(clichesList, cp)
   return "\nCreated: " + cp.Cliche + " " + cp.Counter + "\n"
}
// Edit an existing clichePair
func editPair(id int, cliche string, counter string) string {
   msg := "\n" + "Bad Id: " + strconv.Itoa(id) + "\n"
   index := findCliche(id)
   if index >= 0 {
      clichesList[index].Cliche = cliche
      clichesList[index].Counter = counter
      msg = "\nCliche edited: " + cliche + " " + counter + "\n"
   }
   return msg
}
// Delete a clichePair
func deletePair(id int) string {
   idStr := strconv.Itoa(id)
   msg := "\n" + "Bad Id: " + idStr + "\n"
   index := findCliche(id)
   if index >= 0 {
      clichesList = append(clichesList[:index], clichesList[index + 1:]...)
      msg = "\nCliche " + idStr + " deleted\n"
   }
   return msg
}
//*** utility functions
func findCliche(id int) int {
   for i := 0; i < len(clichesList); i++ {
      if id == clichesList[i].Id {
         return i;
      }
   }
   return -1 // not found
}
func getIdFromRequest(req *http.Request) int {
   vars := mux.Vars(req)
   id, _ := strconv.Atoi(vars["id"])
   return id
}
func getDataFromRequest(req *http.Request) (string, string) {
   // Extract the user-provided data for the new clichePair
   req.ParseForm()
   form := req.Form
   cliche := form["cliche"][0]    // 1st and only member of a list
   counter := form["counter"][0]  // ditto
   return cliche, counter
}
func logIt(msg string) {
   fmt.Println(msg)
}
func populateClichesList() {
   var cliches = []string {
      "Out of sight, out of mind.",
      "A penny saved is a penny earned.",
      "He who hesitates is lost.",
   }
   var counterCliches = []string {
      "Absence makes the heart grow fonder.",
      "Penny-wise and dollar-foolish.",
      "Look before you leap.",
   }
   for i := 0; i < len(cliches); i++ {
      cp := new(clichePair)
      cp.Id = masterId
      masterId++
      cp.Cliche = cliches[i]
      cp.Counter = counterCliches[i]
      clichesList = append(clichesList, cp)
   }
}
```
为了专注于请求路由和验证crud 应用程序不使用 HTML 页面作为请求响应。 相反,请求会产生明文响应消息:陈词滥调对的列表是对 GET 请求的响应,确认新的陈词滥调对已添加到列表中是对 POST 请求的响应,依此类推。 这种简化使得使用命令行实用程序(如 [curl] [1])可以轻松地测试应用程序,尤其是 `gorilla/mux` 组件。
`gorilla/mux` 包可以从 [GitHub] [2] 安装。 crud app 无限期运行; 因此,应使用 Control-C 或同等命令终止。 crud 应用程序的代码,以及自述文件和简单的 curl 测试,可以在[我的网站] [3]上找到。
### 2\. 请求路由
`mux.Router` 扩展了 REST 风格的路由,它赋给 HTTP 方法例如GET和 URL 末尾的 URI 或路径(例如/cliches相同的权重。 URI 用作 HTTP 动词(方法)的名词。 例如在HTTP请求中有一个起始行例如
```
GET /cliches
```
意味着得到所有的陈词滥调对,而一个起始线,如
```
POST /cliches
```
意味着从HTTP正文中的数据创建一个陈词滥调对。
在 crud web 应用程序中有五个函数充当HTTP请求的五种变体的请求处理程序
```
ClichesAll(...)    # GET: 获取所有的陈词滥调对
ClichesOne(...)    # GET: 获取指定的陈词滥调对
ClichesCreate(...) # POST: 创建新的陈词滥调对
ClichesEdit(...)   # PUT: 编辑现有的陈词滥调对
ClichesDelete(...) # DELETE: 删除指定的陈词滥调对
```
每个函数都有两个参数:一个 `http.ResponseWriter` 用于向请求者发送一个响应,一个指向 `http.Request` 的指针,该指针封装了底层 HTTP 请求的信息。 使用 `gorilla/mux` 包可以轻松地将这些请求处理程序注册到Web服务器并执行基于正则表达式的验证。
crud 应用程序中的 `startServer` 函数注册请求处理程序。 考虑这对注册,`router` 作为 `mux.Router` 实例:
```
router.HandleFunc("/", ClichesAll).Methods("GET")
router.HandleFunc("/cliches", ClichesAll).Methods("GET")
```
这些语句意味着对单斜线/ 或 /cliches 的 GET 请求应该路由到 `ClichesAll` 函数,然后处理请求。 例如curl 请求(使用%作为命令行提示符)
```
% curl --request GET localhost:8888/
```
会产生如下结果
```
1: Out of sight, out of mind.  Absence makes the heart grow fonder.
2: A penny saved is a penny earned.  Penny-wise and dollar-foolish.
3: He who hesitates is lost.  Look before you leap.
```
三个陈词滥调对是 crud 应用程序中的初始数据。
在这句注册语句中
```
router.HandleFunc("/cliches", ClichesAll).Methods("GET")
router.HandleFunc("/cliches", ClichesCreate).Methods("POST")
```
URI是相同的/cliches但动词不同第一种情况下为 GET 请求,第二种情况下为 POST 请求。 此注册举例说明了 REST 样式的路由,因为仅动词的不同就足以将请求分派给两个不同的处理程序。
注册中允许多个 HTTP 方法,尽管这会影响 REST 风格路由的精髓:
```
router.HandleFunc("/cliches", DoItAll).Methods("POST", "GET")
```
除了动词和 URI 之外,还可以在功能上路由 HTTP 请求。 例如,注册
```
router.HandleFunc("/cliches", ClichesCreate).Schemes("https").Methods("POST")
```
要求对 POST 请求进行 HTTPS 访问以创建新的陈词滥调对。 以类似的方式,注册可能需要具有指定的 HTTP 头元素(例如,认证凭证)的请求。
### 3\. Request validation
`gorilla/mux` 包采用简单,直观的方法通过正则表达式进行请求验证。 考虑此请求处理程序以获取一个操作:
```
router.HandleFunc("/cliches/{id:[0-9]+}", ClichesOne).Methods("GET")
```
此注册排除了 HTTP 请求,例如
```
% curl --request GET localhost:8888/cliches/foo
```
因为 foo 不是十进制数字。 该请求导致熟悉的 404未找到状态码。 在此处理程序注册中包含正则表达式模式可确保仅在请求 URI 以十进制整数值结束时才调用 `ClichesOne` 函数来处理请求:
```
% curl --request GET localhost:8888/cliches/3  # ok
```
另一个例子,请求如下
```
% curl --request PUT --data "..." localhost:8888/cliches
```
此请求导致状态代码为 405错误方法因为 /cliches URI 在 crud 应用程序中仅在 GET 和 POST 请求中注册。 像 GET 请求一样PUT 请求必须在 URI 的末尾包含一个数字id
```
router.HandleFunc("/cliches/{id:[0-9]+}", ClichesEdit).Methods("PUT")
```
### 4\. 并发问题
`gorilla/mux` 路由器作为单独的 goroutine 执行对已注册的请求处理程序的每次调用,这意味着并发性被烘焙到包中。 例如,如果有十个同时发出的请求,例如
```
% curl --request POST --data "..." localhost:8888/cliches
```
然后 `mux.Router` 启动十个 goroutines 来执行 `ClichesCreate` 处理程序。
GET allGET onePOSTPUT 和 DELETE 中的五个请求操作中,最后三个改变了所请求的资源,即包含陈词滥调对的共享 `clichesList`。 因此crudapp 需要通过协调对`clichesList` 的访问来保证安全的并发性。 在不同但等效的术语中crud app 必须防止 `clichesList` 上的竞争条件。 在生产环境中,可以使用数据库系统来存储诸如 `clichesList` 之类的资源,然后可以通过数据库事务来管理安全并发。
crud 应用程序采用推荐的Go方法来实现安全并发
* 只有一个 goroutine资源管理器在 crud app`startServer` 函数中启动,一旦 Web 服务器开始侦听请求,就可以访问 `clichesList`
* 诸如 `ClichesCreate``ClichesAll` 之类的请求处理程序向 Go 通道发送(指向)`crudRequest` 实例(默认情况下是线程安全的),并且资源管理器单独从该通道读取。 然后,资源管理器对 `clichesList` 执行请求的操作。
安全并发体系结构绘制如下:
```
                 crudRequest                   读/写
请求处理程序 -------------> 资源托管者 ------------> 陈词滥调列表
```
在这种架构中,不需要显式锁定 `clichesList`,因为一旦 CRUD 请求开始进入,只有一个 goroutine资源管理器访问 `clichesList`
为了使 crud 应用程序尽可能保持并发,在一方请求处理程序与另一方的单一资源管理器之间进行有效的分工至关重要。 在这里,为了审查,是 `ClichesCreate` 请求处理程序:
```
func ClichesCreate(res http.ResponseWriter, req *http.Request) {
   cliche, counter := getDataFromRequest(req)
   cp := new(clichePair)
   cp.Cliche = cliche
   cp.Counter = counter
   cr := &crudRequest{verb: POST, cp: cp, confirm: make(chan string)}
   completeRequest(cr, res, "create")
}ClichesCreateres httpResponseWriterreqclichecountergetDataFromRequestreqcpclichePaircpClicheclichecpCountercountercr&crudRequestverbPOSTcpcpconfirmcompleteRequestcrres
```
`ClichesCreate` 调用实用函数 `getDataFromRequest`,它从 POST 请求中提取新的陈词滥调和反陈词滥调。 然后 `ClichesCreate` 函数创建一个新的 `ClichePair`,设置两个字段,并创建一个 `crudRequest` 发送给单个资源管理器。 此请求包括一个确认通道,资源管理器使用该通道将信息返回给请求处理程序。 所有设置工作都可以在不涉及资源管理器的情况下完成,因为尚未访问 `clichesList`
请求处理程序调用实用程序函数,该函数从 POST 请求中提取新的陈词滥调和反陈词滥调。 然后,该函数创建一个新的,设置两个字段,并创建 ato 发送到单个资源管理器。 此请求包括一个确认通道,资源管理器使用该通道将信息返回给请求处理程序。 所有设置工作都可以在不涉及资源管理器的情况下完成,因为尚未访问它。
`completeRequest` 实用程序函数在 `ClichesCreate` 函数和其他请求处理程序的末尾调用
```
completeRequest(cr, res, "create") // shown above
```
通过将 `crudRequest` 放入 `crudRequests` 频道,使资源管理器发挥作用:
```
func completeRequest(cr *crudRequest, res http.ResponseWriter, logMsg string) {
   crudRequests<-cr          // 向资源托管者发送请求
   msg := <-cr.confirm       // 等待确认
   res.Write([]byte(msg))    // 向请求方发送确认
   logIt(logMsg)             // 打印到标准输出
}
```
对于 POST 请求,资源管理器调用实用程序函数 `addPair`,它会更改 `clichesList` 资源:
```
func addPair(cp *clichePair) string {
   cp.Id = masterId  // 分配一个唯一的 ID
   masterId++        // 更新 ID 计数器
   clichesList = append(clichesList, cp) // 更新列表
   return "\nCreated: " + cp.Cliche + " " + cp.Counter + "\n"
}
```
资源管理器为其他CRUD操作调用类似的实用程序函数。 值得重复的是,一旦 Web 服务器开始接受请求,资源管理器就是唯一可以读取或写入 `clichesList` 的 goroutine。
对于任何类型的 Web 应用程序,`gorilla/mux` 包在简单直观的API中提供请求路由请求验证和相关服务。 crud web 应用程序突出了软件包的主要功能。 给包裹一个测试驱动,你可能会成为买主。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/8/http-request-routing-validation-gorillamux
作者:[Marty Kalin][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[yongshouzhang](https://github.com/yongshouzhang)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://opensource.com/users/mkalindepauledu
[1]:https://curl.haxx.se/
[2]:https://github.com/gorilla/mux
[3]:http://condor.depaul.edu/mkalin

View File

@ -0,0 +1,228 @@
量子计算的开源框架 Cirq 介绍
======
我们即将讨论的内容正如标题所示,本文通过使用 Cirq 的一个开源视角,尝试去了解我们已经在量子计算领域取得多大的成就,和该领域的发展方向,以加快科学和技术研究。
首先,我们将引领你进入量子计算的世界。在我们深入了解 Cirq 在未来的量子计算中扮演什么样的重要角色之前我们将尽量向你解释其背后的基本概念。Cirq你最近可能听说过在这个领域中已经发生了重大新闻在 Open Science 上的文章中,我们将去尝试找出答案。
<https://www.youtube.com/embed/WVv5OAR4Nik?enablejsapi=1&autoplay=0&cc_load_policy=0&iv_load_policy=1&loop=0&modestbranding=1&rel=0&showinfo=0&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=2&>
在我们开始了解量子计算之前,必须先去了解“量子”这个术语,量子是已知的 [亚原子粒子][1] 中最小的物质。[量子][2] 这个词来自拉丁语 Quantus意思是 “有多少”,在下面的短视频链接中有描述:
<https://www.youtube.com/embed/-pUOxVsxu3o?enablejsapi=1&autoplay=0&cc_load_policy=0&iv_load_policy=1&loop=0&modestbranding=1&rel=0&showinfo=0&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=2&>
为了易于我们理解量子计算,我们将量子计算与<ruby>经典计算<rt>Classical Computing</rt></ruby>(也有译做传统计算)进行比较。经典计算是指设计用于工作的、正在使用的计算机,正如你现在用于阅读本文的设备,就是我们所谓的经典计算设备。
### 经典计算
经典计算是描述计算机如何工作的另一种方式。它们通过一个二进制系统工作,即信息使用 1 或 0 来存储。经典计算机不会理解除 1 或 0 之外的任何其它东西。
直白来说在计算机内部一个晶体管只能是开1或关0。我们输入的任何信息都被转换为无数个 1 和 0所以计算机只能理解和存储 1 和 0。所有的东西都只能用无数个 1 和 0 的组合来表示。
<https://www.youtube.com/embed/Xpk67YzOn5w?enablejsapi=1&autoplay=0&cc_load_policy=0&iv_load_policy=1&loop=0&modestbranding=1&rel=0&showinfo=0&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=2&>
### 量子计算
然而,量子计算不再像经典计算那样遵循 “开或关” 的模式。而是,借助量子的名为 [叠加和纠缠][3] 的两个现象,能同时处理信息的多个状态,因此能以更快的速率加速计算,并且在信息存储方面效率更高。
请注意,叠加和纠缠 [不是同一个现象][4]。
<https://www.youtube.com/embed/jiXuVIEg10Q?enablejsapi=1&autoplay=0&cc_load_policy=0&iv_load_policy=1&loop=0&modestbranding=1&rel=0&showinfo=0&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=2&>
![][5]
就像在经典计算中,我们有<ruby>比特<rt>bit</rt></ruby>,在量子计算中,我们相应也有<ruby>量子比特<rt>qubits</rt></ruby>(或 Quantum bits。想了解它们二者之间的巨大差异之处请查看这个 [页面][6],从那里的图片中可以得到答案。
量子计算机并不是来替代我们的经典计算机的。但是,有一些非常巨大的任务用我们的经典计算机是无法完成的,而那些正是量子计算机大显身手的好机会。下面链接的视频详细描述了上述情况,同时也描述了量子计算机的原理。
<https://www.youtube.com/embed/JhHMJCUmq28?enablejsapi=1&autoplay=0&cc_load_policy=0&iv_load_policy=1&loop=0&modestbranding=1&rel=0&showinfo=0&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=2&>
下面的视频全面描述了量子计算领域到目前为止的最新进展:
<https://www.youtube.com/embed/CeuIop_j2bI?enablejsapi=1&autoplay=0&cc_load_policy=0&iv_load_policy=1&loop=0&modestbranding=1&rel=0&showinfo=0&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=2&>
### 嘈杂中型量子
根据最新更新的2018 年 7 月 31 日)研究论文,术语 “Noisy” 是指由于对量子比特未能完全控制所产生的不准确性。正是这种不准确性严重制约了量子设备短期内实现其目标。
“中型” 指的是在接下来的几年中,量子计算机将要实现的量子规模大小,届时,量子比特的数目将可能从 50 到几百个不等。50 个量子比特是一个重大的量程碑,因为它将超越现有的最强大的 [超级计算机][8] 的 [暴力][7] 模拟能力。更多信息请阅读 [这里的][9] 论文。
随着 Cirq 出现,许多事情将会发生变化。
### Cirq 是什么?
Cirq 是一个 python 框架它用于创建、编辑和调用我们前面讨论的嘈杂中型量子NISQ。换句话说Cirq 能够解决挑战,去改善精确度和降低量子计算中的噪声。
Cirq 并不需要必须有一台真实的量子计算机。Cirq 能够使用一个类似模拟器的界面去执行量子电路模拟。
Cirq 的前进步伐越来越快了,[Zapata][10] 是使用它的首批用户之一Zapata 是由来自哈佛大学的一群专注于量子计算的科学家在去年成立的。
### Linux 上使用 Cirq 入门
开源的 [Cirq 库][12] 开发者建议将它安装在像 [virtualenv][14] 这样的一个 [虚拟 python 环境][13] 中。在 Linux 上的开发者安装指南可以在 [这里][15] 找到。
但我们在 Ubuntu 16.04 的系统上成功地安装和测试了 Python3 的 Cirq 库,安装步骤如下:
#### 在 Ubuntu 上安装 Cirq
![Cirq Framework for Quantum Computing in Linux][16]
首先,我们需要 pip 或 pip3 去安装 Cirq。[Pip][17] 是推荐用于安装和管理 Python 包的工具。
对于 Python 3.x 版本Pip 能够用如下的命令来安装:
```
sudo apt-get install python3-pip
```
Python3 包能够通过如下的命令来安装:
```
pip3 install <package-name>
```
我们继续去使用 Pip3 为 Python3 安装 Cirq 库:
```
pip3 install cirq
```
#### 启用 Plot 和 PDF 生成(可选)
可选系统的依赖没有安装的,可以使用 pip 去安装它:
```
sudo apt-get install python3-tk texlive-latex-base latexmk
```
* python3-tk 是 Python 自有的启用了绘图功能的图形库
* texlive-latex-base 和 latexmk 启动了 PDF 输出功能。
最后,我们使用如下的命令和代码成功测试了 Cirq
```
python3 -c 'import cirq; print(cirq.google.Foxtail)'
```
我们得到的输出如下图:
![][18]
#### 为 Cirq 配置 Pycharm IDE
我们也配置了一个 Python IDE [PyCharm][19] 去测试同样的结果:
因为在我们的 Linux 系统上为 Python3 安装了 Cirq我们在 IDE 中配置项目解释器路径:
```
/usr/bin/python3
```
![][20]
在上面的输出中你可能注意到我们刚设置的项目解释器路径与测试程序文件test.py的路径显示在一起。退出代码 0 表示程序已经成功退出,没有错误。
因此,那是一个现成的 IDE 环境,你可以导入 Cirq 库去开始使用 Python 去编程和模拟量子电路。
#### Cirq 使用入门
Criq 入门的一个好的开端就是它 GitHub 页面上的 [示例][21]。
Cirq 的开发者在 GitHub 上已经放了学习 [教程][22]。如果你想认真地学习量子计算,他们推荐你去看一本非常好的书,它是[由 Nielsen 和 Chuang 写的名为 “量子计算和量子信息“][23]。
#### OpenFermion-Cirq
[OpenFermion][24] 是一个开源库,它是为了在量子计算机上模拟获取和操纵代表的费米系统(包含量子化学)。根据 [粒子物理学][26] 理论,按照 [费米— 狄拉克统计][27],费米系统与 [费米子][25] 的产生相关。
OpenFermion 被称为从事 [量子化学][29] 的化学家和研究人员的 [一个极好的实践工具][28]。量子化学主要专注于 [量子力学][30] 在物理模型和化学系统实验中的应用。量子化学也被称为 [分子量子力学][31]。
Cirq 的出现使 OpenFermion 通过提供程序和工具去扩展功能成为了可能,通过使用 Cirq 可以去编译和构造仿真量子电路。
#### Google Bristlecone
2018 年 3 月 5 日,在洛杉矶举行的一年一度的 [美国物理学会会议][33] 上Google 发布了 [Bristlecone][32],这是他们的最新的量子处理器。这个 [基于门的超导系统][34] 为 Google 提供了一个测试平台,用以研究 [量子比特技术][37] 的 [系统错误率][35] 和 [扩展性][36] ,以及在量子 [仿真][38]、[优化][39]、和 [机器学习][40] 方面的应用。
Google 希望在不久的将来,能够制造出它的 [云可访问][41] 的 72 个量子比特的 Bristlecone 量子处理器。Bristlecone 将越来越有能力完成一个经典超级计算机无法在合理时间内完成的任务。
Cirq 将让研究人员直接在云上为 Bristlecone 写程序变得很容易,它提供了一个非常方便的、实时的、量子编程和测试的接口。
Cirq 将允许我们去:
* 量子电路的微调管理
* 使用原生门去指定 [门][42] 行为
* 在设备上放置适当的门
* 并调度这个门的时刻
### Open Science 关于 Cirq 的观点
我们知道 Cirq 是在 GitHub 上开源的,它除了在 Open Science 社区之外,特别是那些专注于量子研究的人们,都可以高效率地合作,通过开发新方法,去降低现有量子模型中的错误率和提升精确度,以解决目前在量子计算中所面临的挑战。
如果 Cirq 不走开源模型的路线,事情可能变得更具挑战。一个伟大的创举可能就此错过,我们可能在量子计算领域止步不前。
### 总结
最后我们总结一下,我们首先通过与经典计算相比较,介绍了量子计算的概念,然后是一个非常重要的视频来介绍了自去年以来量子计算的最新发展。接着我们简单讨论了嘈杂中型量子,也就是为什么要特意构建 Cirq 的原因所在。
我们看了如何在一个 Ubuntu 系统上安装和测试 Cirq。我们也在一个更好用的 IDE 环境中做了安装测试,并使用一些资源去开始学习有关概念。
最后,我们看了两个示例 OpenFermion 和 Bristlecone介绍了在量子计算中Cirq 在开发研究中具有什么样的基本优势。最后我们以 Open Science 社区的视角对 Cirq 进行了一些精彩的思考,结束了我们的话题。
我们希望能以一种易于理解的方式向你介绍量子计算框架 Cirq 的使用。如果你有与此相关的任何反馈,请在下面的评论区告诉我们。感谢阅读,希望我们能在 Open Science 的下一篇文章中再见。
--------------------------------------------------------------------------------
via: https://itsfoss.com/qunatum-computing-cirq-framework/
作者:[Avimanyu Bandyopadhyay][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[qhwdw](https://github.com/qhwdw)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/avimanyu/
[1]:https://en.wikipedia.org/wiki/Subatomic_particle
[2]:https://en.wikipedia.org/wiki/Quantum
[3]:https://www.clerro.com/guide/491/quantum-superposition-and-entanglement-explained
[4]:https://physics.stackexchange.com/questions/148131/can-quantum-entanglement-and-quantum-superposition-be-considered-the-same-phenom
[5]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/bit-vs-qubit.jpg
[6]:http://www.rfwireless-world.com/Terminology/Difference-between-Bit-and-Qubit.html
[7]:https://en.wikipedia.org/wiki/Proof_by_exhaustion
[8]:https://www.explainthatstuff.com/how-supercomputers-work.html
[9]:https://arxiv.org/abs/1801.00862
[10]:https://www.xconomy.com/san-francisco/2018/07/19/google-partners-with-zapata-on-open-source-quantum-computing-effort/
[11]:https://www.zapatacomputing.com/about/
[12]:https://github.com/quantumlib/Cirq
[13]:https://itsfoss.com/python-setup-linux/
[14]:https://virtualenv.pypa.io
[15]:https://cirq.readthedocs.io/en/latest/install.html#installing-on-linux
[16]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/cirq-framework-linux.jpeg
[17]:https://pypi.org/project/pip/
[18]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/cirq-test-output.jpg
[19]:https://itsfoss.com/install-pycharm-ubuntu/
[20]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/cirq-tested-on-pycharm.jpg
[21]:https://github.com/quantumlib/Cirq/tree/master/examples
[22]:https://github.com/quantumlib/Cirq/blob/master/docs/tutorial.md
[23]:http://mmrc.amss.cas.cn/tlb/201702/W020170224608149940643.pdf
[24]:http://openfermion.org
[25]:https://en.wikipedia.org/wiki/Fermion
[26]:https://en.wikipedia.org/wiki/Particle_physics
[27]:https://en.wikipedia.org/wiki/Fermi-Dirac_statistics
[28]:https://phys.org/news/2018-03-openfermion-tool-quantum-coding.html
[29]:https://en.wikipedia.org/wiki/Quantum_chemistry
[30]:https://en.wikipedia.org/wiki/Quantum_mechanics
[31]:https://ocw.mit.edu/courses/chemical-engineering/10-675j-computational-quantum-mechanics-of-molecular-and-extended-systems-fall-2004/lecture-notes/
[32]:https://techcrunch.com/2018/03/05/googles-new-bristlecone-processor-brings-it-one-step-closer-to-quantum-supremacy/
[33]:http://meetings.aps.org/Meeting/MAR18/Content/3475
[34]:https://en.wikipedia.org/wiki/Superconducting_quantum_computing
[35]:https://en.wikipedia.org/wiki/Quantum_error_correction
[36]:https://en.wikipedia.org/wiki/Scalability
[37]:https://research.googleblog.com/2015/03/a-step-closer-to-quantum-computation.html
[38]:https://research.googleblog.com/2017/10/announcing-openfermion-open-source.html
[39]:https://research.googleblog.com/2016/06/quantum-annealing-with-digital-twist.html
[40]:https://arxiv.org/abs/1802.06002
[41]:https://www.computerworld.com.au/article/644051/google-launches-quantum-framework-cirq-plans-bristlecone-cloud-move/
[42]:https://en.wikipedia.org/wiki/Logic_gate

View File

@ -0,0 +1,60 @@
认识存储:块、文件和对象
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/block2_1920.jpg?itok=s1y6RLhT)
现在,对于那些创建或消费数据的公司来说,处理生成的数量巨大的数据是个非常大的挑战。而对于那些解决存储相关问题的科技公司来说,也是一个挑战。
Red Hat 存储首席产品营销经理 Michael St. Jean 说,“数据每年呈几何级增长,而我们发现数据大量增长的主要原因是由于消费增长和为拓展价值而进行的产业转型,毫无疑问,物联网对数据增长的贡献很大,但对软件定义存储来说最重要的挑战是,如何处理用户场景相关的数据增长。“
任何挑战都意味着机遇。Azure 存储、介质和边缘总经理 Tad Brockway 说,“今天,新旧数据源产生的海量数据为我们满足客户在规模、性能、灵活性、治理方面急剧增长的需求提供了一个机遇。”
### 现代软件定义存储的三种类型
这里有三个不同类型的存储解决方案 — 块、文件、和对象 — 虽然它们每个都可以与其它的共同工作,但它们每个都有不同的用途。
块存储是数据存储的最古老形式,数据都存储在固定长度的块或多个块中。块存储适用于企业存储环境,并且通常使用光纤通道或 iSCSI 接口。根据 SUSE 软件定义存储高级产品经理 Larry Morris 的说法,“块存储要求一个应用去映射存储设备上存储数据块的位置”。
块存储在存储区域网和软件定义存储系统中是虚拟的,它是处于一个共享的硬件基础设施上的抽象逻辑设备,它创建和存在于服务器、虚拟服务器、或运行在基于像 SCSI、SATA、SAS、FCP、FCoE、或 iSCSI 这样的协议的系统管理程序上。
St. Jean 说“块存储将单个的存储卷(像一个虚拟或云存储节点、或一个老式硬盘)分割成单独的被称为块的实体。“
每个块独立存在,并且能够用它自己的数据传输协议和操作系统格式化 — 给用户完全的配置自主权。由于块存储系统并不负责像文件存储系统那样的文件查找职责,所以,块存储是一个非常快的存储系统。由于同时具备速度和配置灵活性,使得块存储非常适合原始服务器存储或富媒体数据库。
块存储适合于宿主机操作系统、应用程序、数据库、完整虚拟机和容器。传统上,块存储仅能够被独立的机器、或集群中呈现出的机器访问。
### 基于文件的存储
基于文件的存储使用一个文件系统去映射存储设备上数据的存储位置。这种技术在直接或网络附加存储系统应用领域中处于支配地位。它需要做两件事情:组织数据并呈现给用户。 St. Jean 说,”使用文件存储时,数据在服务器侧的排列格式与客户端用户所看到的是完全相同的。这就允许用户通过一些唯一标识符(像文件名、位置、或 URL去请求一个文件使用特定的数据传输协议与存储系统沟通。
最终成为了一种能够从上到下进行浏览的分层的文件结构。文件存储处于块存储之上,允许用户去查看和访问文件、文件夹这样的数据,但是限制访问处于这些文件和文件夹之下的数据块。
Brockway 解释说,“文件存储一般用于像 NFS 和 CIFS/SMB 这种很多服务器基于 IP 网络进行访问的共享文件系统上。访问控制通过用户和组的权限实现在文件、目录、和导出级别上。基于文件的存储可用于被多个用户和机器、二进制应用程序、数据库、虚拟机所需要的文件的存储上,以及容器上。“
### 对象存储
对象存储是最新的数据存储形式,它为非结构化数据提供一个库,它将内容从索引中分离出来,并允许多个文件连接到一个对象上。一个对象就是与任何相关元数据配对的一个数据块,这些元数据提供对象中包含的字节的上下文(比如数据创建时间和数据大小等)。也就是说这两样东西 — 数据和元数据 — 构成了一个对象。
对象存储的一个好处是每个数据块都关联了一个唯一标识符。访问数据需要唯一标识符,并且不需要应用程序或用户知道数据的真实存储位置。对象数据是通过 API 来访问的。
St. Jean 说,“对象中存储的数据是没有压缩和加密的,对象本身被安排在对象存储(一个填满其它对象的中心库)中或容器(包含应用程序运行所需要的所有文件的一个包)中。与文件存储系统的层次结构相比,对象、对象存储和容器在本质上是平面的 — 这使得它们在存储规模巨大时访问速度很快。”
对象存储可以扩展到很多 PB 字节大小,以适应巨大的数据集,因此它是图像、音频、视频、日志、备份、和分析服务所使用的数据存储的最佳选择。
### 结论
现在你已经知道了各种类型的存储以及它们的用处。后面我们将继续研究这个主题的更多内容,敬请关注。
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/2018/9/know-your-storage-block-file-object
作者:[Swapnil Bhartiya][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[qhwdw](https://github.com/qhwdw)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.linux.com/users/arnieswap
[1]: https://events.linuxfoundation.org/events/elc-openiot-europe-2018/

View File

@ -0,0 +1,108 @@
在 Linux 下交换 Ctrl 与 Caps Lock 键
======
Linux 桌面环境使你可以根据需要轻松设置键盘。下面来演示如何去做。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/keyboard_numbers_letters_type_game.jpg?itok=fLlWGw1K)
对于许多使用计算机很多年的用户来说,自从第一批 PC 键盘从生产线上下线后不久Ctrl 和 Caps Lock 键就已经在错误的位置上了。对我来说,这张 1995 年 Sun 工作站的老式键盘照片上的两个键的位置才是正确的。(原谅我放了一张模糊的图片,它是在昏暗的光线下使用 Minox 间谍相机拍摄的。)
感兴趣的话,可以读一下维基百科上对于 [Ctrl 键位置的历史][1] 的介绍。我不打算讨论将 Ctrl 键放在“a”旁边而不是 Shift 键下方的各种理由,不评论 Caps Lock 键的无用性,也没有打算与那些主张使用手掌根来触发 Ctrl 键的人争论,即使在一些笔记本电脑键盘上也不可能这样做,因为有的键会位于腕托以下。
相反,我将假设我不是唯一喜欢把 Ctrl 键放在“a”旁边的人并说明如何使用 Linux 自带的灵活性在各种桌面环境中交换 Ctrl 和 Caps Lock 键的位置。请注意,下面的演示可能只有有限的有效期,因为调整桌面设置的方法经常发生变化,但我希望这为你开了一个好头。
### GNOME 3
[GNOME 3][2] 桌面环境用户可以使用 [Tweaks][3] 工具交换 Caps Lock 和 Ctrl 键,如下所示。![](https://opensource.com/sites/default/files/uploads/tweaks-tool.png)
具体步骤如下:
1. 从你的 Linux 发行版的软件仓库安装 Tweaks 工具。
2. 启动 Tweaks 程序。
3. 从左侧菜单中选择“Keyboard & Mouse”。
4. 单击“Additional Layout Options”。
5. 在打开的窗口中单击“Ctrl position”然后选择“Swap Ctrl and Caps Lock”。
完成!顺便说一句,你可以使用 Tweaks 工具做很多很酷的事情。例如,我将我的右 Ctrl 键设置为 Compose 键,这让我可以使用键盘快捷键打出各种字符,例如通过 `Compose+c+,`、`Compose+e+'`、`Compose+O+^` 以及 `Compose+n+~` 分别键入 ç、é、ô 和 ñ。
### KDE
我不使用 [KDE][4],但我的同事 Seth Kenlon 写的 [KDE tweaks that will change your life][5] 这篇文章的第 5 项演示了如何重新映射按键。
### Xfce
据我所知,[Xfce][6] 桌面环境没有一个方便的工具来管理这些(指交换按键)设置。 但是,`setxkbmap` 命令的 `ctrl:swapcaps` 选项可以帮助你完成交换按键的修改。这个修改包含两部分:
1. 弄清楚命令的用法;
2. 找出调用命令的位置,以便在桌面启动时激活它。
第一部分非常简单,命令是:
```
/usr/bin/setxkbmap -option "ctrl:nocaps"
```
在终端窗口中执行此命令,以确保结果符合你的预期。
假设上述命令有效,应该在哪里调用此命令呢?这需要一些实验。一种可能是在用户主目录的 `.profile` 文件中;另一个可能是将命令添加到 Xfce 的自启动配置在设置管理器中查找“Session and Startup”里。
还有一种可能性是在文件 `/etc/default/keyboard` 中使用相同的选项,最终可能看起来像这样:
```
# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) manual page.
XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS="ctrl:swapcaps"
BACKSPACE="guess"
```
注意,这个更改将影响所有用户,因此如果你和其他人共享计算机,请准备好进行一些说明。此外,系统更新可能会覆盖此文件,因此如果你的设置失效了,就需要再次编辑它。将相同的信息放在用户主目录中的 `.keyboard` 文件内,可以为每个用户进行设置。
最后请注意,这些更改需要重新启动 Xfce除非在终端窗口中的命令行上运行但这在会话结束之后便会失效
### LXQt 和其他桌面环境
我没有用过 [LXQt][7],但根据我使用 [LXDE][8] 的经验,我会尝试上面用于 Xfce 的方法。我也希望适用于 Xfce 的方法可以用于其他 Linux 桌面环境。当然了,在其他桌面环境上遇到问题的时候,可以通过你最喜欢的搜索引擎来查找解决办法。
### 控制台
我没有在控制台上进行过尝试,因为我很少有机会与控制台(你在服务器上看到的或你的窗口系统没有正确显示时出现的界面)进行交互。上面给出的方法以人们希望的方式(即与其他应用程序一致)调整终端窗口。
但是,如果像上面一样已经编辑了 `/etc/default/keyboard` 文件或 `〜/.keyboard`,则实用程序 `setupcon` 可以用于更改控制台的键盘设置,以便实现相同的功能。[链接 1][9]、[链接 2][10] 和 [链接 3][11] 给出了一些关于如何从这两个文件实现这些更改的想法。第三个链接还讨论了使用 `dumpkeys``loadkeys` 来实现想要的效果。[setupcon 的手册][12] 简短而重要,值得阅读,再结合上面 StackExchange 问题的一些评论,应该足以得到一个解决办法。
### 其他环境
最后,上面 StackExchange 的链接中提到的这一点值得强调--配置控制台与配置终端窗口不同;如前所述,后者是通过桌面管理器进行配置的。
`setxkbmap`、`xkeyboard-config`、`keyboard`、`console-setup` 和 `setupcon` 命令的手册都是有用的参考资料。或者,如果你不喜欢阅读手册,可以看一下 [这篇极好的文章][13]。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/11/how-swap-ctrl-and-caps-lock-your-keyboard
作者:[Chris Hermansen][a]
选题:[lujun9972][b]
译者:[jlztan](https://github.com/jlztan)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/clhermansen
[b]: https://github.com/lujun9972
[1]: https://en.wikipedia.org/wiki/Control_key
[2]: https://www.gnome.org/gnome-3/
[3]: https://wiki.gnome.org/Apps/Tweaks
[4]: https://www.kde.org/
[5]: https://opensource.com/article/17/5/7-cool-kde-tweaks-will-improve-your-life
[6]: https://www.xfce.org/
[7]: https://lxqt.org/
[8]: https://lxde.org/
[9]: https://askubuntu.com/questions/485454/how-to-remap-keys-on-a-user-level-both-with-and-without-x
[10]: https://unix.stackexchange.com/questions/198791/how-do-i-permanently-change-the-console-tty-font-type-so-it-holds-after-reboot
[11]: https://superuser.com/questions/290115/how-to-change-console-keymap-in-linux
[12]: http://man.he.net/man1/setupcon
[13]: http://www.noah.org/wiki/CapsLock_Remap_Howto

View File

@ -0,0 +1,86 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (SMPlayer in Linux: Features, Download and Installation)
[#]: via: (https://itsfoss.com/smplayer/)
[#]: author: (Aquil Roshan;Abhishek Prakash https://itsfoss.com/author/aquil/)
[#]: url: ( )
Linux 中的 SMPlayer功能下载和安装
======
当你要播放视频时,你会在[全新安装的 Ubuntu][1],或其他许多发行版中,会注意到一个消息:
![][2]
默认媒体播放器没有适合的编解码器
这意味着系统上没有安装播放媒体的[所需编解码器][3]。现在,由于某些版权问题,某些基于 Linux 的操作系统无法在安装介质中预先打包编解码器。但是它们能让你只需点击即可下载和安装编解码器,或者你可以安装拥有所有媒体编解码器的媒体播放器。了解一下 [SMPlayer][4]。
### 认识 SMPlayer适用于 Linux 的更好的媒体播放器
SMPlayer 是一款免费的开源媒体播放器,它基于强大的 [MPlayer][5] 媒体引擎。SMPlayer 能够播放 avi、mp4、mkv、mpeg、mov、divx、h.264 以及其他任何主要媒体格式。锦上添花的是,它也可以播放 [YouTube][6] 视频,并且无广告。
![SMPlayer default interface][7]
SMPlayer 是一个完整的媒体解决方案。它是跨平台的,因此可在所有操作系统上使用。如果你是双启动,则可以将其安装在 Windows 和 Linux 操作系统上,以便在两个系统上获得统一的体验。它还支持带触摸的可变形笔记本。
你也可以在 SMPlayer 上播放 YouTube。我知道每次复制粘贴视频 URL 并在外部播放器上播放是不切实际的。但是当你观看相对较长的视频时SMPlayer 特别有用。SMPlayer 以相当好的质量播放 YouTube 视频,我觉得比在浏览器中播放得更好。通过在 SMPlayer 上播放较长的视频,你可以远离视频中间弹出的插播广告。
如果你在观看没有字幕的电影,你可以直接通过 SMPlayer 下载字幕。它集成了 [opensubtitles.org][8]。所以打开浏览器搜索字幕下载相应的字幕解压缩将它们放在视频文件夹中并将字幕连接到电影这些都不需要SMPlayer 会为你服务。
![Automatic subtitle download in SMPlayer][9]
SMPlayer 支持 30 多种语言,并可高度自定义。它还有应用主题和大量的图标集。
如果你觉得 SMPlayer 的默认界面看起来不太好,只需点击几下,它就可以看起来像这样:
![SMPlayer skin change][10]
SMPlayer 为高级用户提供了许多工具和功能。它有均衡器、视频速度控制、宽高比和缩放控制、视频过滤器、屏幕截图等等。
总而言之,我真的很喜欢 SMPlayer。它在一个小巧轻量级的安装包中提供了很多功能。我认为它是 Linux PC 上必备的视频播放器。除了轻松播放所有媒体格式外,它还提供了大量的控制。
### 在 Linux 上安装 SMPlayer
SMPlayer 应该可在所有主要 Linux 发行版的软件中心获取。你可以搜索它并从那里安装它。
在 Ubuntu/ Linux Mint/ Elementary OS 上,你还可以通过在终端中运行以下命令来安装 SMPlayer
```
sudo apt install smplayer
```
或者,你可以在[这里][11]下载 Fedora、Arch Linux、OpenSUSE 和 Debian 的软件包
### 总结
有很多像 VLC 媒体播放器那样成熟的播放器。SMPlayer 是拥有完整功能和插件优势的最佳产品之一。我认为它是[必备 Linux 应用][12]之一。
请尝试一下并在下面的评论栏与我们分享你的想法。
--------------------------------------------------------------------------------
via: https://itsfoss.com/smplayer/
作者:[Aquil Roshan;Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[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/aquil/
[b]: https://github.com/lujun9972
[1]: https://itsfoss.com/things-to-do-after-installing-ubuntu-18-04/
[2]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-warning.jpg?fit=800%2C450&ssl=1
[3]: https://packages.ubuntu.com/trusty/ubuntu-restricted-extras
[4]: https://www.smplayer.info/
[5]: http://www.mplayerhq.hu/design7/news.html
[6]: https://www.youtube.com/
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-coco.jpg?fit=800%2C450&ssl=1
[8]: https://www.opensubtitles.org/en/search
[9]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-icon-packs.jpg?fit=800%2C450&ssl=1
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-theme.jpg?fit=800%2C450&ssl=1
[11]: https://software.opensuse.org/download.html?project=home%3Asmplayerdev&package=smplayer
[12]: https://itsfoss.com/essential-linux-applications/

View File

@ -0,0 +1,212 @@
Bash 环境变量的那些事
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/wynand-van-poortvliet-40467-unsplash.jpg?itok=tr6Eb4N0)
bash 变量,尤其是讨厌的环境变量,已经是一个老生常谈的话题了。我们也更应该对它有一个详细的了解,让它为我们所用。
下面就打开终端,开始吧。
### 环境变量
`HOME` 除了是你脱下帽子惬意休息的地方,同时也是 Linux 中的一个变量,它是当前用户主目录的路径:
```
echo $HOME
```
以上这个命令会显示当前用户的主目录路径,通常都在 `/home/` 下。
顾名思义一个变量的值并不是固定的。实际上Linux 系统中每一个用户的 `HOME` 变量都是不一样的,当然你也可以这样自行更改 `HOME` 变量的值:
```
HOME=/home/<your username>/Documents
```
以上这个命令将会把 `HOME` 变量设置为 `/home/<your username>/Documents` 目录。
其中有三点需要留意:
1. `=` 符号和其两侧的内容之间不加空格。空格在 shell 中有专门的意义,不能随意地在任何地方添加空格。
2. 如果你需要对变量进行赋值,只需要使用变量名称就可以了。但如果需要读取或者使用变量的值,需要在变量前面加上一个 `$` 号。
3. 更改 `HOME` 变量具有一定的风险。有很多程序是依赖于 `HOME` 变量的,更改 `HOME` 变量可能会导致一些不可预见的结果。例如,如果按照上面的方式更改了 `HOME` 变量,然后执行不带有任何参数的 `cd` 命令,在通常情况下,会跳转到用户的主目录下,但在这个时候,会跳转到 `HOME` 变量指定的目录下。
上面第 3 点中环境变量的更改并不是持久有效的,在终端关闭后重新打开终端,又或者是新建一个终端,执行 `echo $HOME` 命令输出的仍然会是初始的值,而不是重新自定义的值。
在讨论如何持久地更改一个环境变量之前,我们先来看一下另一个比较重要的环境变量。
### PATH 变量
`PATH` 变量中存放了一系列目录,而且是放置了可执行程序的目录。正是由于 `PATH` 变量的存在,让你不需要知道应用程序具体安装到了什么目录,而 shell 却可以正确地找到这些应用程序。
如果你查看 `PATH` 变量的值,大概会是以下这样:
```
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin
```
每两个目录之间使用冒号(`:`)分隔。如果某个应用程序的所在目录不在 `PATH` 变量中,那么运行的时候就需要声明应用程序的目录让 shell 能够找到。
```
/home/<user name>/bin/my_program.sh
```
例如以上命令就会执行当前用户 `bin/` 目录下的 `my_program.sh` 文件。
有一个常见的问题:如果你不希望弄乱系统的 `bin/` 目录,同时也不希望你自己的文件被其它人运行,还不想每次运行的时候都要输入完整的路径,那么,你可以在你的主目录中创建一个独立的 `bin/` 目录:
```
mkdir $HOME/bin
```
然后将这个目录添加到 `PATH` 变量中:
```
PATH=$PATH:$HOME/bin
```
然后 `/home/<user name>/bin/` 目录就会出现在 `PATH` 变量中了。但正如之前所说,这个变更只会在当前的 shell 生效,当前的 shell 一旦关闭,环境变量的值就又恢复原状了。
如果要让变更对当前用户持续生效,就不能在 shell 中直接执行对应的变更,而是应该将这些变更操作卸载每次启动 shell 时都会运行的文件当中。这个文件就是当前用户主目录中的 `.bashrc` 文件。文件名前面的点号表明这是一个隐藏文件,执行普通的 `ls` 命令是不会将这个文件显示出来的,但只要在 `ls` 命令中加入 `-a` 参数就可以看到这个文件了。
你可以使用诸如 [kate][1]、[gedit][2]、[nano][3] 或者 [vim][4] 这些文本编辑器来打开 `.bashrc` 文件(但不要用 LibreOffice Writer它是一个文字处理软件跟前面几个文字编辑器并不一个量级的东西。打开 `.bashrc` 文件之后,你会看见里面放置了一些 shell 命令,是用于为当前用户设置环境的。
在文件的末尾添加新行并输入以下内容:
```
export PATH=$PATH:$HOME/bin
```
保存并关闭 `.bashrc` 文件,接下来你就会看到 `export` 语句的效果。执行以下的命令让刚才的修改立即生效:
```
source .bashrc
```
刚才执行的 `source` 命令让 `.bashrc` 文件在当前的 shell 立即生效,并且对于之后打开的 shell 都会有效。因此另一个等效的方法是退出并重新进入 shell但这样也太麻烦了。
现在,你的 shell 就能自动寻找到 `/home/<user name>/bin/` 下的程序了,执行这个目录下的程序也不需要完整地写出程序的路径。
### 自定义变量
当然,你也可以定义自己的变量。刚才我们看到的变量名称都是全大写的,实际上[变量名称的定义还是比较灵活的][5]。
定义新变量的过程非常直观,直接对它赋值就可以了:
```
new_variable="Hello"
```
然后可以用一下的方式读取到已定义变量的值:
```
echo $new_variable
```
程序的正常工作离不开各种变量,例如要将某个选项设置为 on又或者让程序找到所需的代码库都需要使用变量。在 bash 中运行程序的时候会生成一个子 shell这个子 shell 和执行原程序的父 shell 并不是完全一样的,只是继承了父 shell 的部分内容,而且默认是不继承父 shell 中的变量的。因为变量默认情况下是局部变量,出于安全原因,一个 shell 中的局部变量不会被另一个 shell 读取到,即使是子 shell 也不可以。
下面举一个例子。首先定义一个变量:
```
robots="R2D2 & C3PO"
```
然后执行:
```
bash
```
现在是在 bash shell 中创建了一个子 shell。
执行这个命令看看还能不能读取到刚才定义的变量:
```
echo $robots
```
你会发现读取不到。
还是在这个子 shell 中,为 `robots` 变量赋一个不同的值:
```
robots="These aren't the ones you are looking for"
```
再读取一次:
```
$ echo $robots
These aren't the ones you are looking for
```
退出这个子 shell
```
exit
```
然后再看一下现在 `robots` 变量的值:
```
$ echo $robots
R2D2 & C3P0
```
这一个特性可以有效避免配置过程中产生混乱,同时也会导致一个问题:如果程序中需要设置变量,但却由于子 shell 的原因无法正常访问到这个变量,该如何解决呢?这个时候就需要用到 `export` 了。
重复一次刚才的过程,但这一次不是通过 `robots="R2D2 & C3PO"` 方式来设置变量,而是使用 `export` 命令:
```
export robots="R2D2 & C3PO"
```
现在你会发现,在进入子 shell 之后,`robots` 变量的值仍然是最初赋予的值。
要注意的是,尽管子 shell 会继承通过 `export` 导出的变量,但如果在子 shell 中对这个变量重新赋值,是不会影响到父 shell 中对应变量的。
如果要查看所有通过 `export` 导出的变量,可以执行以下命令:
```
export -p
```
自定义的变量会显示在这个列表的末尾。这个列表中还有一些常见的变量:例如 `USER` 的值是当前用户的用户名,`PWD` 的值是当前用户当前所在的目录,而 `OLDPWD` 的值则是当前用户上一个访问过的目录。因此如果执行:
```
cd -
```
就会切换到上一个访问过的目录,那是因为 `cd` 命令读取到了 `OLDPWD` 变量的值。
你也可以使用 `env` 命令查看所有环境变量。
如果要取消导出一个变量,可以加上 `-n` 参数:
```
export -n robots
```
### 接下来
了解过环境变量的知识之后,你已经到达了可能对自己和他人造成危险的水平,接下来就需要了解如何通过使用 `_aliases` 来让环境变得更安全、更友好以保护自己了。
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/learn/2018/12/bash-variables-environmental-and-otherwise
作者:[Paul Brown][a]
选题:[lujun9972][b]
译者:[HankChow](https://github.com/HankChow)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.linux.com/users/bro66
[b]: https://github.com/lujun9972
[1]: https://www.kde.org/applications/utilities/kate/
[2]: https://help.gnome.org/users/gedit/stable/
[3]: https://www.nano-editor.org/
[4]: https://www.vim.org/
[5]: https://bash.cyberciti.biz/guide/Rules_for_Naming_variable_name

View File

@ -0,0 +1,60 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (Bring some color to your Linux terminal with lolcat)
[#]: via: (https://opensource.com/article/18/12/linux-toy-lolcat)
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
[#]: url: ( )
使用 lolcat 为你的 Linux 终端带来一些颜色
======
使用这个简单的程序,你可以为所需的任何程序的输出添加彩色。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/uploads/linux-toy-lolcat.png?itok=Es6dYcph)
今天是 Linux 命令行玩具日历的第五天。如果这是你第一次访问该系列,你可能会问自己,什么是命令行玩具。即使我不太确定,但一般来说,它可能是一个游戏,或任何简单的可以帮助你在终端玩得开心的东西。
很可能你们中的一些人之前已经看过我们日历中的各种选择,但我们希望每个人至少见到一件新事物。
今日的选择,**lolcat**,是我选择的第一个没有在我的 Linux 发行版中打包的程序,但它安装仍然很简单。它是一个 Ruby 程序,你应该可以使用下面的命令轻松地添加到系统中。
```
$ gem install lolcat
```
之后,只需将一些文本传送给它,就可以看到彩色的输出。例如,尝试几个之前在我们的日历中出现的程序,使用以下命令:
```
$ fortune | boxes -a c -d parchment | lolcat
```
根据你的运气,你可能会看到这样:
![](https://opensource.com/sites/default/files/uploads/linux-toy-lolcat-parchment.png)
你可以传递给 **lolcat** 一些参数而不必重复它们,我建议你访问 **lolcat** 的 [GitHub 页面][1] 或者在终端输入 **lolcat --help** 了解。但一般来说,它们能设置彩虹的传递和频率,以及我个人最喜欢的动画。谁不喜欢终端的彩色动画打印?让我们再试一次,用一个不同的边框(当然是以猫为主题)和一句在我的句子列表中的适合猫的句子。
```
fortune -m "nine tails" | boxes -a c -d cat | lolcat -a
```
![](https://opensource.com/sites/default/files/uploads/linux-toy-lolcat-animated.gif)
**lolcat** 是 BSD 许可下的开源软件。
你有特别喜欢的命令行小玩具需要我介绍的吗?这个系列要介绍的小玩具大部分已经有了落实,但还预留了几个空位置。如果你有特别想了解的可以评论留言,我会查看的。如果还有空位置,我会考虑介绍它的。如果没有,但如果我得到了一些很好的意见,我会在最后做一些有价值的提及。
了解一下昨天的玩具,[在 Linux 命令行中拥有一头牛][2],还有记得明天再来!
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/12/linux-toy-lolcat
作者:[Jason Baker][a]
选题:[lujun9972][b]
译者:[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/jason-baker
[b]: https://github.com/lujun9972
[1]: https://github.com/busyloop/lolcat
[2]: https://opensource.com/article/18/12/linux-toy-cowsay

View File

@ -1,294 +0,0 @@
# 中文文案排版指北
[![devDependency Status](https://david-dm.org/mzlogin/chinese-copywriting-guidelines/dev-status.svg)](https://david-dm.org/mzlogin/chinese-copywriting-guidelines#info=devDependencies)
统一中文文案、排版的相关用法,降低团队成员之间的沟通成本,增强网站气质。
Other languages:
- [English](https://github.com/mzlogin/chinese-copywriting-guidelines/blob/Simplified/README.en.md)
- [Chinese Traditional](https://github.com/sparanoid/chinese-copywriting-guidelines)
- [Chinese Simplified](README.md)
-----
## 目录
- [空格](#空格)
- [中英文之间需要增加空格](#中英文之间需要增加空格)
- [中文与数字之间需要增加空格](#中文与数字之间需要增加空格)
- [数字与单位之间需要增加空格](#数字与单位之间需要增加空格)
- [全角标点与其他字符之间不加空格](#全角标点与其他字符之间不加空格)
- [`-ms-text-autospace` to the rescue?](#-ms-text-autospace-to-the-rescue)
- [标点符号](#标点符号)
- [不重复使用标点符号](#不重复使用标点符号)
- [全角和半角](#全角和半角)
- [使用全角中文标点](#使用全角中文标点)
- [数字使用半角字符](#数字使用半角字符)
- [遇到完整的英文整句、特殊名词,其內容使用半角标点](#遇到完整的英文整句特殊名词其內容使用半角标点)
- [名词](#名词)
- [专有名词使用正确的大小写](#专有名词使用正确的大小写)
- [不要使用不地道的缩写](#不要使用不地道的缩写)
- [争议](#争议)
- [链接之间增加空格](#链接之间增加空格)
 - [简体中文不要使用直角引号](#简体中文不要使用直角引号)
- [工具](#工具)
- [谁在这样做?](#谁在这样做)
- [参考文献](#参考文献)
## 空格
「有研究显示,打字的时候不喜欢在中文和英文之间加空格的人,感情路都走得很辛苦,有七成的比例会在 34 岁的时候跟自己不爱的人结婚,而其余三成的人最后只能把遗产留给自己的猫。毕竟爱情跟书写都需要适时地留白。
与大家共勉之。」——[vinta/paranoid-auto-spacing](https://github.com/vinta/pangu.js)
### 中英文之间需要增加空格
正确:
> 在 LeanCloud 上,数据存储是围绕 `AVObject` 进行的。
错误:
> 在LeanCloud上数据存储是围绕`AVObject`进行的。
> 在 LeanCloud上数据存储是围绕`AVObject` 进行的。
完整的正确用法:
> 在 LeanCloud 上,数据存储是围绕 `AVObject` 进行的。每个 `AVObject` 都包含了与 JSON 兼容的 key-value 对应的数据。数据是 schema-free 的,你不需要在每个 `AVObject` 上提前指定存在哪些键,只要直接设定对应的 key-value 即可。
例外「豆瓣FM」等产品名词按照官方所定义的格式书写。
### 中文与数字之间需要增加空格
正确:
> 今天出去买菜花了 5000 元。
错误:
> 今天出去买菜花了 5000元。
> 今天出去买菜花了5000元。
### 数字与单位之间需要增加空格
正确:
> 我家的光纤入户宽带有 10 GbpsSSD 一共有 20 TB。
错误:
> 我家的光纤入户宽带有 10GbpsSSD 一共有 10TB。
例外:度/百分比与数字之间不需要增加空格:
正确:
> 今天是 233° 的高温。
> 新 MacBook Pro 有 15% 的 CPU 性能提升。
错误:
> 今天是 233 ° 的高温。
> 新 MacBook Pro 有 15 % 的 CPU 性能提升。
### 全角标点与其他字符之间不加空格
正确:
> 刚刚买了一部 iPhone好开心
错误:
> 刚刚买了一部 iPhone ,好开心!
### `-ms-text-autospace` to the rescue?
Microsoft 有个 [`-ms-text-autospace`](http://msdn.microsoft.com/en-us/library/ie/ms531164(v=vs.85).aspx) 的 CSS 属性可以实现自动为中英文之间增加空白。不过目前并未普及,另外在其他应用场景,例如 OS X、iOS 的用户界面目前并不存在这个特性,所以请继续保持随手加空格的习惯。
## 标点符号
### 不重复使用标点符号
正确:
> 德国队竟然战胜了巴西队!
> 她竟然对你说“喵”?!
错误:
> 德国队竟然战胜了巴西队!!
> 德国队竟然战胜了巴西队!!!!!!!!
> 她竟然对你说「喵」??!!
> 她竟然对你说「喵」?!?!??!!
## 全角和半角
不明白什么是全角(全形)与半角(半形)符号?请查看维基百科词条『[全角和半角](http://zh.wikipedia.org/wiki/%E5%85%A8%E5%BD%A2%E5%92%8C%E5%8D%8A%E5%BD%A2)』。
### 使用全角中文标点
正确:
> 嗨!你知道嘛?今天前台的小妹跟我说“喵”了哎!
> 核磁共振成像NMRI是什么原理都不知道JFGI
错误:
> 嗨! 你知道嘛? 今天前台的小妹跟我说 "喵" 了哎!
> 嗨!你知道嘛?今天前台的小妹跟我说"喵"了哎!
> 核磁共振成像 (NMRI) 是什么原理都不知道? JFGI!
> 核磁共振成像(NMRI)是什么原理都不知道?JFGI!
### 数字使用半角字符
正确:
> 这件蛋糕只卖 1000 元。
错误:
> 这件蛋糕只卖 元。
例外:在设计稿、宣传海报中如出现极少量数字的情形时,为方便文字对齐,是可以使用全角数字的。
### 遇到完整的英文整句、特殊名词,其內容使用半角标点
正确:
> 乔布斯那句话是怎么说的“Stay hungry, stay foolish.”
> 推荐你阅读《Hackers & Painters: Big Ideas from the Computer Age》非常的有趣。
错误:
> 乔布斯那句话是怎么说的「Stay hungrystay foolish。」
> 推荐你阅读《HackersPaintersBig Ideas from the Computer Age》非常的有趣。
## 名词
### 专有名词使用正确的大小写
大小写相关用法原属于英文书写范畴,不属于本 wiki 讨论內容,在这里只对部分易错用法进行简述。
正确:
> 使用 GitHub 登录
> 我们的客户有 GitHub、Foursquare、Microsoft Corporation、Google、Facebook, Inc.。
错误:
> 使用 github 登录
> 使用 GITHUB 登录
> 使用 Github 登录
> 使用 gitHub 登录
> 使用 gイんĤЦ8 登录
> 我们的客户有 github、foursquare、microsoft corporation、google、facebook, inc.。
> 我们的客户有 GITHUB、FOURSQUARE、MICROSOFT CORPORATION、GOOGLE、FACEBOOK, INC.。
> 我们的客户有 Github、FourSquare、MicroSoft Corporation、Google、FaceBook, Inc.。
> 我们的客户有 gitHub、fourSquare、microSoft Corporation、google、faceBook, Inc.。
> 我们的客户有 gイんĤЦ8、キouЯƧquムгє、๓เςг๏ร๏Ŧt ς๏гק๏гคtเ๏ภn、900913、ƒ4ᄃëв๏๏к, IПᄃ.。
注意当网页中需要配合整体视觉风格而出现全部大写小写的情形HTML 中请使用标准的大小写规范进行书写;并通过 `text-transform: uppercase;``text-transform: lowercase;` 对表现形式进行定义。
### 不要使用不地道的缩写
正确:
> 我们需要一位熟悉 JavaScript、HTML5至少理解一种框架如 Backbone.js、AngularJS、React 等)的前端开发者。
错误:
> 我们需要一位熟悉 Js、h5至少理解一种框架如 backbone、angular、RJS 等)的 FED。
## 争议
以下用法略带有个人色彩,既:无论是否遵循下述规则,从语法的角度来讲都是**正确**的。
### 链接之间增加空格
用法:
> 请 [提交一个 issue](#) 并分配给相关同事。
> 访问我们网站的最新动态,请 [点击这里](#) 进行订阅!
对比用法:
> 请[提交一个 issue](#) 并分配给相关同事。
> 访问我们网站的最新动态,请[点击这里](#)进行订阅!
### 简体中文不要使用直角引号
不管中英文,如果没有特殊要求,**不要用直角引号**。
## 工具
仓库 | 语言
--- | ---
[vinta/paranoid-auto-spacing](https://github.com/vinta/paranoid-auto-spacing) | JavaScript
[huei90/pangu.node](https://github.com/huei90/pangu.node) | Node.js
[huacnlee/auto-correct](https://github.com/huacnlee/auto-correct) | Ruby
[sparanoid/space-lover](https://github.com/sparanoid/space-lover) | PHP (WordPress)
[nauxliu/auto-correct](https://github.com/NauxLiu/auto-correct) | PHP
[hotoo/pangu.vim](https://github.com/hotoo/pangu.vim) | Vim
[sparanoid/grunt-auto-spacing](https://github.com/sparanoid/grunt-auto-spacing) | Node.js (Grunt)
[hjiang/scripts/add-space-between-latin-and-cjk](https://github.com/hjiang/scripts/blob/master/add-space-between-latin-and-cjk) | Python
## 谁在这样做?
网站 | 文案 | UGC
--- | --- | ---
[Apple 中国](http://www.apple.com/cn/) | Yes | N/A
[Apple 香港](http://www.apple.com/hk/) | Yes | N/A
[Apple 台湾](http://www.apple.com/tw/) | Yes | N/A
[Microsoft 中国](http://www.microsoft.com/zh-cn/) | Yes | N/A
[Microsoft 香港](http://www.microsoft.com/zh-hk/) | Yes | N/A
[Microsoft 台湾](http://www.microsoft.com/zh-tw/) | Yes | N/A
[LeanCloud](https://leancloud.cn/) | Yes | N/A
[知乎](https://www.zhihu.com/) | Yes | 部分用户达成
[V2EX](https://www.v2ex.com/) | Yes | Yes
[SegmentFault](https://segmentfault.com/) | Yes | 部分用户达成
[Apple4us](http://apple4us.com/) | Yes | N/A
[豌豆荚](https://www.wandoujia.com/) | Yes | N/A
[Ruby China](https://ruby-china.org/) | Yes | 标题达成
[PHPHub](https://phphub.org/) | Yes | 标题达成
## 参考文献
- [Guidelines for Using Capital Letters](http://grammar.about.com/od/punctuationandmechanics/a/Guidelines-For-Using-Capital-Letters.htm)
- [Letter case - Wikipedia](http://en.wikipedia.org/wiki/Letter_case)
- [Punctuation - Oxford Dictionaries](http://www.oxforddictionaries.com/words/punctuation)
- [Punctuation - The Purdue OWL](https://owl.english.purdue.edu/owl/section/1/6/)
- [How to Use English Punctuation Corrently - wikiHow](http://www.wikihow.com/Use-English-Punctuation-Correctly)
- [格式 - openSUSE](https://zh.opensuse.org/index.php?title=Help:%E6%A0%BC%E5%BC%8F)
- [全角和半角 - 维基百科](http://zh.wikipedia.org/wiki/%E5%85%A8%E5%BD%A2%E5%92%8C%E5%8D%8A%E5%BD%A2)
- [引号 - 维基百科](http://zh.wikipedia.org/wiki/%E5%BC%95%E8%99%9F)
- [疑问惊叹号 - 维基百科](http://zh.wikipedia.org/wiki/%E7%96%91%E5%95%8F%E9%A9%9A%E5%98%86%E8%99%9F)
## CopyRight
[中文文案排版指北](https://github.com/sparanoid/chinese-copywriting-guidelines)

View File

@ -1,65 +0,0 @@
选题标题格式:
```
原文日期 标题.md
```
其中:
- 原文日期为该文章发表时的日期,采用 8 位数字表示
- 标题需去除特殊字符,使用 `_` 替换。
正文内容:
```
[#]: collector: (选题人 GitHub ID)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: subject: (文章标题)
[#]: via: (原文 URL)
[#]: author: (作者名 作者链接 URL)
[#]: url: ( )
标题
=======
### 子一级标题
正文
#### 子二级标题
正文内容
![][1]
### 子一级标题
正文内容 I have a [dream][2]。
--------------------------------------------------------------------------------
via: 原文 链接 URL
作者:[作者名][a]
译者:[选题 ID][b]
译者:[译者 ID](https://github.com/译者 ID)
校对:[校对 ID](https://github.com/校对 ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: 作者链接 URL
[b]: 选题链接 URL
[1]: 图片链接地址
[2]: 文内链接地址
```
说明:
1. 标题层级很多时从 `##` 开始
2. 图片链接和引文链接地址在下方集中写
3. 因为 Windows 系统文件名有限制,所以文章名不要有特殊符号,如 `\/:*"<>|`,同时也不推荐全大写,或者其它不利阅读的格式
4. 正文格式参照中文排版指北(https://github.com/LCTT/TranslateProject/blob/master/%E4%B8%AD%E6%96%87%E6%8E%92%E7%89%88%E6%8C%87%E5%8C%97.md)
5. 我们使用的 markdown 语法和 GitHub 一致。而实际中使用的都是基本语法,比如链接、包含图片、标题、列表、字体控制和代码高亮。
6. 选题的内容分为两类: 干货和湿货。干货就是技术文章,比如针对某种技术、工具的介绍、讲解和讨论。湿货则是和技术、开发、计算机文化有关的文章。选题时主要就是根据这两条来选择文章,文章需要对大家有益处,篇幅不宜太短,可以是系列文章,也可以是长篇大论,但是文章要有内容,不能有严重的错误,最好不要选择已经有翻译的原文。