Merge pull request #18 from LCTT/master

update
This commit is contained in:
zxp 2020-12-20 19:31:53 +08:00 committed by GitHub
commit b57f9ec1a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 1389 additions and 739 deletions

View File

@ -0,0 +1,158 @@
[#]: collector: (lujun9972)
[#]: translator: (zxp93)
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-12935-1.html)
[#]: subject: (How I use Python to map the global spread of COVID-19)
[#]: via: (https://opensource.com/article/20/4/python-map-covid-19)
[#]: author: (AnuragGupta https://opensource.com/users/999anuraggupta)
如何使用 Python 绘制 COVID-19 的全球扩散图
======
> 使用这些开源框架创建一个彩色地图,显示病毒的可能的传播路径。
![](https://img.linux.net.cn/data/attachment/album/202012/20/005146t8voetski8ocm5c2.jpg)
对于一个全球旅行司空见惯的世界来说,疾病的传播是一个真正令人担忧的问题。一些组织会跟踪重大的流行病(还有所有普遍的流行病),并将他们的跟踪工作获得的数据公开出来。不过,这些原始的数据对人来说可能很难处理,这就是为什么数据科学如此重要的原因。比如,用 Python 和 Pandas 可视化 COVID-19 在全球范围内的传播路径可能对这些数据的分析有所帮助。
最开始,当面对如此大数量的原始数据时可能难以下手。但当你开始处理数据之后,慢慢地就会发现一些处理数据的方式。下面是用于处理 COVID-19 数据的一些常见的情况:
1. 从 GitHub 上下载 COVID-19 的国家每日传播数据,保存为一个 Pandas 中的 DataFrame 对象。这时你需要使用 Python 中的 Pandas 库。
2. 处理并清理下载好的数据,使其满足可视化数据的输入格式。所下载的数据的情况很好(数据规整)。这个数据有一个问题是它用国家的名字来标识国家,但最好是使用三位数的 ISO 3 码(国家代码表)来标识国家。为了生成 ISO 3 码,可是使用 `pycountry` 这个 Python 库。生成了这些代码之后,可以在原有的 DataFrame 上增加一列,然后用这些代码填充进去。
3. 最后为了实现可视化,使用 Plotly 库中的 `express` 模块。这篇文章是使用名为choropleth 的地图(可在 Plotly 库中获得)来可视化该疾病在全球的传播。
### 第一步Corona 数据
从下面这个网站上下载最新的 corona 数据LCTT 译注2020-12-14 仍可访问,有墙):
- <https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv>
我们之间将这个下载好的数据载入为 Pandas 的 DataFrame。Pandas 提供了一个函数, `read_csv()`,可以直接使用 URL 读取数据,并返回一个 DataFrame 对象,具体如下所示:
```
import pycountry
import plotly.express as px
import pandas as pd
URL_DATASET = r'https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv'
df1 = pd.read_csv(URL_DATASET)
print(df1.head(3))  # Get first 3 entries in the dataframe
print(df1.tail(3))  # Get last 3 entries in the dataframe
```
在 Jupyter 上的输出截图:
![Jupyter screenshot][2]
从这个输出可以看到这个 DataFrame`df1`)包括以下几列数据:
1. `Date`
2. `Country`
3. `Confirmed`
4. `Recovered`
5. `Dead`
之后还可以看到 `Date` 这一列包含了从 1 月 22 日到 3 月 31 日的条目信息。这个数据是每天更新的,所以你会得到你当天的值。
### 第二步:清理和修改 DataFrame
我们要往这个 DataFrame 中增加一列数据,就是那个包含了 ISO 3 编码。可以通过以下三步完成这个任务:
1. 创建一个包含所有国家的列表。因为在 `df1``Country` 列中,国家都是每个日期就重复一次。所以实际上 `Country` 列中对每个国家就会有多个条目。我使用 `unique().tolist()` 函数完成这个任务。
2. 我使用 `d_country_code` 字典对象(初始为空),然后将其键设置为国家的名称,然后它的值设置为其对应的 ISO 3 编码。
3. 我使用 `pycountry.countries.search_fuzzy(country)` 为每个国家生成 ISO 3 编码。你需要明白的是这个函数的返回值是一个 `Country` 对象的列表。我将这个函数的返回值赋给 `country_data` 对象。以这个对象的第一个元素(序号 `0`)为例。这个 `\` 对象有一个 `alpha_3` 属性。所以我使用 `country_data[0].alpha_3` 就能“获得”第一个元素的 ISO 3 编码。然而,在这个 DataFrame 中有些国家的名称可能没有对应的 ISO 3 编码(比如有争议的领土)。那么对这些“国家/地区”,我就用一个空白字符串来替代 ISO 3 编码。你也可以用一个 `try-except` 代码来替换这部分。`except` 中的语句可以写:`print(could not add ISO 3 code for ->', country)`。这样就能在找不到这些“国家/地区”对应的 ISO 3 编码时给出一个输出提示。实际上,你会发现这些“国家/地区”会在最后的输出中用白色来表示。
4. 在获得了每个国家的 ISO 3 编码(有些是空白字符串)之后,我把这些国家的名称(作为键)还有国家对应的 ISO 3 编码(作为值)添加到之前的字典 `d_country_code` 中。可以使用 Python 中字典对象的 `update()` 方法来完成这个任务。
5. 在创建好了一个包含国家名称和对应 ISO 3 编码的字典之后,我使用一个简单的循环将他们加入到 DataFrame 中。
### 第三步:使用 Plotly 可视化传播路径
choropleth 地图是一个由彩色多边形组成的地图。它常常用来表示一个变量在空间中的变化。我们使用 Plotly 中的 `px` 模块来创建 choropleth 图,具体函数为:`px.choropleth`。
这个函数的所包含的参数如下:
```
plotly.express.choropleth(data_frame=None, lat=None, lon=None, locations=None, locationmode=None, geojson=None, featureidkey=None, color=None, hover_name=None, hover_data=None, custom_data=None, animation_frame=None, animation_group=None, category_orders={}, labels={}, color_discrete_sequence=None, color_discrete_map={}, color_continuous_scale=None, range_color=None, color_continuous_midpoint=None, projection=None, scope=None, center=None, title=None, template=None, width=None, height=None)
```
`choropleth()` 这个函数还有几点需要注意:
1. `geojson` 是一个 `geometry` 对象(上面函数第六个参数)。这个对象有点让人困扰,因为在函数文档中没有明确地提到这个对象。你可以提供,也可以不提供 `geojson` 对象。如果你提供了 `geojson` 对象,那么这个对象就会被用来绘制地球特征,如果不提供 `geojson` 对象,那这个函数默认就会使用一个内建的 `geometry` 对象。(在我们的实验中,我们使用内建的 `geometry` 对象,因此我们不会为 `geojson` 参数提供值)
2. DataFrame 对象有一个 `data_frame` 属性,在这里我们先前就提供了一个我们创建好的`df1`。
3. 我们用 `Confirmed`(确诊数)来决定每个国家多边形的颜色。
4. 最后,我们 `Date` 列创建一个 `animation_frame`。这样我们就能通过日期来划分数据,国家的颜色会随着 `Confirmed` 的变化而变化。
最后完整的代码如下:
```
import pycountry
import plotly.express as px
import pandas as pd
# ----------- Step 1 ------------
URL_DATASET = r'https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv'
df1 = pd.read_csv(URL_DATASET)
# print(df1.head) # Uncomment to see what the dataframe is like
# ----------- Step 2 ------------
list_countries = df1['Country'].unique().tolist()
# print(list_countries) # Uncomment to see list of countries
d_country_code = {} # To hold the country names and their ISO
for country in list_countries:
try:
country_data = pycountry.countries.search_fuzzy(country)
# country_data is a list of objects of class pycountry.db.Country
# The first item ie at index 0 of list is best fit
# object of class Country have an alpha_3 attribute
country_code = country_data[0].alpha_3
d_country_code.update({country: country_code})
except:
print('could not add ISO 3 code for ->', country)
# If could not find country, make ISO code ' '
d_country_code.update({country: ' '})
# print(d_country_code) # Uncomment to check dictionary
# create a new column iso_alpha in the df
# and fill it with appropriate iso 3 code
for k, v in d_country_code.items():
df1.loc[(df1.Country == k), 'iso_alpha'] = v
# print(df1.head) # Uncomment to confirm that ISO codes added
# ----------- Step 3 ------------
fig = px.choropleth(data_frame = df1,
locations= "iso_alpha",
color= "Confirmed", # value in column 'Confirmed' determines color
hover_name= "Country",
color_continuous_scale= 'RdYlGn', # color scale red, yellow green
animation_frame= "Date")
fig.show()
```
这段代码的输出就是下面这个图的内容:
![Map][3]
你可以从这里下载并运行[完整代码][4]。
最后,这里还有一些关于 Plotly 绘制 choropleth 图的不错的资源。
* <https://github.com/plotly/plotly.py/blob/master/doc/python/choropleth-maps.md>
* <https://plotly.com/python/reference/#choropleth>
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/4/python-map-covid-19
作者:[AnuragGupta][a]
选题:[lujun9972][b]
译者:[zhangxiangping](https://github.com/zxp93)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/999anuraggupta
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cloud-globe.png?itok=_drXt4Tn (Globe up in the clouds)
[2]: https://opensource.com/sites/default/files/uploads/jupyter_screenshot.png (Jupyter screenshot)
[3]: https://opensource.com/sites/default/files/uploads/map_2.png (Map)
[4]: https://github.com/ag999git/jupyter_notebooks/blob/master/corona_spread_visualization
[5]: tmp.azs72dmHFd#choropleth

View File

@ -1,18 +1,20 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-12930-1.html)
[#]: subject: (Experience the useful features of the Xedit text editor)
[#]: via: (https://opensource.com/article/20/12/xedit)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
体验 Xedit 文本编辑器的实用功能
======
Xedit 是 X11 图形服务器的一部分,它没什么好看的,但却有足够的隐藏功能,使它成为一个严肃的文本编辑器。
![Computer screen with files or windows open][1]
X11 图形服务器由 [X.org][2] 发布,它有一些象征性的应用来展示如何使用它提供的工具进行编程。这些应用包括 [TWM][3] 桌面到愚蠢但催眠的 Xeyes。它还包括一个名为 Xedit 的文本编辑器,它是一个看似简单的应用,却有足够的隐藏功能,使其成为一个严肃的编辑器。
> Xedit 是 X11 图形服务器的一部分,它不算好看,但却有足够的隐藏功能,使它成为一个严肃的文本编辑器。
![](https://img.linux.net.cn/data/attachment/album/202012/18/075942uzhgjgxfxve7p2ot.jpg)
X11 图形服务器由 [X.org][2] 发布,它有一些象征性的应用来展示如何使用它提供的工具进行编程。这些应用包括从 [TWM][3] 桌面到愚蠢但催眠的 Xeyes。它还包括一个名为 Xedit 的文本编辑器,它是一个看似简单的应用,却有足够的隐藏功能,使其成为一个严肃的编辑器。
### 安装 Xedit
@ -22,77 +24,67 @@ X11 图形服务器由 [X.org][2] 发布,它有一些象征性的应用来展
### 启动 Xedit
如果它被列出的话,你可以从你的应用菜单中启动 Xedit。有些发行版将它视为命令而不是 GUI 应用,尽管它绝对是一个 GUI 应用,所以它可能不会被列在应用菜单中。这时,你可以从终端启动 Xedit。如果你输入 `xedit &` 来启动应用,它就会启动一个空的 Xedit 编辑器可以随时输入。如果你在输入启动命令的同时输入一个现有的文件名Xedit 启动时会将文件加载到缓冲区。
如果它被列在你的应用菜单的话,你可以从中启动 Xedit。尽管它绝对是一个 GUI 应用,但有些发行版将它视为命令而不是 GUI 应用,所以它可能不会被列在应用菜单中。这时,你可以从终端启动 Xedit。如果你输入 `xedit &` 来启动应用,它就会启动一个空的 Xedit 编辑器可以随时输入。如果你在输入启动命令的同时输入一个现有的文件名Xedit 启动时会将文件加载到缓冲区。
```
`$ xedit example.txt &`
$ xedit example.txt &
```
![Xedit][5]
(Seth Kenlon, [CC BY-SA 4.0][6])
### 加载文件
在打开的 Xedit 实例中,你可以在顶部文本输入框中输入文件的路径来加载文件。点击 **Load** 按钮(在文本输入框的左边),将文件读入 Xedit 窗口。
![Load Xedit][7]
(Seth Kenlon, [CC BY-SA 4.0][6])
你可以同时打开多个文件。当一个文件被加载时,它将获取焦点并出现在你的主 Xedit 缓冲区(主窗口中的大文本输入框),并将任何现有的文件切换到一个隐藏的缓冲区。
你可以使用组合键在缓冲区之间切换,这对 Emacs 用户而言很熟悉,但对其他用户会感到困惑。首先,按下 **Ctrl+X**。放开然后按 **Ctrl+B**
你可以使用组合键在缓冲区之间切换,这对 Emacs 用户而言很熟悉,但对其他用户会感到困惑。首先,按下 `Ctrl+X`。放开然后按 `Ctrl+B`
### 组合键
一开始执行需要连续_两_个键盘快捷键的操作感觉很奇怪,但过了一段时间,你就会习惯。事实上,作为一个经常使用 Emacs 的用户,我发现复合键组合很有节奏感。我很惊讶也很高兴地发现,我最喜欢的一些快捷键在 Xedit 中也有效。
一开始执行需要连续*两*个键盘快捷键的操作感觉很奇怪,但过了一段时间,你就会习惯。事实上,作为一个经常使用 Emacs 的用户,我发现复合键组合很有节奏感。我很惊讶也很高兴地发现,我最喜欢的一些快捷键在 Xedit 中也有效。
原来Xedit 从几个灵感源借用了键盘快捷键。如果你是 Emacs 用户,你会发现最常见的组合在 Xedit 中有效。例如,**C-x** **C-f** (即 **Ctrl+X** 后是 **Ctrl+F**)可以回到顶部的文本输入框来加载文件,而 **C-x** **C-s** **Ctrl+X** 后是 **Ctrl+S**)可以保存文件。令人惊讶的是,**C-x** **3** 甚至可以垂直分割窗口,而**C-x** **2** 则可以水平分割,**C-x** **0** 或 **1**则可以移除分割。
原来Xedit 从几个灵感源借用了键盘快捷键。如果你是 Emacs 用户,你会发现最常见的组合在 Xedit 中有效。例如,`C-x C-f` (即 `Ctrl+X` 后是 `Ctrl+F`)可以回到顶部的文本输入框来加载文件,而 `C-x C-s``Ctrl+X` 后是 `Ctrl+S`)可以保存文件。令人惊讶的是,`C-x 3` 甚至可以垂直分割窗口,而 `C-x 2` 则可以水平分割,`C-x 0` 或 `C-x 1` 则可以移除分割。
Emacs 或 Bash 用户熟悉的编辑命令也适用:
* **Ctrl+A** 移动到行首。
* **Ctrl+E** 移至行尾。
* **Alt+B** 向后移动一个单词。
* **Ctrl+B** 向后移动一个字符。
* **Ctrl+F** 向前移动一个字符。
* **Alt+F** 向前移动一个单词。
* **Ctrl+D** 删除下一个字符。
* `Ctrl+A` 移动到行首。
* `Ctrl+E` 移至行尾。
* `Alt+B` 向后移动一个单词。
* `Ctrl+B` 向后移动一个字符。
* `Ctrl+F` 向前移动一个字符。
* `Alt+F` 向前移动一个单词。
* `Ctrl+D 删除下一个字符。
还有更多,它们都在 Xedit 手册页面上列出。
### 使用行编辑模式
Xedit 还含有一个类似 **ex** 的行编辑器,这对 [Vi][8] 和 `ed` 甚至 `sed` 用户应该很熟悉。要进入行编辑模式,按下 **Esc** 键。这将使你处于顶部的文本输入框,但处于命令模式。编辑命令使用的语法是:_行号_后面跟着一个_命令_和_参数_
Xedit 还含有一个类似 `ex` 的行编辑器,这对 [Vi][8] 和 `ed` 甚至 `sed` 用户应该很熟悉。要进入行编辑模式,按下 `Esc` 键。这将使你处于顶部的文本输入框,但处于命令模式。编辑命令使用的语法是:*行号*后面跟着一个*命令*和*参数*
比如说你有这个文本文件:
```
ed is the standard Unix text editor.
This is line number two.
```
你决定将第 1 行的 `ed` 改为 `Xedit`。在 Xedit 中,移动到第 1 行,按下 **Esc**,然后输入 `.,s/ed/Xedit/`
你决定将第 1 行的 `ed` 改为 `Xedit`。在 Xedit 中,移动到第 1 行,按下 `Esc`,然后输入 `.,s/ed/Xedit/`
```
Xedit is the standard Unix text editor.
This is line number two.
```
不用将光标移到下一行,你可以将 `two` 改为 `the second`。按下 **Esc**,然后输入 `2,s/two/the second/`
不用将光标移到下一行,你可以将 `two` 改为 `the second`。按下 `Esc`,然后输入 `2,s/two/the second/`
可能的命令和有效的参数在 Xedit 的手册页中列出。
各种命令和有效的参数在 Xedit 的手册页中列出。
### 简单但稳定
Xedit 并没有什么好看的,它很简单,没有菜单可言,但它借鉴了一些最好的 Unix 编辑器的流行的便利性。下次你在寻找新的编辑器时,不妨试试 Xedit。
Xedit 并不算好看,它很简单,没有菜单可言,但它借鉴了一些最好的 Unix 编辑器的流行的便利性。下次你在寻找新的编辑器时,不妨试试 Xedit。
--------------------------------------------------------------------------------
@ -101,7 +93,7 @@ via: https://opensource.com/article/20/12/xedit
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[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/) 荣誉推出

View File

@ -0,0 +1,272 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-12936-1.html)
[#]: subject: (Add storage to your Fedora system with LVM)
[#]: via: (https://fedoramagazine.org/add-storage-to-your-fedora-system-with-lvm/)
[#]: author: (Tim Bosse https://fedoramagazine.org/author/maztaim/)
使用 LVM 为你的 Fedora 系统添加存储
======
![][1]
有时需要在系统中添加另一块磁盘。这就是<ruby>逻辑卷管理<rt>Logical Volume Management</rt></ruby>LVM的用武之地。LVM 的好处之处在于它相当灵活。有几种方法可以添加一块磁盘。这篇文章介绍了一种方法。
### 注意!
这篇文章并不包括将新的磁盘物理地安装到系统中的过程。请查阅你的系统和磁盘文档,了解如何正确地进行安装。
**重要:** 一定要确保你已经备份重要数据。如果新磁盘已有数据,那么本文中描述的步骤将破坏数据。
### 最好了解
本文并没有深入介绍 LVM 的每一个功能重点是添加磁盘。但基本上你要了解LVM 有<ruby>卷组<rt>volume group</rt></ruby>VG它由一个或多个分区和/或磁盘组成。你把这些分区或磁盘以<ruby>物理卷<rt>physical volume</rt></ruby>PV的方式添加到卷组。一个卷组可以分成许多<ruby>逻辑卷<rt>logical volume</rt></ruby>LV。逻辑卷可以作为文件系统、ramdisk 等其他存储使用。更多信息可以在[这里][2]中找到。
可以看作是,把物理卷形成一个存储池(一个卷组),然后从这个存储池中划分出逻辑卷,供你的系统直接使用。
### 准备
确保你能看到你要添加的磁盘。在添加磁盘之前使用 `lsblk` 查看哪些存储空间已经可用或正在使用。
```
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
zram0 251:0 0 989M 0 disk [SWAP]
vda 252:0 0 20G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 19G 0 part
└─fedora_fedora-root 253:0 0 19G 0 lvm /
```
本文使用的是带有虚拟存储的虚拟机,因此设备名称以 `vda` 开头代表第一个磁盘,`vdb` 代表第二个磁盘,以此类推。你的设备名称可能不同。许多系统会将 `sda` 作为第一个物理磁盘,`sdb` 代表第二个磁盘,以此类推。
当已连接新磁盘,并且你的系统已备份且正在运行,再次使用 `lsblk` 来查看新的块设备。
```
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
zram0 251:0 0 989M 0 disk [SWAP]
vda 252:0 0 20G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 19G 0 part
└─fedora_fedora-root 253:0 0 19G 0 lvm /
vdb 252:16 0 10G 0 disk
```
现在有一个名为 `vdb` 的新设备。该设备的位置是 `/dev/vdb`
```
$ ls -l /dev/vdb
brw-rw----. 1 root disk 252, 16 Nov 24 12:56 /dev/vdb
```
我们可以看到磁盘,但我们还不能用 LVM 来使用它。如果你运行 `blkid`,你应该不会看到它被列出。对于这个和之后的命令,你需要确保你的系统[已配置好,这样你可以使用 sudo][3]
```
$ sudo blkid
/dev/vda1: UUID="4847cb4d-6666-47e3-9e3b-12d83b2d2448" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="830679b8-01"
/dev/vda2: UUID="k5eWpP-6MXw-foh5-Vbgg-JMZ1-VEf9-ARaGNd" TYPE="LVM2_member" PARTUUID="830679b8-02"
/dev/mapper/fedora_fedora-root: UUID="f8ab802f-8c5f-4766-af33-90e78573f3cc" BLOCK_SIZE="4096" TYPE="ext4"
/dev/zram0: UUID="fc6d7a48-2bd5-4066-9bcf-f062b61f6a60" TYPE="swap"
```
### 将磁盘添加到 LVM 中
使用 `pvcreate` 初始化磁盘。你需要传递设备的完整路径。在这个例子中,它是 `/dev/vdb`。在你的系统中,它可能是 `/dev/sdb` 或其他设备名。
```
$ sudo pvcreate /dev/vdb
Physical volume "/dev/vdb" successfully created.
```
当你运行 `blkid` 时,你应该看到磁盘已经被初始化为一个 `LVM2_member`
```
$ sudo blkid
/dev/vda1: UUID="4847cb4d-6666-47e3-9e3b-12d83b2d2448" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="830679b8-01"
/dev/vda2: UUID="k5eWpP-6MXw-foh5-Vbgg-JMZ1-VEf9-ARaGNd" TYPE="LVM2_member" PARTUUID="830679b8-02"
/dev/mapper/fedora_fedora-root: UUID="f8ab802f-8c5f-4766-af33-90e78573f3cc" BLOCK_SIZE="4096" TYPE="ext4"
/dev/zram0: UUID="fc6d7a48-2bd5-4066-9bcf-f062b61f6a60" TYPE="swap"
/dev/vdb: UUID="4uUUuI-lMQY-WyS5-lo0W-lqjW-Qvqw-RqeroE" TYPE="LVM2_member"
```
你可以使用 `pvs` 列出当前所有可用的物理卷:
```
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 fedora_fedora lvm2 a-- <19.00g 0
/dev/vdb lvm2 --- 10.00g 10.00g
```
`/dev/vdb` 被列为一个 PV (物理卷),但还没有分配到一个 VG (卷组)。
### 将物理卷添加到一个卷组
你可以使用 `vgs` 找到可用的卷组列表:
```
$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
fedora_fedora 1 1 0 wz--n- 19.00g 0
```
在本例中,只有一个卷组可用。接下来,将物理卷添加到 `fedora_fedora`
```
$ sudo vgextend fedora_fedora /dev/vdb
Volume group "fedora_fedora" successfully extended
```
你现在应该看到物理卷已被添加到卷组中:
```
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 fedora_fedora lvm2 a <19.00g 0
/dev/vdb fedora_fedora lvm2 a <10.00g <10.00g
```
看一下卷组:
```
$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
fedora_fedora 2 1 0 wzn- 28.99g <10.00g
```
你也可以获得具体卷组和物理卷的详细列表:
```
$ sudo vgdisplay fedora_fedora
--- Volume group ---
VG Name fedora_fedora
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 28.99 GiB
PE Size 4.00 MiB
Total PE 7422
Alloc PE / Size 4863 / 19.00 GiB
Free PE / Size 2559 / 10.00 GiB
VG UUID C5dL2s-dirA-SQ15-TfQU-T3yt-l83E-oI6pkp
```
看下物理卷:
```
$ sudo pvdisplay /dev/vdb
--- Physical volume ---
PV Name /dev/vdb
VG Name fedora_fedora
PV Size 10.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2559
Free PE 2559
Allocated PE 0
PV UUID 4uUUuI-lMQY-WyS5-lo0W-lqjW-Qvqw-RqeroE
```
现在我们已经添加了磁盘,我们可以为逻辑卷 LV 分配空间:
```
$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root fedora_fedora -wi-ao---- 19.00g
```
看一下逻辑卷。下面是详细的逻辑卷信息:
```
$ sudo lvdisplay fedora_fedora/root
--- Logical volume ---
LV Path /dev/fedora_fedora/root
LV Name root
VG Name fedora_fedora
LV UUID yqc9cw-AvOw-G1Ni-bCT3-3HAa-qnw3-qUSHGM
LV Write Access read/write
LV Creation host, time fedora, 2020-11-24 11:44:36 -0500
LV Status available
LV Size 19.00 GiB
Current LE 4863
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
```
查看根文件系统(`/`)的大小,并将它与逻辑卷大小进行比较。
```
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/fedora_fedora-root 19G 1.4G 17G 8% /
```
逻辑卷和文件系统大小都为 19G。让我们给根逻辑卷`root`)增加 5G。
```
$ sudo lvresize -L +5G fedora_fedora/root
Size of logical volume fedora_fedora/root changed from 19.00 GiB (4863 extents) to 24.00 GiB (6143 extents).
Logical volume fedora_fedora/root successfully resized.
```
我们现在有 24G 的逻辑卷可用。看看根文件系统(`/`)。
```
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/fedora_fedora-root 19G 1.4G 17G 8% /
```
我们仍然显示只有 19G 的空闲空间,这是因为逻辑卷与文件系统不一样。要使用增加到逻辑卷的新空间,请调整文件系统的大小。
```
$ sudo resize2fs /dev/fedora_fedora/root
resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/fedora_fedora/root is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 3
The filesystem on /dev/fedora_fedora/root is now 6290432 (4k) blocks long.
```
看看文件系统的大小。
```
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/fedora_fedora-root 24G 1.4G 21G 7% /
```
正如你所看到的,根文件系统(`/`)已经占用了逻辑卷上的所有可用空间,而且不需要重新启动。
现在你已经将一个磁盘初始化为物理卷,并使用新的物理卷扩展了卷组。之后,你增加了逻辑卷的大小,并调整了文件系统的大小,以使用逻辑卷的新空间。
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/add-storage-to-your-fedora-system-with-lvm/
作者:[Tim Bosse][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://fedoramagazine.org/author/maztaim/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2020/11/lvm-add-disk-816x345.jpg
[2]: https://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)
[3]: https://fedoramagazine.org/howto-use-sudo/

View File

@ -1,24 +1,26 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-12933-1.html)
[#]: subject: (Optimize your GNOME experience with the Gedit text editor)
[#]: via: (https://opensource.com/article/20/12/gedit)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
使用 Gedit 文本编辑器优化你的 GNOME 体验
使用 gedit 文本编辑器优化你的 GNOME 体验
======
它是一个可以完成工作的简约编辑器,并以隐藏的增强功能使得事情更简单。
![Working from home at a laptop][1]
作为默认的文本编辑器是一项吃力不讨好的工作。人们通常把默认文本编辑器几乎看作是一个演示应用,一个稍微好一点的 “hello World” 示例,说明应用在该平台上的是如何运行的。在极少数情况下,当用户需要将一些文本保存到一个可能永远不会再看的文件中时,用户会找到默认文本编辑器。对于“严肃”的工作,他们会转向文字处理器或 IDE或终端中的编辑器或者至少是一个不同的文本编辑器必须像“真正的”应用一样下载和安装
> 它是一个可以完成工作的简约编辑器,并以隐藏的增强功能使得事情更简单。
很奇怪,默认的文本编辑器很难被人重视,然而 GNOME 桌面的编辑器 Gedit 却被广泛认为是一个真正有价值的文本编辑器,超越了它所在的桌面。它被用作网页设计课程的必备文本编辑器,是新手开发者和系统管理员的推荐工具,也是许多桌面 Linux 用户最喜欢的可靠伙伴。
![](https://img.linux.net.cn/data/attachment/album/202012/19/110419snchihpnjn8juxqc.jpg)
作为默认的文本编辑器是一项吃力不讨好的工作。人们通常把默认文本编辑器几乎看作是一个演示应用、一个稍微好一点的 “hello World” 示例,说明应用在该平台上的是如何运行的。在极少数情况下,当用户需要将一些文本保存到一个可能永远不会再看的文件中时,用户会找到默认文本编辑器。对于“严肃”的工作,他们会转向文字处理器或 IDE或终端中的编辑器或者至少是一个不同的文本编辑器必须像“真正的”应用一样下载和安装。
很奇怪,默认的文本编辑器很难被人重视,然而 GNOME 桌面的编辑器 gedit 却被广泛认为是一个真正有价值的文本编辑器,超越了它所在的桌面。它被用作网页设计课程的必备文本编辑器,是新手开发者和系统管理员的推荐工具,也是许多桌面 Linux 用户最喜欢的可靠伙伴。
### 安装 gedit
如果你运行的是 GNOME 桌面,你可能已经安装了 gedit尽管它可能只作为“文本编辑器”出现在你的应用菜单中。如果你不确定只需在你的活动界面中输入 **gedit**,然后在打开的文本编辑器中进入**关于**菜单项。
如果你运行的是 GNOME 桌面,你可能已经安装了 gedit尽管它可能只作为“文本编辑器”出现在你的应用菜单中。如果你不确定只需在你的活动界面中输入 `gedit`,然后在打开的文本编辑器中进入 “About” 菜单项。
![gedit terminal box with black background and white letters][2]
@ -28,7 +30,7 @@
### 使用 gedit
当你第一次启动 gedit 时,你会看到一个简约的界面,包括一个文本输入面板、一个标题栏和一个位于窗口底部的状态面板。底部的状态面板提供了一些常用的设置:你想使用哪种语法高亮模式、你喜欢的标签宽度、以及一些流行的偏好,如行号、文本换行等等。这些选项中的大部分也可以在“首选项”菜单中进行全局设置,它可在应用程序右上角的“汉堡”样式的菜单中找到。
当你第一次启动 gedit 时,你会看到一个简约的界面,包括一个文本输入面板、一个标题栏和一个位于窗口底部的状态面板。底部的状态面板提供了一些常用的设置:你想使用哪种语法高亮模式、你喜欢的制表符宽度、以及一些流行的偏好,如行号、文本换行等等。这些选项中的大部分也可以在 “Preferences” 菜单中进行全局设置,它可在应用程序右上角的 “汉堡” 样式的菜单中找到。
### gedit 的隐藏功能
@ -36,19 +38,17 @@
这些键盘功能在 gedit 中并没有被记录下来:
* **Ctrl+D** 删除当前行。这对于编码者或以 markdown 格式(如 Asciidoc、reST 或 CommonMark写作的人特别有用。
* **Ctrl+I** 会弹出 **Go to Line** 下拉框。输入一个数字,你就会立即跳到该行。
* **Alt+向上箭头** 或 **Alt+向下箭头** 会抓取当前行,并将它在文档中向上或向下移动。
* **Alt+向左箭头** 或 **Alt+向右箭头** 抓取最近的单词(在光标左侧)并将其向左或向右移动。
* 要输入特殊的 Unicode 字符,请按下并松开 **Shift+Ctrl+U**,然后输入 Unicode 字符代码。你通常必须查找字符代码(除非你已经记住了一些,但谁有记性来记住这些字符代码?)例如,要打出一只企鹅,按下然后松开 **Shift+Ctrl+U**。当你松开按键后,你会看到一个带下划线的 U然后输入 **1F427**,后面跟一个空格,你的 Unicode 字符就会变成一个友好的 🐧。诚然,这并不完全是 gedit 所独有的,但这是个很有用的技巧,而且它在 gedit 中也确实有效。
* `Ctrl+D` 删除当前行。这对于编码者或以标记格式(如 Asciidoc、reST 或 CommonMark写作的人特别有用。
* `Ctrl+I` 会弹出 “Go to Line” 下拉框。输入一个数字,你就会立即跳到该行。
* `Alt+向上箭头``Alt+向下箭头` 会抓取当前行,并将它在文档中向上或向下移动。
* `Alt+向左箭头``Alt+向右箭头` 抓取最近的单词(在光标左侧)并将其向左或向右移动。
* 要输入特殊的 Unicode 字符,请按下 `Shift+Ctrl+U` 并松开,然后输入 Unicode 字符代码。你通常必须查找字符代码(除非你已经记住了一些,但谁有记性来记住这些字符代码?)例如,要打出一只企鹅,按下 `Shift+Ctrl+U` 然后松开。当你松开按键后,你会看到一个带下划线的 U然后输入 `1F427`,后面跟一个空格,你的 Unicode 字符就会变成一个友好的 `🐧`。诚然,这并不完全是 gedit 所独有的,但这是个很有用的技巧,而且它在 gedit 中也确实有效。
### 稳定简单
Gedit 很像 GNOME 本身。它客观上比许多同类软件(比如 KDE 的 Kate更简单但它仍然能够满足你日常 80% 或 90% 的期望。
当然,可能会有一些任务 gedit 不是最佳工具。你可能会发现自己要深入研究一些独特的日志文件,或者需要一个精确的解析器或代码检查器,你会转向专门的应用。这没关系。Gedit 并不意味着对所有用户都适用。但对于那些需要文本编辑器的人来说,它是一个很好的文本编辑器,有时这就是所需要的。在 Linux 或者在任何你正在使用的平台上,试一下 gedit因为它很有可能是一个比默认的更好的选择。
当然,可能会有一些任务 gedit 不是最佳工具。你可能会发现自己要深入研究一些独特的日志文件,或者需要一个精确的解析器或代码检查器,你会转向专门的应用。这没关系。gedit 并不意味着对所有用户都适用。但对于那些需要文本编辑器的人来说,它是一个很好的文本编辑器,有时这就是所需要的。在 Linux 或者在任何你正在使用的平台上,试一下 gedit因为它很有可能是一个比默认应用的更好的选择。
--------------------------------------------------------------------------------
@ -57,7 +57,7 @@ via: https://opensource.com/article/20/12/gedit
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[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/) 荣誉推出

View File

@ -1,138 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (robsean)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to Write, Compile and Run a C Program in Ubuntu and Other Linux Distributions [Beginners Tip])
[#]: via: (https://itsfoss.com/run-c-program-linux/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
How to Write, Compile and Run a C Program in Ubuntu and Other Linux Distributions [Beginners Tip]
======
How do you program in C on Linux? It is indeed very easy and consists of three simple steps.
**Step 1**: You write your program and save the file with a .c extension. For example, my_program.c.
**Step 2**: You compile the program and generate the object file using gcc compiler in a terminal like this:
```
gcc -o my_program my_program.c
```
**Step 3**: You run the generated object file to run your C program in Linux:
```
./my_program
```
![][1]
This was just the quick summary on how to compile and run C program in Linux. If you are new to either C or Linux, Ill show these steps in detail so that you feel comfortable coding C program in Linux environment.
In fact, Ill discuss how to run C programs in Linux terminal as well as in code editor.
![][2]
### Method 1: How to run C programs in Linux terminal
In order to run a C program in Linux, you need to have a C compiler present on your systems. The most popular compiler is gcc ([GNU Compiler Collection][3]).
You can install gcc using your distributions package manager. In Debian and Ubuntu-based Linux distributions, use the apt command:
```
sudo apt install gcc
```
Switch to directory where you have kept your C program (or provide the path) and then generate the object file by compiling the program:
```
gcc -o my_program my_program.c
```
Keep in mind that it is optional to provide the output object file (-o my_program). If you wont do that, an object file named a.out will be automatically generated. But this is not good because it will be overwritten for each C program and you wont be able to know which program the a.out object file belongs to.
Once you have your object file generated, run it to run the C program. It is already executable. Simple use it like this:
```
./my_program
```
And it will display the desired output, if your program is correct. As you can see, this is not very different from [running C++ programs in Linux][4].
_**Every time you make a change in your program, you have to compile it first and then run the generated object file to run the C program.**_
### Method 2: How to run C programs in Linux using a code editor like Visual Studio Code
Not everyone is comfortable with command line and terminal and I totally understand that.
You can use a proper C/C++ IDE like Eclipse or Code Blocks but they are often too heavy programs and more suitable for large projects.
I recommend using an open source code editor like Visual Studio Code or Atom. These are basically text editors and you can install add-ons to compile and run programs directly from the graphical code editor.
I am using [Visual Studio Code editor][5] in this example. Its a hugely [popular open source code editor][6] from Microsoft.
First thing first, [install Visual Studio Code in Ubuntu][7] from the software center. For other distributions, please check your Linux distributions package manager or software center. You may also check the official website for more information.
Start Visual Studio Code and open/create a project and create your C program here. I am using a sample Hello World program.
![][8]
You must ensure that you have gcc compiler installed on your Linux system.
```
sudo apt install gcc
```
Next thing you would want is to use an extension that allows you to run the C code. Microsoft may prompt you for installing its own extension for C/C++ program but it is complicated to setup and hence I wont recommend it.
Instead, I suggest using the Code Runner extension. Its a no-nonsense extension and you can run C and C++ code easily without additional configuration.
Go to the Extensions tab and search for Code Runner and install it.
![Install Code Runner extension for running C/C++ program][9]
Restart Visual Studio Code. Now, you should be able to run the C code by using one of the following way:
* Using the shortcut Ctrl+Alt+N.
* Press F1 and then select or type Run Code.
* Right click the text editor and the click Run code from context menu.
![Right click the program file and choose Run Code][10]
When you run the program, it is compiled automatically and then run. You can see the output in terminal that is opened at the bottom of the editor. What could be better than this?
![Program output is displayed in the bottom section of the editor][11]
Which method do you prefer?
Running a few C programs in Linux command line is okay but using a code editor is much easier and saves time. Wont you agree?
I let you decide whichever method you want to use.
--------------------------------------------------------------------------------
via: https://itsfoss.com/run-c-program-linux/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/11/running-c-program-linux.png?resize=795%2C399&ssl=1
[2]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/11/Run-C-Program-Linux.png?resize=800%2C450&ssl=1
[3]: https://gcc.gnu.org/
[4]: https://itsfoss.com/c-plus-plus-ubuntu/
[5]: https://code.visualstudio.com
[6]: https://itsfoss.com/best-modern-open-source-code-editors-for-linux/
[7]: https://itsfoss.com/install-visual-studio-code-ubuntu/
[8]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/11/c-program-visual-studio-code-linux.png?resize=800%2C441&ssl=1
[9]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/11/running-c-program-in-linux-with-visual-studio-code.png?resize=800%2C500&ssl=1
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/11/running-c-program-in-linux-with-visual-studio-code.jpg?resize=800%2C500&ssl=1
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/11/run-c-program-in-linux-with-visual-studio-code.jpg?resize=800%2C500&ssl=1

View File

@ -0,0 +1,70 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Find out how your text will be read with Norka)
[#]: via: (https://opensource.com/article/20/12/norka)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
Find out how your text will be read with Norka
======
This is a no-frills text editor designed to provide insight into how
your writing will be read and understood.
![Reading a book, selfcare][1]
Some text editors are designed for programming, others for specialized text formats, others for document design. The Norka text editor is designed for reading. It might seem strange to create a text editor designed for _reading_, but actually, it makes a lot of sense if you think about it. Your text is written once or thrice, depending on your personal tolerance for iteration, but its meant to be read for years to come. Norka makes it easy for you to focus on how your writing is going to get read.
### Installing
The Norka text editor is licensed with an MIT license and can be [installed as a Flatpak on Linux][2]. It is open source, so if you want to try your hand at installing it on a different platform, you may [clone its Github repository][3].
### Norka interface
The Norka interface is simple—a button back to your Norka document collection, an export button, and a preference menu. The rest of the window is blank space for you to write text into, and in the bottom right corner, theres a read time calculator to help you understand how long it might take for readers to get through what youve written.
![Dark Norka terminal box with green and white text][4]
Thats nearly all there is to Norka. There are no page breaks or line numbers, no code-folding or regex searches. This is an editor meant for text writing words, not styling documents or keeping track of a complex data schema.
There are, of course, some extra features. Copy and paste work as expected with **Ctrl+C** and **Ctrl+V**. You can undo with **Ctrl+Z** and find with **Ctrl+F**. You can even insert emoji with **Ctrl+:**.
![Norka terminal box with pop up box of emoji search menu][5]
#### Styling text
While Norka definitely has no interest in helping you design, say, a brochure or flyer, it does have some ability to indicate how you want your text styled. It does this through [Markdown][6], a simple convention for writing in plain text but with special notation to indicate how the text should be rendered later in HTML or EPUB or PDF or whatever your destination may be.
In most editors, you have to know Markdown to use Markdown, but Norka translates common word processor keyboard shortcuts to produce Markdown for you. For instance, to make a word bold, you can press **Ctrl+B**, which inserts four asterisks on either side of your cursor. When you type the next word, its surrounded on either side with two asterisks, which is the Markdown notation for strong (rendered in boldface by default) text. You can view all Markdown shortcuts in the hamburger menu in the upper-right corner of the Norka window.
#### Saving and exporting
You can think of Norka like a notebook. All of the documents you start in Norka remain in Norkas internal database, and everything is saved automatically by default. To work with a file outside of Norka, you use the **Share** button in the top right corner of your open document. Alternately, you can right-click on any document from Norka's file view and select **Export**. You can export (or _share_—Norka uses both terms interchangeably) a document to **Text**, **HTML**, or **Markdown**.
### Try Norka
Norka is easy to try and easy to use. It helps you focus on writing by keeping its interface simple, almost to the point of restriction. But restrictions can be a powerful creative tool, sometimes.
Norka might not be your best choice for heavy revisions or text processing. It doesnt have exciting features like case conversion, integrated **sed** commands, character swapping, and so on. Its a text writer for readers. If that makes sense to you, then you may be just the audience Norka is seeking.
Thanks for spending two minutes and 39 seconds reading this article!
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/12/norka
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/reading_book_selfcare_wfh_learning_education_520.png?itok=H6satV2u (Reading a book, selfcare)
[2]: https://flathub.org/apps/details/com.github.tenderowl.norka
[3]: https://github.com/TenderOwl/Norka
[4]: https://opensource.com/sites/default/files/uploads/norka-31_days-norka-opensource.png (Dark Norka terminal box with green and white text)
[5]: https://opensource.com/sites/default/files/uploads/norka_emoji-31_days-norka-opensource.png (Norka terminal box with pop up box of emoji search menu)
[6]: https://opensource.com/article/19/9/introduction-markdown

View File

@ -1,122 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to Install RPM Files on Fedora Linux [Beginners Tutorial])
[#]: via: (https://itsfoss.com/install-rpm-files-fedora/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
How to Install RPM Files on Fedora Linux [Beginners Tutorial]
======
_**This beginner article explains how to install RPM packages on Fedora and Red Hat Linux. It also shows you how to remove those RPM packages afterwards.**_
When you start using Fedora Linux in the Red Hat domain, sooner or later, youll come across .rpm files. Like .exe files in Windows and .deb files in Ubuntu and Debian, .rpm files enable you to quickly install a software from it on [Fedora][1].
You could find and install plenty of software from the software center, specially [if you enable additional repositories in Fedora][2]. But sometimes youll find software available on their website in RPM format.
Like .exe files in Windows, you **download the .rpm file and double click on it to install it**. Dont worry, Ill show you the detailed steps.
### Installing RPM files on Fedora and Red Hat Linux
Ill be showing you three ways to install RPM files:
* [Install RPM files with software center][3] (GUI method)
* [Install RPM files using DNF command][4] (CLI method)
* [Install RPM files using Yum command][5] (CLI method for Red Hat)
#### Method 1: Use software center
The simplest method is to use the default software center in Fedora. Its really simple. Go to the folder where you downloaded the .rpm file. It is usually the Downloads folder.
Just **double click on the RPM file and it will be opened in the software center**.
Alternatively, you can right click on the file and choose to install it via Software Center.
![Either double click or right click and choose Software Install][6]
When it is opened in the software center, you should see the installation option. Just hit the install button and enter your accounts password when prompted for it.
![Install RPM via Fedora Software Center][7]
Its easy, right?
#### Method 2: Use DNF command to install RPM file
This is the command line method. Fedora uses the new DNF [package manager][8] and you can use it to install downloaded RPM files as well.
Open a terminal and switch to the directory where you have the RPM file downloaded. You can also provide the path to the RPM file. Use the DNF command like this:
```
sudo dnf install rpm_file_name
```
Heres a screenshot where I installed [Google Chrome on Fedora with dnf command][9]:
![Installing RPM files using DNF command][10]
#### Method 3: Install RPM files in Red Hat using Yum command
Unlike Fedora, Red Hat still uses the good old Yum package manager. You wont find the DNF command here, yet.
The process is the same as DNF command. You go to the directory where the RPM file is located or provide its path.
```
sudo yum install path_to_RPM_file
```
Thats it. Nothing fancier.
### How to remove RPM packages
Removing a RPM package isnt a big deal either. And no, you dont need the original rpm file that you used to install the program.
You may find the installed package in the software center and remove application from there.
![Removing RPM Package][11]
Alternatively, you can use the DNF or YUM command with `remove` option.
With DNF, use this command:
```
sudo dnf remove rpm_package_name
```
With Yum, use this command:
```
sudo yum remove rpm_package_name
```
You probably wont remember the exact package name and thats fine. What you can do is to type the first few letters of the package and then hit tab. This is assuming that you have tab completion enabled which usually is.
And thats all you need to do here. Pretty simple, right? Being a beginner, you may struggle with a simple task like this and I hope you feel more confident with Fedora thanks to quick tutorials like this.
--------------------------------------------------------------------------------
via: https://itsfoss.com/install-rpm-files-fedora/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://getfedora.org/
[2]: https://itsfoss.com/fedora-third-party-repos/
[3]: tmp.TvkJtlRJ6T#gui-method
[4]: tmp.TvkJtlRJ6T#use-dnf
[5]: tmp.TvkJtlRJ6T#use-yum
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/installing-rpm-file-fedora.png?resize=800%2C449&ssl=1
[7]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/12/install-rpm-fedora-software-center.jpg?resize=799%2C193&ssl=1
[8]: https://itsfoss.com/package-manager/
[9]: https://itsfoss.com/install-google-chrome-fedora/
[10]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/12/install-rpm-using-dnf-install.jpg?resize=800%2C474&ssl=1
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/remove-rpm-package-fedora.jpg?resize=790%2C190&ssl=1

View File

@ -0,0 +1,68 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (The role of empathy in DevOps)
[#]: via: (https://opensource.com/article/20/12/empathy-devops)
[#]: author: (Will Kelly https://opensource.com/users/willkelly)
The role of empathy in DevOps
======
DevOps is all about people, and people need empathy to thrive and be
productive. Here's how to build it into your team.
![Teamwork starts with communication across silos][1]
DevOps teams dig in their heels for strength as they face stress and challenges at work and home. Its not something covered in the [DevOps manifesto][2]. Theres also no software you can integrate into your toolchain to help either. What needs to happen is your DevOps teams need to put empathy before tools.
In his book, _[The DevOps Paradox][3]_, Viktor Farcic reasons, if DevOps is, at a fundamental level, about getting different teams to collaborate, you could say that DevOps is a discipline that promotes empathy.
### Recognizing DevOps is a people game
If you agree with Farcic, you see DevOps, at its roots, as a people game. When I was coming up in the tech industry as a technical writer, I realized that development and operations teams spoke different languages. They also had their own cultures. These differences were at the root of arguments between those teams.
"Over the last few decades, though, the notion that empathy cannot co-exist with critical thinking has been slowly diminishing, but not fast enough to have a widespread impact within our industry," according to _[InfoQ][4]_.
Empathy becomes part of the DevOps equation as you develop [more partnerships][5] across your software delivery and business organizations. The silos that arise during waterfall software development include those between software developers, security, and operations. Cultural stereotypes abound between departments. Some software developers are OK with breaking things. The security team is the department of "no." Operations teams want to maintain a pristine operational state, never taking risks, while abiding by their service level agreements (SLAs). Lets not forget that business stakeholders may be out of touch with all those operations. Poking and jabbing at each others real or perceived competence is counterproductive. Talking to each other and learning the other teams processes, appreciating what keeps them up at night, is a powerful step to understanding each other.
The cross-team relationships prevalent in DevOps make empathy necessary. Theres no room in a DevOps toolchain for the stereotypical animosity between developers, operations, and security. Keep your communications channels open. Encourage a culture where making mistakes is about learning and change, not recriminations.
### Practicing empathy in DevOps
Promoting empathy throughout the team is a must for DevOps managers. As a manager, you need to look for opportunities to embed technologists across your business units for one. Getting people to talk across teams is another crucial goal for managers. While DevOps aims to break down silos, it doesnt mean that old rivalries from your pre-DevOps world will go away overnight.
Building empathy as a team isnt about watching an online training video and clicking through a quiz to receive a PDF of a certificate of completion. It starts with relationship building. Look for opportunities to cross-train team members in other jobs. Its not about preparing them to do the job; its about showing them the challenges their other team members face and facilitating knowledge transfer. Manage change in iterations and give your team—developers and sysadmins alike—a feedback channel where problems, challenges, and victories can get the ear of management and their team members.
Empathy powers productivity because it gives your team members a sense of safety, which is a feeling that may be in short supply right now for some team members. Empathy and a little understanding can take some pressure off team members, giving them some more fuel to focus on their tasks at hand.
### Providing empathy as a developer
You also must treat your customer conversations with empathy. Whether your DevOps team is serving internal or external customers, youre bound to notice some personal and business changes in the customer. Leading organizations create value and show empathy in several ways: streamlining or simplifying the customer experience, reacting to the market and environmental changes in near real-time, and predicting customer needs ahead of time, according to _[The Enterprisers Project][6]_.
Other industry watchers see that developers with empathy are best prepared for the rise of artificial intelligence (AI) and empathy helps DevOps teams adjust to more agile forms of thinking.
### Empathy and remote DevOps during COVID-19
Providing empathy during this time starts with remembering that you dont know what somebody is going through when the web conferencing camera is off. Its something Ive had to remind myself a bunch of times since the beginning of the pandemic.
The next steps for remote work are different for all of us. Some DevOps teams will return to their offices at some point in 2021. Some may find themselves in hybrid working arrangements while other groups may remain remote. Unfortunately, some DevOps teams may split up as their employers conduct layoffs, and lucky coworkers land new positions with other employers. As in our personal lives, each unique and developing work situation requires a measure of empathy to help steer the team through change.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/12/empathy-devops
作者:[Will Kelly][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/willkelly
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/happy-team-sticker-laptop.png?itok=91K77IgE (Teamwork starts with communication across silos)
[2]: https://sites.google.com/a/jezhumble.net/devops-manifesto/
[3]: https://www.amazon.com/DevOps-Paradox-truth-about-people/dp/1789133637
[4]: https://www.infoq.com/articles/guide-empathy-boost-career/
[5]: https://enterprisersproject.com/article/2020/8/it-leadership-how-build-empathy
[6]: https://enterprisersproject.com/article/2020/7/customer-experience-how-develop-empathy

View File

@ -0,0 +1,190 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Using pods with Podman on Fedora)
[#]: via: (https://fedoramagazine.org/podman-pods-fedora-containers/)
[#]: author: (Darshna Das https://fedoramagazine.org/author/climoiselle/)
Using pods with Podman on Fedora
======
![Using Pods with Podman][1]
Photo by [Dick Martin][2] on [Unsplash][3]
This article shows the reader how easy it is to get started using pods with Podman on Fedora. But what is Podman? Well, we will start by saying that Podman is a container engine developed by Red Hat, and yes, if you thought about Docker when reading container engine, you are on the right track. A whole new revolution of containerization started with Docker, and Kubernetes added the concept of pods in the area of container orchestration when dealing with containers that share some common resources. But hold on! Do you really think it is worth sticking with Docker alone by assuming its the only effective way of containerization? Podman can also manage pods on Fedora as well as the containers used in those pods.
> [Podman][4] is a daemonless, open source, Linux native tool designed to make it easy to find, run, build, share and deploy applications using Open Containers Initiative ([OCI][5]) [Containers][6] and [Container Images][7].
>
> From the official Podman documentation at <http://docs.podman.io/en/latest/>
### Why should we switch to Podman?
Podman is a daemonless container engine for developing, managing, and running OCI Containers on your Linux System. Containers can either be run as root or in rootless mode. Podman directly interacts with an image registry, containers and image storage.
### Install Podman:
```
sudo dnf -y install podman
```
### Creating a Pod:
To start using the pod we first need to create it and for that we have a basic command structure
```
```
$ podman pod create
```
```
![][8]
The command above contains no arguments and hence it will create a pod with a randomly generated name. You might however, want to give your pod a relevant name. For that you just need to modify the above command a bit.
```
```
$ podman pod create --name climoiselle
```
```
![][9]
The pod will be created and will report back to you the ID of the pod. In the example shown the pod was given the name climoiselle. To view the newly created pod is easy by using the command shown below:
```
```
$ podman pod list
```
```
![Newly created pods have been deployed][10]
As you can see, there are two pods listed here, one named darshna and the one created from the example named climoiselle. No doubt you notice that both pods already include one container, yet we sisnt deploy a container to the pods yet. What is that extra container inside the pod? This randomly generated container is an infra container. Every podman pod includes this infra container and in practice these containers do nothing but go to sleep. Their purpose is to hold the namespaces associated with the pod and to allow Podman to connect other containers to the pod. The other purpose of the infra container is to allow the pod to keep running when all associated containers have been stopped.
You can also view the individual containers within a pod with the command:
```
```
$ podman ps -a --pod
```
```
![][11]
### Add a container
The cool thing is, you can add more containers to your newly deployed pod. Always remember the name of your pod. Its important as youll need that name in order to deploy the container in that pod. Well use the official ubuntu image and deploy a container using it running the top command.
```
```
$ podman run -dt --pod climoiselle ubuntu top
```
```
![][12]
### Everything in a Single Command:
Podman has an agile characteristic when it comes to deploying a container in a pod which you created. You can create a pod and deploy a container to the said pod with a single command using Podman. Lets say you want to deploy an NGINX container, exposing external port 8080 to internal port 80 to a new pod named test_server.
```
```
$ podman run -dt --pod new:test_server -p 8080:80 nginx
```
```
![Created a new pod and deployed a container together][13]
Lets check all pods that have been created and the number of containers running in each of them …
```
```
$ podman pod list
```
```
![List of the containers, their state and number of containers running into them][14]
Do you want to know a detailed configuration of the pods which are running? Just type in the command shown below:
```
```
podman pod inspect [pod's name/id]
```
```
![][15]
### Make it stop!
To stop the pods, we need to use the name or ID of the pod. With the information from podmans pod list command, we can view the pods and their infra id. Simply use podman with the command stop and give the particular name/infra id of the pod.
```
```
$ podman pod stop climoiselle
```
```
![][16]
### Hey take a look!
![My pod climoiselle stopped][17]
After following this short tutorial, you can see how quickly you can use pods with podman on fedora. Its an easy and convenient way to use containers that share resources and interact together.
### Further reading
The fedora Classrom article <https://fedoramagazine.org/fedora-classroom-containers-101-podman/>. A good starting point for beginners <https://developers.redhat.com/blog/2018/02/22/container-terminology-practical-introduction/>. An article on capabilities and podman <https://fedoramagazine.org/podman-with-capabilities-on-fedora/>. Podmans documentation site <http://docs.podman.io/en/latest/>.
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/podman-pods-fedora-containers/
作者:[Darshna Das][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://fedoramagazine.org/author/climoiselle/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2020/12/using-pods-w-podman-816x346.png
[2]: https://unsplash.com/@dick42420?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
[3]: https://unsplash.com/s/photos/seals-in-canada?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
[4]: http://podman.io
[5]: https://www.opencontainers.org/
[6]: https://developers.redhat.com/blog/2018/02/22/container-terminology-practical-introduction/#h.j2uq93kgxe0e
[7]: https://developers.redhat.com/blog/2018/02/22/container-terminology-practical-introduction/#h.dqlu6589ootw
[8]: https://fedoramagazine.org/wp-content/uploads/2020/12/Podman0-1-1-1024x328.png
[9]: https://fedoramagazine.org/wp-content/uploads/2020/12/Podman1-1-1024x355.png
[10]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman3-1024x334.png
[11]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman4-1-1024x221.png
[12]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman8-1024x739.png
[13]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman9-1024x348.png
[14]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman10-1024x341.png
[15]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman5-808x1024.png
[16]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman11-1024x279.png
[17]: https://fedoramagazine.org/wp-content/uploads/2020/12/podman12-1024x362.png

View File

@ -0,0 +1,84 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (6 ways this fullscreen text editor improves focus)
[#]: via: (https://opensource.com/article/20/12/focuswriter)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
6 ways this fullscreen text editor improves focus
======
This fullscreen editor helps you set your writing goals and keeps
distractions to a minimum so you can achieve them.
![Typewriter with hands][1]
The great thing about computers is that theyre really good at multi-tasking.
The bad thing about computers is that theyre really good at multi-tasking.
Whether you consider yourself, as a human, good or bad at multi-tasking, sometimes you need a little help focusing. One of those times is when youre trying to compose clear and concise communication. And thats exactly why Focuswriter was developed.
### Install
On Linux, you can install Focuswriter as a Flatpak from [Flathub][2].
On Windows or Linux (if you dont use Flatpak), you can [install Focuswriter from its website][3]. You can also install from source code, also available from the Focuswriter webpage.
### Using Focuswriter
Focuswriter is, admittedly, actually a cross between a text editor and a word processor. Its default format is the Open Document Text (.odt) format, so it allows you to style and align text, mark headers, and toggle smart quotes on and off. But thats where its word processor features end because Focuswriter does mostly focus on _writing_, not on styling what youve written.
Focuswriter encourages focus in a few different ways.
#### Attractiveness
Focuswriter doesnt look like your usual computer application, much less your usual text editor. When it launches, it loads a theme behind your document. The theme is generally benign—a writing desk is the default, but theres also a starry sky, a faraway landscape, and so on. Youre not meant to become preoccupied with the theme, of course, but it does help you from getting distracted by some other application window or your computer desktop lingering behind your editor. Because its easy to customize, theres little chance of you being left without a theme you like.
![Focuswriter white box with gray wording on wooden writing desk background theme][4]
#### Sound effects
Focuswriter is actually fun to use. Aside from its visual theme, it also has an _optional_ typewriter audio theme. Once enabled, every keypress makes the sound of a mechanical typewriter key. When you press **Return**, the satisfying sound of a carriage return is your reward for completing a paragraph (or a line, if you write one sentence per line to improve version control).
This audio theme is entirely opt-in, and its not on by default. You may doubt its efficacy, but you shouldnt underestimate the satisfaction of making those sounds of productivity while also wielding the powers of modern text editing.
#### Fullscreen display
Focuswriter not only launches fullscreen by default, but it also hides its menus and other widgets from view. To access the main menu bar, you place your cursor to the top of your screen until it appears. Theres a scroll bar hidden on the right, a document switcher widget on the left, and a status bar at the bottom.
#### Minimalism
There isnt much to Focuswriters editing capabilities. It doesnt have advanced search options or specialized options for code formatting or syntax highlighting. It lets you write text, and little else, into a document, by design. Even the contextual right-click menu only offers basic editing functions (copy, cut, paste, and so on) or spell-checking options.
#### Line focus
Another optional feature of Focuswriter is its ability to "grey out" all lines of text but your current one. This helps your eyes lazily locate your current line of text, which can be especially helpful if youre not a touch-typist or if youre transcribing something youve handwritten on physical paper and must look away from the screen often.
#### Goal tracker
You can set a daily word count goal or a timed goal for yourself in Focuswriters preferences. Your progress is tracked as you work and displayed in the status bar at the bottom of the screen. Its hidden from your view unless you hover your cursor over it, so youre not compelled to obsess over it, but its convenient enough to help you stay on track.
### Try Focuswriter (even if you think its silly)
Ive heard about fullscreen text editors before, and Ive never felt it was important for me to try one. After all, nearly any application can be made fullscreen, and I dont personally have trouble focusing anyway.
Having tried Focuswriter, though, I understand the appeal of a good fullscreen "focus first" text editor. It may not be necessary, but then again, open source is thriving. We have the luxury of redundant sets of applications that have minor differences in function but major differences in implementation. Focuswriter makes writing fun; it makes the work enjoyable. Download it, set a goal, and get writing!
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/12/focuswriter
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/typewriter-hands.jpg?itok=oPugBzgv (Typewriter with hands)
[2]: https://flathub.org/apps/details/org.gottcode.FocusWriter
[3]: https://gottcode.org/focuswriter/
[4]: https://opensource.com/sites/default/files/uploads/focuswriter-31_days_focuswriter-opensource.png (Focuswriter white box with gray wording on wooden writing desk background theme)

View File

@ -0,0 +1,242 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Learn a new old language by programming a game in Algol 68)
[#]: via: (https://opensource.com/article/20/12/learn-algol-68)
[#]: author: (Chris Hermansen https://opensource.com/users/clhermansen)
Learn a new old language by programming a game in Algol 68
======
Even "dead languages" can teach you a lot about programming today.
![Old UNIX computer][1]
In this article series, Opensource.com [Correspondents][2] and others have been writing the same "guess the number" game in various programming languages. This exercise shows how the basic concepts you'll find in most programming languages—variables, expressions, and statements—can be applied to learn new languages.
Most languages have a "way of doing things" that's supported by their design, and those ways can be quite different from one program to another. These ways include modularity (grouping related functionality together), declarative vs. imperative, object-orientation, low- vs. high-level syntactic features, and so on.
In the "guess the number" program, the computer picks a number between one and 100 and asks you to guess the number. The program loops until you guess the right answer.
In this article, I'll show you how to write this application in Algol 68. I'll also try to exercise the following concepts you'll find in any programming language:
* Variables
* Input
* Output
* Conditional evaluation
* Loops
### Guess the number in Algol 68
This example uses the [Algol 68][3] Genie compiler, available in many Linux distros, created by [Marcel Van Der Veer][4].
OK, I can hear some of you out there moaning, "oh no, why Algol 68? That language is so old and has been irrelevant since before there were implementations." And I respect your opinions, I really do. Really. But I believe many cool things exist in today's programming languages that come from the hard thinking done by the designers of Algol 68, which justifies learning a bit about the language.
Algol 68 is statically typed and not particularly verbose. Algol 68 Genie compiles and executes in one go, so Algol 68 can feel a bit like a scripting language. The Genie implementation offers many useful hooks into our favorite operating system, which keeps it from feeling horribly dated and means a fair bit of useful work can be done with it.
Some points worth mentioning at the outset:
* One of Algol 68's design principles is letting anything that could reasonably be thought of as an expression (a construct that delivers a value) be legal code.
* Algol 68 "reserved words" are typically expressed as boldface symbols in the program source, which is kind of hard to do with text files, so most compilers have a way of indicating that a token is a reserved word. In Algol 68 Genie, the default is to use all upper case letters; for example, `BEGIN`, `IF`, `THEN`, etc.
* Speaking of things like `BEGIN … END`, `IF … THEN … ELSE`, Algol 68 has a "closed syntax." A `BEGIN` must have a corresponding `END`, similar to `{ }` in C or Java; an `IF` must have a `FI`, and a `DO` must have an `OD`.
* Algol 68 generally treats whitespace as irrelevant—even within numbers or variable names. Therefore, `myvariablename` and `my variable name` (and even `myvar iablename`) all refer to the same variable.
* Algol 68 requires "go on symbols"—semicolons—between (but not following) statements in a sequence to be evaluated statement-by-statement.
* Algol 68 incorporates a "string" type but does not provide a rich set of string processing primitives, which can be a bit frustrating.
* Algol 68 is imperative rather than declarative and not object-oriented.
With that preamble, here is my "guess the number" implementation (with line numbers to make it easier to review some of the specific features):
```
 1      on logical file end (stand in,
 2          (REF FILE f) BOOL: (print(("Goodbye!",new line));stop));
       
 3      first random(42);
 4      INT random number = ENTIER (next random * 100.0) + 1;
       
 5      print(("the secret number is",random number,new line));
       
 6      print("guess a number: ");
 7      WHILE
 8          INT guess = read int;
 9          IF guess &lt; random number THEN
10              print("too low, try again: ");
11              TRUE
12          ELIF guess &gt; random number THEN
13              print("too high, try again: ");
14              TRUE
15          ELSE
16              print(("that's right",new line));
17              FALSE
18          FI
19      DO SKIP OD
```
### Breaking it down
Jumping right in: lines 1 and 2 define what happens when an end of file is detected on the input coming from the console.
This situation is managed by calling the procedure `on logical file end` and passing two arguments: a file to be monitored and a procedure to be called when the end of file is detected. The file you want to monitor is the standard input, `stand in`. Line 2 is the definition of the procedure; this is an expression that yields a procedure. It has one parameter, which is a pointer to a file named "f" that is written as `REF FILE f`. It returns a boolean value, indicated by `BOOL`.
The text after the `:` is the procedure body, which:
* Starts with a brief begin symbol, `(`
* Is followed by a call to the `print` procedure with a list of two arguments, the string `"Goodbye!"` and the `new line` procedure that will emit a newline in the output stream
* Is followed by a "go on symbol"—the semicolon
* Is followed by a call to the procedure `stop`
* Is followed by the brief end symbol, `)`
* Is followed by the parenthesis closing the list of arguments to the "on logical file end "call
* Is followed by the "go on symbol," `;`
More verbosely, I could have written this procedure definition as:
```
(REF FILE f) BOOL: BEGIN
     print(("Goodbye!",new line));
     stop
END
```
It's probably worth mentioning that Algol 68 makes a very strong distinction between values and references to values. An Algol 68 value is conceptually similar to a constant or immutable or final value seen in many of today's popular programming languages. A value cannot be changed. A reference to a value, on the other hand, essentially defines a location where a value can be stored and the contents of that location can be changed. This corresponds to a variable, or mutable, or non-final value.
By way of concrete examples:
```
`INT forty two = 42`
```
defines an "integer value" named `forty two`, which evaluates to the number `42`.
And:
```
`INT fink := 42`
```
defines an integral variable `fink` and uses `:=` to assign the value `42` to it. This expression is actually shorthand for:
```
REF INT fink = LOC INT;
fink := 42
```
This makes the correspondence between values (`INT forty two`) and variables (`REF INT fink`) clearer at the expense of some verbosity. The `LOC INT` thing is a "local generator"—space for an integer value is allocated on the stack. There is also a "heap generator" useful for building structures that persist across procedure calls.
Phew! Back to the code.
Lines 3 and 4 initialize the system random number generator by calling the "setup" procedure first random() with an integer "seed" argument (which kinda hasta be 42, right?), then calling the procedure next random—which takes no arguments and therefore doesn't require parentheses with nothing between—and multiplies that by 100 to give a result between 0.0 and 99.9999…, truncating the result created using the unary operator ENTIER to give a result between 0 and 99, and finally adding 1 to give a result between 1 and 100.
Worth mentioning at this point is that Algol 68 seems to be the first language to support the definition of unary and binary operators, which are distinct from procedures. You must put parentheses around the expression:
```
`next random * 100.0`
```
because otherwise `ENTIER` would bind to the next random, giving the number 0, rather than to the whole expression.
On line 5 is a call to the `print` procedure, which is used here as a debugging thing. Notice the nested parentheses; `print` takes an argument that is either a printable value or expression or a list of printable values or expressions. When it's a list, you use a "denotation," which opens and closes with parentheses.
Line 6 uses `print` again to offer the single string `guess a number:`.
Lines 7 through 20 are a `WHILE … DO … OD` loop. A few interesting things here: First, all the work is done as a part of the logical expression evaluated by the `WHILE`, so the body of the loop contains only the reserved word `SKIP`, which means "do nothing."
Lines 8 through 17 are a sequence of two statements: the definition of the integer value `guess`, which is obtained by calling the procedure `read int` to get an integer from the input, followed by the `IF … THEN … ELIF … ELSE … FI` statement. Note that each of the `THEN`, `ELIF`, and `ELSE` parts end with a boolean value `TRUE` or `FALSE`. This causes the whole `IF… FI` statement to return either `TRUE` or `FALSE`, which, being the last statement in the sequence of statements, is the value "delivered" to `WHILE` to determine whether to loop around again or not.
A more typical language might have a structure similar to:
```
boolean doAgain = true;
while (doAgain) {
       if less then
            doAgain = true
       else if more then
            doAgain = true
       else
            doAgain = false
}
```
Because Algol 68 is expression-oriented, you don't need to declare that variable `doAgain`; you just incorporate the values to be generated into the expression being evaluated by the `WHILE` part.
What's cool about this is you can do things like the ternary operator in C—except much more broadly and better—with the standard `IF...FI`:
```
`do again := IF guess < random number THEN print("something"); TRUE ELIF guess > random number THEN print("something else"); TRUE ELSE print("another thing"); FALSE FI`
```
Note that I also took care not to declare anything as a mutable value when unnecessary. Since the value `guess` only has the scope of the `WHILE` loop, it just defines a new value each time.
One nagging little problem I didn't handle stems from the use of `read int`; if the frustrated user types in a value that is not convertible to an integer, the program will stop with an error condition. You could manage this problem by calling the procedure `on value error`, which is similar to the `on logical file end` procedure. I'll leave that for you to figure out. You didn't think you'd get away from this without an exercise, did you?
### What we learned
In the introduction, I listed the programming concepts this exercise should explore. How did I do?
* **Variables:** This shows that Algol 68 thinks of variables as named locations and supports named (immutable) values.
* **Input:** It used `stand in` as predefined console input and handled end-of-file conditions.
* **Output:** It used `print` to print messages on the console.
* **Conditional evaluation:** It used Algol 68 `if-then-else-fi` and `if` statements as expressions.
* **Loops:** It used Algol 68's `while` loop, including using a sequence of statements to calculate the value to be tested.
It also used some Algol 68 standard library (which Algol 68 calls "standard prelude") functionality, including the random number generator and I/O exception testing.
Run the program:
```
$ a68g guess.a68
the secret number is        +26
guess a number: 50
too high, try again: 25
too low, try again: 37
too high, try again: 31
too high, try again: 28
too high, try again: 26
that's right
$
```
One thing I didn't cover is comments. In Algol 68 Genie, comments can begin and end with the symbol `COMMENT`, or `CO`, or `#`, as in:
```
`# this is a comment #`
```
If you're interested in exploring Algol 68, take a look at [Marcel's site][4] or the many contributed solutions in Algol 68 on [Rosetta Code][5].
In closing, back to the "dead languages" thing. Yes, it's a bit of an esoteric pursuit. But learning obscure languages is a great way to appreciate how far we've come (or, in some cases, not) and to give a more rounded perspective on language features we take for granted.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/12/learn-algol-68
作者:[Chris Hermansen][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/clhermansen
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/retro_old_unix_computer.png?itok=SYAb2xoW (Old UNIX computer)
[2]: https://opensource.com/correspondent-program
[3]: http://www.algol68.org/
[4]: https://jmvdveer.home.xs4all.nl/en.algol-68-genie.html
[5]: http://www.rosettacode.org/wiki/Rosetta_Code

View File

@ -1,154 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (zhangxiangping)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How I use Python to map the global spread of COVID-19)
[#]: via: (https://opensource.com/article/20/4/python-map-covid-19)
[#]: author: (AnuragGupta https://opensource.com/users/999anuraggupta)
如何使用Python绘制COVID-19的全球扩散图
======
使用这些开源框架创建一个彩色地图,显示病毒的可能的传播路径。![Globe up in the clouds][1]
在全球范围内的旅行中疾病的传播是一个令人担忧的问题。一些组织会跟踪重大的流行病还有所有普遍的流行病并将他们的跟踪工作获得的数据公开出来。这些原生的数据对人来说可能很难处理这就是为什么数据科学如此重要的原因。比如将COVID-19在全球范围内的传播路径用Python和Pandas进行可视化可能对这些数据的分析有所帮助。
最开始当面对如此大数量的原始数据时可能难以下手。但当你开始处理数据之后慢慢地就会发现一些处理数据的方式。下面是用于处理COVID-19数据的一些常见的情况
1. 从Github上下载COVID-19的国际间每日传播数据保存为一个Pandas中的DataFrame对象。这时你需要使用Python中的Pandas库。
2. 处理并清理下载好的数据使其满足可视化数据的输入格式。所下载的数据的情况很好数据规整。这个数据有一个问题是它用国家的名字来标识国家但最好是使用ISO 3码国家代码表来标识国家。为了生成三位ISO 3码可是使用pycountry这个Python库。生成了这些代码之后可以在原有的DataFrame上增加一列然后用这些代码填充进去。
3. 最后为了可视化使用Plotly库中的**express**模块。这篇文章是使用choropleth maps在Plotly库中来对疾病在全球的传播进行可视化的。
### 第一步Corona数据
从下面这个网站上下载最新的corona数据译者注2020-12-14仍可访问有墙
<https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv>
我们之间将这个下载好的数据载入为Pandas的DataFrame。Pandas提供了一个函数 **read_csv()**可以直接使用URL读取数据并返回一个DataFrame对象具体如下所示
```
import pycountry
import plotly.express as px
import pandas as pd
URL_DATASET = r'<https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv>'
df1 = pd.read_csv(URL_DATASET)
print(df1.head(3))  # Get first 3 entries in the dataframe
print(df1.tail(3))  # Get last 3 entries in the dataframe
```
在Jupyter上的输出截图
![Jupyter screenshot][2]
从这个输出可以看到这个DataFramedf1包括以下几列数据
1. Date
2. Country
3. Confirmed
4. Recovered
5. Dead
之后还可以看到**Date**这一列包含了从1月22日到3月31日的条目信息。这个数据是每天更新的所以你会得到你当天的值。
### 第二步:清理和修改数据框
我们要往这个DataFrame中增加一列数据就是那个包含了ISO 3编码。可以通过以下三步完成这个任务
1. 创建一个包含所有国家的list。因为在**df**的**Country**列中,国家都是每个日期就重复一次。所以实际上**Country**列中对每个国家就会有多个条目。我使用**unique().tolist()**函数完成这个任务。
2. 我使用**d_country_code**字典对象初始为空然后将其键设置为国家的名称然后它的值设置为其对应的ISO 3编码。
3. 我使用**pycountry.countries.search_fuzzy(country)**为每个国家生成ISO 3编码。你需要明白的是这个函数的返回值是一个**Country**对象的list。我将这个函数的返回值赋给country_data对象。之以这个对象的第一个元素序号0为例。这个**\**对象有一个**alpha_3**属性。所以我使用**country_data[0].alpha_3**就能"获得"第一个元素的ISO 3编码。然而在这个DataFrame中有些国家的名称可能没有对应的ISO 3编码比如有争议的领土。那么对这些“国家”我就用一个空白字符串来替代ISO编码。你也可以用一个try-except代码来替换这部分。except中的语句可以写**print(_could not add ISO 3 code for -&gt;'_, country)**。这样就能在找不到这些“国家”对应的ISO 3编码时给出一个输出提示。实际上你会发现这些“国家”会在最后的输出中用白色来表示。
4. 在获得了每个国家的ISO 3编码有些是空白字符串之后我把这些国家的名称作为键还有国家对应的ISO 3编码作为值添加到之前的字典**d_country_code**中。可以使用Python中字典对象的**update()**方法来完成这个任务。
5. 在创建好了一个包含国家名称和对应ISO 3编码的字典之后我使用一个简单的循环将他们加入到DataFrame中。
### 第三步使用Plotly可视化传播路径
choropleth图是一个由彩色多边形组成的图。它常常用来表示一个变量在空间中的变化。我们使用Plotly中的**px**模块来创建choropleth图具体函数为**px.choropleth**。
这个函数的所包含的参数如下:
```
`plotly.express.choropleth(data_frame=None, lat=None, lon=None, locations=None, locationmode=None, geojson=None, featureidkey=None, color=None, hover_name=None, hover_data=None, custom_data=None, animation_frame=None, animation_group=None, category_orders={}, labels={}, color_discrete_sequence=None, color_discrete_map={}, color_continuous_scale=None, range_color=None, color_continuous_midpoint=None, projection=None, scope=None, center=None, title=None, template=None, width=None, height=None)`
```
**choropleth()**这个函数还有几点需要注意:
1. **geojson**是一个geometry对象上面函数第六个参数。这个对象有点让人困扰因为在函数文档中没有明确地提到这个对象。你可以提供也可以不提供**geojson**对象。如果你提供了**geojson**对象,那么这个对象就会被用来绘制地球特征,如果不提供**geojson**对象那这个函数默认就会使用一个内建的geometry对象。在我们的实验中我们使用内建的geometry对象因此我们不会为**geojson**参数提供值)
2. DataFrame对象有一个**data_frame**属性,在这里我们先前就提供了一个我们创建好的**df1**。
3. 我们用**Confirmed**(确诊)来决定每个国家多边形的颜色。
4. 最后,我们**Date**列创建一个**animation_frame**。这样我们就能通过日期来划分数据,国家的颜色会随着**Confirmed**的变化而变化。
最后完整的代码如下:
```
import pycountry
import plotly.express as px
import pandas as pd
# ----------- Step 1 ------------
URL_DATASET = r'<https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv>'
df1 = pd.read_csv(URL_DATASET)
# print(df1.head) # Uncomment to see what the dataframe is like
# ----------- Step 2 ------------
list_countries = df1['Country'].unique().tolist()
# print(list_countries) # Uncomment to see list of countries
d_country_code = {}  # To hold the country names and their ISO
for country in list_countries:
    try:
        country_data = pycountry.countries.search_fuzzy(country)
        # country_data is a list of objects of class pycountry.db.Country
        # The first item  ie at index 0 of list is best fit
        # object of class Country have an alpha_3 attribute
        country_code = country_data[0].alpha_3
        d_country_code.update({country: country_code})
    except:
        print('could not add ISO 3 code for -&gt;', country)
        # If could not find country, make ISO code ' '
        d_country_code.update({country: ' '})
# print(d_country_code) # Uncomment to check dictionary  
# create a new column iso_alpha in the df
# and fill it with appropriate iso 3 code
for k, v in d_country_code.items():
    df1.loc[(df1.Country == k), 'iso_alpha'] = v
# print(df1.head)  # Uncomment to confirm that ISO codes added
# ----------- Step 3 ------------
fig = px.choropleth(data_frame = df1,
                    locations= "iso_alpha",
                    color= "Confirmed",  # value in column 'Confirmed' determines color
                    hover_name= "Country",
                    color_continuous_scale= 'RdYlGn',  #  color scale red, yellow green
                    animation_frame= "Date")
fig.show()
```
这段代码的输出就是下面这个图的内容:
![Map][3]
你可以从这里下载并运行完整代码[complete code][4]。
最后这里还有一些关于Plotly绘制choropleth图的不错的资源。
* <https://github.com/plotly/plotly.py/blob/master/doc/python/choropleth-maps.md>
* [https://plotly.com/python/reference/#choropleth][5]
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/4/python-map-covid-19
作者:[AnuragGupta][a]
选题:[lujun9972][b]
译者:[zhangxiangping](https://github.com/zxp93)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/999anuraggupta
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cloud-globe.png?itok=_drXt4Tn (Globe up in the clouds)
[2]: https://opensource.com/sites/default/files/uploads/jupyter_screenshot.png (Jupyter screenshot)
[3]: https://opensource.com/sites/default/files/uploads/map_2.png (Map)
[4]: https://github.com/ag999git/jupyter_notebooks/blob/master/corona_spread_visualization
[5]: tmp.azs72dmHFd#choropleth

View File

@ -0,0 +1,138 @@
[#]: collector: (lujun9972)
[#]: translator: (robsean)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to Write, Compile and Run a C Program in Ubuntu and Other Linux Distributions [Beginners Tip])
[#]: via: (https://itsfoss.com/run-c-program-linux/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
如何在 Ubuntu 和其它的 Linux 发行版中编写,编译和运行一个 C 程序 [Beginners Tip]
======
你是如何在 Linux 上使用 C 编写你的程序的?它确实是非常简单的,它由三个简单的步骤组成的。
**步骤 1**: 你编写你的程序,并使用一个 .c 的扩展名进行保存。例如my_program.c 。
**步骤 2**: 你在一个终端中使用 gcc 编译器来编译程序并生成目标文件,像这样:
```
gcc -o my_program my_program.c
```
**步骤 3**: 在 Linux 中,你以运行生成的对象文件的方式来运行你的 C 程序:
```
./my_program
```
![][1]
这只是如何在 Linux 中编译和运行 C 程序的简要总结。假设你是 C 语言或 Linux 系统的新手,我将仔细演示这些步骤,以便你能在 Linux 环境中舒服地编写 C 程序。
事实上,我将讨论如何在 Linux 终端中以及在代码编辑器中运行 C 程序。
![][2]
### 方法 1: 在 Linux 终端中运行 C 程序
为了在 Linux 中运行一个 C 程序,你需要在你的系统上有一个 C 编译器。最流行的编译器是 gcc [GNU 编译器套件][3])。
你可以使用你发行版的软件包管理器来安装 gcc 。在基于 Debian 和 Ubuntu 的 Linux 发行版中,使用 apt 命令:
```
sudo apt install gcc
```
切换到你保存你的 C 程序的目录(或者提供路径),然后通过编译程序生成对象文件:
```
gcc -o my_program my_program.c
```
记住,提供输出对象文件(-o my_program是可选的。如果你不提供那么将自动生成一个名称 a.out 的对象文件。但是这样并不好,因为它将会覆盖每一个已生成的 C 程序,而且你也不知道这个 a.out 对象文件究竟属于哪个程序。
在你的对象文件生成后,运行它来运行 C 程序。它已经能够可执行了。像这样简单地使用它:
```
./my_program
```
接下来,如果你的程序是正确的,它将显示出你所期望的输出。正如你所能够看到的,[在 Linux 中运行 C++程序][4] 并不是很难。
_**每更改一次你的程序,你都被必须先重新编译它,然后再次运行生成的对象文件来运行这个新的 C 程序。**_
### 方法 2: 如何在 Linux 中使用一个诸如 Visual Studio Code 之类的代码编辑器来运行 C 程序
并不是每一个人都能适应命令行和终端,我完全理解这一点。
你可以使用一个诸如 Eclipse 或 Code Blocks 之类的真正的 C/C++ IDE ,但是它们是很重量级的程序,通常更适合于大型的工程。
我建议使用一个开放源码的代码编辑器,像 Visual Studio Code 或 Atom 。总体来说它们是文本编辑器,但是你可以通过安装附加组件来直接在图形化代码编辑器中编译和运行程序。
在这个示例中,我使用 [Visual Studio Code ][5] 编辑器。它是来自微软的一个非常 [流行的开放源码的代码编辑器][6] 。
首先,在 Ubuntu 的 [软件中心中安装 Visual Studio Code ][7] 。对于其它发行版来说,请检查你的 Linux 发行版的软件包管理器或软件中心。你可以检查它的官方网站来查看更多的信息。
启动 Visual Studio Code ,打开/创建一个工程,接下来创建你的 C 程序。我使用一个简单的 Hello World 程序作为示例。
![][8]
你必须确保你已经在你的 Linux 系统上安装了 gcc 编译器。
```
sudo apt install gcc
```
接下来你想做事是使用一个允许你运行 C 代码的扩展。微软可能会提示你安装它自己的 C/C++ 程序扩展,但是安装是很复杂的,因此我不建议你使用它。
作为替换,我建议你使用 Code Runner 扩展。它是一个简单直接的扩展,你可以在不使用额外配置的情况下轻松地运行 C 和 C++ 代码。
转到扩展标签页,在其中搜索和安装 Code Runner
![安装 Code Runner 扩展来运行 C/C++ 程序][9]
重新启动 Visual Studio Code 。现在,你能够使用下面方法中的其中一个来运行 C 代码:
* 使用快捷键 Ctrl+Alt+N 。
* 按下 F1 ,接下来选择或输入 Run Code 。
* 在文本编辑器中右键单击,从上下文菜单中单击 Run code 。
![右键单击程序文件,然后选择 Run Code][10]
当你运行这个 C 程序时,它将会被自动编译和运行。你可以在编辑器底部打开的终端中看到输出。还有比这更好的吗?
![程序输出显示在编辑器的底部][11]
你更喜欢哪一种方法?
在 Linux 命令行中运行一些 C 程序是没有问题的,但是使用一个代码编辑器会更容易一些,而且会节省时间。你不同意吗?
我让你来决定你想使用哪一种方法。
--------------------------------------------------------------------------------
via: https://itsfoss.com/run-c-program-linux/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[robsean](https://github.com/robsean)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/11/running-c-program-linux.png?resize=795%2C399&ssl=1
[2]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/11/Run-C-Program-Linux.png?resize=800%2C450&ssl=1
[3]: https://gcc.gnu.org/
[4]: https://itsfoss.com/c-plus-plus-ubuntu/
[5]: https://code.visualstudio.com
[6]: https://itsfoss.com/best-modern-open-source-code-editors-for-linux/
[7]: https://itsfoss.com/install-visual-studio-code-ubuntu/
[8]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/11/c-program-visual-studio-code-linux.png?resize=800%2C441&ssl=1
[9]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/11/running-c-program-in-linux-with-visual-studio-code.png?resize=800%2C500&ssl=1
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/11/running-c-program-in-linux-with-visual-studio-code.jpg?resize=800%2C500&ssl=1
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/11/run-c-program-in-linux-with-visual-studio-code.jpg?resize=800%2C500&ssl=1

View File

@ -1,272 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Add storage to your Fedora system with LVM)
[#]: via: (https://fedoramagazine.org/add-storage-to-your-fedora-system-with-lvm/)
[#]: author: (Tim Bosse https://fedoramagazine.org/author/maztaim/)
使用 LVM 为你的 Fedora 系统添加存储
======
![][1]
有时需要在系统中添加另一块磁盘。这就是逻辑卷管理 LVM 的用武之地。LVM 的好处之处在于它相当灵活。有几种方法可以添加一块磁盘。这篇文章介绍了一种方法。
### 注意!
这篇文章并不包括将新的磁盘物理地安装到系统中的过程。请查阅你的系统和磁盘文档,了解如何正确地进行安装。
**重要:**一定要确保你已经备份重要数据。如果新磁盘已有数据,那么本文中描述的步骤将破坏数据。
### 最好了解
本文并没有深入介绍 LVM 的每一个功能重点是添加磁盘。但基本上LVM 有_卷组_它由一个或多个分区和/或磁盘组成。你把这些分区或磁盘添加为_物理卷_。一个卷组可以分成许多_逻辑卷_。逻辑卷可以作为文件系统、ramdisk 等其他存储使用。更多信息可以在[这里][2]中找到。
把物理卷看作是形成一个存储池(一个卷组),然后从这个存储池中划分出逻辑卷,供你的系统直接使用。
### 准备
确保你能看到你要添加的磁盘。在添加磁盘之前使用 _lsblk_ 查看哪些存储空间已经可用或正在使用。
```
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
zram0 251:0 0 989M 0 disk [SWAP]
vda 252:0 0 20G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 19G 0 part
└─fedora_fedora-root 253:0 0 19G 0 lvm /
```
本文使用的是带有虚拟存储的虚拟机,因此设备名称以 _vda_ 开头代表第一个磁盘_vdb_ 代表第二个磁盘,以此类推。你的设备名称可能不同。许多系统会将 _sda_ 作为第一个物理磁盘_sdb_ 代表第二个磁盘,以此类推。
当已连接新磁盘,并且你的系统已备份且正在运行,再次使用 _lsblk_ 来查看新的块设备。
```
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
zram0 251:0 0 989M 0 disk [SWAP]
vda 252:0 0 20G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 19G 0 part
└─fedora_fedora-root 253:0 0 19G 0 lvm /
vdb 252:16 0 10G 0 disk
```
现在有一个名为 _vdb_ 的新设备。该设备的位置是 _/dev/vdb_
```
$ ls -l /dev/vdb
brw-rw----. 1 root disk 252, 16 Nov 24 12:56 /dev/vdb
```
我们可以看到磁盘,但我们还不能用 LVM 来使用它。如果你运行 _blkid_,你应该不会看到它被列出。对于这个和之后的命令,你需要确保你的系统[已配置,这样你可以使用 _sudo_][3]
```
$ sudo blkid
/dev/vda1: UUID="4847cb4d-6666-47e3-9e3b-12d83b2d2448" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="830679b8-01"
/dev/vda2: UUID="k5eWpP-6MXw-foh5-Vbgg-JMZ1-VEf9-ARaGNd" TYPE="LVM2_member" PARTUUID="830679b8-02"
/dev/mapper/fedora_fedora-root: UUID="f8ab802f-8c5f-4766-af33-90e78573f3cc" BLOCK_SIZE="4096" TYPE="ext4"
/dev/zram0: UUID="fc6d7a48-2bd5-4066-9bcf-f062b61f6a60" TYPE="swap"
```
### 将磁盘添加到 LVM 中
使用 _pvcreate_ 初始化磁盘。你需要传递设备的完整路径。在这个例子中,它是 _/dev/vdb_。在你的系统中,它可能是 _/dev/sdb_ 或其他设备名。
```
$ sudo pvcreate /dev/vdb
Physical volume "/dev/vdb" successfully created.
```
当你运行 _blkid_ 时,你应该看到磁盘已经被初始化为一个 LVM2_member
```
$ sudo blkid
/dev/vda1: UUID="4847cb4d-6666-47e3-9e3b-12d83b2d2448" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="830679b8-01"
/dev/vda2: UUID="k5eWpP-6MXw-foh5-Vbgg-JMZ1-VEf9-ARaGNd" TYPE="LVM2_member" PARTUUID="830679b8-02"
/dev/mapper/fedora_fedora-root: UUID="f8ab802f-8c5f-4766-af33-90e78573f3cc" BLOCK_SIZE="4096" TYPE="ext4"
/dev/zram0: UUID="fc6d7a48-2bd5-4066-9bcf-f062b61f6a60" TYPE="swap"
/dev/vdb: UUID="4uUUuI-lMQY-WyS5-lo0W-lqjW-Qvqw-RqeroE" TYPE="LVM2_member"
```
你可以使用 _pvs_ 列出当前所有可用的物理卷:
```
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 fedora_fedora lvm2 a-- <19.00g 0
/dev/vdb lvm2 --- 10.00g 10.00g
```
_/dev/vdb_ 被列为一个 PV (物理卷),但还没有分配到一个 VG (卷组)。
### 将物理卷添加到一个卷组
你可以使用 _vgs_ 找到可用的卷组列表:
```
$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
fedora_fedora 1 1 0 wz--n- 19.00g 0
```
在本例中,只有一个卷组可用。接下来,将物理卷添加到 _fedora_fedora_
```
$ sudo vgextend fedora_fedora /dev/vdb
Volume group "fedora_fedora" successfully extended
```
你现在应该看到物理卷已被添加到卷组中:
```
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 fedora_fedora lvm2 a <19.00g 0
/dev/vdb fedora_fedora lvm2 a <10.00g <10.00g
```
看一下卷组:
```
$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
fedora_fedora 2 1 0 wzn- 28.99g <10.00g
```
你也可以获得具体卷组和物理卷的详细列表:
```
$ sudo vgdisplay fedora_fedora
--- Volume group ---
VG Name fedora_fedora
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 28.99 GiB
PE Size 4.00 MiB
Total PE 7422
Alloc PE / Size 4863 / 19.00 GiB
Free PE / Size 2559 / 10.00 GiB
VG UUID C5dL2s-dirA-SQ15-TfQU-T3yt-l83E-oI6pkp
```
看下物理卷:
```
$ sudo pvdisplay /dev/vdb
--- Physical volume ---
PV Name /dev/vdb
VG Name fedora_fedora
PV Size 10.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2559
Free PE 2559
Allocated PE 0
PV UUID 4uUUuI-lMQY-WyS5-lo0W-lqjW-Qvqw-RqeroE
```
现在我们已经添加了磁盘,我们可以为逻辑卷 LV 分配空间:
```
$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root fedora_fedora -wi-ao---- 19.00g
```
看一下逻辑卷。下面是详细的逻辑卷信息:
```
$ sudo lvdisplay fedora_fedora/root
--- Logical volume ---
LV Path /dev/fedora_fedora/root
LV Name root
VG Name fedora_fedora
LV UUID yqc9cw-AvOw-G1Ni-bCT3-3HAa-qnw3-qUSHGM
LV Write Access read/write
LV Creation host, time fedora, 2020-11-24 11:44:36 -0500
LV Status available
LV Size 19.00 GiB
Current LE 4863
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
```
查看根文件系统的大小,并将它与逻辑卷大小进行比较。
```
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/fedora_fedora-root 19G 1.4G 17G 8% /
```
逻辑卷和文件系统大小都为 19G。让我们给根逻辑卷增加 5G。
```
$ sudo lvresize -L +5G fedora_fedora/root
Size of logical volume fedora_fedora/root changed from 19.00 GiB (4863 extents) to 24.00 GiB (6143 extents).
Logical volume fedora_fedora/root successfully resized.
```
我们现在有 24G 的逻辑卷可用。看看 _/_ 文件系统。
```
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/fedora_fedora-root 19G 1.4G 17G 8% /
```
我们仍然显示只有 19G 的空闲空间,这是因为逻辑卷与文件系统不一样。要使用增加到逻辑卷的新空间,请调整文件系统的大小。
```
$ sudo resize2fs /dev/fedora_fedora/root
resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/fedora_fedora/root is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 3
The filesystem on /dev/fedora_fedora/root is now 6290432 (4k) blocks long.
```
看看文件系统的大小。
```
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/fedora_fedora-root 24G 1.4G 21G 7% /
```
正如你所看到的,根文件系统 _/_ 已经占用了逻辑卷上的所有可用空间,而且不需要重新启动。
现在你已经将一个磁盘初始化为物理卷,并使用新的物理卷扩展了卷组。之后,你增加了逻辑卷的大小,并调整了文件系统的大小,以使用逻辑卷的新空间。
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/add-storage-to-your-fedora-system-with-lvm/
作者:[Tim Bosse][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://fedoramagazine.org/author/maztaim/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2020/11/lvm-add-disk-816x345.jpg
[2]: https://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)
[3]: https://fedoramagazine.org/howto-use-sudo/

View File

@ -0,0 +1,122 @@
[#]: collector: (lujun9972)
[#]: translator: (robsean)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to Install RPM Files on Fedora Linux [Beginners Tutorial])
[#]: via: (https://itsfoss.com/install-rpm-files-fedora/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
如何在 Fedora Linux 上安装 RPM 文件 [初学者教程]
======
_**这篇初学者文章介绍如何在 Fedora 和 Red Hat Linux 上安装 RPM 软件包。它也随后向你展示如何移除这些 RPM 软件包。**_
当你开始使用 Red Hat 系的 Fedora Linux 时,你早晚会偶然发现 .rpm 文件。就像在 Windows 中的 .exe 文件,以及在 Ubuntu 和 Debian 中的 .deb 文件一样,一个 rpm 文件能够使你在 [Fedora][1] 上快速安装一个软件。
你可以从软件中心中找到并安装大量的软件,特别是 [如果你在 Fedora 中启用附加的存储库的话][2]。但是有时你会在它们的网站上找到可用的 RPM 格式的软件包。
就像在 Windows 中的 .exe 文件一样,你可以通过 **下载 .rpm 文件并双击它来安装**。不用担心,我将向你展示详细的步骤。
### 在 Fedora 和 Red Hat Linux 上安装 RPM 文件
我将向你展示安装 RPM 文件的三个方法:
* [使用软件中心安装 RPM 文件][3] (GUI 方法)
* [使用 DNF 命令安装 RPM 文件][4] (CLI 方法)
* [使用 Yum 命令安装 RPM 文件][5] (Red Hat 的 CLI 方法)
#### 方法 1: 使用软件中心
在 Fedora 中使用默认的软件中心是最简单的方法。它真地很简单。转到你下载的 .rpm 文件的文件夹位置。它通常在 Downloads 文件夹。
只需要 **双击 RPM 文件,它将会在软件中心中打开**
或者,你可以在 RPM 文件上右键单击并选择通过软件中心来安装它。
![或者双击或者右键并选择软件安装][6]
当它在软件中心打开时,你应该会看到安装选项。只需要点击安装按钮并在提示时输入你的账号密码。
![通过 Fedora 软件中心安装 RPM][7]
它很简单,对吗?
#### 方法 2: 使用 DNF 命令来安装 RPM 文件
这是命令行方法。Fedora 使用新的 DNF [软件包管理器][8] ,你也可以使用它来安装下载的 RPM 文件。
打开一个终端并切换到你下载 RPM 文件的目录下。你也可以通过到 RPM 文件的路径。像这样使用 DNF 命令:
```
sudo dnf install rpm_file_name
```
这是一个我 [在 Fedora 上使用 dnf 命令安装 Google Chrome][9] 屏幕截图:
![使用 DNF 命令安装 RPM 文件][10]
#### 方法 3: 在 Red Hat 中使用 Yum 命令安装 RPM 文件
不像 Fedora Red Hat 仍然使用很好的旧式的 Yum 软件包管理器。在这里你还不能找到 DNF 命令。
这个过程与 DNF 命令相同。转到 RPM 文件所在的目录或提供它的路径。
```
sudo yum install path_to_RPM_file
```
就是这样。没有一点异常花哨的东西。
### 如何移除 RPM 软件包
移除一个 RPM 软件包也不是一个什么大的问题。并且,你不需要原始的用来安装程序的 rpm 文件。
你可以在软件中心中找到已安装的软件包,并从其中移除应用程序。
![移除 RPM 软件包][11]
或者,你可以使用带有 `remove` 选项的 DNF 或 YUM 命令。
使用 DNF ,使用这个命令:
```
sudo dnf remove rpm_package_name
```
使用 Yum ,使用这个命令:
```
sudo yum remove rpm_package_name
```
你可能不记得准确的软件包名称,没有关系。你可以做的是输入软件包的前几个字母,然后敲击 tab 按键。这是假设你已经启用 tab 按键补全,通常是这样的。
这就是你需要做的全部。相当简单,对吧?作为一个初学者,你可能会为这样一个简单的任务而挣扎,我希望像这样的快速教程会让你对 Fedora 更自信一些。
--------------------------------------------------------------------------------
via: https://itsfoss.com/install-rpm-files-fedora/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[robsean](https://github.com/robsean)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://getfedora.org/
[2]: https://itsfoss.com/fedora-third-party-repos/
[3]: tmp.TvkJtlRJ6T#gui-method
[4]: tmp.TvkJtlRJ6T#use-dnf
[5]: tmp.TvkJtlRJ6T#use-yum
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/installing-rpm-file-fedora.png?resize=800%2C449&ssl=1
[7]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/12/install-rpm-fedora-software-center.jpg?resize=799%2C193&ssl=1
[8]: https://itsfoss.com/package-manager/
[9]: https://itsfoss.com/install-google-chrome-fedora/
[10]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/12/install-rpm-using-dnf-install.jpg?resize=800%2C474&ssl=1
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/remove-rpm-package-fedora.jpg?resize=790%2C190&ssl=1