Merge pull request #4 from LCTT/master

update 0728
This commit is contained in:
SamMa 2021-07-28 09:01:28 +08:00 committed by GitHub
commit 41a46615b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 2623 additions and 896 deletions

View File

@ -3,22 +3,24 @@
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
[#]: collector: (lujun9972)
[#]: translator: (piaoshi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-13622-1.html)
编程秘笈Java 中的输入和输出
编程基础Java 中的输入和输出
======
学习 Java 如何外理数据的读与写
![Coffee beans and a cup of coffee][1]
> 学习 Java 如何外理数据的读与写。
![](https://img.linux.net.cn/data/attachment/album/202107/27/101854by7yizpokqyo77kk.jpg)
当你写一个程序时,你的应用程序可能需要读取和写入存储在用户计算机上的文件。这在你想加载或存储配置选项,你需要创建日志文件,或你的用户想要保存工作以待后用的情况下是很常见的。每种语言处理这项任务的方式都有所不同。本文演示了如何用 Java 处理数据文件。
### 安装 Java
不管你的计算机是什么平台,你都可以从 [AdoptOpenJDK][2] 安装 Java。这个网站提供安全和开源的 Java 构建。在 Linux 上,你的软件库中也可能找到 AdvertOpenJDK 的构建。
不管你的计算机是什么平台,你都可以从 [AdoptOpenJDK][2] 安装 Java。这个网站提供安全和开源的 Java 构建。在 Linux 上,你的软件库中也可能找到 AdoptOpenJDK 的构建。
我建议你使用最新的长期支持LTS版本。最新的非 LTS 版本对希望尝试最新 Java 功能的开发者来说是最好的,但它很可能超过大多数用户所安装的版本——要么是系统上默认安装的,要么是以前为其他 Java 应用安装的。使用 LTS 版本可以确保你与大多数用户所安装的版本保持一致。
我建议你使用最新的长期支持LTS版本。最新的非 LTS 版本对希望尝试最新 Java 功能的开发者来说是最好的,但它很可能超过大多数用户所安装的版本 —— 要么是系统上默认安装的,要么是以前为其他 Java 应用安装的。使用 LTS 版本可以确保你与大多数用户所安装的版本保持一致。
一旦你安装好了 Java就可以打开你最喜欢的文本编辑器并准备开始写代码了。你可能还想要研究一下 [Java 集成开发环境][3]。BlueJ 是新程序员的理想选择,而 Eclipse 和 Netbeans 对中级和有经验的编码者更友好。
@ -28,33 +30,32 @@ Java 使用 `File` 类来加载文件。
这个例子创建了一个叫 `Ingest` 的类来读取文件中数据。当你要在 Java 中打开一个文件时,你创建了一个 `Scanner` 对象,它可以逐行扫描你提供的文件。事实上,`Scanner` 与文本编辑器中的光标是相同的概念,这样你可以用 `Scanner` 的一些方法(如 `nextLine`)来控制这个“光标”以进行读写。
```
import java.io.File;
import java.util.Scanner;
import java.io.FileNotFoundException;
public class Ingest {
  public static void main([String][4][] args) {
   
      try {
          [File][5] myFile = new [File][5]("example.txt");
          Scanner myScanner = new Scanner(myFile);
          while (myScanner.hasNextLine()) {
              [String][4] line = myScanner.nextLine();
              [System][6].out.println(line);
          }
          myScanner.close();
      } catch ([FileNotFoundException][7] ex) {
          ex.printStackTrace();  
      } //try
    } //main
public static void main(String[] args) {
try {
File myFile = new File("example.txt");
Scanner myScanner = new Scanner(myFile);
while (myScanner.hasNextLine()) {
String line = myScanner.nextLine();
System.out.println(line);
}
myScanner.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} //try
} //main
} //class
```
这段代码首先在假设存在一个名为 `example.txt` 的文件的情况下创建了变量 `myfile`。如果该文件不存在Java 就会“抛出一个异常”(这意味着它在你试图做的事情中发现了一个错误,并这样告诉你),这个异常是被非常明确`FileNotFoundException` 类所“捕获”。事实上,有一个专门的类来处理这个明确的错误,这说明这个错误是多么常见。
这段代码首先在假设存在一个名为 `example.txt` 的文件的情况下创建了变量 `myfile`。如果该文件不存在Java 就会“抛出一个异常”(如它所说的,这意味着它在你试图做的事情中发现了一个错误),这个异常是被非常特定`FileNotFoundException` 类所“捕获”。事实上,有一个专门的类来处理这个明确的错误,这说明这个错误是多么常见。
接下来,它创建了一个 `Scanner` 并将文件加载到其中。我把它叫做 `myScanner`,以区别于它的通用类模板。接着,一个 `while` 循环将 `myScanner` 逐行送入文件中只要_存在_下一行。这就是 `hasNextLine` 方法的作用:它检测“光标”之后是否还有数据。你可以通过在文本编辑器中打开一个文件来模拟这个过程:你的光标从文件的第一行开始,你可以用键盘控制光标来向下扫描文件,直到你完了所有的行。
接下来,它创建了一个 `Scanner` 并将文件加载到其中。我把它叫做 `myScanner`,以区别于它的通用类模板。接着,一个 `while` 循环将 `myScanner` 逐行送入文件中,只要 _存在_ 下一行。这就是 `hasNextLine` 方法的作用:它检测“光标”之后是否还有数据。你可以通过在文本编辑器中打开一个文件来模拟这个过程:你的光标从文件的第一行开始,你可以用键盘控制光标来向下扫描文件,直到你完了所有的行。
`while` 循环创建了一个变量 `line`,并将文件当前行的数据分配给它。然后将 `line` 的内容打印出来以提供反馈。一个更有用的程序可能会解析每一行的内容,从而提取它所包含的任何重要数据。
@ -64,45 +65,42 @@ public class Ingest {
将你的代码保存到 `Ingest.java` 文件(这是一个 Java 惯例,将类名的首字母大写,并以类名来命名相应的文件)。如果你试图运行这个简单的应用程序,你可能会接收到一个错误信息,这是因为还没有 `example.txt` 文件供应用程序加载:
```
$ java ./Ingest.java
java.io.[FileNotFoundException][7]:
java.io.FileNotFoundException:
example.txt (No such file or directory)
```
正好可以编写一个将数据写入文件的 Java 应用程序,多么完美的时机!
正好可以编写一个将数据写入文件的 Java 应用程序,多么完美的时机
### 利用 Java 将数据写入文件
无论你是存储用户使用你的应用程序创建的数据,还是仅仅存储关于用户在应用程序中做了什么的元数据(例如,游戏保存或最近播放的歌曲),有很多很好的理由来存储数据供以后使用。在 Java 中,这是通过 `FileWriter` 类实现的,这次先打开一个文件,向其中写入数据,然后关闭该文件。
```
import java.io.FileWriter;
import java.io.IOException;
public class Exgest {
  public static void main([String][4][] args) {
    try {
        [FileWriter][8] myFileWriter = new [FileWriter][8]("example.txt", true);
        myFileWriter.write("Hello world\n");
        myFileWriter.close();
    } catch ([IOException][9] ex) {
        [System][6].out.println(ex);
    } // try
  } // main
public static void main(String[] args) {
try {
FileWriter myFileWriter = new FileWriter("example.txt", true);
myFileWriter.write("Hello world\n");
myFileWriter.close();
} catch (IOException ex) {
System.out.println(ex);
} // try
} // main
}
```
这个类的逻辑和流程与读取文件类似。但它不是一个 `Scanner`,而是以一个文件的名字为参数创建的一个 `FileWriter` 对象。`FileWriter` 语句末尾的 `true` 标志告诉 `FileWriter` 将文本_追加_到文件的末尾。要覆盖一个文件的内容请移除 `true` 标志。
这个类的逻辑和流程与读取文件类似。但它不是一个 `Scanner`,而是以一个文件的名字为参数创建的一个 `FileWriter` 对象。`FileWriter` 语句末尾的 `true` 标志告诉 `FileWriter` 将文本 _追加_ 到文件的末尾。要覆盖一个文件的内容,请移除 `true` 标志。
```
`FileWriter myFileWriter = new FileWriter("example.txt", true);`
```
因为我在向文件中写入纯文本所以我在写入文件的数据Hello world的结尾处手动添加了换行符\n
因为我在向文件中写入纯文本,所以我在写入文件的数据(`Hello world`)的结尾处手动添加了换行符(`\n`)。
### 试试代码
@ -110,7 +108,6 @@ public class Exgest {
既然你已经掌握了用 Java 创建和读取数据的方法,你可以按相反的顺序尝试运行你的新应用程序。
```
$ java ./Exgest.java
$ java ./Ingest.java
@ -120,7 +117,6 @@ $
因为程序是把数据追加到文件末尾,所以你可以重复执行你的应用程序以多次写入数据,只要你想把更多的数据添加到你的文件中。
```
$ java ./Exgest.java
$ java ./Exgest.java
@ -134,7 +130,7 @@ $
### Java 和数据
不经常向文件中写入原始文本;事上,你可能会使用一个其它的类库以写入特定的格式。例如,你可能使用 XML 类库来写复杂的数据,使用 INI 或 YAML 类库来写配置文件,或者使用任何数量的专门类库来写二进制格式,如图像或音频。
你不经常向文件中写入原始文本;事上,你可能会使用一个其它的类库以写入特定的格式。例如,你可能使用 XML 类库来写复杂的数据,使用 INI 或 YAML 类库来写配置文件,或者使用各种专门类库来写二进制格式,如图像或音频。
更完整的信息,请参阅 [OpenJDK 文档][10]。
@ -145,7 +141,7 @@ via: https://opensource.com/article/21/3/io-java
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[piaoshi](https://github.com/piaoshi)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -3,60 +3,47 @@
[#]: author: (Arindam https://www.debugpoint.com/author/admin1/)
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-13621-1.html)
如何在 Kubuntu 21.04 Hirsute Hippo 中获得 KDE Plasma 5.22
如何在 Kubuntu 21.04 中安装和升级 KDE Plasma 5.22
======
KDE 团队启用了向后移植 PPA你可以使用它在 Kubuntu 21.04 Hirsute Hippo 中安装和升级到 KDE Plasma 5.22。
> KDE 团队启用了向后移植 PPA你可以使用它在 Kubuntu 21.04 Hirsute Hippo 中安装和升级到 KDE Plasma 5.22。
![Kubnutu 21.04 running with KDE Plasma 5.22][1]
KDE 团队最近发布了 KDE Plasma 5.22,其中有相当多的增强功能、错误修复以及更新的 KDE 框架和应用版本。这个版本带来了一些改进,如面板的自适应透明度,文件操作弹出时的用户友好通知,“发现”中的软件包类型显示,各种 Wayland 的变化等。在[这里][2]查看更多关于功能细节。
如果你正在运行 Kubuntu 21.04 Hirsute Hippo 或者,在 [Ubuntu 21.04 Hisrsute Hippo][3] 中安装了自定义的 KDE Plasma你可以通过以下步骤升级到最新版本。目前的 Hirsute Hippo 系列提供了 KDE Plasma 5.21.04 与 KDE Framework 5.80 的先前版本。
本指南包含下列主题:
1. [如何在 Kubuntu 21.04 中安装 KDE Plasma 5.22][4]
2. [如何在 Ubuntu 21.04 中与 GNOME 一起安装 KDE Plasma 5.22][5]
3. [我可以在 Ubuntu 20.04 LTS 中安装 KDE Plasma 5.22 么][6]
4. [如何卸载][7]
KDE 团队最近发布了 KDE Plasma 5.22,其中有相当多的增强功能、错误修复以及更新的 KDE 框架和应用版本。这个版本带来了一些改进,如面板的自适应透明度,文件操作弹出时的用户友好通知,“发现”中的软件包类型显示,各种 Wayland 的变化等。在 [这里][2] 查看更多关于功能细节。
如果你正在运行 Kubuntu 21.04 Hirsute Hippo或者在 [Ubuntu 21.04 Hirsute Hippo][3] 中安装了自定义的 KDE Plasma你可以通过以下步骤升级到最新版本。目前的 Hirsute Hippo 系列提供了先前版本 KDE Plasma 5.21.04 与 KDE Framework 5.80。
### 在 Kubuntu 21.04 Hirsute Hippo 中安装 KDE Plasma 5.22 的步骤
按照下面的步骤进行。
如果你想使用图形方法,那么在“发现”中添加到软件源,然后点击更新。
如果你想使用图形方法,那么在“发现”中将 `ppa:kubuntu-ppa/backports` 添加到软件源,然后点击“更新”。
或者,使用下面的终端方法,以加快安装速度。
* **步骤 1**:打开一个终端,添加下面的 KDE Backports PPA。
```
sudo add-apt-repository ppa:kubuntu-ppa/backports
```
```
sudo add-apt-repository ppa:kubuntu-ppa/backports
```
* **步骤 2**:然后运行以下程序来启动系统升级。这将在你的 Hirsute Hippo 系统中安装最新的 KDE Plasma 5.22。
```
sudo apt update
sudo apt full-upgrade
```
```
sudo apt update
sudo apt full-upgrade
```
![Upgrade to Plasma 5.22][8]
![Upgrade to Plasma 5.22][8]
* **步骤 3**:更新后重新启动,你应该会看到一个更新的 KDE Plasma 5.22 桌面。
考虑到整个桌面环境的完整版本升级,安装可能需要一些时间。
考虑到这是整个桌面环境的完整版本升级,安装可能需要一些时间。
### 在 Ubuntu 21.04 中安装 KDE Plasma 5.22
@ -90,7 +77,7 @@ Ubuntu 20.04 LTS 版拥有早期的 KDE Plasma 5.18、KDE Framework 5.68、KDE A
### 卸载 KDE Plasma 5.22
如果你改变主意,想回到 KDE Plasma 的原始版本,那么安装 ppa-purge 并清除 PPA。这将使软件包降级并启用仓库版本。
如果你改变主意,想回到 KDE Plasma 的原始版本,那么安装 `ppa-purge` 并清除 PPA。这将使软件包降级并启用仓库版本。
```
sudo apt install ppa-purge
@ -102,8 +89,6 @@ sudo apt update
我希望这个快速指南能帮助你在 Kubuntu 21.04 Hirsute Hippo 中安装最新的 KDE Plasma 5.22。这可以让你体验到最新的 KDE 技术以及 KDE 框架和应用。然而,你应该知道,并不是所有的功能都应该在向后移植 PPA 中提供,它只有选定的功能和错误修复,这才能通过回归测试并安全使用。也就是说,你总是可以把 KDE Neon 安装成一个全新的系统来享受 KDE 的最新技术。
* * *
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/2021/06/plasma-5-22-kubuntu-21-04/
@ -111,7 +96,7 @@ via: https://www.debugpoint.com/2021/06/plasma-5-22-kubuntu-21-04/
作者:[Arindam][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,132 @@
[#]: subject: "What is XML?"
[#]: via: "https://opensource.com/article/21/7/what-xml"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: "amwps290"
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-13624-1.html"
什么是 XML
======
> 了解一下 XML 吧,它是一种严格但灵活的标记语言,无论是在文档还是图像方面应用都十分广泛。
![](https://img.linux.net.cn/data/attachment/album/202107/28/082605rhju4ckqez0zvcwc.jpg)
XML 是一种分层的标记语言。它使用打开和关闭标签来定义数据,它常用来存储和交换数据,而且由于它极大的灵活性,不论是在 [文档][2] 还是 [图像][3] 中都用的非常多。
这里是一个 XML 文档的例子:
```
<xml>
  <os>
   <linux>
    <distribution>
      <name>Fedora</name>
      <release>8</release>
      <codename>Werewolf</codename>
    </distribution>
    <distribution>
      <name>Slackware</name>
      <release>12.1</release>
      <mascot>
        <official>Tux</official>
        <unofficial>Bob Dobbs</unofficial>
      </mascot>
    </distribution>
   </linux>
  </os>    
</xml>
```
阅读这个示例 XML你可能会发现这个 XML 的格式具有直观的特性。 无论你是否熟悉这个文档的主题,你都可能理解本文档中的数据。 这部分原因是因为 XML 被认为是冗长的。 它使用了很多标签,标签可以有很长的描述性名称,并且数据以分层的方式排序,这有助于解释数据之间的关系。 你可能从这个示例中了解到 Fedora 发行版和 Slackware 发行版是两个不同且不相关的 Linux 发行版,因为每个实例都“包含”在自己独立的 `<distribution>` 标签中。
XML 也非常灵活。 与 HTML 不同,它没有预定义的标签列表。 你可以自由创建你需要表示任何数据结构的标签。
### XML 的组成
数据的存在为了读取,当计算机“读取”数据时,该过程称为 _解析_。 再次使用示例 XML 数据,以下是大多数 XML 解析器认为重要的术语。
* **文档**`<xml>` 标签标记文档的开始, `</xml>` 标签标记文档的结束。
* **节点**`<os>`、`<distribution>`、`<mascot>` 这些都是节点,在解析术语中,节点是包含其他标签的标签。
* **元素**:像 `<name>Fedora</name>``<official>Tux</official>` 这些都是元素。从第一个`<`开始,到最后一个 `>` 结束是一个元素。
* **内容**:在两个元素标签之间的数据被称之为内容,在第一个 `<name>` 标签中,`Fedora` 字符串就是一个内容。
### XML 模式
XML 文档中的标签和标签继承性称为 _模式_
一些模式是随意组成的(例如,本文中的示例 XML 代码纯粹是即兴创作的),而其他模式则由标准组织严格定义。 例如可缩放矢量图形SVG模式 [由 W3C 定义][4],而 [DocBook 模式][5] 由 Norman Walsh 定义。
模式强制执行一致性。 最基本的模式通常也是最严格的。 在我的示例 XML 代码中,将发行版名称放在 `<mascot>` 节点中是没有意义的,因为文档的隐含模式清楚地表明 `mascot` 必须是发行版的“子”元素。
### 数据对象模型DOM
如果你必须不断地描述标签和位置(例如,“系统部分中的 Linux 部分中第二个发行版标签的名称标签”),那么谈论 XML 会让人感到困惑因此解析器使用文档对象模型DOM的概念来表示 XML 数据。 DOM 将 XML 数据放入一种“家谱”结构中,从根元素(在我的示例 XML 中,即 `os` 标记)开始并包括路径上的每个标记。
![Document Object Model][6]
这种相同的 XML 数据结构可以表示为路径,就像 Linux 系统中的文件或互联网上网页的位置一样。 例如,`<mascot>` 标签的路径可以表示为 `//os/linux/distribution/slackware/mascot`
两个 `<distribution>` 标签可以被表示为 `//os/linux/distribution` ,因为这里有两个发行版的节点,因此一个解析器可以直接将两个节点的内容载入到一个数组中,可以进行查询。
### 严格的 XML
XML 也以严格而著称。 这意味着大多数应用程序被设计为在遇到 XML 错误时就会故意失败。 这听起来可能有问题,但这是开发人员最欣赏 XML 的事情之一,因为当应用程序试图猜测如何解决错误时,可能会发生不可预测的事情。 例如,在 HTML 定义明确之前,大多数 Web 浏览器都包含“怪癖模式”,因此当人们试图查看糟糕的 HTML 代码时Web 浏览器却可以加载作者可能想要的内容。 结果非常难以预测,尤其是当一个浏览器的猜测与另一个浏览器不同时。
XML 通过在出现故意错误时失败而不允许这样做。 这让作者可以修复错误,直到它们生成有效的 XML。 因为 XML 是良好定义的,所以有许多应用程序的验证器插件以及像 `xmllint``xmlstarlet` 这样的独立命令来帮助你及早定位错误。
### 转换 XML
因为 XML 通常用作数据交换,所以将 XML 转换为其他数据格式或其他 XML 模式是很常见的。 经典示例包括 XSLTProc、xmlto 和 [pandoc][8],但从技术上讲,还有许多其他应用程序或者至少程序的一部分就是在转换 XML。
事实上LibreOffice 使用 XML 来布局其文字处理器和电子表格文档,因此无论何时你导出或 [从 LibreOffice 转换文件][9],你都在转换 XML。
[开源 EPUB 格式的电子书][10] 使用 XML因此无论何时你 [将文档转换为 EPUB][11] 或从 EPUB 转换,你都在转换 XML。
Inkscape 是基于矢量的插图应用程序,它将其文件保存在 SVG 中,这是一种专为图形设计的 XML 模式。 任何时候你将 Inkscape 中的图像导出为 PNG 文件时,你都在转换 XML。
名单还可以一直继续下去。 XML 是一种数据存储格式,旨在确保你的数据,无论是画布上的点和线、图表上的节点,还是文档中的文字,都可以轻松准确地提取、更新和转换。
### 学习 XML
编写 XML 很像编写 HTML。 感谢 Jay Nick 的辛勤工作,[在线提供免费且有趣的 XML 课程][3] 可以教你如何使用 XML 创建图形。
通常,探索 XML 所需的特殊工具很少。 由于 HTML 和 XML 之间的密切关系,你可以 [使用 Web 浏览器查看 XML][12]。 此外,[QXmlEdit][13]、[NetBeans][14] 和 [Kate][15] 等开源文本编辑器通过有用的提示、自动完成、语法验证等,使键入和阅读 XML 变得容易。
### 选择 XML
XML 起初可能看起来有很多数据,但它与 HTML 并没有太大的不同实际上HTML 已经 [以 XHTML 的形式重新实现为 XML][16])。 XML 有一个独特的好处,即构成其结构的标签也恰好是元数据,提供有关其存储内容的信息。 精心设计的 XML 模式包含并描述你的数据,使用户能够一目了然并快速解析它,并使开发人员能够使用一些库 [快速解析][17]。
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/7/what-xml
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[amwps290](https://github.com/amwps290)
校对:[wxy](https://github.com/wxy)
本文由 [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/browser_screen_windows_files.png?itok=kLTeQUbY "Computer screen with files or windows open"
[2]: https://opensource.com/article/17/9/docbook
[3]: https://opensource.com/article/17/5/coding-scalable-vector-graphics-make-steam
[4]: https://www.w3.org/TR/SVG11/
[5]: http://docbook.org
[6]: https://opensource.com/sites/default/files/uploads/dom.jpg "Document Object Model"
[7]: https://creativecommons.org/licenses/by-sa/4.0/
[8]: https://opensource.com/article/20/5/pandoc-cheat-sheet
[9]: https://opensource.com/article/21/3/libreoffice-command-line
[10]: https://opensource.com/education/15/11/ebook-open-formats
[11]: https://opensource.com/life/13/8/how-create-ebook-open-source-way
[12]: https://opensource.com/article/18/12/xml-browser
[13]: https://opensource.com/article/17/7/7-ways-handle-xml-qxmledit
[14]: https://opensource.com/article/20/12/netbeans
[15]: https://opensource.com/article/20/12/kate-text-editor
[16]: https://www.w3.org/TR/xhtml1/
[17]: https://opensource.com/article/21/6/parsing-config-files-java

View File

@ -3,22 +3,20 @@
[#]: author: (Arman Arisman https://fedoramagazine.org/author/armanwu/)
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-13625-1.html)
满足日常需求的应用第一部分:网络浏览器
满足日常需求的应用Web 浏览器
======
![][1]
照片由 [Brooke Cagle][2] 发布在 [Unsplash][3]。
满足日常需求的重要应用之一是网络浏览器。这是因为上网是大多数人在电脑前进行的一项活动。本文将介绍一些你可以在 Fedora Linux 上使用的开源网络浏览器。你需要安装上述软件。本文提到的所有浏览器都已经在官方的 Fedora 软件库中提供。如果你不熟悉如何在 Fedora Linux 中添加软件包,请参阅我之前的文章[安装 Fedora 34 工作站后要做的事情][4]。
满足日常需求的重要应用之一是 Web 浏览器。这是因为上网是大多数人在电脑前进行的一项活动。本文将介绍一些你可以在 Fedora Linux 上使用的开源 Web 浏览器。你需要安装上述软件。本文提到的所有浏览器都已经在官方的 Fedora 软件库中提供。如果你不熟悉如何在 Fedora Linux 中添加软件包,请参阅我之前的文章 [安装 Fedora 34 工作站后要做的事情][4]。
### Firefox
火狐是一个快速且注重隐私的浏览器,可以在许多设备上使用。它是由 [Mozilla][5] 创建的,是一个具有完整功能的浏览器,提供许多扩展。你可以为你的火狐浏览器添加许多强大的功能和有用的特性。它只使用适量的内存来创造一个流畅的体验,使你的电脑保持对其他任务的响应。你可以创建一个账户,让你在多个设备上共享配置,所以你不需要在每个设备上设置火狐浏览器。
<ruby>火狐<rt>Firefox</rt></ruby>是一个快速且注重隐私的浏览器,可以在许多设备上使用。它是由 [Mozilla][5] 创建的,是一个具有完整功能的浏览器,提供许多扩展。你可以为你的火狐浏览器添加许多强大的功能和有用的特性。它只使用适量的内存来创造一个流畅的体验,使你的电脑保持对其他任务的响应。你可以创建一个账户,让你在多个设备上共享配置,所以你不需要在每个设备上设置火狐浏览器。
![][6]
@ -30,13 +28,11 @@
* 设备之间的同步
* 画中画
关于火狐浏览器的更多信息可在此链接中找到:[https://www.mozilla.org/en-US/firefox][7]
### GNOME Web
GNOME Web 是 GNOME 桌面的一个浏览器,它是 Fedora 工作站的默认桌面环境。如果你使用 GNOME 作为默认桌面环境的 Fedora Workstation它可能非常适合作为你的主浏览器。这个浏览器有一个简单、干净、漂亮的外观。GNOME Web 的功能比 Firefox 少,但对于普通用途来说已经足够了。
GNOME Web 是 GNOME 桌面Fedora 工作站的默认桌面环境)的一个浏览器。如果你使用 GNOME 作为默认桌面环境的 Fedora 工作站它可能非常适合作为你的主浏览器。这个浏览器有一个简单、干净、漂亮的外观。GNOME Web 的功能比 Firefox 少,但对于普通用途来说已经足够了。
![][8]
@ -47,13 +43,11 @@ GNOME Web 提供了以下功能:
* 内置广告拦截器
* 智能跟踪预防
关于 GNOME Web 的更多信息可以在这个链接中找到:<https://wiki.gnome.org/Apps/Web>
### Chromium
Chromium 是一个来自 Chromium 项目的开源网络浏览器,它有一个极简的用户界面。它的外观与 Chrome 相似,因为它实际上是作为 Chrome 和其他几个浏览器的基础。许多人使用 Chromium 是因为他们已经习惯了 Chrome。
Chromium 是一个来自 Chromium 项目的开源 Web 浏览器,它有一个极简的用户界面。它的外观与 Chrome 相似,因为它实际上是作为 Chrome 和其他几个浏览器的基础。许多人使用 Chromium 是因为他们已经习惯了 Chrome。
![][9]
@ -63,13 +57,11 @@ Chromium 提供以下功能:
* 扩展程序
* 密码的自动填写
关于 Chromium 浏览器的更多信息可在此链接中找到:<https://www.chromium.org/Home>
### qutebrowser
这个浏览与上面提到的稍有不同qutebrowser 是一个以键盘为中心的浏览器,具有最小的 GUI。因此你不会发现通常在其他浏览器中的按钮如返回、主页、重新加载等。相反你可以用键盘输入命令来运行 qutebrowser 中的功能。它使用 Vim 风格的键绑定,所以它适合 Vim 用户。如果你有兴趣在上网时获得不同的体验,你应该试试这个浏览器。
这个浏览与上面提到的稍有不同qutebrowser 是一个以键盘为中心的浏览器,具有精简的 GUI。因此你不会发现通常在其他浏览器中的按钮如返回、主页、重新加载等。相反你可以用键盘输入命令来运行 qutebrowser 中的功能。它使用 Vim 风格的键绑定,所以它适合 Vim 用户。如果你有兴趣在上网时获得不同的体验,你应该试试这个浏览器。
![][10]
@ -79,8 +71,6 @@ qutebrowser 提供以下功能:
* 隐私浏览模式
* 快速书签
关于 qutebrowser 浏览器的更多信息可在此链接中找到:<https://qutebrowser.org/>
### 总结
@ -94,7 +84,7 @@ via: https://fedoramagazine.org/apps-for-daily-needs-part-1-web-browsers/
作者:[Arman Arisman][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,216 @@
[#]: subject: (Linux package managers: dnf vs apt)
[#]: via: (https://opensource.com/article/21/7/dnf-vs-apt)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
[#]: collector: (lujun9972)
[#]: translator: (perfiffer)
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-13620-1.html)
Linux 包管理器比较dnf 和 apt
======
> 包管理器提供大致相同的功能:安装、管理和移除应用,但是它们还是有一些不一样的地方。
![](https://img.linux.net.cn/data/attachment/album/202107/27/083002sd5zzxu37yhiz6yc.jpg)
[在 Linux 系统上获取一个应用][2] 有多种方式。例如,有新的 Flatpak 和容器方式,也有 DEB 和 RPM 这样一直以来经过考验的方式。
并没有一种通用的可以用于所有的操作系统的应用安装程序。如今,因为有无数的开发者发布软件,这导致了大部分的操作系统使用了应用商店(包括第一方和第三方)、拖放式安装,还有安装向导。不同的开发者对于他们发布的代码有不同的需求,这直接导致了他们所选择的安装方式的不同。
Linux 开创了一种通过命令行安装、管理、移除应用的包管理器的概念。`apt` 和 `dnf` 就是两种较为常见的包管理器。`apt` 命令是用来管理 DEB 格式的包,`dnf` 命令是用来管理 RPM 格式的包。这两种包管理器在理论上并不是完全互斥的尽管在实际的实践中Linux 发行版通常只会使用到其中的一种。理论上,这两种命令可以运行在同一个系统上,但是会造成安装包的重叠,版本控制也会更加困难,命令也会是冗余的。然而,如果你是在一个混合的 Linux 环境下工作,比如你的工作站运行的是一个发行版,同时需要与运行另外一种发行版的服务器进行交互,那么你最好同时掌握这两种包管理器。
### 搜索应用
当你通过包管理器安装一个应用时,你需要先知道包的名称。通常,应用的名称和包的名称是一样的。`dnf` 和 `apt` 验证要安装的包名的过程是完全相同的。
```
$ sudo dnf search zsh
====== Name Exactly Matched: zsh ======
zsh.x86_64 : Powerful interactive shell
[...]
```
使用 `apt`:
```
$ sudo apt search zsh
Sorting... Done
Full Text Search... Done
csh/stable 20110502-4+deb10u1 amd64
Shell with C-like syntax
ddgr/stable 1.6-1 all
DuckDuckGo from the terminal
direnv/stable 2.18.2-2 amd64
Utility to set directory specific environment variables
draai/stable 20180521-1 all
Command-line music player for MPD
[...]
```
如果想通过 `apt` 更快的获取相关的搜索结果,你可以使用 [正则表达式][3]
```
apt search ^zsh
Sorting... Done
Full Text Search... Done
zsh/stable 5.7.1-1 amd64
shell with lots of features
[...]
```
### 查找应用程序包
有一些命令是与其它命令捆绑在一起的,都在一个包中。在这种情况下,你可以通过包管理器去了解哪个包提供了你需要的命令。`dnf` 和 `apt` 命令在如何搜索这类元数据上是有区别的。
使用 `dnf`
```
$ sudo dnf provides pgrep
procps-ng-3.3.15-6.el8.x86_64 : System and process monitoring utilities
Repo : baseos
Matched from:
Filename : /usr/bin/pgrep
```
`apt` 命令使用子命令 `apt-file`。要使用 `apt-file`,你必须先安装它,然后提示它更新缓存:
```
$ sudo apt install apt-file
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libapt-pkg-perl libexporter-tiny-perl liblist-moreutils-perl libregexp-assemble-perl
The following NEW packages will be installed:
apt-file libapt-pkg-perl libexporter-tiny-perl liblist-moreutils-perl libregexp-assemble-perl
0 upgraded, 5 newly installed, 0 to remove and 14 not upgraded.
Need to get 297 kB of archives.
After this operation, 825 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
$ sudo apt-file update
[...]
```
你可以通过 `apt-file` 搜索命令。你可以使用此命令进行广泛的全局搜索,但假如你知道命令的执行路径,它会更准确:
```
$ sudo apt-file search /usr/bin/pgrep
pgreplay: /usr/bin/pgreplay              
procps: /usr/bin/pgrep
```
### 安装应用程序
使用`apt` 和 `dnf` 安装应用程序基本上是相同的:
```
$ sudo apt install zsh
```
使用 `dnf`,你可以使用同样的方式来安装一个包:
```
$ sudo dnf install zsh
```
许多基于 RPM 的发行版都具有组包安装的特性它会将有时表面相关的应用程序收集到一个易于安装的目标中。例如Fedora 中的 [Design Suite][4] 组包就包含流行的创意应用程序。那些想要某一个创意应用程序的艺术家可能也想要类似的应用程序,选择安装一整个组包一个简单而快速的方法,可以合理地开始建立一个数字工作室。你可以通过 `group list` 来查看可用的组包(使用 `-v` 来查看不带空格的组名):
```
$ sudo dnf group list -v
[...]
Available Groups:
Container Management (container-management)
RPM Development Tools (rpm-development-tools)
Design Suite (design-suite)
Development Tools (development)
[...]
```
使用 `group install` 子命令安装 RPM 组包:
```
$ sudo dnf group install design-suite
```
你可以使用 `@` 符号来减少输入:
```
$ sudo dnf install @design-suite
```
### 更新应用程序
使用包管理器的一个优点是,它知道所有已经安装的应用。这样你不必去寻找应用程序的更新版本。相反,你可以通过包管理器去获取更新的版本。
`dnf``apt` 使用的子命令略有不同。因为 `apt` 保存了一个需要定期更新的缓存信息,它使用 `upgrade` 子命令来更新应用程序:
```
$ sudo apt upgrade
```
相比之下,`dnf` 命令在你每次使用时都会更新元信息,所以 `update``upgrade` 子命令是可以互换的:
```
$ sudo dnf upgrade
```
这等同于:
```
$ sudo dnf update
```
### 移除应用程序
如果你曾经尝试在任何一个平台上手动删除一个应用程序,你就会知道,应用程序删除后,在硬盘上会残留各种文件,比如首选项文件、数据或图标。所以包管理器的另一个优点是,包管理器管理着包中安装的每一个文件,可以很方便的删除:
```
$ sudo dnf remove zsh
```
`remove` 子命令也适用于 `apt`
```
$ sudo apt remove zsh
```
使用 `apt` 命令删除一个包并不会删除已修改的用户配置文件,以防你意外删除了包。如果你想通过 `apt` 命令删除一个应用及其配置文件,请在你之前删除过的应用程序上使用 `purge` 子命令:
```
$ sudo apt purge zsh
```
`apt``dnf` 都不会删除家目录中的数据和配置文件(即使使用 `purge` 子命令)。如果想要从家目录中删除数据,你必须手动操作(通常你可以在 `~/.config``~/.local` 文件中找到)。
### 了解包管理
无论你选择的发行版支持的是 `apt` 还是 `dnf`,这些命令的用途大致相同。它们可以帮助你安装、更新和移除包。这两种包管理器是目前最通用的包管理器。它们的语法元素在很大程度上是相同的,所以在两者之间切换非常容易。
`apt``dnf` 还有一些高级功能,例如仓库管理,但这些功能并不像你使用 `search``install` 那样频繁。
无论你更经常使用哪种包管理器,你都可以下载我们的 [apt 备忘单][5] 和 [dnf 备忘单][6],以便你在最需要的时候可以查询使用语法。
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/7/dnf-vs-apt
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[perfiffer](https://github.com/perfiffer)
校对:[wxy](https://github.com/wxy)
本文由 [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/OSDC_gift_giveaway_box_520x292.png?itok=w1YQhNH1 (Gift box opens with colors coming out)
[2]: https://opensource.com/article/18/1/how-install-apps-linux
[3]: https://opensource.com/article/18/5/getting-started-regular-expressions
[4]: https://labs.fedoraproject.org/en/design-suite/
[5]: https://opensource.com/downloads/apt-cheat-sheet
[6]: https://opensource.com/downloads/dnf-cheat-sheet

View File

@ -0,0 +1,75 @@
[#]: subject: (GitLabs New Open Source Tool Will Detect Malicious Code)
[#]: via: (https://news.itsfoss.com/gitlab-open-source-tool-malicious-code/)
[#]: author: (Ankush Das https://news.itsfoss.com/author/ankush/)
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
GitLabs New Open Source Tool Will Detect Malicious Code
======
There are several open-source tools available for security researchers. Now, GitLab has introduced a new one to the arsenal that lets you detect malicious code in dependencies.
The tool is also known as “Package Hunter” and is an important addition that could help secure every type of software.
### What is Package Hunter?
Every software includes some form of dependencies, which makes it possible for a developer to quickly build an app.
While this facilitates the reuse of code to achieve the task, they often just “trust” the dependencies used without separate review.
Package Hunter comes to the rescue here and lets you easily detect malicious code in a dependency package.
### Enhanching Software Supply Chain Security
Many supply chain attacks involve a compromised dependency package.
Normally, the attacker injects malicious code in the dependency code available to the public or creates a separate private repository to distribute the malicious dependency that looks safe.
Even if you are using a package manager to get trusted packages, it can be tricked to download packages from a private repository. And, you will have no idea about it.
Hence, with an additional check to the supply chain which is as convenient as Package Hunter, the software supply chain security should improve.
And, especially, if the open-source supply chain security improves, [open source software security][1] will gradually get a boost as well.
### How Does it Work? How Can You Get it?
Package Hunter scans for malicious code and keeps an eye on unexpected behavior of the dependencies.
It installs the dependencies in a sandbox environment to monitor and detect any anomalies.
As of now, it supports testing NodeJS modules and Ruby Jems.
GitLab has been using the tool internally for a while. And, now, it seamlessly integrates with GitLab.
You can learn more about setting it up by referring to the [official documentation][2] and the [Package Hunter CLI instructions][3].
It is available as a free and open-source project on [GitLab][4].
_What do you think about GitLabs open-source tool to help detect malicious code? Feel free to share your thoughts in the comments below._
#### Big Tech Websites Get Millions in Revenue, It's FOSS Got You!
If you like what we do here at It's FOSS, please consider making a donation to support our independent publication. Your support will help us keep publishing content focusing on desktop Linux and open source software.
I'm not interested
--------------------------------------------------------------------------------
via: https://news.itsfoss.com/gitlab-open-source-tool-malicious-code/
作者:[Ankush 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://news.itsfoss.com/author/ankush/
[b]: https://github.com/lujun9972
[1]: https://news.itsfoss.com/open-source-software-security/
[2]: https://gitlab.com/gitlab-org/security-products/package-hunter/-/blob/main/README.md
[3]: https://gitlab.com/gitlab-org/security-products/package-hunter-cli/-/blob/main/README.md#gitlab-ci
[4]: https://gitlab.com/gitlab-org/security-products/package-hunter/activity

View File

@ -0,0 +1,90 @@
[#]: subject: (Avoid this common open source scanning error)
[#]: via: (https://opensource.com/article/21/7/open-source-scanning-error)
[#]: author: (Jeffrey Robert Kaufman https://opensource.com/users/jkaufman)
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
Avoid this common open source scanning error
======
Why do source-code scanners sometimes report incorrect license
information?
![Target practice][1]
[Pete Townshend][2], legendary guitar player for British rock band The Who, is well-known for playing suspended chords. Suspended chords add musical tension to a song. For those piano players reading this who (like me) love to play in the key of C, simply play a C major chord (the notes C, E, and G) and replace the E note with either an F or a D. You are now on your way to becoming a British rock star![1][3]
Music is often filled with combinations of chords, like suspended chords, that provide tension, then release. Although adding tension to a musical composition is desirable, adding tension to scanning software with open source tools is certainly unwelcome.
An issue at Red Hat involving scanning software led me to write this article.
Recently, an important customer raised a concern after scanning some of our software's source code. As you may know, Red Hat provides the source code of its software. The customer's scanning tool reported that a certain software file was licensed under the GPLv3, which was not expected. In fact, the software file was explicitly and solely marked as being licensed under the Apache 2.0 license. The customer requested that we look into this issue, and we were happy to do so.
After our in-depth research, we concluded that their scanning software is clearly incorrect. We developed a hypothesis that explains the anomaly, which I will now explain.
A popular type of open source software scanning tool compares the software being scanned to vast repositories of preexisting open source software and reports any matches. For example, assume there is an open source file named MIT.c that returns an integer one higher than the integer passed to it. In other words, it is a simple adder. It could look like this:
```
Copyright 2021 Jeffrey R. Kaufman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
int foo(int x) {
        x+=1;
        return x;
}
```
For this hypothetical example, assume that MIT.c was placed in a GitHub repository named The Simple Maths Project as an open source community-based project for solving simple arithmetic problems. This project contains many other similar C language files, all under the same MIT License.
Since this hypothetical example function is so useful (of course it isn't, but stay with me here), it was included to provide simple arithmetic utility in many other open source projects on GitHub. Also, assume that one of these other projects, named The Sustained Chord Calculator, uses this MIT.c source file from The Simple Maths Project to help calculate the musical formulation for suspended chords.
The hypothetical Suspended Chord Calculator project, in addition to using MIT.c, also includes several source files licensed under GPLv2. When The Suspended Chord Calculator project is compiled, you can assume the resulting executable will contain both GPLv2-licensed software and the MIT-licensed MIT.c as one combined work in such a way that MIT.c cannot be reasonably considered independent and a separate work in itself. That resulting executable would rightly be considered licensed under the GPLv2, and the obligations of the GPLv2 must be complied with. Compliance means providing (or offering to provide for three years) all of the sources used to create the binary or executable, including all the software files licensed under GPLv2 and MIT.c.
Moving back to our problem…
Suppose one of your software products uses MIT.c, in addition to your own authored software. Since MIT.c is solely under the MIT License, this would obligate you to comply with only the MIT License terms, which is easy to do. Typically, people comply by providing a copy of the MIT License along with the copyright notice with their software distribution. Or, if you are a company like Red Hat, providing the source code that contains the license text is also a method of compliance—and my recommended approach. (See [_An economically efficient model for open source software license compliance_][4].)
If you decide to scan the source code of your software product using a source-code scanner of the type that references repositories of open source projects, your scanner may likely report that MIT.c is licensed under the GPLv2! Why? Because it will see MIT.c, in source-code form, associated with The Suspended Chord Calculator project licensed under the GPLv2 and assume, naively, that MIT.c also must be subject to GPLv2 terms. This is notwithstanding that the MIT.c source file is clearly marked with an MIT License, and you copied it only from the original MIT-licensed The Simple Maths Project.
This is an unfortunate consequence of using these types of scanning systems. In this example, such systems will erroneously report generally every single open source project in its repository that uses MIT.c. There could be tens, hundreds, or even thousands of programs that use MIT.c, all under different licenses, and you will be provided with a giant stack of projects to review indicating that MIT.c could be MIT licensed, BSD licensed, GPLv2 licensed, or, frankly, carry any other open source license under the sun from a project that just happens to use MIT.c. And in the end, you will discover that the file was solely under MIT.c. In my experience, there are very few situations where this type of scanning is warranted and, even when it is justifiable, that the file license results are something other than you expected. It happens, but it is rare.
There is another type of software scanning system that reports on licensing by looking only for matches to known license texts in the source files of the project. This type of scanner would detect the MIT License text in the source code and correctly report that the software is subject to the terms of the MIT License, notwithstanding the fact that MIT.c may be used in many other open source projects under varying license terms. Although this type of source-code scanner can also have false positives, in my experience, source-code scanners of the type that reference repositories of open source projects have significantly higher rates of misreporting for the reasons discussed previously.
Frankly, source-code scanners that reference repositories of open source software to ascertain license data can be useful in certain situations, such as when you may be hyper concerned that an engineer has inadvertently copied and pasted source code from an unacceptable license without also copying over the applicable license text. In that situation, a source-code scanner of the type that looks only for matches to license texts would not detect that inclusion. However, as I stated before, this situation is exceptionally rare, making repository-matching source-code scanners prone to errors and a waste of resources for tracking down the truth. This is time and resources that could be devoted to more issues of substance. You can also address this situation by training your developers to never copy software from another source without also copying over any applicable license.
A scanner that reports the incorrect license is doing a tremendous disservice to your organization by requiring you to resolve a false positive. Countless hours of wasted resources are devoted to these wild-goose chases…as our customer experienced.
We won't be fooled again!
* * *
_I want to thank my colleague Richard Fontana for suggesting the title of this article. Read some of his great articles on Opensource.com under the [Law section][5]._
1\. If you want to learn more about music theory and suspended chords, check out Rick Beato's analysis of another great track from The Who at [What Makes This Song Great?™ Ep. 96 The Who][6].
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/7/open-source-scanning-error
作者:[Jeffrey Robert Kaufman][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/jkaufman
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/target-security.png?itok=Ca5-F6GW (Target practice)
[2]: https://en.wikipedia.org/wiki/Pete_Townshend
[3]: tmp.K7c2OyIB7H#1
[4]: https://opensource.com/article/17/9/economically-efficient-model
[5]: https://opensource.com/tags/law
[6]: https://www.bing.com/videos/search?q=rick+biato+what+makes+this+song+great+who&view=detail&mid=BBF5E938C3E5AD6D73BCBBF5E938C3E5AD6D73BC&FORM=VIRE

View File

@ -1,210 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (YungeG)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Trace code in Fedora with bpftrace)
[#]: via: (https://fedoramagazine.org/trace-code-in-fedora-with-bpftrace/)
[#]: author: (Augusto Caringi https://fedoramagazine.org/author/acaringi/)
Trace code in Fedora with bpftrace
======
![][1]
bpftrace is [a new eBPF-based tracing tool][2] that was first included in Fedora 28. It was developed by Brendan Gregg, Alastair Robertson and Matheus Marchini with the help of a loosely-knit team of hackers across the Net. A tracing tool lets you analyze what a system is doing behind the curtain. It tells you which functions in code are being called, with which arguments, how many times, and so on.
This article covers some basics about bpftrace, and how it works. Read on for more information and some useful examples.
### eBPF (extended Berkeley Packet Filter)
[eBPF][3] is a tiny virtual machine, or a virtual CPU to be more precise, in the Linux Kernel. The eBPF can load and run small programs in a safe and controlled way in kernel space. This makes it safer to use, even in production systems. This virtual machine has its own instruction set architecture ([ISA][4]) resembling a subset of modern processor architectures. The ISA makes it easy to translate those programs to the real hardware. The kernel performs just-in-time translation to native code for main architectures to improve the performance.
The eBPF virtual machine allows the kernel to be extended programmatically. Nowadays several kernel subsystems take advantage of this new powerful Linux Kernel capability. Examples include networking, seccomp, tracing, and more. The main idea is to attach eBPF programs into specific code points, and thereby extend the original kernel behavior.
eBPF machine language is very powerful. But writing code directly in it is extremely painful, because its a low level language. This is where bpftrace comes in. It provides a high-level language to write eBPF tracing scripts. The tool then translates these scripts to eBPF with the help of clang/LLVM libraries, and then attached to the specified code points.
## Installation and quick start
To install bpftrace, run the following command in a terminal [using][5] _[sudo][5]_:
```
$ sudo dnf install bpftrace
```
Try it out with a “hello world” example:
```
$ sudo bpftrace -e 'BEGIN { printf("hello world\n"); }'
```
Note that you must run _bpftrace_ as _root_ due to the privileges required. Use the _-e_ option to specify a program, and to construct the so-called “one-liners.” This example only prints _hello world_, and then waits for you to press **Ctrl+C**.
_BEGIN_ is a special probe name that fires only once at the beginning of execution. Every action inside the curly braces _{ }_ fires whenever the probe is hit — in this case, its just a _printf_.
Lets jump now to a more useful example:
```
$ sudo bpftrace -e 't:syscalls:sys_enter_execve { printf("%s called %s\n", comm, str(args->filename)); }'
```
This example prints the parent process name _(comm)_ and the name of every new process being created in the system. _t:syscalls:sys_enter_execve_ is a kernel tracepoint. Its a shorthand for _tracepoint:syscalls:sys_enter_execve_, but both forms can be used. The next section shows you how to list all available tracepoints.
_comm_ is a bpftrace builtin that represents the process name. _filename_ is a field of the _t:syscalls:sys_enter_execve_ tracepoint. You can access these fields through the _args_ builtin.
All available fields of the tracepoint can be listed with this command:
```
bpftrace -lv "t:syscalls:sys_enter_execve"
```
## Example usage
### Listing probes
A central concept for _bpftrace_ are **probe points**. Probe points are instrumentation points in code (kernel or userspace) where eBPF programs can be attached. They fit into the following categories:
* _kprobe_ kernel function start
* _kretprobe_ kernel function return
* _uprobe_ user-level function start
* _uretprobe_ user-level function return
* _tracepoint_ kernel static tracepoints
* _usdt_ user-level static tracepoints
* _profile_ timed sampling
* _interval_ timed output
* _software_ kernel software events
* _hardware_ processor-level events
All available _kprobe/kretprobe_, _tracepoints_, _software_ and _hardware_ probes can be listed with this command:
```
$ sudo bpftrace -l
```
The _uprobe/uretprobe_ and _usdt_ probes are userspace probes specific to a given executable. To use them, use the special syntax shown later in this article.
The _profile_ and _interval_ probes fire at fixed time intervals. Fixed time intervals are not covered in this article.
### Counting system calls
**Maps** are special BPF data types that store counts, statistics, and histograms. You can use maps to summarize how many times each syscall is being called:
```
$ sudo bpftrace -e 't:syscalls:sys_enter_* { @[probe] = count(); }'
```
Some probe types allow wildcards to match multiple probes. You can also specify multiple attach points for an action block using a comma separated list. In this example, the action block attaches to all tracepoints whose name starts with _t:syscalls:sys_enter__, which means all available syscalls.
The bpftrace builtin function _count()_ counts the number of times this function is called. _@[]_ represents a map (an associative array). The key of this map is _probe_, which is another bpftrace builtin that represents the full probe name.
Here, the same action block is attached to every syscall. Then, each time a syscall is called the map will be updated, and the entry is incremented in the map relative to this same syscall. When the program terminates, it automatically prints out all declared maps.
This example counts the syscalls called globally, its also possible to filter for a specific process by _PID_ using the bpftrace filter syntax:
```
$ sudo bpftrace -e 't:syscalls:sys_enter_* / pid == 1234 / { @[probe] = count(); }'
```
### Write bytes by process
Using these concepts, lets analyze how many bytes each process is writing:
```
$ sudo bpftrace -e 't:syscalls:sys_exit_write /args->ret > 0/ { @[comm] = sum(args->ret); }'
```
_bpftrace_ attaches the action block to the write syscall return probe (_t:syscalls:sys_exit_write_). Then, it uses a filter to discard the negative values, which are error codes _(/args-&gt;ret &gt; 0/)_.
The map key _comm_ represents the process name that called the syscall. The _sum()_ builtin function accumulates the number of bytes written for each map entry or process. _args_ is a bpftrace builtin to access tracepoints arguments and return values. Finally, if successful, the _write_ syscall returns the number of written bytes. _args-&gt;ret_ provides access to the bytes.
### Read size distribution by process (histogram):
_bpftrace_ supports the creation of histograms. Lets analyze one example that creates a histogram of the _read_ size distribution by process:
```
$ sudo bpftrace -e 't:syscalls:sys_exit_read { @[comm] = hist(args->ret); }'
```
Histograms are BPF maps, so they must always be attributed to a map (_@_). In this example, the map key is _comm_.
The example makes _bpftrace_ generate one histogram for every process that calls the _read_ syscall. To generate just one global histogram, attribute the _hist()_ function just to _@_ (without any key).
bpftrace automatically prints out declared histograms when the program terminates. The value used as base for the histogram creation is the number of read bytes, found through _args-&gt;ret_.
### Tracing userspace programs
You can also trace userspace programs with _uprobes/uretprobes_ and _USDT_ (User-level Statically Defined Tracing). The next example uses a _uretprobe_, which probes to the end of a user-level function. It gets the command lines issued in every _bash_ running in the system:
```
$ sudo bpftrace -e 'uretprobe:/bin/bash:readline { printf("readline: \"%s\"\n", str(retval)); }'
```
To list all available _uprobes/uretprobes_ of the _bash_ executable, run this command:
```
$ sudo bpftrace -l "uprobe:/bin/bash"
```
_uprobe_ instruments the beginning of a user-level functions execution, and _uretprobe_ instruments the end (its return). _readline()_ is a function of _/bin/bash_, and it returns the typed command line. _retval_ is the return value for the instrumented function, and can only be accessed on _uretprobe_.
When using _uprobes_, you can access arguments with _arg0..argN_. A _str()_ call is necessary to turn the _char *_ pointer to a _string_.
## Shipped Scripts
There are many useful scripts shipped with bpftrace package. You can find them in the _/usr/share/bpftrace/tools/_ directory.
Among them, you can find:
* _killsnoop.bt_ Trace signals issued by the kill() syscall.
* _tcpconnect.bt_ Trace all TCP network connections.
* _pidpersec.bt_ Count new procesess (via fork) per second.
* _opensnoop.bt_ Trace open() syscalls.
* _vfsstat.bt_ Count some VFS calls, with per-second summaries.
You can directly use the scripts. For example:
```
$ sudo /usr/share/bpftrace/tools/killsnoop.bt
```
You can also study these scripts as you create new tools.
## Links
* bpftrace reference guide <https://github.com/iovisor/bpftrace/blob/master/docs/reference_guide.md>
* bpftrace (DTrace 2.0) for Linux 2018 <http://www.brendangregg.com/blog/2018-10-08/dtrace-for-linux-2018.html>
* BPF: the universal in-kernel virtual machine <https://lwn.net/Articles/599755/>
* Linux Extended BPF (eBPF) Tracing Tools <http://www.brendangregg.com/ebpf.html>
* Dive into BPF: a list of reading material [https://qmonnet.github.io/whirl-offload/2016/09/01/dive-into-bpf][6]
* * *
_Photo by _[_Roman Romashov_][7]_ on _[_Unsplash_][8]_._
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/trace-code-in-fedora-with-bpftrace/
作者:[Augusto Caringi][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/acaringi/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2019/08/bpftrace-816x345.jpg
[2]: https://github.com/iovisor/bpftrace
[3]: https://lwn.net/Articles/740157/
[4]: https://github.com/iovisor/bpf-docs/blob/master/eBPF.md
[5]: https://fedoramagazine.org/howto-use-sudo/
[6]: https://qmonnet.github.io/whirl-offload/2016/09/01/dive-into-bpf/
[7]: https://unsplash.com/@wehavemegapixels?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
[8]: https://unsplash.com/search/photos/trace?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText

View File

@ -2,7 +2,7 @@
[#]: via: (https://opensource.com/article/21/4/linux-cheat-sheets)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (YungeG)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -1,136 +0,0 @@
[#]: subject: (What is XML?)
[#]: via: (https://opensource.com/article/21/7/what-xml)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
[#]: collector: (lujun9972)
[#]: translator: (amwps290)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
What is XML?
======
Get to know XML, a strict yet flexible markup language used for
everything from documentation to graphics.
![Computer screen with files or windows open][1]
XML is a hierarchical markup language. It uses opening and closing tags to define data. It's used to store and exchange data, and because of its extreme flexibility, it's used for everything from [documentation][2] to [graphics][3].
Here's a sample XML document:
```
&lt;xml&gt;
  &lt;os&gt;
   &lt;linux&gt;
    &lt;distribution&gt;
      &lt;name&gt;Fedora&lt;/name&gt;
      &lt;release&gt;8&lt;/release&gt;
      &lt;codename&gt;Werewolf&lt;/codename&gt;
    &lt;/distribution&gt;
    &lt;distribution&gt;
      &lt;name&gt;Slackware&lt;/name&gt;
      &lt;release&gt;12.1&lt;/release&gt;
      &lt;mascot&gt;
        &lt;official&gt;Tux&lt;/official&gt;
        &lt;unofficial&gt;Bob Dobbs&lt;/unofficial&gt;
      &lt;/mascot&gt;
    &lt;/distribution&gt;
   &lt;/linux&gt;
  &lt;/os&gt;    
&lt;/xml&gt;
```
Reading the sample XML, you might find there's an intuitive quality to the format. You can probably understand the data in this document whether you're familiar with the subject matter or not. This is partly because XML is considered verbose. It uses lots of tags, the tags can have long and descriptive names, and the data is ordered in a hierarchical manner that helps explain the data's relationships. You probably understand from this sample that the Fedora distribution and the Slackware distribution are two different and unrelated instances of Linux because each one is "contained" inside its own independent `<distribution>` tag.
XML is also extremely flexible. Unlike HTML, there's no predefined list of tags. You are free to create whatever data structure you need to represent.
### Components of XML
Data exists to be read, and when a computer "reads" data, the process is called _parsing_. Using the sample XML data again, here are the terms that most XML parsers consider significant.
* **Document:** The `<xml>` tag opens a _document_, and the `</xml>` tag closes it.
* **Node:** The `<os>`, `<distribution>`, and `<mascot>` are _nodes_. In parsing terminology, a node is a tag that contains other tags.
* **Element:** An entity such as `<name>Fedora</name>` and `<official>Tux</official>`, from the first `<` to the last `>` is an _element_.
* **Content:** The data between two element tags is considered _content_. In the first `<name>` element, the string `Fedora` is the content.
### XML schema
Tags and tag inheritance in an XML document are known as _schema_.
Some schemas are made up as you go (for example, the sample XML code in this article was purely improvised), while others are strictly defined by a standards group. For example, the Scalable Vector Graphics (SVG) schema is [defined by the W3C][4], while the [DocBook schema][5] is defined by Norman Walsh.
A schema enforces consistency. The most basic schemas are usually also the most restrictive. In my example XML code, it wouldn't make sense to place a distribution name within the `<mascot>` node because the implied schema of the document makes it clear that a mascot must be a "child" element of a distribution.
### Data object model (DOM)
Talking about XML would get confusing if you had to constantly describe tags and positions (e.g., "the name tag of the second distribution tag in the Linux part of the OS section"), so parsers use the concept of a Document Object Model (DOM) to represent XML data. The DOM places XML data into a sort of "family tree" structure, starting from the root element (in my sample XML, that's the `os` tag) and including each tag.
![Document Object Model][6]
(Seth Kenlon, [CC BY-SA 4.0][7])
This same XML data structure can be expressed as paths, just like files in a Linux system or the location of web pages on the internet. For instance, the path to the `<mascot>` tag can be represented as `//os/linux/distribution/slackware/mascot`.
The path to _both_ `<distribution>` tags can be represented as `//os/linux/distribution`. Because there are two distribution nodes, a parser loads both nodes (and the contents of each) into an array that can be queried.
### Strict XML
XML is also known for being strict. This means that most applications are designed to intentionally fail when they encounter errors in XML. That may sound problematic, but it's one of the things developers appreciate most about XML because unpredictable things can happen when applications try to guess how to resolve an error. For example, back before HTML was well defined, most web browsers included a "quirks mode" so that when people tried to view poor HTML code, the web browser could load what the author _probably_ intended. The results were wildly unpredictable, especially when one browser guessed differently than another.
XML disallows this by intentionally failing when there's an error. This lets the author fix errors until they produce valid XML. Because XML is well-defined, there are validator plugins for many applications and standalone commands like `xmllint` and `xmlstarlet` to help you locate errors early.
### Transforming XML
Because XML is often used as an interchange format, it's common to transform XML into some other data format or into some other XML schema. Classic examples include XSLTProc, xmlto, and [pandoc][8], but technically there are many other applications designed, at least in part, to convert XML.
In fact, LibreOffice uses XML to layout its word processor and spreadsheet documents, so any time you export or [convert a file from LibreOffice][9], you're transforming XML.
[Ebooks in the open source EPUB format][10] use XML, so any time you [convert a document into an EPUB][11] or from an EPUB, you're transforming XML.
Inkscape, the vector-based illustration application, saves its files in SVG, which is an XML schema designed for graphics. Any time you export an image from Inkscape as a PNG file, you're transforming XML.
The list could go on and on. XML is a data storage format, and it's designed to ensure that your data, whether it's points and lines on a canvas, nodes on a chart, or just words in a document, can be easily and accurately extracted, updated, and converted. 
### Learning XML
Writing XML is a lot like writing HTML. Thanks to the hard work of Jay Nick, [free and fun XML lessons are available online][3] that teach you how to create graphics with XML.
In general, very few special tools are required to explore XML. Thanks to the close relationship between HTML and XML, you can [view XML using a web browser][12]. In addition, open source text editors like [QXmlEdit][13], [NetBeans][14], and [Kate][15] make typing and reading XML easy with helpful prompts, autocompletion, syntax verification, and more.
### Choose XML
XML may look like a lot of data at first, but it's not that much different than HTML (in fact, HTML has been [reimplemented as XML in the form of XHTML][16]). XML has the unique benefit that the components forming its structure also happen to be metadata providing information about what it's storing. A well-designed XML schema contains and describes your data, allowing a user to understand it at a glance and parse it quickly, and enabling developers to [parse it efficiently][17] with convenient programming libraries.
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/7/what-xml
作者:[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/browser_screen_windows_files.png?itok=kLTeQUbY (Computer screen with files or windows open)
[2]: https://opensource.com/article/17/9/docbook
[3]: https://opensource.com/article/17/5/coding-scalable-vector-graphics-make-steam
[4]: https://www.w3.org/TR/SVG11/
[5]: http://docbook.org
[6]: https://opensource.com/sites/default/files/uploads/dom.jpg (Document Object Model)
[7]: https://creativecommons.org/licenses/by-sa/4.0/
[8]: https://opensource.com/article/20/5/pandoc-cheat-sheet
[9]: https://opensource.com/article/21/3/libreoffice-command-line
[10]: https://opensource.com/education/15/11/ebook-open-formats
[11]: https://opensource.com/life/13/8/how-create-ebook-open-source-way
[12]: https://opensource.com/article/18/12/xml-browser
[13]: https://opensource.com/article/17/7/7-ways-handle-xml-qxmledit
[14]: https://opensource.com/article/20/12/netbeans
[15]: https://opensource.com/article/20/12/kate-text-editor
[16]: https://www.w3.org/TR/xhtml1/
[17]: https://opensource.com/article/21/6/parsing-config-files-java

View File

@ -2,7 +2,7 @@
[#]: via: (https://opensource.com/article/21/7/rust-tools-linux)
[#]: author: (Sudeshna Sur https://opensource.com/users/sudeshna-sur)
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (amwps290 )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -1,232 +0,0 @@
[#]: subject: (Linux package managers: dnf vs apt)
[#]: via: (https://opensource.com/article/21/7/dnf-vs-apt)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
[#]: collector: (lujun9972)
[#]: translator: (perfiffer )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
Linux package managers: dnf vs apt
======
Package managers do the same general things—installing, managing, and
uninstalling applications—but they don't do everything the same.
![Gift box opens with colors coming out][1]
There are many ways to [get applications onto a Linux system][2]. Some, like Flatpak and containers, are new. Others, like DEB and RPM, are classic formats that have withstood the test of time.
There isn't a universal installer for any operating system. Today, all major OSes use a mix of app stores (both first and third party), drag-and-drop installation, and installation wizards because there are innumerable developers delivering software. Different developers have different requirements for the code they deliver, and this informs the installation method they each choose.
Linux pioneered the concept of a _package manager_, a command to install, manage, and uninstall applications. Two common package manager commands are `apt` and `dnf`. The `apt` command manages DEB packages, while `dnf` manages RPM packages. The two are not strictly exclusive of one another in theory, although in practice, a Linux distribution generally uses one or the other. It's theoretically possible to run both on one system, but package installations would overlap, versioning would be difficult, and the commands would be redundant to one another. However, if you work in a mixed Linux environment, interacting with workstations running one distribution and servers running another, you may need to know both.
### Searching for applications
Before you can install an application with a package manager, you need to know the package's name. Usually, the application name and the package name are the same. The process to verify the name of the package you want to install is exactly the same on `dnf` and `apt`:
```
$ sudo dnf search zsh
====== Name Exactly Matched: zsh ======
zsh.x86_64 : Powerful interactive shell
[...]
```
With `apt`:
```
$ sudo apt search zsh
Sorting... Done
Full Text Search... Done
csh/stable 20110502-4+deb10u1 amd64
  Shell with C-like syntax
ddgr/stable 1.6-1 all
  DuckDuckGo from the terminal
direnv/stable 2.18.2-2 amd64
  Utility to set directory specific environment variables
draai/stable 20180521-1 all
  Command-line music player for MPD
[...]
```
To get relevant results from `apt` earlier in the search, you can use [regex][3]:
```
apt search ^zsh
Sorting... Done
Full Text Search... Done
zsh/stable 5.7.1-1 amd64
  shell with lots of features
[...]
```
### Finding an application's package
Some commands come bundled with other commands, all in one package. When that happens, you can use your package manager to learn which package provides what you need. The `dnf` and `apt` commands diverge on how they search for this kind of metadata.
On `dnf`:
```
$ sudo dnf provides pgrep
procps-ng-3.3.15-6.el8.x86_64 : System and process monitoring utilities
Repo        : baseos
Matched from:
Filename    : /usr/bin/pgrep
```
The `apt` command uses a subcommand, `apt-file`. To use `apt-file`, you must first install it and then prompt it to update its cache:
```
$ sudo apt install apt-file
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following additional packages will be installed:
  libapt-pkg-perl libexporter-tiny-perl liblist-moreutils-perl libregexp-assemble-perl
The following NEW packages will be installed:
  apt-file libapt-pkg-perl libexporter-tiny-perl liblist-moreutils-perl libregexp-assemble-perl
0 upgraded, 5 newly installed, 0 to remove and 14 not upgraded.
Need to get 297 kB of archives.
After this operation, 825 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
$ sudo apt-file update
[...]
```
You can use `apt-file` to search for a command. You can cast a very wide net by just searching for the command, but if you happen to know the command's expected path, it's more accurate:
```
$ sudo apt-file search /usr/bin/pgrep
pgreplay: /usr/bin/pgreplay              
procps: /usr/bin/pgrep
```
### Installing applications
Installing applications is essentially identical with `apt` and `dnf`:
```
`$ sudo apt install zsh`
```
With `dnf`, you can install a single package using the same option:
```
`$ sudo dnf install zsh`
```
Many RPM-based distributions feature _installation groups_, which collect sometimes superficially related applications into one easily installable target. For instance, the [Design Suite][4] group in Fedora contains popular creative applications. Many artists who want one creative application are likely to want similar applications, and installing the whole group is an easy and quick way to get a sensible start on building a digital studio. You can view available groups with `group list` (use `-v` to see the group names without spaces):
```
$ sudo dnf group list -v
[...]
Available Groups:
   Container Management (container-management)
   RPM Development Tools (rpm-development-tools)
   Design Suite (design-suite)
   Development Tools (development)
[...]
```
Install an RPM group using the `group install` subcommands:
```
`$ sudo dnf group install design-suite`
```
You can use the `@` notation to reduce typing:
```
`$ sudo dnf install @design-suite`
```
### Upgrading applications
One advantage of using a package manager is that it is aware of _all_ the applications it has ever installed. That means you don't have to go hunting for updated versions of applications. Instead, you can tell your package manager to scan for updates.
The subcommands used by `dnf` and `apt` are slightly different. Because `apt` keeps a cache of information that requires regular updating, it uses the `upgrade` subcommand for application updates:
```
`$ sudo apt upgrade`
```
By contrast, `dnf` updates metadata every time you use the command, so the `update` and `upgrade` subcommands are interchangeable:
```
`$ sudo dnf upgrade`
```
This is the same as:
```
`$ sudo dnf update`
```
### Removing applications
If you've ever tried to remove an application manually on any platform, then you know there are inevitably leftover files, such as preference files or assets or icons, scattered all around your hard drive after you remove the application. Yet another advantage to using a package manager is that your package manager knows _every single file_ installed with a package:
```
`$ sudo dnf remove zsh`
```
The `remove` subcommand is also used for `apt`:
```
`$ sudo apt remove zsh`
```
Removing a package with `apt` doesn't remove modified user configuration files, in case you removed the package by accident. If you want `apt` to remove an application _and_ its configuration files, use `purge` on an application you've previously removed:
```
`$ sudo apt purge zsh`
```
Both `apt` and `dnf` (even with `purge`) don't remove data or configuration files in your home directory. To remove data from your home directory, you must do it manually (it's usually found in `~/.config` and `~/.local`).
### Learning package management
Whether your Linux distribution of choice favors `apt` or `dnf`, the commands' purposes are broadly identical. They help you install, update, and remove packages. These two, being the most common package managers, largely mirror one another's most important syntactical elements, so switching between them is pretty easy.
Each has some advanced features, such as repository management, that diverge substantially, but those tend not to be run as frequently as the classic sequence of `search` and `install`.
Regardless of which package manager you use more often, you can download our [apt cheat sheet][5] and [dnf cheat sheet][6] so that you have the most important syntax close at hand when you need it the most.
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/7/dnf-vs-apt
作者:[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/OSDC_gift_giveaway_box_520x292.png?itok=w1YQhNH1 (Gift box opens with colors coming out)
[2]: https://opensource.com/article/18/1/how-install-apps-linux
[3]: https://opensource.com/article/18/5/getting-started-regular-expressions
[4]: https://labs.fedoraproject.org/en/design-suite/
[5]: https://opensource.com/downloads/apt-cheat-sheet
[6]: https://opensource.com/downloads/dnf-cheat-sheet

View File

@ -2,7 +2,7 @@
[#]: via: (https://www.debugpoint.com/2021/07/install-shutter-fedora/)
[#]: author: (Arindam https://www.debugpoint.com/author/admin1/)
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -1,135 +0,0 @@
[#]: subject: (Top Android Emulators to Run and Test Android Apps on Linux)
[#]: via: (https://itsfoss.com/android-emulators-linux/)
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
Top Android Emulators to Run and Test Android Apps on Linux
======
Android is built on top of a heavily customized Linux kernel. So, running mobile apps on Linux makes sense using an Android emulator.
While this is not something new that you can do on your Linux machine, it is a feature more in demand after Windows introduced the ability to run Android apps in 2021.
Not just limited to using apps, some of the Android emulators can also come in handy for development and testing.
Hence, I have compiled a list of the best emulators that you can use to test or run Android applications/games on Linux.
### 1\. Anbox
Anbox is a pretty popular emulator that lets Linux users run Android apps. Probably this is what Deepin Linux utilizes to make help run Android apps out of the box.
It isolates the Android operating system from the host using a container, which also lets them make the latest Android version available to use.
Android apps running will not have direct access to your hardware—which is a good security decision.
Unlike some of the other options here, Anbox does not technically need an emulation layer to make Android work. In other words, it is as close to a native Android experience on your Linux system.
For this reason, it may not be the easiest option available. You cannot just use the Google Play Store to install applications, you need to utilize Android Debug Bridge (ADB). All you need is the APK file of an app to install and use it.
[Anbox][1]
### 2\. Genymotion
![][2]
Genymotion is an impressive solution tailored for testing and development.
It is not a free and open-source option. They provide virtual Android experiences as a service through the cloud or a desktop client that is independent of Android Studio.
You can simulate a variety of hardware configurations and Android versions to create a virtual device for testing. It also gives you the ability to scale up and has multiple Android virtual devices running for extensive tests.
It can help you test how file uploading works in your app, impacts battery, performance, memory, and so on.
While it is a premium solution mostly for professionals, it does support the latest Linux distributions that include Ubuntu 20.04 LTS.
[Genymotion][3]
### 3\. Android-x86
![][4]
Android x86 is an open-source project to make Android run on a PC with 32-bit support.
You can choose to install it using a virtual machine manager on your Linux system or directly try it on your PC.
Official [installation instructions][5] are available if you need to go ahead.
Unlike some other options, it is a simple emulator that tries to work on a PC with no fancy features.
[Android x86][6]
### 4\. Android Studio (Virtual Devices)
![][7]
Android Studio is a full-fledged tool for development and testing. Fortunately, with the support for Linux, you can use it to emulate the Android experience for experiments if you need to.
You just need to create an Android Virtual Device (AVD) that you can configure and then simulate as an emulator.
There are good chances to find support for some of the latest smartphones, TVs, and smartwatches as well.
It needs a certain learning curve to be able to pull it off, but it is free and completely open-source.
[Android Studio][8]
### 5\. ARChon
![][9]
An interesting solution is an Android emulator that you can use in Linux and any other platform.
It helps run Android apps on Chrome OS or with Chrome browser on any operating system. Unlike some others, you may not get a complete Android experience but only the ability to run Android apps.
You just have to unpack the runtime and load it into Chrome extensions. Next, add the app you want to use by downloading the APK file onto it.
[ARChon][10]
### 6\. Bliss OS
![][11]
Bliss OS is yet another open-source project, similar to Android x86 that aims to make Android run on PC.
Unlike Android x86, it gives more compatibility options by supporting both 32-bit and 64-bit architectures. Also, you can download the compatible file as per your processor.
It is actively maintained and supports the latest Android versions available in the market.
[Bliss OS][12]
### Wrapping Up
While you will find several Android emulators available for Linux, they may not replace a full-fledged smartphone experience.
Every emulator comes with a set of features along with a specific purpose. Choose the one that you need!
Have you tried Android emulators yet? Whats your favorite emulator that you have used in Linux? Feel free to let me know in the comments down below.
--------------------------------------------------------------------------------
via: https://itsfoss.com/android-emulators-linux/
作者:[Ankush 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://itsfoss.com/author/ankush/
[b]: https://github.com/lujun9972
[1]: https://anbox.io
[2]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/07/genymotion-android-emulator.png?resize=800%2C508&ssl=1
[3]: https://www.genymotion.com
[4]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/07/android-x86-emulator.jpg?resize=1920%2C1080&ssl=1
[5]: https://www.android-x86.org/installhowto.html
[6]: https://www.android-x86.org
[7]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/07/android-virtual-devices-studio.png?resize=800%2C296&ssl=1
[8]: https://developer.android.com/studio
[9]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/07/arcrhon.jpg?resize=800%2C426&ssl=1
[10]: https://archon-runtime.github.io
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/07/bliss-os-android.png?resize=800%2C576&ssl=1
[12]: https://blissos.org

View File

@ -2,7 +2,7 @@
[#]: via: (https://opensource.com/article/21/7/javascript-cheat-sheet)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (lixin555)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
@ -176,7 +176,7 @@ via: https://opensource.com/article/21/7/javascript-cheat-sheet
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
译者:[lixin555](https://github.com/lixin555)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,77 +0,0 @@
[#]: subject: (How to Install VLC on Fedora Linux)
[#]: via: (https://itsfoss.com/install-vlc-fedora/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
How to Install VLC on Fedora Linux
======
If you have just installed Fedora and now wants to install your favorite video player VLC on it, you probably wont find it in the software center. Not immediately, at least.
For reasons best known to their developers, Fedora neither ship with [VLC][1] nor does it include in the official Fedora repository.
So, how do you install VLC on Fedora then? Simple. RPM Fusion is your friend here. Let me show you the steps in detail.
### Installing VLC on Fedora Linux
Using the command line will be easier here. You may use the graphical method as well. Ill discuss it later.
Open a terminal and use the following command to add and enable RPM Fusion repository that contains the VLC package:
```
sudo dnf install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
```
Press Y when asked to confirm adding the new repo. Next, install VLC using DNF command:
```
sudo dnf install vlc
```
It will install VLC in Fedora from the RPM Fusion repository and a few additional dependencies from various repositories.
![Installing VLC in Fedora with DNF command][2]
Once installed, you can search for VLC in the application menu or search for it in the “activities area”.
![Search for VLC][3]
Click on it, start it and enjoy it.
#### Alternate method: Installing VLC from software center
When you have enabled RPM Fusion repository, you can display the applications from this repo in the software center. To do that, use the following command in the terminal:
```
sudo dnf groupupdate core
```
After that, open software center and search for VLC and install from there.
![VLC in Fedora software center][4]
If you have added FlatHub repository, please avoid installing the Flatpak version of VLC because it is around 1 GB in size. The RPM version is a lot smaller in size.
I hope you find this quick tutorial helpful in installing VLC on Fedora. Enjoy.
--------------------------------------------------------------------------------
via: https://itsfoss.com/install-vlc-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://www.videolan.org/
[2]: https://itsfoss.com/wp-content/uploads/2021/07/installing-vlc-fedora-800x422.webp
[3]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/07/vlc-fedora.png?resize=799%2C223&ssl=1
[4]: https://itsfoss.com/wp-content/uploads/2021/07/vlc-in-fedora-software-center-800x486.webp

View File

@ -0,0 +1,386 @@
[#]: subject: (Command line quick tips: wc, sort, sed and tr)
[#]: via: (https://fedoramagazine.org/command-line-quick-tips-wc-sort-sed-and-tr/)
[#]: author: (mahesh1b https://fedoramagazine.org/author/mahesh1b/)
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
Command line quick tips: wc, sort, sed and tr
======
![][1]
Image by Ryan Lerch (CC BY-SA 4.0)
Linux distributions are great to use and they have some tricks under their sleeves which users may not be aware of. Lets have a look at some command line utilities which really come in handy when youre the guy that likes to stick with the terminal rather than using a GUI. 
We all know that using a terminal is more efficient to use the system. In case you are editing or playing with text files on a terminal then these tools will surely make your life easy.
For this article lets have a look at _wc_, _sort_, _tr_, and _sed_ commands.
## **wc**
wc is a utility whose name stands for “word count”. As the name suggests it will count the lines, words or byte count from any file. 
Lets see how it works:
```
$ wc filename
lines words characters filename
```
So in output we get the total number of newlines in the file, total number of words, total number of characters, and the filename.
To get some specific output we have to use options:
* -c To print the byte counts
* -l   To print the newline counts
* -w To print the word counts
* -m To print the character counts
### wc demo
Lets see it in action:
Here we start with a text file, _loremipsm.txt_. First, we print out the file and then use _wc_ on it.
```
$ cat loremipsm.txt
Linux is the best-known and most-used open source operating system.
As an operating system, Linux is software that sits underneath all of the other software on a computer,
receiving requests from those programs and replaying these requests to the computer's hardware.
$ wc loremipsm.txt
3 41 268 loremipsm.txt
```
Suppose I only want to see the byte count of the file: 
```
$ wc -c loremipsm.txt
268 loremipsm.txt
```
For the newline count of the file:
```
$ wc -l loremipsm.txt
3 loremipsm.txt
```
To see the word count of the file:
```
$ wc -w loremipsm.txt
41 loremipsm.txt
```
Now only the character count of the file:
```
$ wc -m loremipsm.txt
268 loremipsm.txt
```
## **sort**
The _sort_ command is one of the most useful tools. It will sort the data in a file. Sorting is by either characters or numbers in ascending or descending order. It can also be used to sort or randomize the lines of files.
Using _sort_ can be very simple.  All we need to do is provide the name of the file.
```
$ sort filename
```
By default it sorts the data in alphabetical order. One thing to note is that the _sort_ command just displays the sorted data. It does not overwrite the file.
Some useful options for _sort_: 
* -r  To sort the lines in the file in reverse order
* -R To shuffle the lines in the file into random order
* -o To save the output in another file
* -k To sort as per specific column
* -t To mention the field separator
* -n To sort the data according to numerical value
### sort demo
Lets use _sort_ in some short demos:
We have a file, _list.txt_, containing names and numeric values separated by commas.
First lets print out the file and just do simple sorting.
```
$ cat list.txt
Cieran Wilks, 9
Adelina Rowland, 4
Hayden Mcfarlnd, 1
Ananya Lamb, 5
Shyam Head, 2
Lauryn Fuents, 8
Kristian Felix, 10
Ruden Dyer, 3
Greyson Meyers, 6
Luther Cooke, 7
$ sort list.txt
Adelina Rowland, 4
Ananya Lamb, 5
Cieran Wilks, 9
Greyson Meyers, 6
Hayden Mcfarlnd, 1
Kristian Felix, 10
Lauryn Fuents, 8
Luther Cooke, 7
Ruden Dyer, 3
Shyam Head, 2
```
Now sort the data in the reverse order.
```
$ sort -r list.txt
Shyam Head, 2
Ruden Dyer, 3
Luther Cooke, 7
Lauryn Fuents, 8
Kristian Felix, 10
Hayden Mcfarlnd, 1
Greyson Meyers, 6
Cieran Wilks, 9
Ananya Lamb, 5
Adelina Rowland, 4
```
Lets shuffle the data.
```
$ sort -R list.txt
Cieran Wilks, 9
Greyson Meyers, 6
Adelina Rowland, 4
Kristian Felix, 10
Luther Cooke, 7
Ruden Dyer, 3
Lauryn Fuents, 8
Hayden Mcfarlnd, 1
Ananya Lamb, 5
Shyam Head, 2
```
Lets make it more complex. This time we sort the data according to the second field, which is the numeric value, and save the output in another file using the -o option.
```
$ sort -n -k2 -t ',' -o sorted_list.txt list.txt
$ ls
sorted_list.txt list.txt
$ cat sorted_list.txt
Hayden Mcfarlnd, 1
Shyam Head, 2
Ruden Dyer, 3
Adelina Rowland, 4
Ananya Lamb, 5
Greyson Meyers, 6
Luther Cooke, 7
Lauryn Fuents, 8
Cieran Wilks, 9
Kristian Felix, 10
```
Here we used -n to sort in numerical order, -k to specify the field to sort (2 in this case) -t to indicate the delimiter or field-separator (a comma) and -o to save the output in the file _sorted_list.txt_. 
## **sed**
Sed is a stream editor that will filter and transform text in the output. This means we are not making changes in the file, only to the output. We can also save the changes in a new file if needed. Sed comes with a lot of options that are useful in filtering or editing the data. 
The syntax for sed is:
```
$ sed [OPTION] PATTERN filename
```
Some of the options used with sed:
* -n : To suppress the printing 
* p: To print the current pattern 
* d : To delete the pattern 
* q : To quit the sed script
### sed demo
Lets see _sed_ in action. We start with the file _data_ with the fields indicating number, name, age and operating system.
Printing the lines twice if they occur in a specific range of lines.
```
$ cat data
1 Vicky Grant 20 linux
2 Nora Burton 19 Mac
3 Willis Castillo 21 Windows
4 Gilberto Mack 30 Windows
5 Aubrey Hayes 17 windows
6 Allan Snyder 21 mac
7 Freddie Dean 25 linux
8 Ralph Martin 19 linux
9 Mindy Howard 20 Mac
$ sed '3,7 p' data
1 Vicky Grant 20 linux
2 Nora Burton 19 Mac
3 Willis Castillo 21 Windows
3 Willis Castillo 21 Windows
4 Gilberto Mack 30 Windows
4 Gilberto Mack 30 Windows
5 Aubrey Hayes 17 windows
5 Aubrey Hayes 17 windows
6 Allan Snyder 21 mac
6 Allan Snyder 21 mac
7 Freddie Dean 25 linux
7 Freddie Dean 25 linux
8 Ralph Martin 19 linux
9 Mindy Howard 20 Mac
```
Here the operation is specified in single quotes indicating lines 3 through 7 and using p to print the pattern found. The default behavior of sed is to print every line after parsing it. This means lines 3 through 7 appear twice because of the p instruction.
So how can you print specific lines from the file? Use the -n option to eliminate lines that do not match from the output.
```
$ sed -n '3,7 p' data
3 Willis Castillo 21 Windows
4 Gilberto Mack 30 Windows
5 Aubrey Hayes 17 windows
6 Allan Snyder 21 mac
7 Freddie Dean 25 linux
```
Only lines 3 through 7 will appear using -n .
Omitting specific lines from the file. This uses the d to delete the lines from the output.
```
$ sed '3 d' data
1 Vicky Grant 20 linux
2 Nora Burton 19 Mac
4 Gilberto Mack 30 Windows
5 Aubrey Hayes 17 windows
6 Allan Snyder 21 mac
7 Freddie Dean 25 linux
8 Ralph Martin 19 linux
9 Mindy Howard 20 Mac
$ sed '5,9 d' data
1 Vicky Grant 20 linux
2 Nora Burton 19 Mac
3 Willis Castillo 21 Windows
4 Gilberto Mack 30 Windows
```
Searching for a specific keyword in the file.
```
$ sed -n '/linux/ p' data
7 Freddie Dean 25 linux
8 Ralph Martin 19 linux
$ sed -n '/linux/I p' data
1 Vicky Grant 20 Linux
7 Freddie Dean 25 linux
8 Ralph Martin 19 linux
```
In these examples we have a regular expression which appears in / /. If we have similar words in the file but not with proper case then we use the “I” to make the search case insensitive. Recall that the -n eliminates the lines that do not match from the output.
Replacing the words in the file.
```
$ sed 's/linux/linus/' data
1 Vicky Grant 20 Linux
2 Nora Burton 19 Mac
3 Willis Castillo 21 Windows
4 Gilberto Mack 30 Windows
5 Aubrey Hayes 17 windows
6 Allan Snyder 21 mac
7 Freddie Dean 25 linus
8 Ralph Martin 19 linus
9 Mindy Howard 20 Mac
```
Here s/ / / denotes that it is a regex. The located word and then the new word to replace it appear between the two /.
## **tr**
The _tr_ command will translate or delete characters. It can transform the lowercase letters to uppercase or vice versa, eliminate repeating characters, and delete specific characters.
One thing weird about _tr_ is that it does not take files as input like _wc_, _sort_ and _sed_ do. We use “|” (the pipe symbol) to provide input to the _tr_ command.
```
$ cat filename | tr [OPTION]
```
Some options used with _tr_:
* -d : To delete the characters in first set of output
* -s : To replace the repeated characters with single occurrence
### tr demo
Now lets use the _tr_ command with the file _letter_ to convert all the characters from lowercase to uppercase.
```
$ cat letter
Linux is too easy to learn,
And you should try it too.
$ cat letter | tr 'a-z' 'A-Z'
LINUX IS TOO EASY TO LEARN,
AND YOU SHOULD TRY IT TOO.
```
Here a-z A-Z denotes that we want to convert characters in the range from “a” to “z” from lowercase to uppercase.
Deleting the “o” character  from the file.
```
$ cat letter | tr -d 'o'
Linux is t easy t learn,
And yu shuld try it t.
```
Squeezing the character “o” from the file means that if “o” is repeated in line then it will remove it and print it only once. 
```
$ cat letter | tr -s 'o'
Linux is to easy to learn,
And you should try it to.
```
## **Conclusion**
This was a quick demonstration of the _wc_, _sort_, _sed_ and _tr_ commands. These commands make it easy to manipulate the text files on the terminal in a quick and efficient way. You may use the _man_ command to learn more about these commands.
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/command-line-quick-tips-wc-sort-sed-and-tr/
作者:[mahesh1b][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/mahesh1b/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2018/10/commandlinequicktips-816x345.jpg

View File

@ -0,0 +1,229 @@
[#]: subject: (Get started with WildFly for Java web development)
[#]: via: (https://opensource.com/article/21/7/wildfly)
[#]: author: (Ranabir Chakraborty https://opensource.com/users/ranabir-chakraborty)
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
Get started with WildFly for Java web development
======
WildFly is a popular choice for developers who want to develop
enterprise-ready applications.
![Coding on a computer][1]
[WildFly][2] is a production-ready, cross-platform, flexible, lightweight, managed application runtime that provides all the necessary features to run a Java web application. It is also a Java EE 8 certified application server almost exclusively in Java, and it implements the [Jakarta EE][3], which was the Java Platform, Enterprise Edition (Java EE) specifications. Therefore you can run it on any operating system.
WildFly, formerly known as JBoss AS, is a fully implemented JEE container—application server, developed by JBoss, which became a part of Red Hat on June 5, 2006, and since then, WildFly became their product.
### **How to get started with WildFly?**
This Java middleware application server known as [WildFly][4] is a robust implementation of the Jakarta platform specification. The latest WildFly 24 architecture built on the Modular Service Container enables services on-demand when your application requires them.
#### **Prerequisites**
Before installing WildFly, there are a few prerequisites:
* Check that you have a JDK on your machine—JDK 8 or higher recommended to start WildFly. You can use the open source JDK called [OpenJDK][5].
Once you install the JDK, set the JAVA_HOME environment variable.
* Ensure you have Maven 3.6.0 or higher installed. You can download Maven from [here][6] and set the environment variables.
* After loading both the variables, check the versions of JDK and Maven.
```
$ java -version
openjdk version “11.0.9” 2020-10-20 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9+11)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9+11, mixed mode)
[/code] [code]
$ mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /usr/share/maven
Java version: 11.0.9, vendor: AdoptOpenJDK, runtime: /usr/lib64/adoptopenjdk
Default locale: en_US, platform encoding: UTF-8
OS name: “linux”, version: “5.9.1”, arch: “amd64”, family: “unix”
```
### Download and install WildFly
There are many ways you can install WildFly, including unzipping our traditional download zip, provisioning a custom installation using Galleon, or building a bootable jar. The official [installation guide][7] helps you identify the kind of WildFly installation that best fits your applications deployment needs. In this article, we'll focus on the typical approach of installing the download zip.
You can download WildFly from [here][8]. The standard WildFly variant is the right choice for most users, but if you'd like a technical preview look at what's coming in the future, try out WildFly Preview. Once downloaded, extract the archive to a folder and install it on any operating system that supports the zip or tar formats.
```
`$ unzip wildfly-preview-24.0.0.Final.zip`
```
### Running WildFly
WildFly has two server modes—_standalone_ and _domain_. The difference between the two modes is not about the capabilities available but about the application server's management. Use the _standalone_ mode when you only need one instance of the server. On the other hand, use the _domain_ mode when you want to run several instances of WildFly, and you want a single point from where you can control the configuration. You can find more about the domain mode in the [documentation][9].
To start WildFly using the default configuration in _standalone_ mode, change the directory to `$JBOSS_HOME/bin` and issue:
```
`$ ./standalone.sh`
```
To start the application server using the default configuration in _domain_ mode, change the directory to `$JBOSS_HOME/bin` and issue:
```
`$ ./domain.sh`
```
After starting the standalone mode, you should find something like the following in your console at the end of the start-up process:
```
00:46:04,500 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Preview 24.0.0.Final (WildFly Core 16.0.0.Final) started in 4080ms - Started 437 of 638 services (350 services are lazy, passive or on-demand)
00:46:04,502 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on <http://127.0.0.1:9990/management>
00:46:04,502 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on <http://127.0.0.1:9990>
```
You can point your browser to `http://localhost:9990` (if using the default configured HTTP port), bringing you to the WildFly welcome page.
![WildFly welcome page][10]
(Ranabir Chakraborty, [CC-BY SA 4.0][11])
#### **Authentication**
Though now you can see that WildFly is running, you can not access the admin console because you need to add a user for that. By default, security comes enabled for the WildFly management interfaces. That means that before you connect using the administration console or remotely using the CLI, you'll need to add a new user. You can achieve that simply by using the `add-user.sh` or the `add-user.bat` script in the bin folder.
After starting the script, the system guides you through the process of adding a new user.
```
$ ./add-user.sh
What type of user do you wish to add?
a) Management User (mgmt.users.properties)
b) Application User (application-users.properties)
(a):
```
Select the default option "a" to add a management user, where the user gets added to the ManagementRealm. Therefore, the user is authorized to perform management operations using the web-based Admin Console or the CLI. The other option is "b," where the user gets added to the ApplicationRealm. This realm provides for use with applications.
```
Enter the details of the new user to add.
Using realm ManagementRealm as discovered from the existing property files.
Username : Ranabir
Password recommendations are listed below. To modify these restrictions, edit the add-user.properties configuration file.
[…]
Passward :
Re-enter Password :
```
Here you choose the management user option and provide the required username and password.
```
What groups do you want this user to belong to?
(Please enter a comma-separated list, or leave blank for none) [ ]:
```
Users can be associated with arbitrary groups of your choice, and you get prompted to consider assigning a new user to a group. Groups are helpful for simplified administration of things like access permissions, but leaving this blank is OK for getting started. You then confirm adding the user. The user gets written to the properties files used for authentication, and a confirmation message displays.
```
Is this new user going to be used for AS process to connect to another AS process?
e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server Jakarta Enterprise Beans calls.
yes/no? no
```
Finally, you get asked whether or not you'll use the account you've added to identify one WildFly process to another—typically in a WildFly managed domain. The answer for this should be "no" because the account you are adding here is for use by a human administrator.
After successfully adding the user, now you can refresh the browser, and the console will look like the following:
![WildFly HAL Management console][12]
#### **Deploy an application**
WildFly provides many ways to deploy your application on the server. But if you are running a standalone WildFly service, a simple way to deploy your application is to copy your application archive (`war/ear/jar`) into the `$JBOSS_HOME/standalone/deployments` directory in the server installation. The deployment-scanner subsystem detects the archive and deploys it. Another straightforward way to perform the same is to go to the **Deployments** section of the console and upload your application archive.
![How to deploy your application from console][13]
You can make your own application and deploy it accordingly but here I have used a demo [helloworld][14] application from [WildFly quickstart][15].
#### **Steps to use WildFly quickstart samples:**
1. Make a separate folder locally and inside that, clone the WildFly quickstart project. After cloning the repository, change the directory to `helloworld` (or you can play with any other sample projects) and build the maven project.
```
$ mkdir WFLY
$ cd WFLY
$ git clone depth 1 [git@github.com][16]:wildfly/quickstart.git
$ cd quickstart/helloworld
$ mvn clean install
```
2. If you face any project build issues, then you must clone the `boms` repository into your current working directory (WFLY in my example) and build it. After that, build the sample project. This step is only required when building a development version of the WildFly server. It isnt required when running a [tagged][17] or [released][18] version of the WildFly server.
```
$ git clone [git@github.com][16]:wildfly/boms.git
$ cd boms
$ mvn clean install
```
3. After successfully building the sample project, take the application archive `helloworld.war` from the target folder and copy it inside the `$JBOSS_HOME/standalone/deployments` directory in the server installation.
```
$ cd quickstart/helloworld/target/
$ cp helloworld.war …/…/…/wildfly-preview-24.0.0.Final/standalone/deployments/
```
4. Now point your browser to `http://localhost:8080/helloworld/` to see your successfully deployed WildFly application.
### **Conclusions**
Despite WildFly being in the market for almost two decades, it's still a popular choice for developers who want to develop enterprise-ready applications. The code quality remains at a high and efficient level. The developers are continuously doing many unique and significant work that is taking WildFly to its new peak. The [latest WildFly][8] runs well on SE 16 and 17, supporting SE 17 in standard WildFly later this year.
Michael Dowden takes a look at four Java web frameworks built for scalability.
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/7/wildfly
作者:[Ranabir Chakraborty][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/ranabir-chakraborty
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_computer_laptop_hack_work.png?itok=aSpcWkcl (Coding on a computer)
[2]: https://www.wildfly.org/
[3]: https://opensource.com/article/18/5/jakarta-ee
[4]: https://github.com/wildfly/wildfly
[5]: http://openjdk.java.net/
[6]: https://maven.apache.org/download.cgi
[7]: https://docs.wildfly.org/24/Installation_Guide.html
[8]: https://www.wildfly.org/downloads/
[9]: https://docs.wildfly.org/24/Admin_Guide.html#Operating_modes
[10]: https://opensource.com/sites/default/files/pictures/welcome_page.png (WildFly welcome page)
[11]: https://creativecommons.org/licenses/by-sa/4.0/
[12]: https://opensource.com/sites/default/files/uploads/console.png (WildFly HAL Management console)
[13]: https://opensource.com/sites/default/files/uploads/deployment.png (How to deploy your application from console)
[14]: https://github.com/wildfly/quickstart/tree/master/helloworld
[15]: https://github.com/wildfly/quickstart
[16]: mailto:git@github.com
[17]: https://github.com/wildfly/quickstart/tags
[18]: https://github.com/wildfly/boms/releases

View File

@ -0,0 +1,84 @@
[#]: subject: (How to Install elementary Tweaks Tool)
[#]: via: (https://www.debugpoint.com/2021/07/elementary-tweaks-install/)
[#]: author: (Arindam https://www.debugpoint.com/author/admin1/)
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
How to Install elementary Tweaks Tool
======
This quick tutorial demonstrates the steps to install elementary Tweaks
tool/Pantheon Tweaks Tool.
The elementary Tweaks tool is a handy utility specially designed for [elementary OS][1]. It gives you various options to change certain settings for elementary. Although elementary provides most of the settings already, however, few Pantheon desktop tweaks are not available via standard settings. Hence, this tool. This is a similar tool like we have in GNOME called [GNOME Tweaks][2].
That said, installing this tool is straight forward. Although its a bit different in [elementary OS 6 Odin][3] than earlier versions such as elementary OS 5 Juno. From the elementary OS 6 Odin onwards, this tool is renamed as Pantheon Tweaks tool. Heres how to install.
### Install elementary Tweaks Tool
The elementary OS doesnt include the software-properties-common package, which is required for adding a PPA. If it is not install already, use the following command to install.
```
sudo apt install software-properties-common
```
#### elementary OS 6 Odin
The Tweak tool is renamed with a new name and being developed separately. It is called [Pantheon Tweaks][4]. And using the following commands you can install it.
```
sudo add-apt-repository -y ppa:philip.scott/pantheon-tweaks
sudo apt install -y pantheon-tweaks
```
#### elementary OS 5 Juno and below
If you are using elementary OS 5 June and below, you can install the earlier [elementary-tweaks][5] using the same PPA. Follow the below commands from terminal.
```
sudo add-apt-repository -y ppa:philip.scott/elementary-tweaks
sudo apt install -y elementary-tweaks
```
### Usage
After installation, you can run it via `Application Menu > System Settings > Tweaks`.
![tweak in settings][6]
In the Tweaks window, you can find several options to change and configure your elementary desktop.
![elementary tweaks after install options][7]
For your information, this tool is just a front end to elementary desktop settings. You can very well change them via terminal provided you know the exact name or property. The settings you get in this tool can also be changed via `dconf` editor in `io.elementary` path.
[][8]
SEE ALSO:   elementary OS 5.1 Hera Released. Heres Whats New
Let me know in the comment box below, if you face any trouble installing, or using this tweak tool.
* * *
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/2021/07/elementary-tweaks-install/
作者:[Arindam][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lujun9972
[1]: https://www.debugpoint.com/tag/elementary
[2]: https://www.debugpoint.com/2018/05/customize-your-ubuntu-desktop-using-gnome-tweak/
[3]: https://www.debugpoint.com/2020/09/elementary-os-6-odin-new-features-release-date/
[4]: https://github.com/pantheon-tweaks/pantheon-tweaks
[5]: https://github.com/elementary-tweaks/elementary-tweaks
[6]: https://www.debugpoint.com/blog/wp-content/uploads/2021/07/tweak-in-settings.png
[7]: https://www.debugpoint.com/blog/wp-content/uploads/2021/07/elementary-tweaks-after-install-options.png
[8]: https://www.debugpoint.com/2019/12/elementary-os-hera-released/

View File

@ -0,0 +1,116 @@
[#]: subject: (How to use cron on Linux)
[#]: via: (https://opensource.com/article/21/7/cron-linux)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
How to use cron on Linux
======
The cron system is a method to automatically run commands on a schedule.
![Cron expression][1]
The cron system is a method to automatically run commands on a schedule. A scheduled job is called a _cronjob_, and its created in a file called a _crontab_. Its the easiest and oldest way for a computer user to automate their computer.
### Writing a cronjob
To create a cronjob, you edit your `crontab` using the `-e` option:
```
`$ crontab -e`
```
This opens your crontab your default text editor. To set the text editor explicitly, use the `EDITOR` [environment variable][2]:
```
`$ EDITOR=nano crontab -e`
```
### Cron syntax
To schedule a cronjob, you provide the command you want your computer to execute, followed by a cron expression. The cron expression schedules when the command gets run:
* minute (0 to 59)
* hour (0 to 23, with 0 being midnight)
* day of month (1 to 31)
* month (1 to 12)
* day of week (0 to 6, with Sunday being 0)
An asterisk (`*`) in a field translates to "every." For example, this expression runs a backup script at the 0th minute of _every_ hour on _every_ day of _every_ month:
```
`/opt/backup.sh 0 * * * *`
```
This expression runs a backup script at 3:30 AM on Sunday:
```
`/opt/backup.sh 30 3 * * 0`
```
### Simplified syntax
Modern cron implementations accept simplified macros instead of a cron expression:
* `@hourly` runs at the 0th minute of every hour of every day
* `@daily` runs at the 0th minute of the 0th hour of every day
* `@weekly` runs at the 0th minute of the 0th hour on Sunday
* `@monthly` runs at the 0th minute of the 0th hour on the first day of the month
For example, this crontab line runs a backup script every day at midnight:
```
`/opt/backup.sh @daily`
```
### How to stop a cronjob
Once you've started a cronjob, it's designed to run on schedule forever. To stop a cronjob once you've started it, you must edit your crontab, remove the line that triggers the job, and then save the file.
```
`$ EDITOR=nano crontab -e`
```
To stop a job that's actively running, [use standard Linux process commands][3] to stop a running process.
### Its automated
Once youve written your crontab, save the file and exit your editor. Your cronjob has been scheduled, so cron does the rest.
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/7/cron-linux
作者:[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/cron-splash.png?itok=AoBigzts (Cron expression)
[2]: https://opensource.com/article/19/8/what-are-environment-variables
[3]: https://opensource.com/article/18/5/how-kill-process-stop-program-linux

25
sources/tech/20210727 .md Normal file
View File

@ -0,0 +1,25 @@
[#]: subject: ()
[#]: via: (https://www.2daygeek.com/recover-restore-deleted-logical-volume-linux/)
[#]: author: ( )
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
======
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/recover-restore-deleted-logical-volume-linux/
作者:[][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:
[b]: https://github.com/lujun9972

View File

@ -0,0 +1,404 @@
[#]: subject: (Analyze the Linux kernel with ftrace)
[#]: via: (https://opensource.com/article/21/7/linux-kernel-ftrace)
[#]: author: (Gaurav Kamathe https://opensource.com/users/gkamathe)
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
Analyze the Linux kernel with ftrace
======
Ftrace is a great way to learn more about the internal workings of the
Linux kernel.
![Linux keys on the keyboard for a desktop computer][1]
An operating system's kernel is one of the most elusive pieces of software out there. It's always there running in the background from the time your system gets turned on. Every user achieves their computing work with the help of the kernel, yet they never interact with it directly. The interaction with the kernel occurs by making system calls or having those calls made on behalf of the user by various libraries or applications that they use daily.
I've covered how to trace system calls in an earlier article using `strace`. However, with `strace`, your visibility is limited. It allows you to view the system calls invoked with specific parameters and, after the work gets done, see the return value or status indicating whether they passed or failed. But you had no idea what happened inside the kernel during this time. Besides just serving system calls, there's a lot of other activity happening inside the kernel that you're oblivious to.
### Ftrace Introduction
This article aims to shed some light on tracing the kernel functions by using a mechanism called `ftrace`. It makes kernel tracing easily accessible to any Linux user, and with its help you can learn a lot about Linux kernel internals.
The default output generated by the `ftrace` is often massive, given that the kernel is always busy. To save space, I've kept the output to a minimum and, in many cases truncated the output entirely.
I am using Fedora for these examples, but they should work on any of the latest Linux distributions.
### Enabling ftrace
`Ftrace` is part of the Linux kernel now, and you no longer need to install anything to use it. It is likely that, if you are using a recent Linux OS, `ftrace` is already enabled. To verify that the `ftrace` facility is available, run the mount command and search for `tracefs`. If you see output similar to what is below, `ftrace` is enabled, and you can easily follow the examples in this article:
```
$ sudo mount | grep tracefs
none on /sys/kernel/tracing type tracefs (rw,relatime,seclabel)
```
To make use of `ftrace`, you first must navigate to the special directory as specified in the mount command above, from where you'll run the rest of the commands in the article:
```
`$ cd /sys/kernel/tracing`
```
### General work flow
First of all, you must understand the general workflow of capturing a trace and obtaining the output. If you're using `ftrace` directly, there isn't any special `ftrace-`specific commands to run. Instead, you basically write to some files and read from some files using standard command-line Linux utilities.
The general steps:
1. Write to some specific files to enable/disable tracing.
2. Write to some specific files to set/unset filters to fine-tune tracing.
3. Read generated trace output from files based on 1 and 2.
4. Clear earlier output or buffer from files.
5. Narrow down to your specific use case (kernel functions to trace) and repeat steps 1, 2, 3, 4.
### Types of available tracers
There are several different kinds of tracers available to you. As mentioned earlier, you need to be in a specific directory before running any of these commands because the files of interest are present there. I use relative paths (as opposed to absolute paths) in my examples.
You can view the contents of the `available_tracers` file to see all the types of tracers available. You can see a few listed below. Don't worry about all of them just yet:
```
$ pwd
/sys/kernel/tracing
$ sudo cat available_tracers
hwlat blk mmiotrace function_graph wakeup_dl wakeup_rt wakeup function nop
```
Out of all the given tracers, I focus on three specific ones: `function` and `function_graph` to enable tracing, and `nop` to disable tracing.
### Identify current tracer
Usually, by default, the tracer is set to `nop`. That is, "No operation" in the special file `current_tracer`, which usually means tracing is currently off:
```
$ pwd
/sys/kernel/tracing
$ sudo cat current_tracer
nop
```
### View Tracing output
Before you enable any tracing, take a look at the file where the tracing output gets stored. You can view the contents of the file named `trace` using the [cat][2] command:
```
$ sudo cat trace
# tracer: nop
#
# entries-in-buffer/entries-written: 0/0   #P:8
#
#                                _-----=&gt; irqs-off
#                               / _----=&gt; need-resched
#                              | / _---=&gt; hardirq/softirq
#                              || / _--=&gt; preempt-depth
#                              ||| /     delay
#           TASK-PID     CPU#  ||||   TIMESTAMP  FUNCTION
#              | |         |   ||||      |         |
```
### Enable function tracer
You can enable your first tracer called `function` by writing `function` to the file `current_tracer` (its earlier content was `nop`, indicating that tracing was off.) Think of this operation as a way of enabling tracing:
```
$ pwd
/sys/kernel/tracing
$ sudo cat current_tracer
nop
$ echo function &gt; current_tracer
$
$ cat current_tracer
function
```
### View updated tracing output for function tracer
Now that you've enabled tracing, it's time to view the output. If you view the contents of the `trace` file, you see a lot of data being written to it continuously. I've piped the output and am currently viewing only the top 20 lines to keep things manageable. If you follow the headers in the output on the left, you can see which task and Process ID are running on which CPU. Toward the right side of the output, you see the exact kernel function running, followed by its parent function. There is also time stamp information in the center:
```
$ sudo cat trace | head -20
# tracer: function
#
# entries-in-buffer/entries-written: 409936/4276216   #P:8
#
#                                _-----=&gt; irqs-off
#                               / _----=&gt; need-resched
#                              | / _---=&gt; hardirq/softirq
#                              || / _--=&gt; preempt-depth
#                              ||| /     delay
#           TASK-PID     CPU#  ||||   TIMESTAMP  FUNCTION
#              | |         |   ||||      |         |
          &lt;idle&gt;-0       [000] d...  2088.841739: tsc_verify_tsc_adjust &lt;-arch_cpu_idle_enter
          &lt;idle&gt;-0       [000] d...  2088.841739: local_touch_nmi &lt;-do_idle
          &lt;idle&gt;-0       [000] d...  2088.841740: rcu_nocb_flush_deferred_wakeup &lt;-do_idle
          &lt;idle&gt;-0       [000] d...  2088.841740: tick_check_broadcast_expired &lt;-do_idle
          &lt;idle&gt;-0       [000] d...  2088.841740: cpuidle_get_cpu_driver &lt;-do_idle
          &lt;idle&gt;-0       [000] d...  2088.841740: cpuidle_not_available &lt;-do_idle
          &lt;idle&gt;-0       [000] d...  2088.841741: cpuidle_select &lt;-do_idle
          &lt;idle&gt;-0       [000] d...  2088.841741: menu_select &lt;-do_idle
          &lt;idle&gt;-0       [000] d...  2088.841741: cpuidle_governor_latency_req &lt;-menu_select
```
Remember that tracing is on, which means the output of tracing continues to get written to the trace file until you turn tracing off.
### Turn off tracing
Turning off tracing is simple. All you have to do is replace `function` tracer with `nop` in the `current_tracer` file and tracing gets turned off:
```
$ sudo cat current_tracer
function
$ sudo echo nop &gt; current_tracer
$ sudo cat current_tracer
nop
```
### Enable function_graph tracer
Now try the second tracer, called `function_graph`. You can enable this using the same steps as before: write `function_graph` to the `current_tracer` file:
```
$ sudo echo function_graph &gt; current_tracer
$ sudo cat current_tracer
function_graph
```
### Tracing output of function_graph tracer
Notice that the output format of the `trace` file has changed. Now, you can see the CPU ID and the duration of the kernel function execution. Next, you see curly braces indicating the beginning of a function and what other functions were called from inside it:
```
$ sudo cat trace | head -20
# tracer: function_graph
#
# CPU  DURATION                  FUNCTION CALLS
# |     |   |                     |   |   |   |
 6)               |              n_tty_write() {
 6)               |                down_read() {
 6)               |                  __cond_resched() {
 6)   0.341 us    |                    rcu_all_qs();
 6)   1.057 us    |                  }
 6)   1.807 us    |                }
 6)   0.402 us    |                process_echoes();
 6)               |                add_wait_queue() {
 6)   0.391 us    |                  _raw_spin_lock_irqsave();
 6)   0.359 us    |                  _raw_spin_unlock_irqrestore();
 6)   1.757 us    |                }
 6)   0.350 us    |                tty_hung_up_p();
 6)               |                mutex_lock() {
 6)               |                  __cond_resched() {
 6)   0.404 us    |                    rcu_all_qs();
 6)   1.067 us    |                  }
```
### Enable trace settings to increase the depth of tracing
You can always tweak the tracer slightly to see more depth of the function calls using the steps below. After which, you can view the contents of the `trace` file and see that the output is slightly more detailed. For readability, the output of this example is omitted:
```
$ sudo cat max_graph_depth
0
$ sudo echo 1 &gt; max_graph_depth
$ # or
$ sudo echo 2 &gt; max_graph_depth
$ sudo cat trace
```
### Finding functions to trace
The steps above are sufficient to get started with tracing. However, the amount of output generated is enormous, and you can often get lost while trying to find out items of interest. Often you want the ability to trace specific functions only and ignore the rest. But how do you know which processes to trace if you don't know their exact names? There is a file that can help you with this—`available_filter_functions` provides you with a list of available functions for tracing:
```
$ sudo wc -l available_filter_functions  
63165 available_filter_functions
```
### Search for general kernel functions
Now try searching for a simple kernel function that you are aware of. User-space has `malloc` to allocate memory, while the kernel has its `kmalloc` function, which provides similar functionality. Below are all the `kmalloc` related functions:
```
$ sudo grep kmalloc available_filter_functions
debug_kmalloc
mempool_kmalloc
kmalloc_slab
kmalloc_order
kmalloc_order_trace
kmalloc_fix_flags
kmalloc_large_node
__kmalloc
__kmalloc_track_caller
__kmalloc_node
__kmalloc_node_track_caller
[...]
```
### Search for kernel module or driver related functions
From the output of `available_filter_functions`, you can see some lines ending with text in brackets, such as `[kvm_intel]` in the example below. These functions are related to the kernel module `kvm_intel`, which is currently loaded. You can run the `lsmod` command to verify:
```
$ sudo grep kvm available_filter_functions | tail
__pi_post_block [kvm_intel]
vmx_vcpu_pi_load [kvm_intel]
vmx_vcpu_pi_put [kvm_intel]
pi_pre_block [kvm_intel]
pi_post_block [kvm_intel]
pi_wakeup_handler [kvm_intel]
pi_has_pending_interrupt [kvm_intel]
pi_update_irte [kvm_intel]
vmx_dump_dtsel [kvm_intel]
vmx_dump_sel [kvm_intel]
$ lsmod  | grep -i kvm
kvm_intel             335872  0
kvm                   987136  1 kvm_intel
irqbypass              16384  1 kvm
```
### Trace specific functions only
To enable tracing of specific functions or patterns, you can make use of the `set_ftrace_filter` file to specify which functions from the above output you want to trace.
This file also accepts the `*` pattern, which expands to include additional functions with the given pattern. As an example, I am using the `ext4` filesystem on my machine. I can specify `ext4` specific kernel functions to trace using the following commands:
```
$ sudo mount | grep home
/dev/mapper/fedora-home on /home type ext4 (rw,relatime,seclabel)
$ pwd
/sys/kernel/tracing
$ sudo cat set_ftrace_filter
#### all functions enabled ####
$
$ echo ext4_* &gt; set_ftrace_filter
$
$ cat set_ftrace_filter
ext4_has_free_clusters
ext4_validate_block_bitmap
ext4_get_group_number
ext4_get_group_no_and_offset
ext4_get_group_desc
[...]
```
Now, when you see the tracing output, you can only see functions `ext4` related to kernel functions for which you had set a filter earlier. All the other output gets ignored:
```
$ sudo cat trace |head -20
# tracer: function
#
# entries-in-buffer/entries-written: 3871/3871   #P:8
#
#                                _-----=&gt; irqs-off
#                               / _----=&gt; need-resched
#                              | / _---=&gt; hardirq/softirq
#                              || / _--=&gt; preempt-depth
#                              ||| /     delay
#           TASK-PID     CPU#  ||||   TIMESTAMP  FUNCTION
#              | |         |   ||||      |         |
           cupsd-1066    [004] ....  3308.989545: ext4_file_getattr &lt;-vfs_fstat
           cupsd-1066    [004] ....  3308.989547: ext4_getattr &lt;-ext4_file_getattr
           cupsd-1066    [004] ....  3308.989552: ext4_file_getattr &lt;-vfs_fstat
           cupsd-1066    [004] ....  3308.989553: ext4_getattr &lt;-ext4_file_getattr
           cupsd-1066    [004] ....  3308.990097: ext4_file_open &lt;-do_dentry_open
           cupsd-1066    [004] ....  3308.990111: ext4_file_getattr &lt;-vfs_fstat
           cupsd-1066    [004] ....  3308.990111: ext4_getattr &lt;-ext4_file_getattr
           cupsd-1066    [004] ....  3308.990122: ext4_llseek &lt;-ksys_lseek
           cupsd-1066    [004] ....  3308.990130: ext4_file_read_iter &lt;-new_sync_read
```
### Exclude functions from being traced
You don't always know what you want to trace but, you surely know what you don't want to trace. For that, there is this file aptly named `set_ftrace_notrace`—notice the "no" in there. You can write your desired pattern in this file and enable tracing, upon which everything except the mentioned pattern gets traced. This is often helpful to remove common functionality that clutters our output:
```
$ sudo cat set_ftrace_notrace
#### no functions disabled ####
```
### Targetted tracing
So far, you've been tracing everything that has happened in the kernel. But that won't help us if you wish to trace events related to a specific command. To achieve this, you can turn tracing on and off on-demand and, and in between them, run our command of choice so that you do not get extra output in your trace output. You can enable tracing by writing `1` to `tracing_on`, and `0` to turn it off:
```
$ sudo cat tracing_on
0
$ sudo echo 1 &gt; tracing_on
$ sudo cat tracing_on
1
$ # Run some specific command that we wish to trace here
$ sudo echo 0 &gt; tracing_on
$ cat tracing_on
0
```
### Tracing specific PID
If you want to trace activity related to a specific process that is already running, you can write that PID to a file named `set_ftrace_pid` and then enable tracing. That way, tracing is limited to this PID only, which is very helpful in some instances:
```
`$ sudo echo $PID > set_ftrace_pid`
```
### Conclusion
`Ftrace` is a great way to learn more about the internal workings of the Linux kernel. With some practice, you can learn to fine-tune `ftrace` and narrow down your searches. To understand `ftrace` in more detail and its advanced usage, see these excellent articles written by the core author of `ftrace` himself—Steven Rostedt.
* [Debugging the Linux kernel, part 1][3]
* [Debugging the Linux kernel, part 2][4]
* [Debugging the Linux kernel, part 3][5]
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/7/linux-kernel-ftrace
作者:[Gaurav Kamathe][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/gkamathe
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/linux_keyboard_desktop.png?itok=I2nGw78_ (Linux keys on the keyboard for a desktop computer)
[2]: https://opensource.com/article/19/2/getting-started-cat-command
[3]: https://lwn.net/Articles/365835/
[4]: https://lwn.net/Articles/366796/
[5]: https://lwn.net/Articles/370423/

View File

@ -0,0 +1,110 @@
[#]: subject: (Check used disk space on Linux with du)
[#]: via: (https://opensource.com/article/21/7/check-disk-space-linux-du)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
Check used disk space on Linux with du
======
Find out how much disk space you're using with the Linux du command.
![Check disk usage][1]
No matter how much storage space you have, there's always the possibility for it to fill up. On most personal devices, drives get filled up with photos and videos and music, but on servers, it's not unusual for space to diminish due to data in user accounts and log files. Whether you're in charge of managing a multi-user system or just your own laptop, you can check in on disk usage with the `du` command.
By default, `du` provides the amount of disk space used in your current directory, as well as the size of each subdirectory:
```
$ du
12 ./.backups
60 .
```
In this example, my current directory takes up all of 60 KB, 12 KB of which is occupied by the subdirectory `.backups`.
If you find that confusing and would prefer to see all sizes separately, you can use the `--separate-dirs` (or `-S` for short) option:
```
$ du --separate-dirs
12 ./.backups
48 .
```
It's the same information (48 and 12 is 60) but each directory is treated independently of one another.
To see even more detail, use the --all (or -a for short) option, which displays each file in each directory:
```
$ du --separate-dirs --all                
4       ./example.adoc
28      ./graphic.png
4       ./.backups/example.adoc~
12      ./.backups
4       ./index.html
4       ./index.adoc
48      .
```
### See modification time of files
When looking through files to find out what's taking up space, it can be useful to see when a file was last modified. Something that hasn't been touched in a year is a likely candidate for archival, especially if you're running out of space.
To see modification times of files with du, use the `--time` option:
```
$ du --separate-dirs --all --time
28      2021-07-21 11:12        ./graphic.png
4       2021-07-03 10:43        ./example.adoc
4       2021-07-13 13:03        ./index.html
4       2021-07-23 14:18        ./index.adoc
48      2021-07-23 14:19        .
```
### Set a threshold for file size
When reviewing files in the interest of disk space, you may only care about files of nontrivial size. You set a threshold for the file sizes you want to see with the `--threshold` (or `-t` for short) option. For instance, to view only sizes larger than 1 GB:
```
$ \du --separate-dirs --all --time --threshold=1G ~/Footage/
1839008 2021-07-14 13:55        /home/tux/Footage/snowfall.mp4
1577980 2020-04-11 13:10        /home/tux/Footage/waterfall.mp4
8588936 2021-07-14 13:55        /home/tux/Footage/
```
When file sizes get particularly large, they can be difficult to read. Make file sizes easier with the `--human-readable` (or `-h` for short) option:
```
$ \du --separate-dirs --all --time \
\--threshold=1G --human-readable ~/Footage/
1.8G 2021-07-14 13:55        /home/tux/Footage/snowfall.mp4
1.6G 2020-04-11 13:10        /home/tux/Footage/waterfall.mp4
8.5G 2021-07-14 13:55        /home/tux/Footage/
```
### See available disk space
To just get a summary of how much disk space remains on a drive, read our article about the [df command][2].
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/7/check-disk-space-linux-du
作者:[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/du-splash.png?itok=nRLlI-5A (Check disk usage)
[2]: https://opensource.com/article/21/7/use-df-check-free-disk-space-linux

View File

@ -0,0 +1,139 @@
[#]: subject: (How to Change Lock and Login Screen Wallpaper in elementary OS)
[#]: via: (https://www.debugpoint.com/2021/07/change-lock-login-screen-background-elementary-os/)
[#]: author: (Arindam https://www.debugpoint.com/author/admin1/)
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
How to Change Lock and Login Screen Wallpaper in elementary OS
======
This tutorial explains the steps you need to change lock and login
screen background in elementary OS. This will replace the default grey
background.
Changing the lock or login screen background grey default wallpaper in elementary OS is a bit difficult. The typical greeter configuration change with the path of the image file would not work.
Unfortunately, its not an easier solution because the grey background is an image file and its data is hard coded in the greeter and need to be recompiled with new image to make it work.
Heres how.
![Lock / Login screen background elementary OS \(Odin\)][1]
### Change Lock and Login Screen Background elementary OS
* Open a terminal in your elementary OS.
* Install git and following dependencies for [greeter package][2].
```
sudo apt install git
```
```
sudo apt install -y gnome-settings-daemon libaccountsservice-dev libgdk-pixbuf2.0-dev libgranite-dev libgtk-3-dev libhandy-1-dev liblightdm-gobject-1-dev libmutter-6-dev libwingpanel-dev libx11-dev meson valac
```
* Go to temporary /tmp directory and clone the latest greeter master branch from GitHub.
```
cd /tmp
git clone https://github.com/elementary/greeter.git
```
* After cloning is complete, open the path `/tmp/greeter/data` in a file manager.
* The elementary OS uses a PNG file of 100×100 px as default background in the login screen/lock screen. The image is tiled, and it gives an impression of grey background.
* Rename your desired wallpaper image with `texture.png` and overwrite the following file in the path.
![gray background is created using this file][3]
```
/tmp/greeter/data/texture.png
```
* Open the file `/tmp/greeter/compositor/SystemBackground.vala` in a text editor and replace the following line
![change the path of image][4]
```
resource:///io/elementary/desktop/gala/texture.png
```
With
```
resource:///io/elementary/greeter/texture.png
```
* Save the file.
* Open the terminal again and build `greeter` using the following commands.
```
cd /tmp/greeter
meson _build --prefix=/usr
sudo ninja install -C _build
```
![building greeter][5]
* If you face any build error, let me know in the comment below. You should not be seeing any error, as I have tested it.
[][6]
SEE ALSO:   elementary OS 5.1 Hera Released. Heres Whats New
After the above commands are complete, you can test the login screen by running lightdm in test mode
```
lightdm --test-mode --debug
```
If it looks good, reboot the system. And you should be seeing your wallpaper in the login screen in elementary OS.
This guide should work in [elementary OS 6 Odin][7], elementary OS 5 Juno and below.
### Closing Notes
I hope this guide helps you to change the background of lock or login screen in your elementary OS. Honestly, its 2021 and changing a background image of login screen requires compilation of code surprises me.
If you run into error, let me know in the comment box below.
* * *
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/2021/07/change-lock-login-screen-background-elementary-os/
作者:[Arindam][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lujun9972
[1]: https://www.debugpoint.com/blog/wp-content/uploads/2021/07/elementary-OS-Login-Screen-in-Odin-1024x768.jpg
[2]: https://github.com/elementary/greeter
[3]: https://www.debugpoint.com/blog/wp-content/uploads/2021/07/gray-background-is-created-using-this-file.jpg
[4]: https://www.debugpoint.com/blog/wp-content/uploads/2021/07/change-the-path-of-image-1024x450.jpg
[5]: https://www.debugpoint.com/blog/wp-content/uploads/2021/07/building-greeter.png
[6]: https://www.debugpoint.com/2019/12/elementary-os-hera-released/
[7]: https://www.debugpoint.com/tag/elementary-os-6

View File

@ -0,0 +1,118 @@
[#]: subject: (Zathura: A Minimalist Document Viewer for Keyboard Shortcut Pros)
[#]: via: (https://itsfoss.com/zathura-document-viewer/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
Zathura: A Minimalist Document Viewer for Keyboard Shortcut Pros
======
Every Linux distribution comes with a document viewer app that lets you read PDF and other documents.
Most of the time, it is [Evince from GNOME][1] that is displayed as Document Viewer in Ubuntu and some other distributions. Evince is a handy tool and supports a wide variety of document formats.
However, there are other applications for reading documents. Take [Foliate][2] for example. Its an excellent [application for reading ebooks on Linux][3].
I recently came across another document viewer called Zathura.
### Enjoy a mouse-free document reading experience with Zathura
[Zathura][4] is a highly customizable document viewer based on the [girara user interface][5] and several document libraries. girara implements a simple and minimalist user interface.
Zathura sure feels to load fast. It is minimalist, so you just get an application window with no sidebar, application menu or anything of that sort.
![Zathura Document Viewer Interface][6]
You may open its command line prompt by pressing the : key. You may close the CLI prompt with Esc key.
If you want to create a bookmark, type :bmark and then provide an index number to the bookmarked page.
![Bookmarking in Zathura][7]
You may highlight all the links by pressing the F key. It will also display a number beside the highlighted URL and the command line prompt will appear at the bottom. If you type the URL number and press enter, the URL will be opened in the default web browser.
![Highlighting and opening links in documents][8]
Zathura also has automatic reloading feature. So if you make some changes to the document with some other application, the changes will be reflected as Zathura reloads the document.
You may also install additional plugins to improve the capabilities of Zathura and use it for reading comics or PostScript.
The problem with Zathura is that you wont see any documentation or help option anywhere on the application interface. This makes things a bit more difficult if you are not already familiar with the tool.
You may get the default keyboard shortcuts information from its [man page][9]. Here are a few of them:
* R: Rotate
* D: Toggle between single and double page viewing mode
* F: Highlight all links on the current screen
* HJKL: Moving with the Vim type keys
* Arrows or PgUp/PgDown or the mouse/touchpad for moving up and down
* / and search for text, press n or N for moving to next or previous search (like less command)
* Q: Close
You may find the documentation on the project website to learn about configuration, but I still found it confusing.
### Installing Zathura on Linux
Zathura is available in the repositories of the most Linux distributions. I could see it available for Ubuntu, Fedora, Arch and Debian, thanks to the [pkgs.org website][10]. This means that you can use the [package manager of your distribution][11] or the software center to install it.
On Debian and Ubuntu based distributions, use this command to install Zathura:
```
sudo apt install zathura
```
On Fedora, use:
```
sudo dnf install zathura
```
[Use pacman command on Arch Linux][12]:
```
sudo pacman -Sy zathura
```
And if you want to have a look at its source code, you may visit its GitLab repository:
[Zathura Source Code][13]
### Conclusion
Ill be honest with you. I am not a fan of mouse-free tools. This is why I prefer Nano over Vim as I cannot remember so many shortcuts.
I know there are people who swear by their keyboards. However, I would prefer not to spend time learning to configure a document viewer. This is more because I do not read too many documents on my desktop and for the limited PDF viewing, the default application is sufficient.
Its not that Zathura does not have it usage. If you are someone who has to deal a lot with documents, be it PDF or LaTex, Zathura could be your next favorite tool if you are a keyboard love.
--------------------------------------------------------------------------------
via: https://itsfoss.com/zathura-document-viewer/
作者:[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://wiki.gnome.org/Apps/Evince
[2]: https://itsfoss.com/foliate-ebook-viewer/
[3]: https://itsfoss.com/best-ebook-readers-linux/
[4]: https://pwmt.org/projects/zathura/
[5]: https://git.pwmt.org/pwmt/girara
[6]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/07/Zathura-Document-Viewer-Interface.png?resize=800%2C492&ssl=1
[7]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/07/bookmarking-in-zathura.png?resize=800%2C639&ssl=1
[8]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/07/Follow-link-in-Zathura.png?resize=800%2C639&ssl=1
[9]: https://itsfoss.com/linux-man-page-guide/
[10]: https://pkgs.org/
[11]: https://itsfoss.com/package-manager/
[12]: https://itsfoss.com/pacman-command/
[13]: https://git.pwmt.org/pwmt/zathura

View File

@ -0,0 +1,210 @@
[#]: collector: (lujun9972)
[#]: translator: (YungeG)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Trace code in Fedora with bpftrace)
[#]: via: (https://fedoramagazine.org/trace-code-in-fedora-with-bpftrace/)
[#]: author: (Augusto Caringi https://fedoramagazine.org/author/acaringi/)
在 Fedora 中用 bpftrace 追踪代码
======
![][1]
bpftrace 是一个[基于 eBPF 的新型追踪工具][2],在 Fedora 28 第一次引入。Brendan GreggAlastair Robertson 和 Matheus Marchini 在分散于全网络的黑客团队的帮助下开发了 bpftrace一个允许你分析系统在幕后正在执行的操作的追踪工具告诉你代码中正在被调用的函数、传递给函数的参数、函数的调用次数等。
这篇文章的内容涉及了 bpftrace 的一些基础,以及它是如何工作的,请继续阅读获取更多的信息和一些有用的实例。
### eBPF (extended Berkeley Packet Filter)
[eBPF][3] 是一个微型虚拟机,更确切的说是一个虚拟 CPU位于 Linux 内核中。eBPF 可以在内核空间以一种安全可控的方式加载和运行体积较小的程序,保证 eBPF 的使用更加安全即使在生产环境系统中。eBPF 虚拟机有自己的指令集([ISA][4]),类似于现代处理器架构的一个子集。通过这个 ISA可以很容易将 eBPF 程序转化为真实硬件上的代码。内核即时将程序转化为主流处理器架构上的本地代码,从而提升性能。
eBPF 虚拟机允许通过编程扩展内核,目前已经有一些内核子系统使用这一新型强大的 Linux Kernel 功能,比如网络,安全计算、追踪等。这些子系统的主要思想是添加 eBPF 程序到特定的代码点,从而扩展原生的内核行为。
虽然 eBPF 机器语言功能强大由于是一种底层语言直接用于编写代码很费力bpftrace 就是为了解决这个问题而生的。eBPF 提供了一种高级语言编写 eBPF 追踪脚本,然后在 clang / LLVM 库的帮助下将这些脚本转化为 eBPF最终添加到特定的代码点。
## 安装和快速入门
在终端 [使用][5] _[sudo][5]_ 执行下面的命令安装 bpftrace
```
$ sudo dnf install bpftrace
```
使用“hello world”进行实验
```
$ sudo bpftrace -e 'BEGIN { printf("hello world\n"); }'
```
注意,出于特权级的需要,你必须使用 _root_ 运行 _bpftrace_,使用 _-e_ 选项指明一个程序,构建一个所谓的“单行程序”。这个例子只会打印 _hello world_,接着等待你按下 **Ctrl+C**
_BEGIN_ 是一个特殊的探针名,只在执行一开始生效一次;每次探针命中时,大括号 _{}_ 内的操作——这个例子中只是一个 _printf_——都会执行。
现在让我们转向一个更有用的例子:
```
$ sudo bpftrace -e 't:syscalls:sys_enter_execve { printf("%s called %s\n", comm, str(args->filename)); }'
```
这个例子打印系统中正在创建的每个新进程的父进程名 _(comm)_。_t:syscalls:sys_enter_execve_ 是一个内核追踪点,是 _tracepoint:syscalls:sys_enter_execve_ 的简写,两种形式都可以使用。下一部分会向你展示如何列出所有可用的追踪点。
_comm_ 是一个 bpftrace 内建指令代表进程名_filename_ 是 _t:syscalls:sys_enter_execve_ 追踪点的一个域,这些域可以通过 _args_ 内建指令访问。
追踪点的所有可用域可以通过这个命令列出:
```
bpftrace -lv "t:syscalls:sys_enter_execve"
```
## 示例用法
### 列出探针
_bpftrace_ 的一个核心概念是 **探针点**,即 eBPF 程序可以连接到的(内核或用户空间)代码中的测量点,可以分成以下几大类:
* _kprobe_——内核函数的开始处
* _uprobe_——内核函数的返回处
* _uprobe_——用户级函数的开始处
* _uretprobe_——用户级函数的返回处
* _tracepoint_——内核静态追踪点
* _usdt_——用户级静态追踪点
* _profile_——基于时间的采样
* _interval_——基于时间的输出
* _software_——内核软件事件
* _hardware_——用户级事件
所有可用的 _kprobe / kretprobe_、_tracepoints_、_software_ 和 _hardware_ 探针可以通过这个命令列出:
```
$ sudo bpftrace -l
```
_uprobe / uretprobe_ 和 _usdt_ 是用户空间探针,专用于某个可执行文件。要使用这些探针,通过下文中的特殊语法。
_profile_ 和 _interval_ 探针以固定的时间间隔触发;固定的时间间隔不在本文的范畴内。
### 统计系统调用数
### Counting system calls
**Maps** 是保存计数、统计数据和柱状图的特殊 BPF 数据类型,你可以使用映射统计每个系统调用正在被调用的次数:
```
$ sudo bpftrace -e 't:syscalls:sys_enter_* { @[probe] = count(); }'
```
一些探针类型允许使用通配符匹配多个探针,你也可以使用一个逗号隔开的列表为一个操作块指明多个连接点。上面的例子中,操作块连接到了所有名称以 _t:syscalls:sysenter__ 开头的追踪点,即所有可用的系统调用。
bpftrace 的内建函数 _count()_ 统计系统调用被调用的次数_@[]_ 代表一个映射(一个关联的数组)。映射的键是另一个内建指令 _probe_,代表完整的探针名。
这个例子中,相同的操作块连接到了每个系统调用,之后每次有系统调用被调用时,映射就会被更新,映射中和系统调用对应的项就会增加。程序终止时,自动打印出所有声明的映射。
下面的例子统计所有的系统调用,然后通过 bpftrace 过滤语法使用 _PID_ 过滤出某个特定进程调用的系统调用:
```
$ sudo bpftrace -e 't:syscalls:sys_enter_* / pid == 1234 / { @[probe] = count(); }'
```
### 进程写的字节数
让我们使用上面的概念分析每个进程正在写的字节数:
```
$ sudo bpftrace -e 't:syscalls:sys_exit_write /args->ret > 0/ { @[comm] = sum(args->ret); }'
```
_bpftrace_ 连接操作块到写系统调用的返回探针_t:syscalls:sys_exit_write_然后使用过滤器丢掉代表错误代码的负值_/arg->ret > 0/_
映射的键 _comm_ 代表调用系统调用的进程名;内建函数 _sum()_ 累计每个映射项或进程写的字节数_args_ 是一个 `bpftrace` 内建指令用于访问追踪点的参数和返回值。如果执行成功_write_ 系统调用返回写的字节数_arg->ret_ 用于访问这个字节数。
### 进程的读取大小分布(柱状图):
_bpftrace_ 支持创建柱状图。让我们分析一个创建进程的 _read_ 大小分布的柱状图的例子:
```
$ sudo bpftrace -e 't:syscalls:sys_exit_read { @[comm] = hist(args->ret); }'
```
柱状图是 BPF 映射因此必须保存为一个映射_@_这个例子中映射键是 _comm_
这个例子使 _bpftrace_ 给每个调用 _read_ 系统调用的进程生成一个柱状图。要生成一个全局柱状图,直接保存 _hist()_ 函数到 _'@'_(不使用任何键)。
程序终止时bpftrace 自动打印出声明的柱状图。创建柱状图的基准值是通过 _args->ret_ 获取到的读取的字节数。
### 追踪用户空间程序
你也可以通过 _uprobes / uretprobes__USDT_(用户级静态定义的追踪)追踪用户空间程序。下一个例子使用探测用户级函数结尾处的 _uretprobe_ ,获取系统中运行的每个 _bash_ 发出的命令行:
```
$ sudo bpftrace -e 'uretprobe:/bin/bash:readline { printf("readline: \"%s\"\n", str(retval)); }'
```
要列出可执行文件 _bash_ 的所有可用 _uprobes / uretprobes_ 执行这个命令:
```
$ sudo bpftrace -l "uprobe:/bin/bash"
```
_uprobe_ 指向用户级函数执行的开始_uretprobe_ 指向执行的结束返回处_readline()_ 是 _/bin/bash_ 的一个函数返回键入的命令行_retval_ 是被探测的指令的返回值,只能在 _uretprobe_ 访问。
使用 _uprobes_ 时,你可以用 _arg0..argN_ 访问参数。需要调用 _str()__char *_ 指针转化成一个 _string_
## 自带脚本
bpftrace 软件包附带了许多有用的脚本,可以在 _/usr/share/bpftrace/tools/_ 目录找到。
这些脚本中,你可以找到:
* _killsnoop.bt_——追踪 `kill()` 系统调用发出的信号
* _tcpconnect.bt_——追踪所有的 TCP 网络连接
* _pidpersec.bt_——统计每秒钟(通过 fork创建的新进程
* _opensnoop.bt_——追踪 `open()` 系统调用
* _bfsstat.bt_——追踪一些 VFS 调用,按秒统计
你可以直接使用这些脚本,比如:
```
$ sudo /usr/share/bpftrace/tools/killsnoop.bt
```
你也可以在创建新的工具时参考这些脚本。
## 链接
* bpftrace 参考指南——<https://github.com/iovisor/bpftrace/blob/master/docs/reference_guide.md>
* Linux 2018 `bpftrace`DTrace 2.0)——<http://www.brendangregg.com/blog/2018-10-08/dtrace-for-linux-2018.html>
* BPF通用的内核虚拟机——<https://lwn.net/Articles/599755/>
* Linux Extended BPFeBPFTracing Tools——<http://www.brendangregg.com/ebpf.html>
* 深入 BPF一个阅读材料列表—— [https://qmonnet.github.io/whirl-offload/2016/09/01/dive-into-bpf][6]
* * *
_Photo by _[_Roman Romashov_][7]_ on _[_Unsplash_][8]_._
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/trace-code-in-fedora-with-bpftrace/
作者:[Augusto Caringi][a]
选题:[lujun9972][b]
译者:[YungeG](https://github.com/YungeG)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://fedoramagazine.org/author/acaringi/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2019/08/bpftrace-816x345.jpg
[2]: https://github.com/iovisor/bpftrace
[3]: https://lwn.net/Articles/740157/
[4]: https://github.com/iovisor/bpf-docs/blob/master/eBPF.md
[5]: https://fedoramagazine.org/howto-use-sudo/
[6]: https://qmonnet.github.io/whirl-offload/2016/09/01/dive-into-bpf/
[7]: https://unsplash.com/@wehavemegapixels?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
[8]: https://unsplash.com/search/photos/trace?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText

View File

@ -0,0 +1,135 @@
[#]: subject: (Top Android Emulators to Run and Test Android Apps on Linux)
[#]: via: (https://itsfoss.com/android-emulators-linux/)
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
在 Linux 上运行和测试 Android 应用的顶级 Android 模拟器
======
安卓系统是建立在高度定制的 Linux 内核之上的。因此,使用安卓模拟器在 Linux 上运行移动应用是有意义的。
虽然这不是在 Linux 机器上你可以做的新事情,但在 Windows 于 2021 年推出运行安卓应用的能力后,它是一个更需要的功能。
不仅仅限于使用应用,一些安卓模拟器也可以在开发和测试中派上用场。
因此,我总结了一份最好的模拟器清单,你可以用它来测试或在 Linux 上运行 Android 应用/游戏。
### 1\. Anbox
Anbox 是一个相当流行的让 Linux 用户运行 Android 应用的模拟器。可能 Deepin Linux 正是利用它使得开箱即可运行 Android 应用。
它使用一个容器将安卓操作系统与主机隔离,这也让它们可以使用最新的安卓版本。
运行的安卓应用将不能直接访问你的硬件,这是一个很好的安全决定。
与这里的其他一些选项不同Anbox 在技术上不需要仿真层来使安卓系统工作。换句话说,它在你的 Linux 系统上最接近于原生的 Android 体验。
由于这个原因它可能不是最简单的选择。你不能只使用谷歌应用商店来安装应用你需要使用安卓调试桥ADB。你只需要一个应用的 APK 文件就可以安装和使用它。
[Anbox][1]
### 2\. Genymotion
![][2]
Genymotion 是一个为测试和开发量身定做的令人印象深刻的解决方案。
它不是一个免费和开源的选择。它们通过云端或独立于 Android Studio 的桌面客户端,提供虚拟的 Android 体验作为服务。
你可以模拟各种硬件配置和安卓版本,创建一个虚拟设备进行测试。它还让你有能力扩大规模,并有多个安卓虚拟设备运行,进行广泛的测试。
它可以帮助你测试文件上传在你的应用中如何工作,电池影响、性能、内存等等。
虽然它是一个主要针对专业人士的高级解决方案,但它确实支持最新的 Linux 发行版,包括 Ubuntu 20.04 LTS。
[Genymotion][3]
### 3\. Android-x86
![][4]
Android x86 是一个开源项目,使得 Android 在 PC 上运行,并支持 32 位。
你可以选择在你的 Linux 系统上使用虚拟机管理器来安装它,或者直接在你的 PC 上试用它。
如果你需要安装,可以查看官方的[安装说明][5]。
与其他一些选项不同,它是一个简单的试图在 PC 上工作的模拟器,没有花哨的功能。
[Android x86][6]
### 4\. Android Studio (虚拟设备)
![][7]
Android Studio 是一个用于开发和测试的完整工具。幸运的是,由于对 Linux 的支持,如果你需要的话,你可以用它来模拟 Android 的体验进行实验。
你只需要创建一个安卓虚拟设备AVD你可以对其进行配置然后作为模拟器进行模拟。
也有很大的机会找到对一些最新的智能手机、电视和智能手表的支持。
它需要一定的学习曲线才能上手,但它是免费的,而且是完全开源的。
[Android Studio][8]
### 5\. ARChon
![][9]
一个有趣的解决方案是一个你可以在 Linux 和任何其他平台上使用的 Android 模拟器。
它有助于在 Chrome OS 上运行 Android 应用,或者在任何操作系统上使用 Chrome 浏览器。与其他一些不同的是,你可能不会得到完整的安卓体验,而只是能够运行安卓应用。
你只需解压运行时,并将其加载到 Chrome 扩展中。接下来,下载 APK 文件到上面来添加你想使用的应用。
[ARChon][10]
### 6\. Bliss OS
![][11]
Bliss OS 是另一个开源项目,与 Android x86 类似,旨在使 Android 在 PC 上运行。
与 Android x86 不同的是,它通过支持 32 位和 64 位架构提供了更多的兼容性选择。此外,你可以根据你的处理器下载兼容文件。
它有积极的维护,支持市场上最新的安卓版本。
[Bliss OS][12]
### 总结
虽然你会发现有几个可用于 Linux 的安卓模拟器,但它们可能无法取代全面的智能手机体验。
每个模拟器都有一系列的功能和特定目的。请选择你需要的那个!
你试过安卓模拟器么?你在 Linux 中使用的最喜欢的模拟器是什么?欢迎在下面的评论中让我知道。
--------------------------------------------------------------------------------
via: https://itsfoss.com/android-emulators-linux/
作者:[Ankush Das][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/ankush/
[b]: https://github.com/lujun9972
[1]: https://anbox.io
[2]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/07/genymotion-android-emulator.png?resize=800%2C508&ssl=1
[3]: https://www.genymotion.com
[4]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/07/android-x86-emulator.jpg?resize=1920%2C1080&ssl=1
[5]: https://www.android-x86.org/installhowto.html
[6]: https://www.android-x86.org
[7]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/07/android-virtual-devices-studio.png?resize=800%2C296&ssl=1
[8]: https://developer.android.com/studio
[9]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/07/arcrhon.jpg?resize=800%2C426&ssl=1
[10]: https://archon-runtime.github.io
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/07/bliss-os-android.png?resize=800%2C576&ssl=1
[12]: https://blissos.org

View File

@ -0,0 +1,77 @@
[#]: subject: (How to Install VLC on Fedora Linux)
[#]: via: (https://itsfoss.com/install-vlc-fedora/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
如何在 Fedora Linux 上安装 VLC
======
如果你刚刚安装了 Fedora现在想在上面安装你最喜欢的视频播放器 VLC你可能不会在软件中心找到它。至少不会立即找到。
由于开发者最清楚的原因Fedora 既没有安装 [VLC][1],也不包括在 Fedora 官方仓库中。
那么,你如何在 Fedora 上安装 VLC 呢很简单。RPM Fusion 是你的朋友。让我告诉你详细的步骤。
### 在 Fedora Linux 上安装 VLC
在这里使用命令行会更容易。你也可以使用图形化的方法。我将在后面讨论它。
打开终端,使用下面的命令来添加和启用包含 VLC 包的 RPM Fusion 仓库:
```
sudo dnf install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
```
当被要求确认添加新仓库时按 Y。接下来使用 DNF 命令安装 VLC
```
sudo dnf install vlc
```
它将在 Fedora 中从RPM Fusion 仓库中安装 VLC并从不同的仓库中安装一些额外的依赖项。
![Installing VLC in Fedora with DNF command][2]
安装后,你可以在应用程序菜单中搜索 VLC或者在“活动区”中搜索它。
![Search for VLC][3]
点击、启动并享受它。
#### 替代方法:从软件中心安装 VLC
当你已经启用了 RPM Fusion 仓库,你可以在软件中心显示这个仓库的应用。要做到这一点,在终端使用以下命令:
```
sudo dnf groupupdate core
```
之后,打开软件中心,搜索 VLC 并从那里安装。
![VLC in Fedora software center][4]
如果你有添加 FlatHub 仓库,请避免安装 Flatpak 版本的 VLC因为它的大小大约是 1GB。RPM 版本的大小要小得多。
我希望你觉得这个快速教程对在 Fedora 上安装 VLC 有帮助。享受吧。
--------------------------------------------------------------------------------
via: https://itsfoss.com/install-vlc-fedora/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://www.videolan.org/
[2]: https://itsfoss.com/wp-content/uploads/2021/07/installing-vlc-fedora-800x422.webp
[3]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/07/vlc-fedora.png?resize=799%2C223&ssl=1
[4]: https://itsfoss.com/wp-content/uploads/2021/07/vlc-in-fedora-software-center-800x486.webp