mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-13 00:11:22 +08:00
commit
0457e072db
@ -39,7 +39,7 @@ $ ansible <group> -m setup -a "filter=ansible_distribution"
|
||||
|
||||
### 传输文件
|
||||
|
||||
对于传输文件,我们使用模块 “copy” ,完整的命令是这样的:
|
||||
对于传输文件,我们使用模块 `copy` ,完整的命令是这样的:
|
||||
|
||||
```
|
||||
$ ansible <group> -m copy -a "src=/home/dan dest=/tmp/home"
|
||||
@ -47,7 +47,7 @@ $ ansible <group> -m copy -a "src=/home/dan dest=/tmp/home"
|
||||
|
||||
### 管理用户
|
||||
|
||||
要管理已连接主机上的用户,我们使用一个名为 “user” 的模块,并如下使用它。
|
||||
要管理已连接主机上的用户,我们使用一个名为 `user` 的模块,并如下使用它。
|
||||
|
||||
#### 创建新用户
|
||||
|
||||
@ -65,7 +65,7 @@ $ ansible <group> -m user -a "name=testuser state=absent"
|
||||
|
||||
### 更改权限和所有者
|
||||
|
||||
要改变已连接主机文件的所有者,我们使用名为 ”file“ 的模块,使用如下。
|
||||
要改变已连接主机文件的所有者,我们使用名为 `file` 的模块,使用如下。
|
||||
|
||||
#### 更改文件权限
|
||||
|
||||
@ -81,7 +81,7 @@ $ ansible <group> -m file -a "dest=/home/dan/file1.txt mode=777 owner=dan group=
|
||||
|
||||
### 管理软件包
|
||||
|
||||
我们可以通过使用 ”yum“ 和 ”apt“ 模块来管理所有已连接主机的软件包,完整的命令如下:
|
||||
我们可以通过使用 `yum` 和 `apt` 模块来管理所有已连接主机的软件包,完整的命令如下:
|
||||
|
||||
#### 检查包是否已安装并更新
|
||||
|
||||
@ -109,7 +109,7 @@ $ ansible <group> -m yum -a "name=ntp state=absent"
|
||||
|
||||
### 管理服务
|
||||
|
||||
要管理服务,我们使用模块 “service” ,完整命令如下:
|
||||
要管理服务,我们使用模块 `service` ,完整命令如下:
|
||||
|
||||
#### 启动服务
|
||||
|
||||
@ -129,7 +129,7 @@ $ ansible <group> -m service -a "name=httpd state=stopped"
|
||||
$ ansible <group> -m service -a "name=httpd state=restarted"
|
||||
```
|
||||
|
||||
这样我们简单的,单行 Ansible 命令的教程就完成了。此外,在未来的教程中,我们将学习创建 playbook,来帮助我们更轻松高效地管理主机。
|
||||
这样我们简单的、单行 Ansible 命令的教程就完成了。此外,在未来的教程中,我们将学习创建 playbook,来帮助我们更轻松高效地管理主机。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
@ -0,0 +1,72 @@
|
||||
防止文档陷阱的 7 条准则
|
||||
======
|
||||
> 让我们了解一下如何使国外读者更容易理解你的技术文章。
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc-docdish-typewriterkeys-4-series.png?itok=ccZISDxR)
|
||||
|
||||
英语是开源社区的通用语言。为了减少翻译成本,很多团队都改成用英语来写他们的文档。 但奇怪的是,为国际读者写英语并不一定就意味着以英语为母语的人就占据更多的优势。 相反, 他们往往忘记了该文档用的语言可能并不是读者的母语。
|
||||
|
||||
我们以下面这个简单的句子为例: “Encrypt the password using the `foo bar` command。”语法上来说,这个句子是正确的。 鉴于动名词的 “-ing” 形式在英语中很常见,大多数的母语人士都认为这是一种优雅的表达方式, 他们通常会很自然的写出这样的句子。 但是仔细观察, 这个句子存在歧义因为 “using” 可能指的宾语(“the password”)也可能指的动词(“encrypt”)。 因此这个句子有两种解读方式:
|
||||
|
||||
* “加密使用了 `foo bar` 命令的密码。”
|
||||
* “使用命令 `foo bar` 来加密密码。”
|
||||
|
||||
如果你有相关的先验知识(密码加密或者 `foo bar` 命令),你可以消除这种不确定性并且明白第二种方式才是真正的意思。 但是若你没有足够深入的知识怎么办呢? 如果你并不是这方面的专家,而只是一个拥有泛泛相关知识的翻译者而已怎么办呢? 再或者,如果你只是个非母语人士且对像动名词这种高级语法不熟悉怎么办呢?
|
||||
|
||||
即使是英语为母语的人也需要经过训练才能写出清晰直接的技术文档。训练的第一步就是提高对文本可用性以及潜在问题的警觉性, 下面让我们来看一下可以帮助避免常见陷阱的 7 条规则。
|
||||
|
||||
### 1、了解你的目标读者并代入其中。
|
||||
|
||||
如果你是一名开发者,而写作的对象是最终用户, 那么你需要站在他们的角度来看这个产品。 文档的结构是否反映了用户的目标? [<ruby>人格面具<rt>persona</rt></ruby> 技术][1] 能帮你专注于目标受众并为你的读者提供合适层次的细节。
|
||||
|
||||
### 2、遵循 KISS 原则——保持文档简短而简单
|
||||
|
||||
这个原则适用于多个层次,从语法,句子到单词。 比如:
|
||||
|
||||
* 使用合适的最简单时态。比如, 当提到一个动作的结果时使用现在时:
|
||||
* " ~~Click 'OK.' The 'Printer Options' dialog will appear.~~ " -> "Click 'OK.' The 'Printer Options' dialog appears."
|
||||
* 按经验来说,一个句子表达一个主题;然而, 短句子并不一定就容易理解(尤其当这些句子都是由名词组成时)。 有时, 将句子裁剪过度可能会引起歧义,而反过来太多单词则又难以理解。
|
||||
* 不常用的以及很长的单词会降低阅读速度,而且可能成为非母语人士的障碍。 使用更简单的替代词语:
|
||||
* " ~~utilize~~ " -> "use"
|
||||
* " ~~indicate~~ " -> "show","tell" 或 "say"
|
||||
* " ~~prerequisite~~ " -> "requirement"
|
||||
|
||||
### 3、不要干扰阅读流
|
||||
|
||||
将虚词和较长的插入语移到句子的首部或者尾部:
|
||||
|
||||
* " ~~They are not, however, marked as installed.~~ " -> "However, they are not marked as installed."
|
||||
|
||||
将长命令放在句子的末尾可以让自动/半自动的翻译拥有更好的断句。
|
||||
|
||||
### 4、区别对待两种基本的信息类型
|
||||
|
||||
描述型信息以及任务导向型信息有必要区分开来。描述型信息的一个典型例子就是命令行参考, 而 HOWTO 则是属于基于任务的信息;(LCTT 译注:HOWTO 文档是 Linux 文档中的一种)然而, 技术写作中都会涉及这两种类型的信息。 仔细观察, 就会发现许多文本都同时包含了两种类型的信息。 然而如果能够清晰地划分这两种类型的信息那必是极好的。 为了更好地区分它们,可以对它们进行分别标记。 标题应该能够反映章节的内容以及信息的类型。 对描述性章节使用基于名词的标题(比如“Types of Frobnicators”),而对基于任务的章节使用口头表达式的标题(例如“Installing Frobnicators”)。 这可以让读者快速定位感兴趣的章节而跳过对他无用的章节。
|
||||
|
||||
### 5、考虑不同的阅读场景和阅读模式
|
||||
|
||||
有些读者在阅读产品文档时会由于自己搞不定而感到十分的沮丧。他们在一个嘈杂的环境中工作,也很难专注于阅读。 同时,不要期望你的读者会一页一页的进行阅读,很多人都是快速浏览文本,搜索关键字或者通过表格、索引以及全文搜索的方式来查找主题。 请牢记这一点, 从不同的角度来看待你的文字。 通常需要折中才能找到一种适合多种情况的文本结构。
|
||||
|
||||
### 6、将复杂的信息分成小块
|
||||
|
||||
这会让读者更容易记住和吸收信息。例如, 过程不应该超过 7 到 10 个步骤(根据认知心理学中的 [米勒法则][2])。 如果需要更多的步骤, 那么就将任务分拆成不同的过程。
|
||||
|
||||
### 7、形式遵循功能
|
||||
|
||||
根据以下问题检查你的文字:某句话/段落/章节的 _目的_(功能)是什么?比如,它是一个指令呢?还是一个结果呢?还是一个警告呢?如果是指令, 使用主动语气: “Configure the system.” 被动语气可能适合于进行描述: “The system is configured automatically.” 将警告放在危险操作的 _前面_ 。 专注于目的还有助于发现冗余的内容,可以清除类似 “basically” 或者 “easily” 这一类的填充词,类似 “~~already~~ existing ” 或“ ~~completely~~ new” 这一类的不必要的修饰, 以及任何与你的目标大众无关的内容。
|
||||
|
||||
你现在可能已经猜到了,写作就是一个不断重写的过程。 好的写作需要付出努力和练习。 即使你只是偶尔写点东西, 你也可以通过关注目标大众并遵循上述规则来显著地改善你的文字。 文字的可读性越好, 理解就越容易, 这一点对不同语言能力的读者来说都是适合的。 尤其是当进行本地化时, 高质量的原始文本至关重要:“垃圾进, 垃圾出”。 如果原始文本就有缺陷, 翻译所需要的时间就会变长, 从而导致更高的成本。 最坏的情况下, 翻译会导致缺陷成倍增加,需要在不同的语言版本中修正这个缺陷。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/17/12/7-rules
|
||||
|
||||
作者:[Tanja Roth][a]
|
||||
译者:[lujun9972](https://github.com/lujun9972)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com
|
||||
[1]:https://en.wikipedia.org/wiki/Persona_(user_experience)
|
||||
[2]:https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two
|
@ -1,51 +1,45 @@
|
||||
深入看看 Facebook 的开源计划
|
||||
Facebook 的开源计划一窥
|
||||
============================================================
|
||||
|
||||
### Facebook 开发人员 Christine Abernathy 讨论了开源如何帮助公司分享见解并推动创新。
|
||||
> Facebook 开发人员 Christine Abernathy 讨论了开源如何帮助公司分享见解并推动创新。
|
||||
|
||||
![A look inside Facebook's open source program](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/LAW-Internet_construction_9401467_520x292_0512_dc.png?itok=RPkPPtDe "A look inside Facebook's open source program")
|
||||
|
||||
图像来源:opensource.com
|
||||
|
||||
开源逐年变得无处不在,从[政府直辖市][11]到[大学][12]都有。各种规模的公司也越来越多地转向开源软件。事实上,一些公司正在通过财务支持项目或与开发人员合作进一步推进开源。
|
||||
|
||||
开源每年在变得无处不在,从[政府直辖市][11]到[大学] [12]都有。各种规模的公司也越来越多地转向开源软件。事实上,一些公司正在通过财务支持项目或与开发人员合作进一步推进开源。
|
||||
|
||||
例如,Facebook 的开源计划鼓励其他人开源发布他们的代码,同时与社区合作支持开源项目。 [Christine Abernathy][13],一名 Facebook 开发者,开源支持者,公司开源团队成员,去年 11 月访问了罗切斯特理工学院,在[ 11 月][14] 的 FOSS 系列演讲中发表了演讲。在她的演讲中,Abernathy 解释了 Facebook 如何开源以及为什么它是公司所做工作的重要组成部分。
|
||||
例如,Facebook 的开源计划鼓励其他人开源发布他们的代码,同时与社区合作支持开源项目。 [Christine Abernathy][13],是一名 Facebook 开发者、开源支持者,也是该公司开源团队成员,去年 11 月访问了罗切斯特理工学院,在 [11 月][14] 的 FOSS 系列演讲中发表了演讲。在她的演讲中,Abernathy 解释了 Facebook 如何开源以及为什么它是公司所做工作的重要组成部分。
|
||||
|
||||
### Facebook 和开源
|
||||
|
||||
Abernathy 说,开源在 Facebook 创建社区和使世界更加紧密的使命中扮演着重要的角色。这种意识形态的匹配是 Facebook 参与开源的一个激励因素。此外,Facebook 面临着独特的基础设施和开发挑战,而开源则为公司提供了一个平台,以共享可帮助他人的解决方案。开源还提供了一种加速创新和创建更好软件的方法,帮助工程团队生产更好的软件并更透明地工作。今天,Facebook 在 GitHub 上有 443个 项目包括 122,000 个分支,292,000 个提交和 732,000 个关注。
|
||||
|
||||
Abernathy 说,开源在 Facebook 创建社区并使世界更加紧密的使命中扮演着重要的角色。这种意识形态的匹配是 Facebook 参与开源的一个激励因素。此外,Facebook 面临着独特的基础设施和开发挑战,而开源则为公司提供了一个平台,以共享可帮助他人的解决方案。开源还提供了一种加速创新和创建更好软件的方法,帮助工程团队生产更好的软件并更透明地工作。今天,Facebook 在 GitHub 的 443 个项目有 122,000 个分支、292,000 个提交和 732,000 个关注。
|
||||
|
||||
![open source projects by Facebook](https://opensource.com/sites/default/files/images/life-uploads/blog-article-facebook-open-source-projects.png "open source projects by Facebood")
|
||||
|
||||
一些以开源方式发布的 Facebook 项目包括 React、GraphQL、Caffe2 等等。(图片提供:Christine Abernathy 图片,经许可使用)
|
||||
*一些以开源方式发布的 Facebook 项目包括 React、GraphQL、Caffe2 等等。(图片提供:Christine Abernathy 图片,经许可使用)*
|
||||
|
||||
### 得到的教训
|
||||
|
||||
Abernathy 强调说 Facebook 已经从开源社区吸取了很多教训,并期待学到更多。她明确了三个最重要的:
|
||||
|
||||
* 分享有用的东西
|
||||
|
||||
* 突出你的英雄
|
||||
|
||||
* 修复常见的痛点
|
||||
|
||||
_Christine Abernathy 作为 FOSS 演讲系列的嘉宾一员参观了 RIT。每个月,来自开源世界的演讲嘉宾都会与对免费和开源软件感兴趣的学生分享关于开源世界智慧、见解、建议。 [FOSS @MAGIC][3]社区感谢 Abernathy 作为演讲嘉宾出席。_
|
||||
_Christine Abernathy 作为 FOSS 演讲系列的嘉宾一员参观了 RIT。每个月,来自开源世界的演讲嘉宾都会与对自由和开源软件感兴趣的学生分享关于开源世界智慧、见解、建议。 [FOSS @MAGIC][3]社区感谢 Abernathy 作为演讲嘉宾出席。_
|
||||
|
||||
### 关于作者
|
||||
|
||||
[![Picture of Justin W. Flory](https://opensource.com/sites/default/files/styles/profile_pictures/public/pictures/october_2017_cropped_0.jpg?itok=gV-RgINC)][15]
|
||||
Justin 是[罗切斯特理工学院][4]主修网络与系统管理的学生。他目前是 [Fedora Project][5] 的贡献者。在 Fedora 中,Justin 是 [Fedora Magazine][6] 的主编,[社区的领导][7]。。。[更多关于 Justin W. Flory][8]
|
||||
|
||||
[关于我更多][9]
|
||||
Justin 是[罗切斯特理工学院][4]主修网络与系统管理的学生。他目前是 [Fedora Project][5] 的贡献者。在 Fedora 中,Justin 是 [Fedora Magazine][6] 的主编,[社区的领导][7]... [更多关于 Justin W. Flory][8]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/1/inside-facebooks-open-source-program
|
||||
|
||||
作者:[Justin W. Flory ][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
作者:[Justin W. Flory][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,267 +1,197 @@
|
||||
用 PGP 保护代码完整性 - 第一部分: 基本概念和工具
|
||||
用 PGP 保护代码完整性(一): 基本概念和工具
|
||||
======
|
||||
|
||||
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/pgp-security.jpg?itok=lulwyzYc)
|
||||
|
||||
在本系列文章中,我们将深度探讨如何使用 PGP 确保软件完整性。这些文章将为工作于自由软件项目的开发者提供实用指南,并且将包含以下主题:
|
||||
|
||||
|
||||
1. PGP 基础和最佳实践
|
||||
|
||||
1. PGP 基础和最佳实践
|
||||
2. 如何用 Git 使用 PGP
|
||||
|
||||
3. 如何保护你的开发者账户
|
||||
|
||||
|
||||
我们使用与“Freedom”含义相同的词项“Free”,但这个系列中列出的指南也可以被任何其它类型的依赖于分布式团队开发者贡献的软件中。如果你编写进入公共源仓库的代码,你可以从了解和遵循这篇指南中受益。
|
||||
我们使用与“Freedom”含义相同的词项 “Free”,但这个系列中列出的指南也可以被任何其它类型的依赖于分布式团队开发者贡献的软件中。如果你编写进入公共源仓库的代码,你可以从了解和遵循这篇指南中受益。
|
||||
|
||||
### 结构
|
||||
|
||||
每节分为两个部分:
|
||||
|
||||
* 适用于你项目需求的清单
|
||||
|
||||
* 自由形式的考虑事项的列表,解释这些决定取决于什么,并伴随着配置指令
|
||||
|
||||
|
||||
|
||||
* 形式自由的考虑事项的列表,解释这些决定取决于什么,并伴随着配置指令
|
||||
|
||||
#### 清单优先级
|
||||
|
||||
每个清单中各项包含着优先级,用来帮助指导你的决定:
|
||||
|
||||
* (ESSENTIAL) 该项一定要排在考虑事项列表的前面。如果没有这样做,它们将给提交到开源项目中的代码带来高风险。
|
||||
|
||||
* (NICE) 包含该项将提升整体安全性,但会影响你与工作环境的交互方式,并且可能需要学习新的习惯或者放弃旧的习惯。
|
||||
|
||||
|
||||
|
||||
* (必要)该项一定要排在考虑事项列表的前面。如果没有这样做,它们将给提交到开源项目中的代码带来高风险。
|
||||
* (推荐)包含该项将提升整体安全性,但会影响你与工作环境的交互方式,并且可能需要学习新的习惯或者放弃旧的习惯。
|
||||
|
||||
记住,这些只是指导。如果你感到这些优先级不能反映你项目提交的安全,你应该根据自己的需要调整它们。
|
||||
|
||||
## PGP 基本概念和工具
|
||||
### PGP 基本概念和工具
|
||||
|
||||
### 清单
|
||||
#### 清单
|
||||
|
||||
1. 理解 PGP 在自由软件开发中的作用 (ESSENTIAL)
|
||||
|
||||
2. 理解公钥密码学(Public Key Cryptography)的基础知识 (ESSENTIAL)
|
||||
|
||||
3. 理解 PGP 加密和签名的不同 (ESSENTIAL)
|
||||
|
||||
4. 理解 PGP 密钥身份(key identities) (ESSENTIAL)
|
||||
|
||||
5. 理解 PGP 密钥有效性(key validity) (ESSENTIAL)
|
||||
|
||||
6. 安装 GnuPG 工具(版本 2.x) (ESSENTIAL)
|
||||
1. 理解 PGP 在自由软件开发中的作用 (必要)
|
||||
2. 理解<ruby>公钥密码学<rt>Public Key Cryptography</rt></ruby>的基础知识 (必要)
|
||||
3. 理解 PGP 加密和签名的不同 (必要)
|
||||
4. 理解 PGP <ruby>密钥身份<rt>key identities</rt></ruby> (必要)
|
||||
5. 理解 PGP <ruby>密钥有效性<rt>key validity</rt></ruby> (必要)
|
||||
6. 安装 GnuPG 工具(版本 2.x) (必要)
|
||||
|
||||
#### 考虑事项
|
||||
|
||||
|
||||
|
||||
### 考虑事项
|
||||
|
||||
自由软件社区长期依赖于 PGP 确保它生产的软件产品的真实性和完整性。你可能没有注意到,但无论你是一个 linux,Mac 和 Windowas 用户,你都曾依赖 PGP 来确保你电脑环境的完整性:
|
||||
自由软件社区长期依赖于 PGP 确保它生产的软件产品的真实性和完整性。你可能没有注意到,但无论你是一个 Linux
|
||||
、Mac 和 Windowas 用户,你都曾依赖 PGP 来确保你电脑环境的完整性:
|
||||
|
||||
* Linux 发行版依赖 PGP 来确保当二进制或者原代码包从被生产出来到被终端用户安装之间没被更改过
|
||||
|
||||
* 自由软件项目通常会提供分离的 PGP 签名以伴随发行软件存档,使得下游的项目可以把下载的版本集成到自己的分布式下载之前,验证下载版本的完整性。
|
||||
|
||||
* 自由软件项目通常会伴随发行软件的存档提供分离的 PGP 签名,使得下游的项目可以在把下载的版本集成到自己的分布式下载之前,验证下载版本的完整性。
|
||||
* 自由软件项目通常依赖代码本身的 PGP 签名来跟踪起源,并验证项目开发者提交的代码的完整性
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
这与工作于专有平台的程序员使用的开发者证书或代码签名机制非常相似。实际上,这两种技术背后的核心概念非常相似 -- 尽管它们在实现的技术层面和它们委托信任方式的大多不同。PGP 不依赖于集中式认证机构,而是让每个用户为每个证书分配自己的信任。
|
||||
这与工作于专有平台的程序员使用的开发者证书或代码签名机制非常相似。实际上,这两种技术背后的核心概念非常相似 —— 尽管它们在实现的技术层面和它们委托信任方式的大多不同。PGP 不依赖于集中式认证机构,而是让每个用户为每个证书赋予自己的信任。
|
||||
|
||||
我们的目标是使你的项目通过使用 PGP 来进行代码起源和完整性追踪,遵循最佳实践并遵守基本的安全预防措施。
|
||||
|
||||
### 极其基本的 PGP 操作概括
|
||||
#### 极其基本的 PGP 操作概括
|
||||
|
||||
你不需要知道 PGP 如何工作的具体细节 -- 理解核心概念足以成功地达到我们的目的。PGP 依赖于公钥密码学来将明文转换为密文。这个过程需要两种不同的密钥:
|
||||
你不需要知道 PGP 如何工作的具体细节 —— 理解核心概念足以成功地达到我们的目的。PGP 依赖于公钥密码学来将明文转换为密文。这个过程需要两种不同的密钥:
|
||||
|
||||
* 公钥,被所有人知道
|
||||
|
||||
* 私钥,只被拥有者知道
|
||||
|
||||
|
||||
|
||||
|
||||
#### 加密
|
||||
##### 加密
|
||||
|
||||
对加密来说,PGP 使用拥有者的公钥创造一条只能通过拥有者私钥解密的消息:
|
||||
|
||||
1. 发送者生成一条随机的加密密钥(“会话密钥”)
|
||||
|
||||
2. 发送者使用该会话密钥(使用对称密码)加密内容
|
||||
|
||||
1. 发送者生成一个随机的加密密钥(“会话密钥”)
|
||||
2. 发送者使用该会话密钥(使用对称算法)加密内容
|
||||
3. 发送者使用接收者的 PGP 公钥加密会话密钥
|
||||
|
||||
4. 发送者向接收者发送加密后的内容和加密后的会话密钥
|
||||
|
||||
要解密:
|
||||
|
||||
1. 接收者使用他们的 PGP 私钥解密会话密钥
|
||||
2. 接收者使用会话密钥解密消息的内容
|
||||
|
||||
##### 签名
|
||||
|
||||
对于解密:
|
||||
|
||||
1. 接受者使用他们的 PGP 私钥解密会话密钥
|
||||
|
||||
2. 接受者使用会话密钥解密消息的内容
|
||||
|
||||
|
||||
|
||||
|
||||
#### 签名
|
||||
为了创建签名,PGP 私钥或公钥会以相反的方式使用:
|
||||
|
||||
1. 签名者生成内容的校检和哈希
|
||||
2. 签名者使用自己的 PGP 私钥来加密该校检和
|
||||
3. 签名者伴随内容提供加密后的校检和
|
||||
|
||||
|
||||
|
||||
|
||||
为了验证签名:
|
||||
要验证签名:
|
||||
|
||||
1. 验证者生成自己的内容校检和哈希
|
||||
|
||||
2. 验证者使用签名者的 PGP 公钥来解密提供的校检和
|
||||
|
||||
3. 如果校检和匹配,就验证了内容的完整性
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
##### 结合使用
|
||||
|
||||
通常,加密消息也被发送者自己的 PGP 密钥签名。无论何时使用加密消息,这应当是默认的,因为没有认证的加密没有很大意义(除非你是一个告密者或秘密代理并且需要可行的可否认性)
|
||||
|
||||
```
|
||||
Bob Designer (obsolete 1024-bit key) <bob.designer@example.com>
|
||||
#### 理解密钥身份
|
||||
|
||||
```
|
||||
### 理解密钥身份
|
||||
每个 PGP 密钥必须有一个或多个与之关联的身份。通常,“<ruby>身份<rt>Identity</rt></ruby>”指的是以下格式中的人物全名和邮件地址:
|
||||
|
||||
每个 PGP 密钥必须有一个或多个与之关联的身份。通常,一个“身份”指的是以下格式中的人物全名和邮件地址:
|
||||
```
|
||||
Alice Engineer <alice.engineer@example.com>
|
||||
|
||||
```
|
||||
|
||||
有时也会在括号中包含说明,来告诉终端用户关于该特定密钥的更多信息:
|
||||
|
||||
```
|
||||
Bob Designer (obsolete 1024-bit key) <bob.designer@example.com>
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
由于人们可以和多个职业和个人实体相关联,因此在同一密钥上可以有多个身份:
|
||||
|
||||
```
|
||||
Alice Engineer <alice.engineer@example.com>
|
||||
Alice Engineer <aengineer@personalmail.example.org>
|
||||
Alice Engineer <webmaster@girlswhocode.example.net>
|
||||
|
||||
```
|
||||
|
||||
当使用多个身份时,其中之一将被标记为“primary identity”(主要身份)来让检索更简单。
|
||||
当使用多个身份时,其中之一将被标记为“<ruby>primary identity<rt>主要身份</rt></ruby>”来让检索更简单。
|
||||
|
||||
### 理解密钥有效性
|
||||
#### 理解密钥有效性
|
||||
|
||||
为了能使用其他人的公钥来加密或验证,你需要确保它确实属于正确的人(Alice)而不属于冒牌的(Eve)。在 PGP 中,这被称为密钥有效性:
|
||||
为了能使用其他人的公钥来加密或验证,你需要确保它确实属于正确的人(Alice)而不属于冒牌的(Eve)。在 PGP 中,这被称为“密钥有效性”:
|
||||
|
||||
* Validity: full -- 意味着非常确认该密钥属于 Alice
|
||||
* Validity: marginal -- 意味着大致确认该密钥属于 Alice
|
||||
* Validity: unknown -- 意味着不确认该密钥是否属于 Alice
|
||||
* 有效性:<ruby>完全<rt>full</rt></ruby> -- 意味着非常确认该密钥属于 Alice
|
||||
* 有效性:<ruby>临界<rt>marginal</rt></ruby> -- 意味着大致确认该密钥属于 Alice
|
||||
* 有效性:<ruby>未知<rt>unknown</rt></ruby> -- 意味着不确认该密钥是否属于 Alice
|
||||
|
||||
#### Web of Trust (WOT) 与 Trust on First Use (TOFU)
|
||||
|
||||
PGP 使用了一种信任委托机制叫“Web of Trust”。它的核心是尝试替代 HTTPS/TLS 世界中对集中式认证机构的需求。PGP 把这个责任交给了每个用户,而不是各种软件开发商来决定谁应该是你的可信认证实体。
|
||||
|
||||
|
||||
#### Web of Trust (WOT) vs. Trust on First Use (TOFU)
|
||||
|
||||
PGP 使用了一种信任委托机制叫“Web of Trust”。它的核心是尝试替代 HTTPS/TLS 世界中对集中式认证机构的需求。PGP 把这个责任交给了每个用户,而非各种软件制作商来决定谁应该是你的可信认证实体。
|
||||
|
||||
不幸的是,很少有人理解 Web of Trust 的是如何工作的,能让继续工作的人更少。它仍然是 OpenPGP 规范的一个重要方面,但 GnuPG 的近期版本(2.2 及以上)已经实现了一种替代机制叫“Trust on First Use”(TOFU)。
|
||||
不幸的是,很少有人理解 Web of Trust 的是如何工作的,能使用它的人更少。它仍然是 OpenPGP 规范的一个重要方面,但 GnuPG 的近期版本(2.2 及以上)已经实现了一种替代机制叫“Trust on First Use”(TOFU)。
|
||||
|
||||
你可以把 TOFU 当作类似 SSH 的信任方式。使用 SSH,当你第一次连接到远程系统,它的密钥指纹会被记录和保存。如果将来密钥改变,SSH 客户端将会提醒你并拒绝连接,迫使你决定是否信任已改变的的密钥。
|
||||
|
||||
同样,当你第一次导入某人的 PGP 密钥,它被假定可信。如果在将来的任何时候,GnuPG 碰巧发现另一同样身份的密钥,过去导入的密钥和新密钥都将被标记为无效,并且你需要手动指出保留哪个。
|
||||
|
||||
#### 安装 OpenPGP 软件
|
||||
|
||||
### 安装 OpenPGP 软件
|
||||
首先,理解 PGP、OpenPGP、GnuPG 和 gpg 之间的不同很重要:
|
||||
|
||||
首先,理解 PGP, OpenPGP, GnuPG 和 gpg 之间的不同很重要:
|
||||
|
||||
* PGP ("Pretty Good Privacy") 是原始商业软件的名字
|
||||
|
||||
* OpenPGP 是与原始 PGP 工具兼容的 IETF 标准
|
||||
|
||||
* GnuPG ("Gnu Privacy Guard")是实现了 OpenPGP 标准的自由软件
|
||||
|
||||
* PGP (“Pretty Good Privacy”) 是最初商业软件的名字
|
||||
* OpenPGP 是与最初 PGP 工具兼容的 IETF 标准
|
||||
* GnuPG (“Gnu Privacy Guard”)是实现了 OpenPGP 标准的自由软件
|
||||
* GnuPG 的命令行工具称为 “gpg”
|
||||
|
||||
今天,“PGP”这个词几乎被普遍用来表示开放的 OpenPGP 标准,而不是最初的商业软件,因此“PGP”和“OpenPGP”是可以互换的。“GnuPG”和“pgp”这两个词应该仅在提及工具时使用,而不用于它们产生的输出或它们实现的 OpenPGP 功能。举例:
|
||||
|
||||
|
||||
|
||||
|
||||
今天,“PGP”这个词几乎被普遍用来表示开放的 OpenPGP 标准,而不是原始的商业软件,因此“PGP”和“OpenPGP”是可以互换的。“GnuPG”和“pgp”这两个词应该仅在提及工具时使用,而不用于它们产生的输出或它们实现的 OpenPGP 功能。举例:
|
||||
|
||||
* PGP(而非 GnuPG 或 GPG)密钥
|
||||
|
||||
* PGP(而非 GnuPG 或 GPG)签名
|
||||
|
||||
* PGP(而非 GnuPG 或 GPG)密钥服务器
|
||||
|
||||
|
||||
|
||||
* PGP(而非 GnuPG 或 GPG)密钥
|
||||
* PGP(而非 GnuPG 或 GPG)签名
|
||||
* PGP(而非 GnuPG 或 GPG)密钥服务器
|
||||
|
||||
理解这一点应该可以保护你免受来自你遇到的其他 PGP 用户“实际上”不可避免的迂腐。
|
||||
|
||||
#### 安装 GnuPG
|
||||
##### 安装 GnuPG
|
||||
|
||||
如果你正在使用 Linux,你应该已经安装过了 GnuPG。在 Mac 上,你应该安装[GPG-Suite][1],或者使用 brew 安装 gnupg2。在 windows 上,你应该安装[GPG4Win][2],并且为了奏效你可能需要调整指南中的部分命令,除非你设置了类似 unix 的环境。对其他平台来说,你需要自行查找正确的地址来下载和安装 GnuPG。
|
||||
如果你正在使用 Linux,你应该已经安装过了 GnuPG。在 Mac 上,你应该安装 [GPG-Suite][1],或者使用 `brew` 安装 `gnupg2`。在 Windows 上,你应该安装 [GPG4Win][2],并且为了可以工作,你可能需要调整指南中的部分命令,除非你设置了类似 Unix 的环境。对其他平台来说,你需要自行查找正确的地址来下载和安装 GnuPG。
|
||||
|
||||
#### GnuPG 1 vs. 2
|
||||
##### GnuPG 1 vs. 2
|
||||
|
||||
GnuPG v.1 和 GnuPG v.2 都实现了同样的标准,但它们提供不兼容的库和命令行工具,所以许多发行版都发布了旧版本 1 和最新版本 2。你需要确保你总是使用 GnuPG v.2。
|
||||
GnuPG v.1 和 GnuPG v.2 都实现了同样的标准,但它们提供不兼容的库和命令行工具,所以许多发行版都带有了旧的版本 1 和最新的版本 2。你需要确保你总是使用 GnuPG v.2。
|
||||
|
||||
首先,运行:
|
||||
|
||||
```
|
||||
$ gpg --version | head -n1
|
||||
|
||||
```
|
||||
|
||||
如果你看到 gpg (GnuPG) 1.4.x,说明你正使用 GnuPG v.1。尝试 gpg2 命令:
|
||||
如果你看到 `gpg (GnuPG) 1.4.x`,说明你正使用 GnuPG v.1。尝试下 `gpg2` 命令:
|
||||
|
||||
```
|
||||
$ gpg2 --version | head -n1
|
||||
|
||||
```
|
||||
|
||||
如果你看到 gpg (GnuPG) 2.x.x,说明你可以继续了。这篇指南将假设你使用 GnuPG 2.2 版本(或更晚)。如果你正使用 GnuPG 的 2.0 版本,本指南中某些命令可能无效,你应该考虑安装 GnuPG 最新的 2.2 版本
|
||||
如果你看到 `gpg (GnuPG) 2.x.x`,说明你可以继续了。这篇指南将假设你使用 GnuPG 2.2 版本(或更新)。如果你正使用 GnuPG 的 2.0 版本,本指南中某些命令可能无效,你应该考虑安装 GnuPG 最新的 2.2 版本
|
||||
|
||||
#### 确保你总是使用 GnuPG v.2
|
||||
##### 确保你总是使用 GnuPG v.2
|
||||
|
||||
如果你 `gpg` 和 `gpg2` 命令都有,你应该确保总是使用 GnuPG v.2,而不是旧的版本。你可以通过设置别名来确保这一点:
|
||||
|
||||
如果你 gpg 和 gpg2 命令都有,你应该确保总是使用 GnuPG v.2,而不是旧的版本。你可以通过设置别名来确保这一点:
|
||||
```
|
||||
$ alias gpg=gpg2
|
||||
|
||||
```
|
||||
|
||||
你可以把它放在你的 .bashrc 中,以确保它在你使用 gpg 命令时总是被加载。
|
||||
你可以把它放在你的 `.bashrc` 中,以确保它在你使用 `gpg` 命令时总是被加载。
|
||||
|
||||
在本系列的第 2 部分中,我们将介绍生成和保护你的 PGP 主密钥的基本步骤。
|
||||
|
||||
通过 Linux 基金会和 edX 的免费[“Introduction to Linux” ][3]课程了解关于 Linux 的更多信息。
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/blog/learn/2018/2/protecting-code-integrity-pgp-part-1-basic-pgp-concepts-and-tools
|
||||
|
||||
作者:[Konstantin Ryabitsev][a]
|
||||
译者:[kimii](https://github.com/kimii)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,26 +1,27 @@
|
||||
尝试 H2o
|
||||
尝试 H2o 做机器学习
|
||||
======
|
||||
|
||||
![H2o Flow gradient boosting job][1]
|
||||
|
||||
我目前正在参加一个机器学习班,虽然有疯狂的工作量,但我非常喜欢。我最初计划使用 [R][2] 来训练我的数据库,但老师建议我使用一个 FOSS 机器学习框架 [H2o][3]。
|
||||
我目前正在参加一个机器学习班,虽然工作量很疯狂,但我非常喜欢。我最初计划使用 [R][2] 来训练我的数据库,但老师建议我使用一个 FOSS 机器学习框架 [H2o][3]。
|
||||
|
||||
起初我有点怀疑,因为我已经对 R 掌握得不错了,但后来我发现你可以简单地将 H2o 作为 R 库导入。H2o 将大多数 R 函数替换为其自己的并行化函数,以减少处理时间(不再需要 `doParallel` 调用),并且使用“外部”服务端来运行,而不是直接调用 R。
|
||||
|
||||
![H2o Flow gradient boosting model][4]
|
||||
|
||||
直到我真正在实际中开始在 H2o 中使用 R 时,我对这种情况都非常满意。我在使用非常大得数据库时,库变得笨重,我几乎不能做任何有用得事情。大多数时候,我最后只是得到一个很长的 Java 回溯调用。
|
||||
直到我真正在实际中开始在 H2o 中使用 R 时,我对这种情况都非常满意。我在使用非常大的数据库时,库变得笨重,我几乎不能做任何有用得事情。大多数时候,我最后只是得到一个很长的 Java 回溯调用。
|
||||
|
||||
我相信正确地将 H2o 作为一个库使用将非常强大,但可惜的是,它似乎在我的 R-fu 中无效。
|
||||
我相信正确地将 H2o 作为一个库使用将非常强大,但可惜的是,它似乎在我的 R 技能中无效。
|
||||
|
||||
![H2o Flow variable importance weights][5]
|
||||
|
||||
我至少有一整天都很生气 - 无法实现我想做的事 - 直到我意识到 H2o 有一个名为 Flow 的 WebUI。我通常不喜欢使用 web 来完成重要的工作,比如编写代码,但是 Flow 简直太不可思议了。
|
||||
我生了一整天的气 —— 无法实现我想做的事 —— 直到我意识到 H2o 有一个名为 Flow 的 WebUI。我通常不喜欢使用 web 来完成重要的工作,比如编写代码,但是 Flow 简直太不可思议了。
|
||||
|
||||
自动绘图功能,运行资源密集模型时集成 ETA(预计剩余时间),每个模型参数的描述(这些参数甚至会根据您熟悉的统计模型分成不同部分),Flow 似乎拥有所有功能。我很快就能够运行 3 种基本的机器学习模型并获得实际可解释的结果。
|
||||
|
||||
所以,如果你一直渴望使用最先进的机器学习模型分析非常大的数据库,我会推荐使用 H2o。首先尝试使用 Flow,而不是 Python 或 R 的钩子,来看看它能做什么。
|
||||
|
||||
唯一缺点是,H2o 是用 Java 编写的,并依赖 Java 1.7 来运行。并且需要警告:它需要非常强大的处理器和大量的内存。即使有 10 个可用的内核和 10Gb 的 RAM,我可怜的服务器也苦苦挣扎了一段时间。
|
||||
唯一缺点是,H2o 是用 Java 编写的,并依赖 Java 1.7 来运行。并且需要警告的是:它需要非常强大的处理器和大量的内存。即使有 10 个可用的内核和 10Gb 的 RAM,我可怜的服务器也苦苦挣扎了一段时间。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -28,7 +29,7 @@ via: https://veronneau.org/playing-with-water.html
|
||||
|
||||
作者:[Louis-Philippe Véronneau][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,163 +0,0 @@
|
||||
Translating by MjSeven
|
||||
|
||||
|
||||
The Uniq Command Tutorial With Examples For Beginners
|
||||
======
|
||||
If you're working mostly on command line and dealing with a lot of text files every day, you should be aware of **Uniq** command. This command helps you to find repeated/duplicate lines from a file easily. It is not just for finding duplicates, but also we can use uniq command to remove the duplicates, display the number of occurrences of the duplicate lines, display only the repeated lines and display only the unique lines etc. Since the uniq command is part of GNU coreutils package, it comes preinstalled in most Linux distributions. Let us not bother with installation and see some practical examples.
|
||||
|
||||
Please note that the 'uniq' command will not detect repeated lines unless they are adjacent. So, you might need to sort them first or combine the sort command with uniq to get the results. Allow me to show you some examples.
|
||||
|
||||
First, let us create a file with some duplicate lines.
|
||||
```
|
||||
vi ostechnix.txt
|
||||
```
|
||||
```
|
||||
welcome to ostechnix
|
||||
welcome to ostechnix
|
||||
Linus is the creator of Linux.
|
||||
Linux is secure by default
|
||||
Linus is the creator of Linux.
|
||||
Top 500 super computers are powered by Linux
|
||||
```
|
||||
|
||||
As you see in the above file, we have few repeated lines (the first, second, third, and fifth lines are duplicates).
|
||||
|
||||
### **1\. Remove consecutive duplicate lines in a file using Uniq command**
|
||||
|
||||
If you use 'uniq' command without any arguments, it will remove all consecutive duplicate lines and display only the unique lines.
|
||||
```
|
||||
uniq ostechnix.txt
|
||||
```
|
||||
|
||||
Sample output would be:
|
||||
|
||||
[![][1]][2]
|
||||
|
||||
As you can see, uniq command removed all consecutive duplicate lines in the given file. You might also have noticed that the above output still has the duplicates in second and fourth lines. It is because the uniq command will only omit the repeated lines only if they are adjacent. We can, of course, remove that non-consecutive duplicates too. Look at the second example below.
|
||||
|
||||
### **2\. Remove all duplicate lines**
|
||||
```
|
||||
sort ostechnix.txt | uniq
|
||||
```
|
||||
|
||||
Sample output would be:
|
||||
|
||||
[![][1]][3]
|
||||
|
||||
See? There are no duplicates or repeated lines. In other words, the above command will display each line once from file ostechnix.txt. We used the sort command in conjunction with uniq, because, as I already mentioned, uniq will not find the duplicate/repeated lines unless they are adjacent.
|
||||
|
||||
### **3\. Display only unique lines from a file**
|
||||
|
||||
To display only the unique lines from a file, the command would be:
|
||||
```
|
||||
sort ostechnix.txt | uniq -u
|
||||
```
|
||||
|
||||
Sample output:
|
||||
```
|
||||
Linux is secure by default
|
||||
Top 500 super computers are powered by Linux
|
||||
```
|
||||
|
||||
As you can see, we have only two unique lines in the given file.
|
||||
|
||||
### **4\. Display only duplicate lines**
|
||||
|
||||
Similarly, we can also display duplicates lines from a file like below.
|
||||
```
|
||||
sort ostechnix.txt | uniq -d
|
||||
```
|
||||
|
||||
Sample output:
|
||||
```
|
||||
Linus is the creator of Linux.
|
||||
welcome to ostechnix
|
||||
```
|
||||
|
||||
These two are the repeated/duplicated lines in ostechnix.txt file. Please note that -d (small d) will **only print duplicate lines** , **one for each group**. To print **all duplicate lines** , use -D (capital d) like below.
|
||||
```
|
||||
sort ostechnix.txt | uniq -D
|
||||
```
|
||||
|
||||
See the difference between both flags in the below screenshot.
|
||||
|
||||
[![][1]][4]
|
||||
|
||||
### **5\. Display number of occurrences of each line in a file
|
||||
**
|
||||
|
||||
For some reason, you might want to check how many times a line is repeated in the given file. To do so, use **-c** flag like below.
|
||||
```
|
||||
sort ostechnix.txt | uniq -c
|
||||
```
|
||||
|
||||
**Sample output:**
|
||||
```
|
||||
2 Linus is the creator of Linux.
|
||||
1 Linux is secure by default
|
||||
1 Top 500 super computers are powered by Linux
|
||||
2 welcome to ostechnix
|
||||
```
|
||||
|
||||
We can also display number of occurrences of each line along with that line, sorted by the most frequent like below.
|
||||
```
|
||||
sort ostechnix.txt | uniq -c | sort -nr
|
||||
```
|
||||
|
||||
Sample output:
|
||||
```
|
||||
2 welcome to ostechnix
|
||||
2 Linus is the creator of Linux.
|
||||
1 Top 500 super computers are powered by Linux
|
||||
1 Linux is secure by default
|
||||
```
|
||||
|
||||
### 6\. Limit the comparison to 'N' characters
|
||||
|
||||
We can limit the comparison to a particular number of characters of lines in a file using **-w** flag. For example, let us limit the comparison to first 4 characters of lines in a file and display the repeated lines as shown below.
|
||||
```
|
||||
uniq -d -w 4 ostechnix.txt
|
||||
```
|
||||
|
||||
### 7\. Avoid the comparison with the first 'N' characters
|
||||
|
||||
Like limit comparison to N characters of lines in a file, we can also avoid comparing the first N characters using -s flag.
|
||||
|
||||
The following command will avoid the comparison with the first 4 characters of lines in a file:
|
||||
```
|
||||
uniq -d -s 4 ostechnix.txt
|
||||
```
|
||||
|
||||
To avoid comparing the first N fields instead of characters, use '-f' flag in the above command.
|
||||
|
||||
For more details, refer the help section;
|
||||
```
|
||||
uniq --help
|
||||
```
|
||||
|
||||
and man pages.
|
||||
```
|
||||
man uniq
|
||||
```
|
||||
|
||||
And, that's all for today! I hope you now get a basic idea about uniq command and its purpose. If you find our guides useful, please share them on your social, professional networks and support OSTechNix. More good stuffs to come. Stay tuned!
|
||||
|
||||
Cheers!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/uniq-command-tutorial-examples-beginners/
|
||||
|
||||
作者:[][a]
|
||||
译者:[译者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
|
||||
[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[2]:http://www.ostechnix.com/wp-content/uploads/2018/01/uniq-2.png ()
|
||||
[3]:http://www.ostechnix.com/wp-content/uploads/2018/01/uniq-1-1.png ()
|
||||
[4]:http://www.ostechnix.com/wp-content/uploads/2018/01/uniq-4.png ()
|
@ -1,3 +1,5 @@
|
||||
translating---geekpi
|
||||
|
||||
How to add fonts to Fedora
|
||||
===================
|
||||
|
||||
|
@ -1,70 +0,0 @@
|
||||
translating---geekpi
|
||||
|
||||
4 command line note-taking applications for Linux
|
||||
======
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/note-taking.jpeg?itok=fiF5EBEb)
|
||||
When you need to save a code snippet or a URL, an idea or a quote, you probably fire up a text editor or turn to a [desktop][1] or [web-based][2] note-taking tool. But those aren't your only options. If you spend time working in terminal windows, you can use one of the many note-taking tools available for the Linux command line.
|
||||
|
||||
Let's take a look at of those four apps.
|
||||
|
||||
### tnote
|
||||
|
||||
[tnote][3] makes taking notes in a terminal window very simple—almost too simple.
|
||||
|
||||
tnote is a single Python script. When you start it for the first time, it asks you to enter a password and a passphrase to encrypt the [SQLite database][4] that stores your notes. Once you've done that, press "A" to create a note. Type your note, then press CTRL-D to save it.
|
||||
|
||||
Once you have a few (or more than a few) notes, you can view them or search for specific ones, words or phrases, or tags. tnote doesn't pack a lot of features, but it does get the job done.
|
||||
|
||||
### Terminal Velocity
|
||||
|
||||
If you've used Mac OS, you might have come across a popular open source note-taking application called [Notational Velocity][5], a simple and effective way to take notes. [Terminal Velocity][6] does a good job of bringing the Notational Velocity experience to the command line.
|
||||
|
||||
Terminal Velocity opens your default text editor (set by the `$EDITOR` variable in your `.profile` or `.bashrc` file). Type your note, then save it. The note appears in the list in the Terminal Velocity window.
|
||||
|
||||
Use the arrow keys on your keyboard to scroll through your list of notes. To view or edit a note, press Enter. If you have a long list of notes, you can enter the first few characters of the note's title in the `Find or Create` field to narrow down the list. From there, scroll to the note and press Enter to open it.
|
||||
|
||||
### pygmynote
|
||||
|
||||
Of the four applications in this article, [pygmynote][7] is probably the least user-friendly. It is, however, the most flexible.
|
||||
|
||||
Like tnote, pygmynote saves your notes and attachments in an SQLite database. When you fire it up, pygmynote doesn’t look particularly useful. At any time, type `help` and press Enter to get a list of commands.
|
||||
|
||||
You can add and edit notes, view and search for them, and add [tags][8] to your notes. Tags make finding notes easier, especially if you have a lot of them.
|
||||
|
||||
What gives pygmynote flexibility is its ability to add attachments to your notes. Those attachments can be anything: an image, a text or word processor file, a PDF, a spreadsheet, or anything else relevant to the note.
|
||||
|
||||
### jrnl
|
||||
|
||||
[jrnl][9] is the odd application out here. As you've probably guessed from its name, jrnl is intended to be a journaling tool. But that doesn't mean you can't take notes with it. jrnl does that job very well.
|
||||
|
||||
When you first start jrnl, it asks you where you want to put the file `journal.txt` (which stores your notes), and if you want to password-protect the file. If you decide to add a password, you need to enter it whenever you do anything with the application.
|
||||
|
||||
You can enter notes in two ways: directly from the command line, or with your computer's default editor. You can add tags—for example,`@opensource.com`—to your notes, and give them a date and timestamp. Adding tags and dates can help you search for your notes (jrnl has a pretty decent search feature) if you have a lot of them.
|
||||
|
||||
Since jrnl saves your notes in a plain text file, you can sync it across your devices using [ownCloud][10], [Nextcloud][11], or whatever file sharing/syncing service your prefer.
|
||||
|
||||
Do you have a favorite tool or hack for taking notes at the command line? Feel free to share it with the community by leaving a comment.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/3/command-line-note-taking-applications
|
||||
|
||||
作者:[Scott Nesbitt][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/scottnesbitt
|
||||
[1]:https://opensource.com/life/16/9/4-desktop-note-taking-applications
|
||||
[2]:https://opensource.com/alternatives/evernote
|
||||
[3]:https://github.com/tasdikrahman/tnote
|
||||
[4]:http://en.wikipedia.org/wiki/SQLite
|
||||
[5]:http://notational.net/
|
||||
[6]:https://vhp.github.io/terminal_velocity/
|
||||
[7]:https://github.com/dmpop/pygmynote
|
||||
[8]:https://en.wikipedia.org/wiki/Tag_(metadata)
|
||||
[9]:http://jrnl.sh/
|
||||
[10]:https://owncloud.com/
|
||||
[11]:https://nextcloud.com/
|
@ -1,3 +1,5 @@
|
||||
Translating by MjSeven
|
||||
|
||||
Loop better: A deeper look at iteration in Python
|
||||
======
|
||||
|
||||
|
@ -0,0 +1,255 @@
|
||||
9 Useful touch command examples in Linux
|
||||
======
|
||||
Touch command is used to create empty files and also changes the timestamps of existing files on Unix & Linux System. Changing timestamps here means updating the access and modification time of files and directories.
|
||||
|
||||
[![touch-command-examples-linux][1]![touch-command-examples-linux][2]][2]
|
||||
|
||||
Let’s have a look on the syntax and options used in touch command,
|
||||
|
||||
**Syntax** : # touch {options} {file}
|
||||
|
||||
Options used in touch command,
|
||||
|
||||
![touch-command-options][1]
|
||||
|
||||
![touch-command-options][3]
|
||||
|
||||
In this article we will walk through 9 useful touch command examples in Linux,
|
||||
|
||||
### Example:1 Create an empty file using touch
|
||||
|
||||
To create an empty file using touch command on Linux systems, type touch followed by the file name, example is shown below,
|
||||
```
|
||||
[root@linuxtechi ~]# touch devops.txt
|
||||
[root@linuxtechi ~]# ls -l devops.txt
|
||||
-rw-r--r--. 1 root root 0 Mar 29 22:39 devops.txt
|
||||
[root@linuxtechi ~]#
|
||||
|
||||
```
|
||||
|
||||
### Example:2 Create empty files in bulk using touch
|
||||
|
||||
There can be some scenario where we have to create lots of empty files for some testing, this can be easily achieved using touch command,
|
||||
```
|
||||
[root@linuxtechi ~]# touch sysadm-{1..20}.txt
|
||||
|
||||
```
|
||||
|
||||
In the above example we have created 20 empty files with name sysadm-1.txt to sysadm-20.txt, you can change the name and numbers based on your requirements.
|
||||
|
||||
### Example:3 Change / Update access time of a file and directory
|
||||
|
||||
Let’s assume we want to change access time of a file called “ **devops.txt** “, to do this use ‘ **-a** ‘ option in touch command followed by file name, example is shown below,
|
||||
```
|
||||
[root@linuxtechi ~]# touch -a devops.txt
|
||||
[root@linuxtechi ~]#
|
||||
|
||||
```
|
||||
|
||||
Now verify whether access time of a file has been updated or not using ‘stat’ command
|
||||
```
|
||||
[root@linuxtechi ~]# stat devops.txt
|
||||
File: ‘devops.txt’
|
||||
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
|
||||
Device: fd00h/64768d Inode: 67324178 Links: 1
|
||||
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
|
||||
Context: unconfined_u:object_r:admin_home_t:s0
|
||||
Access: 2018-03-29 23:03:10.902000000 -0400
|
||||
Modify: 2018-03-29 22:39:29.365000000 -0400
|
||||
Change: 2018-03-29 23:03:10.902000000 -0400
|
||||
Birth: -
|
||||
[root@linuxtechi ~]#
|
||||
|
||||
```
|
||||
|
||||
**Change access time of a directory** ,
|
||||
|
||||
Let’s assume we have a ‘nfsshare’ folder under /mnt, Let’s change the access time of this folder using the below command,
|
||||
```
|
||||
[root@linuxtechi ~]# touch -m /mnt/nfsshare/
|
||||
[root@linuxtechi ~]#
|
||||
|
||||
[root@linuxtechi ~]# stat /mnt/nfsshare/
|
||||
File: ‘/mnt/nfsshare/’
|
||||
Size: 6 Blocks: 0 IO Block: 4096 directory
|
||||
Device: fd00h/64768d Inode: 2258 Links: 2
|
||||
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
|
||||
Context: unconfined_u:object_r:mnt_t:s0
|
||||
Access: 2018-03-29 23:34:38.095000000 -0400
|
||||
Modify: 2018-03-03 10:42:45.194000000 -0500
|
||||
Change: 2018-03-29 23:34:38.095000000 -0400
|
||||
Birth: -
|
||||
[root@linuxtechi ~]#
|
||||
|
||||
```
|
||||
|
||||
### Example:4 Change Access time without creating new file
|
||||
|
||||
There can be some situations where we want to change access time of a file if it exists and avoid creating the file. Using ‘ **-c** ‘ option in touch command, we can change access time of a file if it exists and will not a create a file, if it doesn’t exist.
|
||||
```
|
||||
[root@linuxtechi ~]# touch -c sysadm-20.txt
|
||||
[root@linuxtechi ~]# touch -c winadm-20.txt
|
||||
[root@linuxtechi ~]# ls -l winadm-20.txt
|
||||
ls: cannot access winadm-20.txt: No such file or directory
|
||||
[root@linuxtechi ~]#
|
||||
|
||||
```
|
||||
|
||||
### Example:5 Change Modification time of a file and directory
|
||||
|
||||
Using ‘ **-m** ‘ option in touch command, we can change the modification time of a file and directory,
|
||||
|
||||
Let’s change the modification time of a file called “devops.txt”,
|
||||
```
|
||||
[root@linuxtechi ~]# touch -m devops.txt
|
||||
[root@linuxtechi ~]#
|
||||
|
||||
```
|
||||
|
||||
Now verify whether modification time has been changed or not using stat command,
|
||||
```
|
||||
[root@linuxtechi ~]# stat devops.txt
|
||||
File: ‘devops.txt’
|
||||
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
|
||||
Device: fd00h/64768d Inode: 67324178 Links: 1
|
||||
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
|
||||
Context: unconfined_u:object_r:admin_home_t:s0
|
||||
Access: 2018-03-29 23:03:10.902000000 -0400
|
||||
Modify: 2018-03-29 23:59:49.106000000 -0400
|
||||
Change: 2018-03-29 23:59:49.106000000 -0400
|
||||
Birth: -
|
||||
[root@linuxtechi ~]#
|
||||
|
||||
```
|
||||
|
||||
Similarly, we can change modification time of a directory,
|
||||
```
|
||||
[root@linuxtechi ~]# touch -m /mnt/nfsshare/
|
||||
[root@linuxtechi ~]#
|
||||
|
||||
```
|
||||
|
||||
### Example:6 Changing access and modification time in one go
|
||||
|
||||
Use “ **-am** ” option in touch command to change the access and modification together or in one go, example is shown below,
|
||||
```
|
||||
[root@linuxtechi ~]# touch -am devops.txt
|
||||
[root@linuxtechi ~]#
|
||||
|
||||
```
|
||||
|
||||
Cross verify the access and modification time using stat,
|
||||
```
|
||||
[root@linuxtechi ~]# stat devops.txt
|
||||
File: ‘devops.txt’
|
||||
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
|
||||
Device: fd00h/64768d Inode: 67324178 Links: 1
|
||||
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
|
||||
Context: unconfined_u:object_r:admin_home_t:s0
|
||||
Access: 2018-03-30 00:06:20.145000000 -0400
|
||||
Modify: 2018-03-30 00:06:20.145000000 -0400
|
||||
Change: 2018-03-30 00:06:20.145000000 -0400
|
||||
Birth: -
|
||||
[root@linuxtechi ~]#
|
||||
|
||||
```
|
||||
|
||||
### Example:7 Set the Access & modification time to a specific date and time
|
||||
|
||||
Whenever we do change access and modification time of a file & directory using touch command, then it set the current time as access & modification time of that file or directory,
|
||||
|
||||
Let’s assume we want to set specific date and time as access & modification time of a file, this is can be achieved using ‘-c’ & ‘-t’ option in touch command,
|
||||
|
||||
Date and Time can be specified in the format: {CCYY}MMDDhhmm.ss
|
||||
|
||||
Where:
|
||||
|
||||
* CC – First two digits of a year
|
||||
* YY – Second two digits of a year
|
||||
* MM – Month of the Year (01-12)
|
||||
* DD – Day of the Month (01-31)
|
||||
* hh – Hour of the day (00-23)
|
||||
* mm – Minutes of the hour (00-59)
|
||||
|
||||
|
||||
|
||||
Let’s set the access & modification time of devops.txt file for future date and time( 2025 year, 10th Month, 19th day of month, 18th hours and 20th minute)
|
||||
```
|
||||
[root@linuxtechi ~]# touch -c -t 202510191820 devops.txt
|
||||
|
||||
```
|
||||
|
||||
Use stat command to view the update access & modification time,
|
||||
|
||||
![stat-command-output-linux][1]
|
||||
|
||||
![stat-command-output-linux][4]
|
||||
|
||||
Set the Access and Modification time based on date string, Use ‘-d’ option in touch command and then specify the date string followed by the file name, example is shown below,
|
||||
```
|
||||
[root@linuxtechi ~]# touch -c -d "2010-02-07 20:15:12.000000000 +0530" sysadm-29.txt
|
||||
[root@linuxtechi ~]#
|
||||
|
||||
```
|
||||
|
||||
Verify the status using stat command,
|
||||
```
|
||||
[root@linuxtechi ~]# stat sysadm-20.txt
|
||||
File: ‘sysadm-20.txt’
|
||||
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
|
||||
Device: fd00h/64768d Inode: 67324189 Links: 1
|
||||
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
|
||||
Context: unconfined_u:object_r:admin_home_t:s0
|
||||
Access: 2010-02-07 20:15:12.000000000 +0530
|
||||
Modify: 2010-02-07 20:15:12.000000000 +0530
|
||||
Change: 2018-03-30 10:23:31.584000000 +0530
|
||||
Birth: -
|
||||
[root@linuxtechi ~]#
|
||||
|
||||
```
|
||||
|
||||
**Note:** In above commands, if we don’t specify ‘-c’ then touch command will create a new file in case it doesn’t exist on the system and will set the timestamps whatever is mentioned in the command.
|
||||
|
||||
### Example:8 Set the timestamps to a file using a reference file (-r)
|
||||
|
||||
In touch command we can use a reference file for setting the timestamps of file or directory. Let’s assume I want to set the same timestamps of file “sysadm-20.txt” on “devops.txt” file. This can be easily achieved using ‘-r’ option in touch.
|
||||
|
||||
**Syntax:** # touch -r {reference-file} actual-file
|
||||
```
|
||||
[root@linuxtechi ~]# touch -r sysadm-20.txt devops.txt
|
||||
[root@linuxtechi ~]#
|
||||
|
||||
```
|
||||
|
||||
### Example:9 Change Access & Modification time on symbolic link file
|
||||
|
||||
By default, whenever we try to change timestamps of a symbolic link file using touch command then it will change the timestamps of original file only, In case you want to change timestamps of a symbolic link file then this can be achieved using ‘-h’ option in touch command,
|
||||
|
||||
**Syntax:** # touch -h {symbolic link file}
|
||||
```
|
||||
[root@linuxtechi opt]# ls -l /root/linuxgeeks.txt
|
||||
lrwxrwxrwx. 1 root root 15 Mar 30 10:56 /root/linuxgeeks.txt -> linuxadmins.txt
|
||||
[root@linuxtechi ~]# touch -t 203010191820 -h linuxgeeks.txt
|
||||
[root@linuxtechi ~]# ls -l linuxgeeks.txt
|
||||
lrwxrwxrwx. 1 root root 15 Oct 19 2030 linuxgeeks.txt -> linuxadmins.txt
|
||||
[root@linuxtechi ~]#
|
||||
|
||||
```
|
||||
|
||||
That’s all from this tutorial, I hope these examples help you to understand touch command. Please do share your valuable feedback and comments.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linuxtechi.com/9-useful-touch-command-examples-linux/
|
||||
|
||||
作者:[Pradeep Kumar][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.linuxtechi.com/author/pradeep/
|
||||
[1]:https://www.linuxtechi.com/wp-content/plugins/lazy-load/images/1x1.trans.gif
|
||||
[2]:https://www.linuxtechi.com/wp-content/uploads/2018/03/touch-command-examples-linux.jpg
|
||||
[3]:https://www.linuxtechi.com/wp-content/uploads/2018/03/touch-command-options.jpg
|
||||
[4]:https://www.linuxtechi.com/wp-content/uploads/2018/03/stat-command-output-linux.jpg
|
@ -0,0 +1,129 @@
|
||||
10 fundamental commands for new Linux users
|
||||
======
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc_terminals.png?itok=CfBqYBah)
|
||||
You may think you're new to Linux, but you're really not. There are [3.74 billion][1] global internet users, and all of them use Linux in some way since Linux servers power 90% of the internet. Most modern routers run Linux or Unix, and the [TOP500 supercomputers][2] also rely on Linux. If you own an Android smartphone, your operating system is constructed from the Linux kernel.
|
||||
|
||||
In other words, Linux is everywhere.
|
||||
|
||||
But there's a difference between using Linux-based technologies and using Linux itself. If you're interested in Linux, but have been using a PC or Mac desktop, you may be wondering what you need to know to use the Linux command line interface (CLI). You've come to the right place.
|
||||
|
||||
The following are the fundamental Linux commands you need to know. Each is simple and easy to commit to memory. In other words, you don't have to be Bill Gates to understand them.
|
||||
|
||||
### 1\. ls
|
||||
|
||||
You're probably thinking, "Is what?" No, that wasn't a typographical error – I really intended to type a lower-case L. `ls`, or "list," is the number one command you need to know to use the Linux CLI. This list command functions within the Linux terminal to reveal all the major directories filed under a respective filesystem. For example, this command:
|
||||
|
||||
`ls /applications`
|
||||
|
||||
shows every folder stored in the applications folder. You'll use it to view files, folders, and directories.
|
||||
|
||||
All hidden files are viewable by using the command `ls -a`.
|
||||
|
||||
### 2\. cd
|
||||
|
||||
This command is what you use to go (or "change") to a directory. It is how you navigate from one folder to another. Say you're in your Downloads folder, but you want to go to a folder called Gym Playlist. Simply typing `cd Gym Playlist` won't work, as the shell won't recognize it and will report the folder you're looking for doesn't exist. To bring up that folder, you'll need to include a backslash. The command should look like this:
|
||||
|
||||
`cd Gym\ Playlist`
|
||||
|
||||
To go back from the current folder to the previous one, you can type in the folder name followed by `cd ..`. Think of the two dots like a back button.
|
||||
|
||||
### 3\. mv
|
||||
|
||||
This command transfers a file from one folder to another; `mv` stands for "move." You can use this short command like you would drag a file to a folder on a PC.
|
||||
|
||||
For example, if I create a file called `testfile` to demonstrate all the basic Linux commands, and I want to move it to my Documents folder, I would issue this command:
|
||||
|
||||
`mv /home/sam/testfile /home/sam/Documents/`
|
||||
|
||||
The first piece of the command (`mv`) says I want to move a file, the second part (`home/sam/testfile`) names the file I want to move, and the third part (`/home/sam/Documents/`) indicates the location where I want the file transferred.
|
||||
|
||||
### 4\. Keyboard shortcuts
|
||||
|
||||
Okay, this is more than one command, but I couldn't resist including them all here. Why? Because they save time and take the headache out of your experience.
|
||||
|
||||
`CTRL+K` Cuts text from the cursor until the end of the line
|
||||
|
||||
`CTRL+Y` Pastes text
|
||||
|
||||
`CTRL+E` Moves the cursor to the end of the line
|
||||
|
||||
`CTRL+A` Moves the cursor to the beginning of the line
|
||||
|
||||
`ALT+F`Jumps forward to the next space
|
||||
|
||||
`ALT+B` Skips back to the previous space
|
||||
|
||||
`ALT+Backspace` Deletes the previous word
|
||||
|
||||
`CTRL+W` Cuts the word behind the cursor
|
||||
|
||||
`Shift+Insert` Pastes text into the terminal
|
||||
|
||||
`Ctrl+D` Logs you out
|
||||
|
||||
These commands come in handy in many ways. For example, imagine you misspell a word in your command text:
|
||||
|
||||
`sudo apt-get intall programname`
|
||||
|
||||
You probably noticed "install" is misspelled, so the command won't work. But keyboard shortcuts make it easy to go back and fix it. If my cursor is at the end of the line, I can click `ALT+B` twice to move the cursor to the place noted below with the `^` symbol:
|
||||
|
||||
`sudo apt-get^intall programname`
|
||||
|
||||
Now, we can quickly add the letter `s` to fix `install`. Easy peasy!
|
||||
|
||||
### 5\. mkdir
|
||||
|
||||
This is the command you use to make a directory or a folder in the Linux environment. For example, if you're big into DIY hacks like I am, you could enter `mkdir DIY` to make a directory for your DIY projects.
|
||||
|
||||
### 6\. at
|
||||
|
||||
If you want to run a Linux command at a certain time, you can add `at` to the equation. The syntax is `at` followed by the date and time you want the command to run. Then the command prompt changes to `at>` so you can enter the command(s) you want to run at the time you specified above
|
||||
|
||||
For example:
|
||||
|
||||
`at 4:08 PM Sat`
|
||||
`at> cowsay 'hello'`
|
||||
`at> CTRL+D`
|
||||
|
||||
This will run the program cowsay at 4:08 p.m. on Saturday night.
|
||||
|
||||
### 7\. rmdir
|
||||
|
||||
This command allows you to remove a directory through the Linux CLI. For example:
|
||||
|
||||
`rmdir testdirectory`
|
||||
|
||||
Bear in mind that this command will not remove a directory that has files inside. This only works when removing empty directories.
|
||||
|
||||
### 8\. rm
|
||||
|
||||
If you want to remove files, the `rm` command is what you want. It can delete files and directories. To delete a single file, type `rm testfile`, or to delete a directory and the files inside it, type `rm -r`.
|
||||
|
||||
### 9\. touch
|
||||
|
||||
The `touch` command, otherwise known as the "make file command," allows you to create new, empty files using the Linux CLI. Much like `mkdir` creates directories, `touch` creates files. For example, `touch testfile` will make an empty file named testfile.
|
||||
|
||||
### 10\. locate
|
||||
|
||||
This command is what you use to find a file in a Linux system. Think of it like search in Windows. It's very useful if you forget where you stored a file or what you named it.
|
||||
|
||||
For example, if you have a document about blockchain use cases, but you can't think of the title, you can punch in `locate -blockchain`or you can look for "blockchain use cases" by separating the words with an asterisk or asterisks (`*`). For example:
|
||||
|
||||
`locate -i*blockchain*use*cases*`.
|
||||
|
||||
There are tons of other helpful Linux CLI commands, like the `pkill` command, which is great if you start a shutdown and realize you didn't mean to. But the 10 simple and useful commands described here are the essentials you need to get started using the Linux command line.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/4/10-commands-new-linux-users
|
||||
|
||||
作者:[Sam Bocetta][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/sambocetta
|
||||
[1]:https://hostingcanada.org/state-of-the-internet/
|
||||
[2]:https://www.top500.org/statistics/details/osfam/1
|
@ -0,0 +1,459 @@
|
||||
17 Ways To Check Size Of Physical Memory (RAM) In Linux
|
||||
======
|
||||
Most of the system administrators checks CPU & Memory utilization when they were facing some performance issue.
|
||||
|
||||
There is lot of utilities are available in Linux to check physical memory.
|
||||
|
||||
These commands are help us to check the physical RAM present in system, also allow users to check memory utilization in varies aspect.
|
||||
|
||||
Most of us know only few commands and we are trying to include all the possible commands in this article.
|
||||
|
||||
You may think, why i want to know all these commands instead of knowing some of the specific and routine commands.
|
||||
|
||||
Don’t think bad or don’t take in negative way because each one has different requirement and perception so, who’s looking for other purpose then this will very helpful for them.
|
||||
|
||||
### What Is RAM
|
||||
|
||||
Computer memory is a physical device which capable to store information temporarily or permanently. RAM stands for Random Access Memory is a volatile memory that stores information used by the operating system, software, and hardware.
|
||||
|
||||
Two types of memory is available.
|
||||
|
||||
* Primary Memory
|
||||
* Secondary Memory
|
||||
|
||||
|
||||
|
||||
Primary memory is the main memory of the computer. CPU can directly read or write on this memory. It is fixed on the motherboard of the computer.
|
||||
|
||||
* **`RAM:`** Random Access Memory is a temporary memory. This information will go away when the computer is turned off.
|
||||
* **`ROM:`** Read Only Memory is permanent memory, that holds the data even if the system is switched off.
|
||||
|
||||
|
||||
|
||||
### Method-1 : Using free Command
|
||||
|
||||
free displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel. The information is gathered by parsing /proc/meminfo.
|
||||
|
||||
**Suggested Read :** [free – A Standard Command to Check Memory Usage Statistics (Free & Used) in Linux][1]
|
||||
```
|
||||
$ free -m
|
||||
total used free shared buff/cache available
|
||||
Mem: 1993 1681 82 81 228 153
|
||||
Swap: 12689 1213 11475
|
||||
|
||||
$ free -g
|
||||
total used free shared buff/cache available
|
||||
Mem: 1 1 0 0 0 0
|
||||
Swap: 12 1 11
|
||||
|
||||
```
|
||||
|
||||
### Method-2 : Using /proc/meminfo file
|
||||
|
||||
/proc/meminfo is a virtual text file that contains a large amount of valuable information about the systems RAM usage.
|
||||
|
||||
It’s report the amount of free and used memory (both physical and swap) on the system.
|
||||
```
|
||||
$ grep MemTotal /proc/meminfo
|
||||
MemTotal: 2041396 kB
|
||||
|
||||
$ grep MemTotal /proc/meminfo | awk '{print $2 / 1024}'
|
||||
1993.55
|
||||
|
||||
$ grep MemTotal /proc/meminfo | awk '{print $2 / 1024 / 1024}'
|
||||
1.94683
|
||||
|
||||
```
|
||||
|
||||
### Method-3 : Using top Command
|
||||
|
||||
Top command is one of the basic command to monitor real-time system processes in Linux. It display system information and running processes information like uptime, average load, tasks running, number of users logged in, number of CPUs & cpu utilization, Memory & swap information. Run top command then hit `E` to bring the memory utilization in MB.
|
||||
|
||||
**Suggested Read :** [TOP Command Examples to Monitor Server Performance][2]
|
||||
```
|
||||
$ top
|
||||
|
||||
top - 14:38:36 up 1:59, 1 user, load average: 1.83, 1.60, 1.52
|
||||
Tasks: 223 total, 2 running, 221 sleeping, 0 stopped, 0 zombie
|
||||
%Cpu(s): 48.6 us, 11.2 sy, 0.0 ni, 39.3 id, 0.3 wa, 0.0 hi, 0.5 si, 0.0 st
|
||||
MiB Mem : 1993.551 total, 94.184 free, 1647.367 used, 252.000 buff/cache
|
||||
MiB Swap: 12689.58+total, 11196.83+free, 1492.750 used. 306.465 avail Mem
|
||||
|
||||
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
||||
9908 daygeek 20 0 2971440 649324 39700 S 55.8 31.8 11:45.74 Web Content
|
||||
21942 daygeek 20 0 2013760 308700 69272 S 35.0 15.1 4:13.75 Web Content
|
||||
4782 daygeek 20 0 3687116 227336 39156 R 14.5 11.1 16:47.45 gnome-shell
|
||||
|
||||
```
|
||||
|
||||
### Method-4 : Using vmstat Command
|
||||
|
||||
vmstat is a standard nifty tool that report virtual memory statistics of Linux system. vmstat reports information about processes, memory, paging, block IO, traps, and cpu activity. It helps Linux administrator to identify system bottlenecks while troubleshooting the issues.
|
||||
|
||||
**Suggested Read :** [vmstat – A Standard Nifty Tool to Report Virtual Memory Statistics][3]
|
||||
```
|
||||
$ vmstat -s | grep "total memory"
|
||||
2041396 K total memory
|
||||
|
||||
$ vmstat -s -S M | egrep -ie 'total memory'
|
||||
1993 M total memory
|
||||
|
||||
$ vmstat -s | awk '{print $1 / 1024 / 1024}' | head -1
|
||||
1.94683
|
||||
|
||||
```
|
||||
|
||||
### Method-5 : Using nmon Command
|
||||
|
||||
nmon is a another nifty tool to monitor various system resources such as CPU, memory, network, disks, file systems, NFS, top processes, Power micro-partition and resources (Linux version & processors) on Linux terminal.
|
||||
|
||||
Just press `m` key to see memory utilization stats (cached, active, inactive, buffered, free in MB & free percent)
|
||||
|
||||
**Suggested Read :** [nmon – A Nifty Tool To Monitor System Resources On Linux][4]
|
||||
```
|
||||
┌nmon─14g──────[H for help]───Hostname=2daygeek──Refresh= 2secs ───07:24.44─────────────────┐
|
||||
│ Memory Stats ─────────────────────────────────────────────────────────────────────────────│
|
||||
│ RAM High Low Swap Page Size=4 KB │
|
||||
│ Total MB 32079.5 -0.0 -0.0 20479.0 │
|
||||
│ Free MB 11205.0 -0.0 -0.0 20479.0 │
|
||||
│ Free Percent 34.9% 100.0% 100.0% 100.0% │
|
||||
│ MB MB MB │
|
||||
│ Cached= 19763.4 Active= 9617.7 │
|
||||
│ Buffers= 172.5 Swapcached= 0.0 Inactive = 10339.6 │
|
||||
│ Dirty = 0.0 Writeback = 0.0 Mapped = 11.0 │
|
||||
│ Slab = 636.6 Commit_AS = 118.2 PageTables= 3.5 │
|
||||
│───────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└───────────────────────────────────────────────────────────────────────────────────────────┘
|
||||
|
||||
```
|
||||
|
||||
### Method-6 : Using dmidecode Command
|
||||
|
||||
Dmidecode is a tool which reads a computer’s DMI (stands for Desktop Management Interface)
|
||||
(some say SMBIOS – stands for System Management BIOS) table contents and display system hardware information in a human-readable format.
|
||||
|
||||
This table contains a description of the system’s hardware components, as well as other useful information such as serial number, Manufacturer information, Release Date, and BIOS revision, etc,.
|
||||
|
||||
**Suggested Read :**
|
||||
[Dmidecode – Easy Way To Get Linux System Hardware Information][5]
|
||||
```
|
||||
# dmidecode -t memory | grep Size:
|
||||
Size: 8192 MB
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
Size: 8192 MB
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
Size: 8192 MB
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
Size: 8192 MB
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
Size: No Module Installed
|
||||
|
||||
```
|
||||
|
||||
Print only installed RAM modules.
|
||||
```
|
||||
|
||||
# dmidecode -t memory | grep Size: | grep -v "No Module Installed"
|
||||
Size: 8192 MB
|
||||
Size: 8192 MB
|
||||
Size: 8192 MB
|
||||
Size: 8192 MB
|
||||
|
||||
```
|
||||
|
||||
Sum all the installed RAM modules.
|
||||
```
|
||||
# dmidecode -t memory | grep Size: | grep -v "No Module Installed" | awk '{sum+=$2}END{print sum}'
|
||||
32768
|
||||
|
||||
```
|
||||
|
||||
### Method-7 : Using hwinfo Command
|
||||
|
||||
hwinfo stands for hardware information tool is another great utility that used to probe for the hardware present in the system and display detailed information about varies hardware components in human readable format.
|
||||
|
||||
It reports information about CPU, RAM, keyboard, mouse, graphics card, sound, storage, network interface, disk, partition, bios, and bridge, etc,.
|
||||
|
||||
**Suggested Read :** [hwinfo (Hardware Info) – A Nifty Tool To Detect System Hardware Information On Linux][6]
|
||||
```
|
||||
$ hwinfo --memory
|
||||
01: None 00.0: 10102 Main Memory
|
||||
[Created at memory.74]
|
||||
Unique ID: rdCR.CxwsZFjVASF
|
||||
Hardware Class: memory
|
||||
Model: "Main Memory"
|
||||
Memory Range: 0x00000000-0x7a4abfff (rw)
|
||||
Memory Size: 1 GB + 896 MB
|
||||
Config Status: cfg=new, avail=yes, need=no, active=unknown
|
||||
|
||||
```
|
||||
|
||||
### Method-8 : Using lshw Command
|
||||
|
||||
lshw (stands for Hardware Lister) is a small nifty tool that generates detailed reports about various hardware components on the machine such as memory configuration, firmware version, mainboard configuration, CPU version and speed, cache configuration, usb, network card, graphics cards, multimedia, printers, bus speed, etc.
|
||||
|
||||
It’s generating hardware information by reading varies files under /proc directory and DMI table.
|
||||
|
||||
**Suggested Read :** [LSHW (Hardware Lister) – A Nifty Tool To Get A Hardware Information On Linux][7]
|
||||
```
|
||||
$ sudo lshw -short -class memory
|
||||
[sudo] password for daygeek:
|
||||
H/W path Device Class Description
|
||||
==================================================
|
||||
/0/0 memory 128KiB BIOS
|
||||
/0/1 memory 1993MiB System memory
|
||||
|
||||
```
|
||||
|
||||
### Method-9 : Using inxi Command
|
||||
|
||||
inxi is a nifty tool to check hardware information on Linux and offers wide range of option to get all the hardware information on Linux system that i never found in any other utility which are available in Linux. It was forked from the ancient and mindbendingly perverse yet ingenius infobash, by locsmif.
|
||||
|
||||
inxi is a script that quickly shows system hardware, CPU, drivers, Xorg, Desktop, Kernel, GCC version(s), Processes, RAM usage, and a wide variety of other useful information, also used for forum technical support & debugging tool.
|
||||
|
||||
**Suggested Read :** [inxi – A Great Tool to Check Hardware Information on Linux][8]
|
||||
```
|
||||
$ inxi -F | grep "Memory"
|
||||
Info: Processes: 234 Uptime: 3:10 Memory: 1497.3/1993.6MB Client: Shell (bash) inxi: 2.3.37
|
||||
|
||||
```
|
||||
|
||||
### Method-10 : Using screenfetch Command
|
||||
|
||||
screenFetch is a bash script. It will auto-detect your distribution and display an ASCII art version of that distribution’s logo and some valuable information to the right.
|
||||
|
||||
**Suggested Read :** [ScreenFetch – Display Linux System Information On Terminal With Distribution ASCII Art Logo][9]
|
||||
```
|
||||
$ screenfetch
|
||||
./+o+- [email protected]
|
||||
yyyyy- -yyyyyy+ OS: Ubuntu 17.10 artful
|
||||
://+//////-yyyyyyo Kernel: x86_64 Linux 4.13.0-37-generic
|
||||
.++ .:/++++++/-.+sss/` Uptime: 44m
|
||||
.:++o: /++++++++/:--:/- Packages: 1831
|
||||
o:+o+:++.`..```.-/oo+++++/ Shell: bash 4.4.12
|
||||
.:+o:+o/. `+sssoo+/ Resolution: 1920x955
|
||||
.++/+:+oo+o:` /sssooo. DE: GNOME
|
||||
/+++//+:`oo+o /::--:. WM: GNOME Shell
|
||||
\+/+o+++`o++o ++////. WM Theme: Adwaita
|
||||
.++.o+++oo+:` /dddhhh. GTK Theme: Azure [GTK2/3]
|
||||
.+.o+oo:. `oddhhhh+ Icon Theme: Papirus-Dark
|
||||
\+.++o+o``-````.:ohdhhhhh+ Font: Ubuntu 11
|
||||
`:o+++ `ohhhhhhhhyo++os: CPU: Intel Core i7-6700HQ @ 2x 2.592GHz
|
||||
.o:`.syhhhhhhh/.oo++o` GPU: llvmpipe (LLVM 5.0, 256 bits)
|
||||
/osyyyyyyo++ooo+++/ RAM: 1521MiB / 1993MiB
|
||||
````` +oo+++o\:
|
||||
`oo++.
|
||||
|
||||
```
|
||||
|
||||
### Method-11 : Using neofetch Command
|
||||
|
||||
Neofetch is a cross-platform and easy-to-use command line (CLI) script that collects your Linux system information and display it on the terminal next to an image, either your distributions logo or any ascii art of your choice.
|
||||
|
||||
**Suggested Read :** [Neofetch – Shows Linux System Information With ASCII Distribution Logo][10]
|
||||
```
|
||||
$ neofetch
|
||||
.-/+oossssoo+/-. [email protected]
|
||||
`:+ssssssssssssssssss+:` --------------
|
||||
-+ssssssssssssssssssyyssss+- OS: Ubuntu 17.10 x86_64
|
||||
.ossssssssssssssssssdMMMNysssso. Host: VirtualBox 1.2
|
||||
/ssssssssssshdmmNNmmyNMMMMhssssss/ Kernel: 4.13.0-37-generic
|
||||
+ssssssssshmydMMMMMMMNddddyssssssss+ Uptime: 47 mins
|
||||
/sssssssshNMMMyhhyyyyhmNMMMNhssssssss/ Packages: 1832
|
||||
.ssssssssdMMMNhsssssssssshNMMMdssssssss. Shell: bash 4.4.12
|
||||
+sssshhhyNMMNyssssssssssssyNMMMysssssss+ Resolution: 1920x955
|
||||
ossyNMMMNyMMhsssssssssssssshmmmhssssssso DE: ubuntu:GNOME
|
||||
ossyNMMMNyMMhsssssssssssssshmmmhssssssso WM: GNOME Shell
|
||||
+sssshhhyNMMNyssssssssssssyNMMMysssssss+ WM Theme: Adwaita
|
||||
.ssssssssdMMMNhsssssssssshNMMMdssssssss. Theme: Azure [GTK3]
|
||||
/sssssssshNMMMyhhyyyyhdNMMMNhssssssss/ Icons: Papirus-Dark [GTK3]
|
||||
+sssssssssdmydMMMMMMMMddddyssssssss+ Terminal: gnome-terminal
|
||||
/ssssssssssshdmNNNNmyNMMMMhssssss/ CPU: Intel i7-6700HQ (2) @ 2.591GHz
|
||||
.ossssssssssssssssssdMMMNysssso. GPU: VirtualBox Graphics Adapter
|
||||
-+sssssssssssssssssyyyssss+- Memory: 1620MiB / 1993MiB
|
||||
`:+ssssssssssssssssss+:`
|
||||
.-/+oossssoo+/-.
|
||||
|
||||
```
|
||||
|
||||
### Method-12 : Using dmesg Command
|
||||
|
||||
dmesg (stands for display message or driver message) is a command on most Unix-like operating systems that prints the message buffer of the kernel.
|
||||
```
|
||||
$ dmesg | grep "Memory"
|
||||
[ 0.000000] Memory: 1985916K/2096696K available (12300K kernel code, 2482K rwdata, 4000K rodata, 2372K init, 2368K bss, 110780K reserved, 0K cma-reserved)
|
||||
[ 0.012044] x86/mm: Memory block size: 128MB
|
||||
|
||||
```
|
||||
|
||||
### Method-13 : Using atop Command
|
||||
|
||||
Atop is an ASCII full-screen system performance monitoring tool for Linux that is capable of reporting the activity of all server processes (even if processes have finished during the interval).
|
||||
|
||||
It’s logging of system and process activity for long-term analysis (By default, the log files are preserved for 28 days), highlighting overloaded system resources by using colors, etc. It shows network activity per process/thread with combination of the optional kernel module netatop.
|
||||
|
||||
**Suggested Read :** [Atop – Monitor real time system performance, resources, process & check resource utilization history][11]
|
||||
```
|
||||
$ atop -m
|
||||
|
||||
ATOP - ubuntu 2018/03/31 19:34:08 ------------- 10s elapsed
|
||||
PRC | sys 0.47s | user 2.75s | | | #proc 219 | #trun 1 | #tslpi 802 | #tslpu 0 | #zombie 0 | clones 7 | | | #exit 4 |
|
||||
CPU | sys 7% | user 22% | irq 0% | | | idle 170% | wait 0% | | steal 0% | guest 0% | | curf 2.59GHz | curscal ?% |
|
||||
cpu | sys 3% | user 11% | irq 0% | | | idle 85% | cpu001 w 0% | | steal 0% | guest 0% | | curf 2.59GHz | curscal ?% |
|
||||
cpu | sys 4% | user 11% | irq 0% | | | idle 85% | cpu000 w 0% | | steal 0% | guest 0% | | curf 2.59GHz | curscal ?% |
|
||||
CPL | avg1 1.98 | | avg5 3.56 | avg15 3.20 | | | csw 14894 | | intr 6610 | | | numcpu 2 | |
|
||||
MEM | tot 1.9G | free 101.7M | cache 244.2M | dirty 0.2M | buff 6.9M | slab 92.9M | slrec 35.6M | shmem 97.8M | shrss 21.0M | shswp 3.2M | vmbal 0.0M | hptot 0.0M | hpuse 0.0M |
|
||||
SWP | tot 12.4G | free 11.6G | | | | | | | | | vmcom 7.9G | | vmlim 13.4G |
|
||||
PAG | scan 0 | steal 0 | | stall 0 | | | | | | | swin 3 | | swout 0 |
|
||||
DSK | sda | busy 0% | | read 114 | write 37 | KiB/r 21 | KiB/w 6 | | MBr/s 0.2 | MBw/s 0.0 | avq 6.50 | | avio 0.26 ms |
|
||||
NET | transport | tcpi 11 | tcpo 17 | udpi 4 | udpo 8 | tcpao 3 | tcppo 0 | | tcprs 3 | tcpie 0 | tcpor 0 | udpnp 0 | udpie 0 |
|
||||
NET | network | ipi 20 | | ipo 33 | ipfrw 0 | deliv 20 | | | | | icmpi 5 | | icmpo 0 |
|
||||
NET | enp0s3 0% | pcki 11 | pcko 28 | sp 1000 Mbps | si 1 Kbps | so 1 Kbps | | coll 0 | mlti 0 | erri 0 | erro 0 | drpi 0 | drpo 0 |
|
||||
NET | lo ---- | pcki 9 | pcko 9 | sp 0 Mbps | si 0 Kbps | so 0 Kbps | | coll 0 | mlti 0 | erri 0 | erro 0 | drpi 0 | drpo 0 |
|
||||
|
||||
PID TID MINFLT MAJFLT VSTEXT VSLIBS VDATA VSTACK VSIZE RSIZE PSIZE VGROW RGROW SWAPSZ RUID EUID MEM CMD 1/1
|
||||
2536 - 941 0 188K 127.3M 551.2M 144K 2.3G 281.2M 0K 0K 344K 6556K daygeek daygeek 14% Web Content
|
||||
2464 - 75 0 188K 187.7M 680.6M 132K 2.3G 226.6M 0K 0K 212K 42088K daygeek daygeek 11% firefox
|
||||
2039 - 4199 6 16K 163.6M 423.0M 132K 3.5G 220.2M 0K 0K 2936K 109.6M daygeek daygeek 11% gnome-shell
|
||||
10822 - 1 0 4K 16680K 377.0M 132K 3.4G 193.4M 0K 0K 0K 0K root root 10% java
|
||||
|
||||
```
|
||||
|
||||
### Method-14 : Using htop Command
|
||||
|
||||
htop is an interactive process viewer for Linux which was developed by Hisham using ncurses library. Htop have many of features and options compared to top command.
|
||||
|
||||
**Suggested Read :** [Monitor system resources using Htop command][12]
|
||||
```
|
||||
$ htop
|
||||
|
||||
1 [||||||||||||| 13.0%] Tasks: 152, 587 thr; 1 running
|
||||
2 [||||||||||||||||||||||||| 25.0%] Load average: 0.91 2.03 2.66
|
||||
Mem[||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||1.66G/1.95G] Uptime: 01:14:53
|
||||
Swp[|||||| 782M/12.4G]
|
||||
|
||||
PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command
|
||||
2039 daygeek 20 0 3541M 214M 46728 S 36.6 10.8 22:36.77 /usr/bin/gnome-shell
|
||||
2045 daygeek 20 0 3541M 214M 46728 S 10.3 10.8 3:02.92 /usr/bin/gnome-shell
|
||||
2046 daygeek 20 0 3541M 214M 46728 S 8.3 10.8 3:04.96 /usr/bin/gnome-shell
|
||||
6080 daygeek 20 0 807M 37228 24352 S 2.1 1.8 0:11.99 /usr/lib/gnome-terminal/gnome-terminal-server
|
||||
2880 daygeek 20 0 2205M 164M 17048 S 2.1 8.3 7:16.50 /usr/lib/firefox/firefox -contentproc -childID 6 -isForBrowser -intPrefs 6:50|7:-1|19:0|34:1000|42:20|43:5|44:10|51:0|57:128|58:10000|63:0|65:400|66
|
||||
6125 daygeek 20 0 1916M 159M 92352 S 2.1 8.0 2:09.14 /usr/lib/firefox/firefox -contentproc -childID 7 -isForBrowser -intPrefs 6:50|7:-1|19:0|34:1000|42:20|43:5|44:10|51:0|57:128|58:10000|63:0|65:400|66
|
||||
2536 daygeek 20 0 2335M 243M 26792 S 2.1 12.2 6:25.77 /usr/lib/firefox/firefox -contentproc -childID 1 -isForBrowser -intPrefs 6:50|7:-1|19:0|34:1000|42:20|43:5|44:10|51:0|57:128|58:10000|63:0|65:400|66
|
||||
2653 daygeek 20 0 2237M 185M 20788 S 1.4 9.3 3:01.76 /usr/lib/firefox/firefox -contentproc -childID 4 -isForBrowser -intPrefs 6:50|7:-1|19:0|34:1000|42:20|43:5|44:10|51:0|57:128|58:10000|63:0|65:400|66
|
||||
|
||||
```
|
||||
|
||||
### Method-15 : Using corefreq Utility
|
||||
|
||||
CoreFreq is a CPU monitoring software designed for Intel 64-bits Processors and supported architectures are Atom, Core2, Nehalem, SandyBridge and superior, AMD Family 0F.
|
||||
|
||||
CoreFreq provides a framework to retrieve CPU data with a high degree of precision.
|
||||
|
||||
**Suggested Read :** [CoreFreq – A Powerful CPU monitoring Tool for Linux Systems][13]
|
||||
```
|
||||
$ ./corefreq-cli -k
|
||||
Linux:
|
||||
|- Release [4.13.0-37-generic]
|
||||
|- Version [#42-Ubuntu SMP Wed Mar 7 14:13:23 UTC 2018]
|
||||
|- Machine [x86_64]
|
||||
Memory:
|
||||
|- Total RAM 2041396 KB
|
||||
|- Shared RAM 99620 KB
|
||||
|- Free RAM 108428 KB
|
||||
|- Buffer RAM 8108 KB
|
||||
|- Total High 0 KB
|
||||
|- Free High 0 KB
|
||||
|
||||
$ ./corefreq-cli -k | grep "Total RAM" | awk '{print $4 / 1024 }'
|
||||
1993.55
|
||||
|
||||
$ ./corefreq-cli -k | grep "Total RAM" | awk '{print $4 / 1024 / 1024}'
|
||||
1.94683
|
||||
|
||||
```
|
||||
|
||||
### Method-16 : Using glances Command
|
||||
|
||||
Glances is a cross-platform curses-based system monitoring tool written in Python. We can say all in one place, like maximum of information in a minimum of space. It uses psutil library to get information from your system.
|
||||
|
||||
Glances capable to monitor CPU, Memory, Load, Process list, Network interface, Disk I/O, Raid, Sensors, Filesystem (and folders), Docker, Monitor, Alert, System info, Uptime, Quicklook (CPU, MEM, LOAD), etc,.
|
||||
|
||||
**Suggested Read :** [Glances (All in one Place)– An Advanced Real Time System Performance Monitoring Tool for Linux][14]
|
||||
```
|
||||
$ glances
|
||||
|
||||
ubuntu (Ubuntu 17.10 64bit / Linux 4.13.0-37-generic) - IP 192.168.1.6/24 Uptime: 1:08:40
|
||||
|
||||
CPU [|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 90.6%] CPU - 90.6% nice: 0.0% ctx_sw: 4K MEM \ 78.4% active: 942M SWAP - 5.9% LOAD 2-core
|
||||
MEM [||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 78.0%] user: 55.1% irq: 0.0% inter: 1797 total: 1.95G inactive: 562M total: 12.4G 1 min: 4.35
|
||||
SWAP [|||| 5.9%] system: 32.4% iowait: 1.8% sw_int: 897 used: 1.53G buffers: 14.8M used: 749M 5 min: 4.38
|
||||
idle: 7.6% steal: 0.0% free: 431M cached: 273M free: 11.7G 15 min: 3.38
|
||||
|
||||
NETWORK Rx/s Tx/s TASKS 211 (735 thr), 4 run, 207 slp, 0 oth sorted automatically by memory_percent, flat view
|
||||
docker0 0b 232b
|
||||
enp0s3 12Kb 4Kb Systemd 7 Services loaded: 197 active: 196 failed: 1
|
||||
lo 616b 616b
|
||||
_h478e48e 0b 232b CPU% MEM% VIRT RES PID USER NI S TIME+ R/s W/s Command
|
||||
63.8 18.9 2.33G 377M 2536 daygeek 0 R 5:57.78 0 0 /usr/lib/firefox/firefox -contentproc -childID 1 -isForBrowser -intPrefs 6:50|7:-1|19:0|34:1000|42:20|43:5|44:10|51
|
||||
DefaultGateway 83ms 78.5 10.9 3.46G 217M 2039 daygeek 0 S 21:07.46 0 0 /usr/bin/gnome-shell
|
||||
8.5 10.1 2.32G 201M 2464 daygeek 0 S 8:45.69 0 0 /usr/lib/firefox/firefox -new-window
|
||||
DISK I/O R/s W/s 1.1 8.5 2.19G 170M 2653 daygeek 0 S 2:56.29 0 0 /usr/lib/firefox/firefox -contentproc -childID 4 -isForBrowser -intPrefs 6:50|7:-1|19:0|34:1000|42:20|43:5|44:10|51
|
||||
dm-0 0 0 1.7 7.2 2.15G 143M 2880 daygeek 0 S 7:10.46 0 0 /usr/lib/firefox/firefox -contentproc -childID 6 -isForBrowser -intPrefs 6:50|7:-1|19:0|34:1000|42:20|43:5|44:10|51
|
||||
sda1 9.46M 12K 0.0 4.9 1.78G 97.2M 6125 daygeek 0 S 1:36.57 0 0 /usr/lib/firefox/firefox -contentproc -childID 7 -isForBrowser -intPrefs 6:50|7:-1|19:0|34:1000|42:20|43:5|44:10|51
|
||||
|
||||
```
|
||||
|
||||
### Method-17 : Using gnome-system-monitor
|
||||
|
||||
System Monitor is a tool to manage running processes and monitor system resources. It shows you what programs are running and how much processor time, memory, and disk space are being used.
|
||||
![][16]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/easy-ways-to-check-size-of-physical-memory-ram-in-linux/
|
||||
|
||||
作者:[Ramya Nuvvula][a]
|
||||
译者:[译者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/ramya/
|
||||
[1]:https://www.2daygeek.com/free-command-to-check-memory-usage-statistics-in-linux/
|
||||
[2]:https://www.2daygeek.com/top-command-examples-to-monitor-server-performance/
|
||||
[3]:https://www.2daygeek.com/linux-vmstat-command-examples-tool-report-virtual-memory-statistics/
|
||||
[4]:https://www.2daygeek.com/nmon-system-performance-monitor-system-resources-on-linux/
|
||||
[5]:https://www.2daygeek.com/dmidecode-get-print-display-check-linux-system-hardware-information/
|
||||
[6]:https://www.2daygeek.com/hwinfo-check-display-detect-system-hardware-information-linux/
|
||||
[7]:https://www.2daygeek.com/lshw-find-check-system-hardware-information-details-linux/
|
||||
[8]:https://www.2daygeek.com/inxi-system-hardware-information-on-linux/
|
||||
[9]:https://www.2daygeek.com/screenfetch-display-linux-systems-information-ascii-distribution-logo-terminal/
|
||||
[10]:https://www.2daygeek.com/neofetch-display-linux-systems-information-ascii-distribution-logo-terminal/
|
||||
[11]:https://www.2daygeek.com/atop-system-process-performance-monitoring-tool/
|
||||
[12]:https://www.2daygeek.com/htop-command-examples-to-monitor-system-resources/
|
||||
[13]:https://www.2daygeek.com/corefreq-linux-cpu-monitoring-tool/
|
||||
[14]:https://www.2daygeek.com/install-glances-advanced-real-time-linux-system-performance-monitoring-tool-on-centos-fedora-ubuntu-debian-opensuse-arch-linux/
|
||||
[15]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[16]:https://www.2daygeek.com/wp-content/uploads/2018/03/check-memory-information-using-gnome-system-monitor.png
|
@ -0,0 +1,362 @@
|
||||
Bring some JavaScript to your Java enterprise with Vert.x
|
||||
======
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_keyboard_laptop_development_blue.png?itok=IfckxN48)
|
||||
If you are a Java programmer, chances are that you've either used JavaScript in the past or will in the near future. Not only is it one of the most popular (and useful) programming languages, understanding some of JavaScript's features could help you build the next uber-popular web application.
|
||||
|
||||
### JavaScript on the server
|
||||
|
||||
The idea to run JavaScript on the server is not new; in fact, in December 1995, soon after releasing JavaScript for browsers, Netscape introduced an implementation of the language for server-side scripting with Netscape Enterprise Server. Microsoft also adopted it on Internet Information Server as JScript, a reverse-engineered implementation of Netscape's JavaScript.
|
||||
|
||||
The seed was planted, but the real boom happened in 2009 when Ryan Dahl introduced Node.js. Node's success was not based on the language but on the runtime itself. It introduced a single process event loop that followed the reactive programming principles and could scale like other platforms couldn't.
|
||||
|
||||
### The enterprise and the JVM
|
||||
|
||||
Many enterprises have standardized on the Java virtual machine (JVM) as the platform of choice to run their mission-critical business applications, and large investments have been made on the JVM, so it makes sense for those organizations to look for a JVM-based JavaScript runtime.
|
||||
|
||||
[Eclipse Vert.x][1] is a polyglot-reactive runtime that runs on the JVM. Using Eclipse Vert.x with JavaScript is not much different from what you would expect from Node.js. There are limitations, such as that the JVM JavaScript engine is not fully compatible with the ES6 standard and not all Node.js package manager (npm) modules can be used with it. But it can still do interesting things.
|
||||
|
||||
### Why Eclipse Vert.x?
|
||||
|
||||
Having a large investment in the JVM and not wanting to switch to a different runtime might be reason enough for an enterprise to be interested in Eclipse Vert.x. But other benefits are that it can interact with any existing Java application and offers one of the best performances possible on the JVM.
|
||||
|
||||
To demonstrate, let's look at how Vert.x works with an existing business rules management system. Imagine for a moment that our fictional enterprise has a mission-critical application running inside JBoss Drools. We now need to create a new web application that can interact with this legacy app.
|
||||
|
||||
For the sake of simplicity, let's say our existing rules are a simple Hello World:
|
||||
```
|
||||
package drools
|
||||
|
||||
|
||||
|
||||
//list any import classes here.
|
||||
|
||||
|
||||
|
||||
//declare any global variables here
|
||||
|
||||
|
||||
|
||||
rule "Greetings"
|
||||
|
||||
when
|
||||
|
||||
greetingsReferenceObject: Greeting( message == "Hello World!" )
|
||||
|
||||
then
|
||||
|
||||
greetingsReferenceObject.greet();
|
||||
|
||||
end
|
||||
|
||||
```
|
||||
|
||||
When this engine runs, we get "Drools Hello World!" This is not amazing, but let's imagine this was a really complex process.
|
||||
|
||||
### Implementing the Eclipse Vert.x JavaScript project
|
||||
|
||||
Like with any other JavaScript project, we'll use the standard npm commands to bootstrap a project. Here's how to bootstrap the project `drools-integration` and prepare it to use Vert.x:
|
||||
```
|
||||
# create an empty project directory
|
||||
|
||||
mkdir drools-integration
|
||||
|
||||
cd drools-integration
|
||||
|
||||
|
||||
|
||||
# create the initial package.json
|
||||
|
||||
npm init -y
|
||||
|
||||
|
||||
|
||||
# add a couple of dependencies
|
||||
|
||||
npm add vertx-scripts --save-dev
|
||||
|
||||
# You should see a tip like:
|
||||
|
||||
#Please add the following scripts to your 'package.json':
|
||||
|
||||
# "scripts": {
|
||||
|
||||
# "postinstall": "vertx-scripts init",
|
||||
|
||||
# "test": "vertx-scripts launcher test -t",
|
||||
|
||||
# "start": "vertx-scripts launcher run",
|
||||
|
||||
# "package": "vertx-scripts package"
|
||||
|
||||
# }
|
||||
|
||||
|
||||
|
||||
# add
|
||||
|
||||
npm add @vertx/web --save-prod
|
||||
|
||||
```
|
||||
|
||||
We have initialized a bare-bones project so we can start writing the JavaScript code. We'll start by adding a simple HTTP server that exposes a simple API. Every time a request is made to the URL `http://localhost:8080/greetings`, we should see the existing Drools engine's execution result in the terminal.
|
||||
|
||||
Start by creating an `index.js` file. If you're using VisualStudio Code, it's wise to add the following two lines to the beginning of your file:
|
||||
```
|
||||
/// <reference types="@vertx/core/runtime" />
|
||||
|
||||
/// @ts-check
|
||||
|
||||
```
|
||||
|
||||
These lines will enable full support and check the code for syntax errors. They aren't required, but they sure help during the development phase.
|
||||
|
||||
Next, add the simple HTTP server. Running on the JVM is not exactly the same as running on Node, and many libraries will not be available. Think of the JVM as a headless browser, and in many cases, code that runs in a browser can run on the JVM. This does not mean we can't have a high-performance HTTP server; in fact, this is exactly what Vert.x does. Let's start writing our server:
|
||||
```
|
||||
import { Router } from '@vertx/web';
|
||||
|
||||
|
||||
|
||||
// route all request based on the request path
|
||||
|
||||
const app = Router.router(vertx);
|
||||
|
||||
|
||||
|
||||
app.get('/greetings').handler(function (ctx) {
|
||||
|
||||
// will invoke our existing drools engine here...
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
vertx
|
||||
|
||||
// create a HTTP server
|
||||
|
||||
.createHttpServer()
|
||||
|
||||
// on each request pass it to our APP
|
||||
|
||||
.requestHandler(function (req) {
|
||||
|
||||
app.accept(req);
|
||||
|
||||
})
|
||||
|
||||
// listen on port 8080
|
||||
|
||||
.listen(8080);
|
||||
|
||||
```
|
||||
|
||||
The code is not complicated and should be self-explanatory, so let's focus on the integration with existing JVM code and libraries in the form of a Drools rule. Since Drools is a Java-based tool, we should build our application with a `java` build tool. Fortunately, because, behind the scenes, `vertx-scripts` delegates the JVM bits to Apache Maven, our work is easy.
|
||||
```
|
||||
mkdir -p src/main/java/drools
|
||||
|
||||
mkdir -p src/main/resources/drools
|
||||
|
||||
```
|
||||
|
||||
Next, we add the file `src/main/resources/drools/rules.drl` with the following content:
|
||||
```
|
||||
package drools
|
||||
|
||||
|
||||
|
||||
//list any import classes here.
|
||||
|
||||
|
||||
|
||||
//declare any global variables here
|
||||
|
||||
|
||||
|
||||
rule "Greetings"
|
||||
|
||||
when
|
||||
|
||||
greetingsReferenceObject: Greeting( message == "Hello World!" )
|
||||
|
||||
then
|
||||
|
||||
greetingsReferenceObject.greet();
|
||||
|
||||
end
|
||||
|
||||
```
|
||||
|
||||
Then we'll add the file `src/main/java/drools/Greeting.java` with the following content:
|
||||
```
|
||||
package drools;
|
||||
|
||||
|
||||
|
||||
public interface Greeting {
|
||||
|
||||
|
||||
|
||||
();
|
||||
|
||||
|
||||
|
||||
void greet();
|
||||
|
||||
}Greeting String getMessagegreet
|
||||
|
||||
```
|
||||
|
||||
Finally, we'll add the helper utility class `src/main/java/drools/DroolsHelper.java`:
|
||||
```
|
||||
package drools;
|
||||
|
||||
|
||||
|
||||
import org.drools.compiler.compiler.*;
|
||||
|
||||
import org.drools.core.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
|
||||
|
||||
public final class DroolsHelper {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* Simple factory to create a Drools WorkingMemory from the given `drl` file.
|
||||
|
||||
*/
|
||||
|
||||
public static WorkingMemory load( drl) throws {
|
||||
|
||||
PackageBuilder packageBuilder = new PackageBuilder();
|
||||
|
||||
packageBuilder.addPackageFromDrl(new StringReader(drl));
|
||||
|
||||
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
|
||||
|
||||
ruleBase.addPackage(packageBuilder.getPackage());
|
||||
|
||||
return ruleBase.newStatefulSession();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* Simple factory to create a Greeting objects.
|
||||
|
||||
*/
|
||||
|
||||
public static Greeting createGreeting( message, ) {
|
||||
|
||||
return new Greeting() {
|
||||
|
||||
@Override
|
||||
|
||||
public () {
|
||||
|
||||
return message;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
public void greet() {
|
||||
|
||||
andThen.run();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}DroolsHelperWorkingMemory load String drl IOException , DroolsParserExceptionPackageBuilder packageBuilderPackageBuilderpackageBuilder.drlRuleBase ruleBaseRuleBaseFactory.ruleBase.packageBuilder.ruleBase.Greeting createGreeting String message, Runnable andThenGreeting@Override String getMessagemessage@OverridegreetandThen.
|
||||
|
||||
```
|
||||
|
||||
We cannot use the file directly; we need to have `drools`. To do this, we add a custom property to our `package.json` named `mvnDependencies` (following the usual pattern):
|
||||
```
|
||||
{
|
||||
|
||||
"mvnDependencies": {
|
||||
|
||||
"org.drools:drools-compiler": "6.0.1.Final"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Of course, since we updated the project file, we should update npm:
|
||||
```
|
||||
npm install
|
||||
|
||||
```
|
||||
|
||||
We are now entering the final step of this project, where we mix Java and JavaScript. We had a placeholder before, so let's fill in the gaps. We first use the helper Java class to create an engine (you can now see the power of Vert.x, a truly polyglot runtime), then invoke our engine whenever an HTTP request arrives.
|
||||
```
|
||||
// get a reference from Java to the JavaScript runtime
|
||||
|
||||
const DroolsHelper = Java.type('drools.DroolsHelper');
|
||||
|
||||
// get a drools engine instance
|
||||
|
||||
const engine = DroolsHelper.load(vertx.fileSystem().readFileBlocking("drools/rules.drl"));
|
||||
|
||||
|
||||
|
||||
app.get('/greetings').handler(function (ctx) {
|
||||
|
||||
// create a greetings message
|
||||
|
||||
var greeting = DroolsHelper.createGreeting('Hello World!', function () {
|
||||
|
||||
// when a match happens you should see this message
|
||||
|
||||
console.log('Greetings from Drools!');
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
// run the engine
|
||||
|
||||
engine.insert(greeting);
|
||||
|
||||
engine.fireAllRules();
|
||||
|
||||
|
||||
|
||||
// complete the HTTP response
|
||||
|
||||
ctx.response().end();
|
||||
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
### Conclusion
|
||||
|
||||
As this simple example shows, Vert.x allows you to be truly polyglot. The reason to choose Vert.x is not because it's another JavaScript runtime, rather it's a runtime that allows you to reuse what you already have and quickly build new code using the tools and language that run the internet. We didn't touch on performance here (as it is a topic on its own), but I encourage you to look at independent benchmarks such as [TechEmpower][2] to explore that topic.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/4/benefits-javascript-vertx
|
||||
|
||||
作者:[Paulo Lopes][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/pml0pes
|
||||
[1]:http://vertx.io/
|
||||
[2]:https://www.techempower.com/benchmarks/#section=data-r15
|
@ -1,69 +0,0 @@
|
||||
防止文档陷阱的 7 条准则
|
||||
======
|
||||
英语是开源社区的通用语言。为了减少翻译成本,很多团队都改成用英语来写他们的文档。 但奇怪的是,为国际读者写英语并不一定就意味着英语为母语的人就占据更多的优势。 相反, 他们往往忘记了写文档用的语言可能并不是读者的母语。
|
||||
|
||||
我们以下面这个简单的句子为例: "Encrypt the password using the `foo bar` command。" 语法上来说,这个句子是正确的。 鉴于动名词的 '-ing' 形式在英语中很常见,大多数的母语人士都认为这是一种优雅的表达方式, 他们通常会很自然的写出这样的句子。 但是仔细观察, 这个句子存在歧义因为 "using" 可能指的宾语 ("the password") 也可能指的动词 ("encrypt")。 因此这个句子有两种解读方式:
|
||||
|
||||
* "加密使用了 `foo bar` 命令的密码。"
|
||||
* "使用命令 `foo bar` 来加密密码。"
|
||||
|
||||
如果你有相关的先验知识 (密码加密或这 `foo bar` 命令),你可以消除这种不确定性并且明白第二种方式才是真正的意思。 但是若你没有足够深入的知识怎么办呢? 如果你并不是这方面的专家,而只是一个拥有泛泛相关知识的翻译者而已怎么办呢? 再或者,如果你只是个非母语人士且对像动名词这种高级语法不熟悉怎么办呢?
|
||||
|
||||
即使是英语为母语的人也需要经过训练才能写出清晰直接的技术文档。训练的第一步就是提高对文本可用性以及潜在问题的警觉性, 下面让我们来看一下可以帮助避免常见陷阱的 7 条规则。
|
||||
|
||||
### 1。了解你的目标读者并代入其中。
|
||||
|
||||
如果你是一名开发者,而写作的对象是终端用户, 那么你需要站在他们的角度来看这个产品。 文档的结构是否反映了用户的目标? [人格面具 (persona) 技术][1] 能帮你专注于目标受众并为你的读者提供合适层次的细节。
|
||||
|
||||
### 2。准训 KISS 原则--保持文档简短而简单
|
||||
|
||||
这个原则适用于多个层次,从语法,句子到单词。 比如:
|
||||
|
||||
* 使用合适的最简单时态。比如, 当提到一个动作的结果时使用现在时:
|
||||
* " ~~Click 'OK。' The 'Printer Options' dialog will appear。~~" -> "Click 'OK。' The 'Printer Options' dialog appears。"
|
||||
* 按经验来说,一个句子表达一个主题; 然而, 短句子并不一定就容易理解(尤其当这些句子都是由名词组成时)。 有时, 将句子裁剪过度可能会引起歧义,而反过来太多单词则又难以理解。
|
||||
* 不常用的以及很长的单词会降低阅读速度,而且可能成为非母语人士的障碍。 使用更简单的替代词语:
|
||||
* " ~~utilize~~ " -> "use"
|
||||
* " ~~indicate~~ " -> "show," "tell," or "say"
|
||||
* " ~~prerequisite~~ " -> "requirement"
|
||||
|
||||
### 3。不要干扰阅读流
|
||||
|
||||
将虚词和较长的插入语移到句子的首部或者尾部:
|
||||
|
||||
* " ~~They are not,however, marked as installed。~~ " -> "However, they are not marked as installed。"
|
||||
|
||||
将长命令放在句子的末尾可以让自动/半自动的翻译拥有更好的断句。
|
||||
|
||||
### 4。区别对待两种基本的信息类型
|
||||
|
||||
描述型信息以及任务导向型信息有必要区分开来。描述型信息的一个典型例子就是命令行参考, 而 how-to 则是属于基于任务的信息; 然而, 技术写作中都会涉及这两种类型的信息。 仔细观察, 就会发现许多文本都同时包含了两种类型的信息。 然而如果能够清晰地划分这两种类型的信息那必是极好的。 为了跟好地区分他们,可以对他们进行分别标记(For better orientation, label them accordingly)。 标题应该能够反应章节的内容以及信息的类型。 对描述性章节使用基于名词的标题(比如"Types of Frobnicators"),而对基于任务的章节使用口头表达式的标题(例如"Installing Frobnicators")。 这可以让读者快速定位感兴趣的章节而跳过他无用的章节。
|
||||
|
||||
### 5。考虑不同的阅读场景和阅读模式
|
||||
|
||||
有些读者在转向阅读产品文档时会由于自己搞不定而感到十分的沮丧。他们也在一个嘈杂的环境中工作,很难专注于阅读。 同时,不要期望你的读者会一页一页的进行阅读,很多人都是快速浏览文本搜索关键字或者通过表格,索引以及全文搜索的方式来查找主题。 请牢记这一点, 从不同的角度来看待你的文字。 通常需要妥协才能找到一种适合多种情况的文本结构。
|
||||
|
||||
### 6。将复杂的信息分成小块。
|
||||
|
||||
这会让读者更容易记住和吸收信息。例如, 过程不应该超过 7 到 10 个步骤(根据认知心理学中的 [Miller's Law][2])。 如果需要更多的步骤, 那么就将任务分拆成不同的过程。
|
||||
|
||||
### 7。形式遵循功能
|
||||
|
||||
根据以下问题检查你的文字: 某句话/段落/章节的 _目的_ (功能)是什么?比如, 它是一个指令呢?还是一个结果呢?还是一个警告呢?如果是指令, 使用主动语气: "Configure the system。" 被动语气可能适合于进行描述: "The system is configured automatically。" 将警告放在危险操作的 _前面_ 。 专注于目的还有助于发现冗余的内容,可以清除类似 "basically" 或者 "easily" 这一类的填充词,类似 " ~~already~~ existing " or " ~~completely~~ new" 这一类的不必要的修改, 以及任何与你的目标大众无关的内容。
|
||||
|
||||
你现在可能已经猜到了,写作就是一个不断重写的过程。 好的写作需要付出努力和练习。 即使你只是偶尔写点东西, 你也可以通过关注目标大众并遵循上述规则来显著地改善你的文字。 文字的可读性越好, 理解就越容易, 这一点对不同语言能力的读者来说都是适合的。 尤其是当进行本地化时, 高质量的原始文本至关重要: "垃圾进, 垃圾出"。 如果原始文本就有缺陷, 翻译所需要的时间就会变长, 从而导致更高的成本。 最坏的情况下, 翻译会导致缺陷成倍增加,需要在不同的语言版本中修正这个缺陷。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/17/12/7-rules
|
||||
|
||||
作者:[Tanja Roth][a]
|
||||
译者:[lujun9972](https://github.com/lujun9972)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com
|
||||
[1]:https://en.wikipedia.org/wiki/Persona_(user_experience)
|
||||
[2]:https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two
|
@ -0,0 +1,158 @@
|
||||
为初学者提供的 Uniq 命令教程及示例
|
||||
=====
|
||||
|
||||
如果你主要是在命令行上工作,并且每天处理大量的文本文件,那么你应该了解下 **Uniq** 命令。该命令会帮助你轻松地从文件中找到重复的行。它不仅用于查找重复项,而且我们还可以使用它来删除重复项,显示重复项的出现次数,只显示重复的行,只显示唯一的行等。由于 uniq 命令是 GNU coreutils 包的一部分,所以它预装在大多数 Linux 发行版中,让我们不需要费心安装。来看一些实际的例子。
|
||||
|
||||
请注意,除非重复行是相邻的,否则 'uniq' 不会删除它们。因此,你可能需要先对它们进行排序,或将排序命令与 uniq 组合以获得结果。让我给你看一些例子。
|
||||
|
||||
首先,让我们创建一个带有一些重复行的文件:
|
||||
```
|
||||
vi ostechnix.txt
|
||||
```
|
||||
```
|
||||
welcome to ostechnix
|
||||
welcome to ostechnix
|
||||
Linus is the creator of Linux.
|
||||
Linux is secure by default
|
||||
Linus is the creator of Linux.
|
||||
Top 500 super computers are powered by Linux
|
||||
```
|
||||
|
||||
正如你在上面的文件中看到的,我们有一些重复的行(第一行和第二行,第三行和第五行是重复的)。
|
||||
|
||||
### **1\. 使用 Uniq 命令删除文件中的连续重复行**
|
||||
|
||||
如果你在不使用任何参数的情况下使用 'uniq' 命令,它将删除所有连续的重复行,只显示唯一的行。
|
||||
```
|
||||
uniq ostechnix.txt
|
||||
```
|
||||
|
||||
示例输出:
|
||||
|
||||
![][2]
|
||||
|
||||
如你所见, uniq 命令删除了给定文件中的所有连续重复行。你可能还注意到,上面的输出仍然有第二行和第四行重复了。这是因为 uniq 命令只有在相邻的情况下才会删除重复的行,当然,我们也可以删除非连续的重复行。请看下面的第二个例子。
|
||||
|
||||
### **2\. 删除所有重复的行**
|
||||
```
|
||||
sort ostechnix.txt | uniq
|
||||
```
|
||||
|
||||
示例输出:
|
||||
|
||||
![][3]
|
||||
|
||||
看到了吗?没有重复的行。换句话说,上面的命令将显示在 ostechnix.txt 中只出现一次的行。我们使用 sort 命令与 uniq 命令结合,因为,就像我提到的,除非重复行是相邻的,否则 uniq 不会删除它们。
|
||||
|
||||
### **3\. 只显示文件中唯一的一行**
|
||||
|
||||
为了只显示文件中唯一的一行,可以这样做:
|
||||
```
|
||||
sort ostechnix.txt | uniq -u
|
||||
```
|
||||
|
||||
示例输出:
|
||||
```
|
||||
Linux is secure by default
|
||||
Top 500 super computers are powered by Linux
|
||||
```
|
||||
|
||||
如你所见,在给定的文件中只有两行是唯一的。
|
||||
|
||||
### **4\. 只显示重复的行**
|
||||
|
||||
同样的,我们也可以显示文件中重复的行就像下面这样:
|
||||
```
|
||||
sort ostechnix.txt | uniq -d
|
||||
```
|
||||
|
||||
示例输出:
|
||||
```
|
||||
Linus is the creator of Linux.
|
||||
welcome to ostechnix
|
||||
```
|
||||
|
||||
这两行在 ostechnix.txt 文件中是重复的行。请注意 -d(小写 d) 将会**只打印重复的行**,**每组有一个**。打印**所有重复的行**,使用 -D(大写 D),如下所示:
|
||||
```
|
||||
sort ostechnix.txt | uniq -D
|
||||
```
|
||||
|
||||
在下面的截图中看两个选项的区别:
|
||||
|
||||
![][4]
|
||||
|
||||
### **5\. 显示文件中每一行的出现次数**
|
||||
|
||||
由于某种原因,你可能想要检查给定文件中每一行重复出现的次数。要做到这一点,使用 **-c** 选项,如下所示:
|
||||
```
|
||||
sort ostechnix.txt | uniq -c
|
||||
```
|
||||
|
||||
**示例输出:**
|
||||
```
|
||||
2 Linus is the creator of Linux.
|
||||
1 Linux is secure by default
|
||||
1 Top 500 super computers are powered by Linux
|
||||
2 welcome to ostechnix
|
||||
```
|
||||
|
||||
我们还可以按照每一行的出现次数进行排序,然后显示,如下所示:
|
||||
```
|
||||
sort ostechnix.txt | uniq -c | sort -nr
|
||||
```
|
||||
|
||||
示例输出:
|
||||
```
|
||||
2 welcome to ostechnix
|
||||
2 Linus is the creator of Linux.
|
||||
1 Top 500 super computers are powered by Linux
|
||||
1 Linux is secure by default
|
||||
```
|
||||
|
||||
### 6\. 将比较限制为 'N' 个字符
|
||||
|
||||
我们可以使用 -w 选项来限制对文件中特定数量字符的比较。例如,让我们比较文件中的前四个字符,并显示重复行,如下所示:
|
||||
```
|
||||
uniq -d -w 4 ostechnix.txt
|
||||
```
|
||||
|
||||
### 7\. 忽略比较指定的 'N' 个字符
|
||||
|
||||
像对文件中行的 N 个字符进行限制比较一样,我们也可以使用 -s 选项来忽略比较前 N 个字符。
|
||||
|
||||
下面的命令将忽略在文件中每行的前四个字符进行比较:
|
||||
```
|
||||
uniq -d -s 4 ostechnix.txt
|
||||
```
|
||||
|
||||
为了忽略比较前 N 字段(译者注:即前几列)而不是字符,在上面的命令中使用 '-f' 选项。
|
||||
|
||||
欲了解更多详情,请参考帮助部分:
|
||||
```
|
||||
uniq --help
|
||||
```
|
||||
|
||||
也可以使用 man 命令查看:
|
||||
```
|
||||
man uniq
|
||||
```
|
||||
|
||||
今天就到这里!我希望你现在对 uniq 命令及其目的有一个基本的了解。如果你发现我们的指南有用,请在你的社交网络上分享,并继续支持 OSTechNix。更多好东西要来了,请继续关注!
|
||||
|
||||
干杯!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/uniq-command-tutorial-examples-beginners/
|
||||
|
||||
作者:[][a]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.ostechnix.com
|
||||
[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[2]:http://www.ostechnix.com/wp-content/uploads/2018/01/uniq-2.png
|
||||
[3]:http://www.ostechnix.com/wp-content/uploads/2018/01/uniq-1-1.png
|
||||
[4]:http://www.ostechnix.com/wp-content/uploads/2018/01/uniq-4.png
|
@ -0,0 +1,68 @@
|
||||
Linux 下的 4 个命令行笔记记录程序
|
||||
======
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/note-taking.jpeg?itok=fiF5EBEb)
|
||||
当你需要保存代码段或 URL、想法或引用时,可能会启动文本编辑器或使用[桌面][1]或[基于 Web 的] [2]笔记记录工具。但那些不是你唯一的选择。如果你在终端窗口中工作,则可以使用 Linux 命令行下的许多笔记记录工具之一。
|
||||
|
||||
我们来看看这四个程序。
|
||||
|
||||
### tnote
|
||||
|
||||
[tnote][3] 使在终端窗口中记笔记很简单 - 几乎太简单了。
|
||||
|
||||
tnote 是一个 Python 脚本。首次启动时,它会要求你输入密码和口令来加密存储笔记的[ SQLite 数据库][4]。完成之后,按 “A” 创建一个笔记。输入你的笔记,然后按 CTRL-D 保存。
|
||||
|
||||
一旦你有几个(或多个)笔记,你可以查看它们或搜索特定的笔记,单词或短语或标签。tnote 不包含很多功能,但它确实实现了任务。
|
||||
|
||||
### Terminal Velocity
|
||||
|
||||
如果你使用的是 Mac OS,你可能会看到一个名为 [Notational Velocity][5] 的流行开源笔记程序,这是一种记录笔记的简单有效方法。[Terminal Velocity][6] 在将 Notational Velocity 体验带入命令行方面做得很好。
|
||||
|
||||
Terminal Velocity 打开你的默认文本编辑器(由你的 `.profile` 或 `.bashrc` 文件中的 `$EDITOR` 变量设置)。输入你的笔记,然后保存。该笔记出现在 Terminal Velocity 窗口的列表中。
|
||||
|
||||
使用键盘上的箭头键滚动查看你的笔记列表。要查看或编辑笔记,请按 Enter 键。如果你有一长串笔记,则可以在 `Find or Create` 字段中输入笔记标题的前几个字符以缩小列表的范围。在那里滚动笔记并按下 Enter 键将其打开。
|
||||
|
||||
### pygmynote
|
||||
|
||||
在本文中的四个应用中,[pygmynote][7] 可能是最不用户友好的。然而,它是最灵活的。
|
||||
|
||||
像 tnote 一样,pygmynote 将你的笔记和附件保存在 SQLite 数据库中。当你启动它时,pygmynote 看起来并不特别有用。在任何时候,输入 `help` 并按下 Enter 键获取命令列表。
|
||||
|
||||
你可以添加、编辑、查看和搜索笔记,并在笔记中添加[标签][8]。标签使找到笔记更容易,特别是如果你有很多笔记的时候。
|
||||
|
||||
pygmynote 的灵活性在于它能够将附件添加到笔记中。这些附件可以是任何东西:图像、文本、word、PDF、电子表格或与笔记相关的任何其他内容。
|
||||
|
||||
### jrnl
|
||||
|
||||
[jrnl][9] 是这里的一个奇怪应用。正如你可能从它的名字中猜到的那样,jrnl 意在成为一种日记工具。但这并不意味着你不能记笔记。 jrnl 做得很好。
|
||||
|
||||
当你第一次启动 jrnl 时,它会询问你想把文件 `journal.txt` (它存储你的笔记)保存的位置以及是否需要密码保护。如果你决定添加密码,那么你在应用内的操作都需要输入密码。
|
||||
|
||||
你可以通过两种方式输入笔记:直接从命令行或使用计算机的默认编辑器。你可以将标签(例如,`@opensource.com`)添加到笔记中,并指定日期和时间戳。如果你有很多笔记的话,添加标签和日期可以帮助搜索你的笔记(jrnl 有一个相当不错的搜索功能)。
|
||||
|
||||
由于 jrnl 将你的笔记保存为纯文本文件,因此你可以使用 [ownCloud][10]、[Nextcloud][11] 或任何你喜欢的文件共享/同步服务在设备间同步它。
|
||||
|
||||
你有没有喜欢的工具或自制的命令行笔记工具?请发表评论,随时与社区分享。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/3/command-line-note-taking-applications
|
||||
|
||||
作者:[Scott Nesbitt][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/scottnesbitt
|
||||
[1]:https://opensource.com/life/16/9/4-desktop-note-taking-applications
|
||||
[2]:https://opensource.com/alternatives/evernote
|
||||
[3]:https://github.com/tasdikrahman/tnote
|
||||
[4]:http://en.wikipedia.org/wiki/SQLite
|
||||
[5]:http://notational.net/
|
||||
[6]:https://vhp.github.io/terminal_velocity/
|
||||
[7]:https://github.com/dmpop/pygmynote
|
||||
[8]:https://en.wikipedia.org/wiki/Tag_(metadata)
|
||||
[9]:http://jrnl.sh/
|
||||
[10]:https://owncloud.com/
|
||||
[11]:https://nextcloud.com/
|
Loading…
Reference in New Issue
Block a user