mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-06 01:20:12 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
fd83ce4792
@ -1,267 +1,197 @@
|
||||
用 PGP 保护代码完整性 - 第一部分: 基本概念和工具
|
||||
用 PGP 保护代码完整性(一): 基本概念和工具
|
||||
======
|
||||
|
||||

|
||||
|
||||
在本系列文章中,我们将深度探讨如何使用 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
|
||||
======
|
||||
|
||||

|
||||
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,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
|
@ -1,63 +1,63 @@
|
||||
How To Manage Disk Partitions Using Parted Command
|
||||
怎样用 Parted 管理硬盘分区
|
||||
======
|
||||
Translating by zyk2290
|
||||
|
||||
We all knows disk partitions is one of the important task for Linux administrator. They can not survive without knowing this.
|
||||
众所周知,硬盘分区对Linux管理员来说是其中一项最重要的管理任务,他们不能不知道这个。
|
||||
|
||||
In worst cases, at least once in a week they would get this request from dependent team but in big environment admins used to get this request very often.
|
||||
在最糟糕的时候,你至少每周一次会收到从依赖小组的请求,在大的环境里会更加频繁 。
|
||||
|
||||
You may ask why we need to use parted instead of fdisk? What is the difference? It’s a good question, i will give you more details about this.
|
||||
你可能会问为什么我们要用Parted而不是fdisk? 有什么区别? 好问题, 我会告诉你这两者的区别。
|
||||
|
||||
* Parted allow users to create a partition when the disk size is larger than 2TB but fdisk doesn’t allow.
|
||||
* Parted is a higher-level tool than fdisk.
|
||||
* It supports multiple partition table which includes GPT.
|
||||
* It allows users to resize the partition but while shrinking the partition it does not worked as expected and i got error most of the time so, i would advise users to do not shrink the partition.
|
||||
* Parted支持用户在大于2TB的硬盘上创建硬盘分区, 但fdisk命令不支持
|
||||
* 对比fdisk来说, Parted是一个更高级的工具
|
||||
* 支持更多的分区表类型,包括GPT ( LCTT译者注:全局唯一标识分区表 )。
|
||||
* 它允许用户调整分区大小, 但当缩减分区空间的时候,它没有在我意料之内工作, 在大部分时候, 我会得到错误。 所以 我会建议用户不要用Parted来缩减分区大小。
|
||||
|
||||
|
||||
|
||||
### What Is Parted
|
||||
### 什么是 Parted
|
||||
|
||||
Parted is a program to manipulate disk partitions. It supports multiple partition table formats, including MS-DOS and GPT.
|
||||
Parted 是一个操作硬盘分区的程序. 它支持多种分区表类型,包括 MS-DOS和 GPT .
|
||||
|
||||
It allows user to create, delete, resize, shrink, move and copy partitions, reorganizing disk usage, and copying data to new hard disks. GParted is a GUI frontend of parted.
|
||||
它允许用户创建, 删除, 调整 ,缩减,移动和复制分区 ,以及重新组织硬盘的使用, 复制数据到新的硬盘上。GParted是parted的图形界面前端。
|
||||
|
||||
### How To Install Parted
|
||||
### 怎样安装Parted
|
||||
|
||||
Parted package is pre-installed on most of the Linux distribution. If not, use the following commands to install parted package.
|
||||
大部分发行版已经预安装了Parted 如果没有, 用下列命令来安装Parted.
|
||||
|
||||
For **`Debian/Ubuntu`** , use [APT-GET Command][1] or [APT Command][2] to install parted.
|
||||
对于 **`Debian/Ubuntu`** 用户, 使用 [APT-GET Command][1] 或者 [APT Command][2] 来安装Parted。
|
||||
```
|
||||
$ sudo apt install parted
|
||||
|
||||
```
|
||||
|
||||
For **`RHEL/CentOS`** , use [YUM Command][3] to install parted.
|
||||
对于 **`RHEL/CentOS`** , 用 [YUM Command][3] 来安装parted。
|
||||
```
|
||||
$ sudo yum install parted
|
||||
|
||||
```
|
||||
|
||||
For **`Fedora`** , use [DNF Command][4] to install parted.
|
||||
对于 **`Fedora`** , 用 [DNF Command][4] 命令来安装parted。
|
||||
```
|
||||
$ sudo dnf install parted
|
||||
|
||||
```
|
||||
|
||||
For **`Arch Linux`** , use [Pacman Command][5] to install parted.
|
||||
对于 **`Arch Linux`** , 用 [Pacman Command][5] 命令来安装parted。
|
||||
```
|
||||
$ sudo pacman -S parted
|
||||
|
||||
```
|
||||
|
||||
For **`openSUSE`** , use [Zypper Command][6] to install parted.
|
||||
对于 **`openSUSE`** , 用 [Zypper Command][6] 命令来安装parted。
|
||||
```
|
||||
$ sudo zypper in parted
|
||||
|
||||
```
|
||||
|
||||
### How To Launch Parted
|
||||
### 怎样启动Parted
|
||||
|
||||
The below parted command picks the `/dev/sda` disk automatically, because this is the first hard drive in this system.
|
||||
下面的parted命令会自动选择 `/dev/sda` , 因为这是系统的第一个硬盘。
|
||||
```
|
||||
$ sudo parted
|
||||
GNU Parted 3.2
|
||||
@ -67,7 +67,7 @@ Welcome to GNU Parted! Type 'help' to view a list of commands.
|
||||
|
||||
```
|
||||
|
||||
Also we can go to the corresponding disk by selecting the appropriate disk using below command.
|
||||
同时我们也可以用下面的命令来重新选择对应的的硬盘。
|
||||
```
|
||||
(parted) select /dev/sdb
|
||||
Using /dev/sdb
|
||||
@ -75,7 +75,7 @@ Using /dev/sdb
|
||||
|
||||
```
|
||||
|
||||
If you wants to go to particular disk, use the following format. In our case we are going to use `/dev/sdb`.
|
||||
如果你想选择特定的硬盘, 用下列的格式来输入命令。 这次 ,我们将选择`/dev/sdb`.
|
||||
```
|
||||
$ sudo parted [Device Name]
|
||||
|
||||
@ -87,9 +87,9 @@ Welcome to GNU Parted! Type 'help' to view a list of commands.
|
||||
|
||||
```
|
||||
|
||||
### How To List Available Disks Using Parted Command
|
||||
### 怎样用 Parted列出所有可用的硬盘
|
||||
|
||||
If you don’t know what are the disks are added in your system. Just run the following command, which will display all the available disks name, and other useful information such as Disk Size, Model, Sector Size, Partition Table, Disk Flags, and partition information.
|
||||
如果你不知道你的电脑上有什么硬盘, 只需要运行下列命令,该命令会显示所有可用硬盘的名字, 以及其它的有用信息比如储存空间, 型号, 扇区大小,硬盘旗帜以及分区信息。
|
||||
```
|
||||
$ sudo parted -l
|
||||
Model: ATA VBOX HARDDISK (scsi)
|
||||
@ -111,17 +111,18 @@ Disk Flags:
|
||||
|
||||
```
|
||||
|
||||
The above error message clearly shows there is no valid disk label for the disk `/dev/sdb`. Hence, we have to set `disk label` first as it doesn’t take any label automatically.
|
||||
上面的错误信息清晰地显示出硬盘 `/dev/sdb` 没有有效的硬盘标签 (disk label) 。 它不会自动选择硬盘标签 (disk label) ,所以, 我们便要自己设置硬盘标签 (disk label) 。
|
||||
|
||||
### How To Create Disk Partition Using Parted Command
|
||||
### 怎样用Parted创建硬盘分区
|
||||
|
||||
Parted allows us to create primary or extended partition. Procedure is same for both but make sure you have to pass an appropriate partition type like `primary` or `extended` while creating the partition.
|
||||
Parted允许用户创建主分区或者拓展分区。 创建这两种类型的分区的步骤还是一样,但请确保你已经指定了需要的分区类型,比如 `primary` 或者`extended`。
|
||||
|
||||
To perform this activity, we have added a new `50GB` hard disk in the system, which falls under `/dev/sdb`.
|
||||
为了演示这项操作 ,我们安装了一个新的`50 GB` 的硬盘到到电脑上,挂载在`/dev/sdb`上
|
||||
|
||||
In two ways we can create a partition, one is detailed way and other one is single command. In the below example we are going to add one primary partition in detailed way. Make a note, we should set `disk label` first as it doesn’t take any label automatically.
|
||||
有两种方法创建分区,第一种是更详细的方法,另一种只是一个命令。 在下面的例子中,我们将用更详细的方法添加一个主分区。提醒一下, 我们应该先设置 `硬盘标签`(disk label),因为它不会自动设置任何标签。
|
||||
|
||||
在下面的例子中,我们将要创建一个`10 GB` 的分区
|
||||
|
||||
We are going to create a new partition with `10GB` of disk in the below example.
|
||||
```
|
||||
$ sudo parted /dev/sdb
|
||||
GNU Parted 3.2
|
||||
@ -149,9 +150,10 @@ Information: You may need to update /etc/fstab.
|
||||
|
||||
```
|
||||
|
||||
Alternatively we can create a new partition using single parted command.
|
||||
同时,我们也可以使用单条Parted命令
|
||||
|
||||
在下面的例子中,我们将在硬盘上创建一个`10 GB` 的分区
|
||||
|
||||
We are going to create second partition with `10GB` of disk in the below example.
|
||||
```
|
||||
$ sudo parted [Disk Name] [mkpart] [Partition Type] [Filesystem Type] [Partition Start Size] [Partition End Size]
|
||||
|
||||
@ -160,11 +162,12 @@ Information: You may need to update /etc/fstab.
|
||||
|
||||
```
|
||||
|
||||
### How To Create A Partition With All Remaining Space
|
||||
### 怎样使用Parted用所有剩余空间创建分区
|
||||
|
||||
You have created all required partitions except `/home` and you wants to use all the remaining space to `/home` partition, how to do that? use the following command to create a partition.
|
||||
你已经创建了所有要求的分区,除了`/home` ,而且你想要用硬盘上所有剩余的空间来创建`/home`分区,要怎样做?可以使用下面的命令来创建分区。
|
||||
|
||||
下面的命令创建了一个 33.7 GB 的分区,从 `20 GB` 开始到 `53 GB`结束。 `100%` 使用率允许用户用硬盘上所有剩余的空余空间。
|
||||
|
||||
The below command create a new partition with 33.7GB, which starts from `20GB` and ends with `53GB`. `100%` end size will allow users to create a new partition with remaining all available space in the disk.
|
||||
```
|
||||
$ sudo parted [Disk Name] [mkpart] [Partition Type] [Filesystem Type] [Partition Start Size] [Partition End Size]
|
||||
|
||||
@ -173,9 +176,10 @@ Information: You may need to update /etc/fstab.
|
||||
|
||||
```
|
||||
|
||||
### How To List All Partitions using Parted
|
||||
### 怎样用Parted列出所有的分区
|
||||
|
||||
你也许注意到了,我们已经在上述步骤中创建了三个分区,如果你想要列出所有在硬盘上可用的分区,可以使用print命令。
|
||||
|
||||
As you aware of, we have created three partitions in the above step and if you want to list all available partitions on the disk use the print command.
|
||||
```
|
||||
$ sudo parted /dev/sdb print
|
||||
Model: ATA VBOX HARDDISK (scsi)
|
||||
@ -191,9 +195,10 @@ Number Start End Size Type File system Flags
|
||||
|
||||
```
|
||||
|
||||
### How To Create A File System On Partition Using mkfs
|
||||
### 怎样用mkfs格式化分区
|
||||
|
||||
用户可以用mkfs命令格式化分区。下面的步骤会用mkfs来格式化分区。
|
||||
|
||||
Users can create a file system on the partition using mkfs. Follow the below procedure to create a filesystem using mkfs.
|
||||
```
|
||||
$ sudo mkfs.ext4 /dev/sdb1
|
||||
mke2fs 1.43.4 (31-Jan-2017)
|
||||
@ -209,14 +214,16 @@ Writing superblocks and filesystem accounting information: done
|
||||
|
||||
```
|
||||
|
||||
Do the same for other partitions as well.
|
||||
同样的。
|
||||
|
||||
```
|
||||
$ sudo mkfs.ext4 /dev/sdb2
|
||||
$ sudo mkfs.ext4 /dev/sdb3
|
||||
|
||||
```
|
||||
|
||||
Create necessary folders and mount the partitions on that.
|
||||
创建必要的文件夹然后将这些分区挂载在上面。
|
||||
|
||||
```
|
||||
$ sudo mkdir /par1 /par2 /par3
|
||||
|
||||
@ -226,7 +233,8 @@ $ sudo mount /dev/sdb3 /par3
|
||||
|
||||
```
|
||||
|
||||
Run the following command to check newly mounted partitions.
|
||||
运行下列命令来检查是否成功挂载上新创建的分区。
|
||||
|
||||
```
|
||||
$ df -h /dev/sdb[1-3]
|
||||
Filesystem Size Used Avail Use% Mounted on
|
||||
@ -236,9 +244,10 @@ Filesystem Size Used Avail Use% Mounted on
|
||||
|
||||
```
|
||||
|
||||
### How To Check Free Space On The Disk
|
||||
### 怎样检查硬盘空闲空间
|
||||
|
||||
运行下列命令来检查硬盘上的空闲空间,这块硬盘上有`25.7 GB`的空闲空间。
|
||||
|
||||
Run the following command to check available free space on the disk. This disk has `25.7GB` of free disk space.
|
||||
```
|
||||
$ sudo parted /dev/sdb print free
|
||||
Model: ATA VBOX HARDDISK (scsi)
|
||||
@ -256,11 +265,12 @@ Number Start End Size Type File system Flags
|
||||
|
||||
```
|
||||
|
||||
### How To Resize Partition Using Parted Command
|
||||
### 怎样使用Parted命令来重新调整分区大小
|
||||
|
||||
Parted allow users to resize the partitions to big and smaller size. As i told in the beginning of the article, do not shrink partitions because this leads to face disk error issue.
|
||||
Parted 允许用户重新调整分区大小。不过我已在文章的开头说了,不要缩小分区大小,不然会有许多错误。
|
||||
|
||||
运行下列命令来检查硬盘分区以及所有可用空间。 可以看到硬盘上有`25.7GB` 的可用空间
|
||||
|
||||
Run the following command to check disk partitions and available free space. I could see `25.7GB` of free space on this disk.
|
||||
```
|
||||
$ sudo parted /dev/sdb print free
|
||||
Model: ATA VBOX HARDDISK (scsi)
|
||||
@ -278,7 +288,8 @@ Number Start End Size Type File system Flags
|
||||
|
||||
```
|
||||
|
||||
Run the following command to resize the partition. We are going to resize (increase) the partition 3 end size from `28GB to 33GB`.
|
||||
运行下列命令来重新调整分区大小。 我们将要重新调整(增加)分区 3的结束位置从 `28GB 到 33GB`。
|
||||
|
||||
```
|
||||
$ sudo parted [Disk Name] [resizepart] [Partition Number] [Partition New End Size]
|
||||
|
||||
@ -287,7 +298,8 @@ Information: You may need to update /etc/fstab.
|
||||
|
||||
```
|
||||
|
||||
Run the following command to verify whether this partition is increased or not. Yes, i could see the partition 3 got increased from `8GB to 13GB`.
|
||||
运行下列命令来确认分区是否已经扩容。可以看到,分区 3 已经从`8GB`增加到`13GB`。
|
||||
|
||||
```
|
||||
$ sudo parted /dev/sdb print
|
||||
Model: ATA VBOX HARDDISK (scsi)
|
||||
@ -303,7 +315,8 @@ Number Start End Size Type File system Flags
|
||||
|
||||
```
|
||||
|
||||
Resize the file system to grow the resized partition.
|
||||
重新调整文件系统大小。
|
||||
|
||||
```
|
||||
$ sudo resize2fs /dev/sdb3
|
||||
resize2fs 1.43.4 (31-Jan-2017)
|
||||
@ -312,7 +325,8 @@ The filesystem on /dev/sdb3 is now 3173952 (4k) blocks long.
|
||||
|
||||
```
|
||||
|
||||
Finally, check whether the mount point has been successfully increased or not.
|
||||
最后,确认分区是否已经扩容。
|
||||
|
||||
```
|
||||
$ df -h /dev/sdb[1-3]
|
||||
Filesystem Size Used Avail Use% Mounted on
|
||||
@ -322,9 +336,10 @@ Filesystem Size Used Avail Use% Mounted on
|
||||
|
||||
```
|
||||
|
||||
### How To Remove Partition Using Parted Command
|
||||
### 怎样用Parted删除分区
|
||||
|
||||
我们用rm命令方便地删除未使用的分区(如果该分区不会再被用到了)。下列步骤中,我们将会删除分区 3(`/dev/sdb3`)。
|
||||
|
||||
We can simple remove the unused partition (if the partition is no longer use) using rm command. See the procedure below. We are going to remove partition 3 `/dev/sdb3` in this example.
|
||||
```
|
||||
$ sudo parted [Disk Name] [rm] [Partition Number]
|
||||
|
||||
@ -338,7 +353,8 @@ Information: You may need to update /etc/fstab.
|
||||
|
||||
```
|
||||
|
||||
We can check the same using below command. Yes, i could see that partition 3 has been removed successfully.
|
||||
我们也可以用下列的命令检查。可以看到,分区 3 已经被成功移除。
|
||||
|
||||
```
|
||||
$ sudo parted /dev/sdb print
|
||||
Model: ATA VBOX HARDDISK (scsi)
|
||||
@ -353,9 +369,9 @@ Number Start End Size Type File system Flags
|
||||
|
||||
```
|
||||
|
||||
### How To Set/Change Partition Flag Using Parted Command
|
||||
### 怎样用Parted命令设置/更改分区旗帜
|
||||
|
||||
We can easily change the partition flag using below command. We are going to set `lvm` flag to partition 2 `/dev/sdb2`.
|
||||
我们可以用下列的命令来轻易更改分区的旗帜。 我们将对`/dev/sdb2`设置 `lvm` 旗帜。
|
||||
```
|
||||
$ sudo parted [Disk Name] [set] [Partition Number] [Flags Name] [Flag On/Off]
|
||||
|
||||
@ -364,7 +380,8 @@ Information: You may need to update /etc/fstab.
|
||||
|
||||
```
|
||||
|
||||
We can verify this modification by listing disk partitions.
|
||||
我们可以列出分区来验证这次的更改。
|
||||
|
||||
```
|
||||
$ sudo parted /dev/sdb print
|
||||
Model: ATA VBOX HARDDISK (scsi)
|
||||
@ -379,7 +396,7 @@ Number Start End Size Type File system Flags
|
||||
|
||||
```
|
||||
|
||||
To know list of available flags, use the following command.
|
||||
如果你想知道可用的旗帜, 只需要用如下的命令。
|
||||
```
|
||||
$ (parted) help set
|
||||
set NUMBER FLAG STATE change the FLAG on partition NUMBER
|
||||
@ -390,7 +407,7 @@ $ (parted) help set
|
||||
|
||||
```
|
||||
|
||||
If you want to know the available options in parted, just navigate to `help` page.
|
||||
如果你想知道parted的其它可用命令, 只需要去到 `help` 页面.
|
||||
```
|
||||
$ sudo parted
|
||||
GNU Parted 3.2
|
@ -0,0 +1,68 @@
|
||||
Linux 下的 4 个命令行笔记记录程序
|
||||
======
|
||||
|
||||

|
||||
当你需要保存代码段或 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