mirror of
https://github.com/LCTT/TranslateProject.git
synced 2026-08-23 04:03:29 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
@@ -1,59 +1,57 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (cycoe)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12150-1.html)
|
||||
[#]: subject: (What you need to know about variables in Emacs)
|
||||
[#]: via: (https://opensource.com/article/20/3/variables-emacs)
|
||||
[#]: author: (Clemens Radermacher https://opensource.com/users/clemera)
|
||||
|
||||
关于 Emacs 中的变量你需要知道的事情
|
||||
======
|
||||
学习 Elisp 是如何处理变量的,以及如何在你的脚本与配置中使用它们。
|
||||
![编程键盘][1]
|
||||
|
||||
> 学习 Elisp 是如何处理变量的,以及如何在你的脚本与配置中使用它们。
|
||||
|
||||

|
||||
|
||||
GNU Emacs 是由 C 和 Emacs Lisp(Elisp,Lisp 编程语言的一种方言)写成,它是一个编辑器的同时,又碰巧是 Elisp 的沙盒。因此,理解 Elisp 中的一些基本编程概念会对你有一些帮助。
|
||||
|
||||
如果你是 [Emacs][2] 新手,请先访问 Sacha Chua 的[《给 Emacs 新手的资源》][3]精品帖。本篇文章假定你熟悉常见的 Emacs 术语,并且能够阅读 Elisp 代码的简单片段并对其进行求值。最好你也听说过变量作用域的概念,知道它在其它编程语言中的作用。本篇文章中的示例假定你使用的是相对较新的 Emacs 版本([v.25 之后的版本][4])。
|
||||
如果你是 [Emacs][2] 新手,请先阅读 Sacha Chua 的《[给 Emacs 新手的资源][3]》精品帖。本篇文章假定你熟悉常见的 Emacs 术语,并且能够阅读并求值 Elisp 代码的简单片段。最好你也听说过变量作用域的概念,知道它在其它编程语言中的作用。本篇文章中的示例假定你使用的是相对较新的 Emacs 版本([v.25 之后的版本][4])。
|
||||
|
||||
[Elisp 手册][5] 包含了 Elisp 的方方面面,但它是写给那些有明确查找目标的人们的,并且它在这方面也做得相当棒。但是很多人希望这些资源能够在更高的层次上解释 Elisp 的概念,同时将信息压缩成最精华的部分。本篇文章也正是我回应这种呼声的一次尝试,为读者描绘基础的大体轮廓。使他们能在配置中用上这些技巧,也让他们在手册中查询细节变得更容易。
|
||||
[Elisp 手册][5] 包含了 Elisp 的方方面面,但它是写给那些有明确查找目标的人们的(它在这方面也做得相当棒)。但是很多人想要能够在更高的层次上解释 Elisp 概念的材料,同时将信息压缩成最精华的部分。本篇文章也正是我回应这种呼声的一次尝试,为读者描绘基础的大体轮廓。使他们能在配置中用上这些技巧,也让他们在手册中查询细节变得更容易。
|
||||
|
||||
### 全局变量
|
||||
|
||||
用 `defcustom` 定义的用户设置和用 `defvar` 或 `defconst` 定义的变量是全局的。使用 `defcustom` 或 `defvar` 声明变量的一个非常重要的原因是,当一个变量已经被<ruby>绑定<rt>bind</rt></ruby>,对它们进行重新求值不会覆盖掉已有的值。举个栗子,如果你在初始化文件中对 `my-var` 进行如下绑定:
|
||||
|
||||
|
||||
```
|
||||
`(setq my-var nil)`
|
||||
(setq my-var nil)
|
||||
```
|
||||
|
||||
对如下表达式求值不会将变量覆盖为 `t`:
|
||||
|
||||
|
||||
```
|
||||
`(defvar my-var t)`
|
||||
(defvar my-var t)
|
||||
```
|
||||
|
||||
注意此处有_一个例外_:如果你用 `C-M-x` 快捷键对上述声明求值,它将调用 `eval-defun` 函数,并将变量覆盖为 `t`。通过此方式,你可以按需将变量强制覆盖。这种行为是刻意而为之的:你可能知道,Emacs 中的许多特性是按需加载的,也可以称为自动加载。如果那些文件中的声明将变量覆盖为它们的默认值,那它也就覆盖了你初始化文件中的设置。
|
||||
注意此处有*一个例外*:如果你用 `C-M-x` 快捷键对上述声明求值,它将调用 `eval-defun` 函数,并将变量覆盖为 `t`。通过此方式,你可以按需将变量强制覆盖。这种行为是刻意而为之的:你可能知道,Emacs 中的许多特性是按需加载的,也可以称为自动加载。如果那些文件中的声明将变量覆盖为它们的默认值,那它也就覆盖了你初始化文件中的设置。
|
||||
|
||||
### 用户选项
|
||||
|
||||
用户选项就是使用 `defcustom` 声明的全局变量。与使用 `defvar` 声明的变量不同,这些变量可以用 `M-x customize` 界面来配置。据我所知,大部分人因为觉得它开销较大而不经常使用。一旦你知道如何在你的初始化文件中设置变量,也就没有理由一定要去使用它了。许多用户没有意识到的一个细节是,通过 **customize** 的方式设置用户选项能够执行代码,有的时间可用来运行一些附加的配置说明:
|
||||
|
||||
用户选项就是使用 `defcustom` 声明的全局变量。与使用 `defvar` 声明的变量不同,这些变量可以用 `M-x customize` 界面来配置。据我所知,大部分人因为觉得它开销较大而不经常使用。一旦你知道如何在你的初始化文件中设置变量,也就没有理由一定要去使用它了。许多用户没有意识到的一个细节是,通过 `customize` 的方式设置用户选项能够执行代码,有的时间可用来运行一些附加的配置说明:
|
||||
|
||||
```
|
||||
(defcustom my-option t
|
||||
"我的用户选项"
|
||||
"My user option."
|
||||
:set (lambda (sym val)
|
||||
(set-default sym val)
|
||||
(message "Set %s to %s" sym val)))
|
||||
```
|
||||
|
||||
若你对这段代码求值,并键入 `M-x customize-option RET my-option RET` 运行 **customize** 界面,lambda 匿名函数就会被调用,回显区域就会显示出该选项的符号名与值。
|
||||
若你对这段代码求值,并键入 `M-x customize-option RET my-option RET` 运行 `customize` 界面,lambda 匿名函数就会被调用,回显区域就会显示出该选项的符号名与值。
|
||||
|
||||
如果你在初始化文件中使用 `setq` 改变该选项的值,那么匿名函数不会运行。要想在 Elisp 中正确设置一个选项,你需要使用函数 `customize-set-variable`。或者,人们在他们的配置文件中使用了各种版本的 `csetq` 宏来自动处理(如你所愿,你可以通过 GitHub 的代码搜索发现更复杂的变体)。
|
||||
|
||||
|
||||
```
|
||||
(defmacro csetq (sym val)
|
||||
`(funcall (or (get ',sym 'custom-set) 'set-default) ',sym ,val))
|
||||
@@ -63,20 +61,18 @@ GNU Emacs 是由 C 和 Emacs Lisp(Elisp,Lisp 编程语言的一种方言)
|
||||
|
||||
在你将以上代码放入到你的初始化文件中之后,你便可以使用 `csetq` 宏在设置变量的同时运行任何现存的 `setter` 函数。要证明这点,你可以使用此宏来改变上面定义的选项,并观察回显区域的消息输出。
|
||||
|
||||
|
||||
```
|
||||
`(csetq my-option nil)`
|
||||
(csetq my-option nil)
|
||||
```
|
||||
|
||||
### 动态绑定与词法绑定
|
||||
|
||||
当你在使用其它编程语言时,你可能不会意识到动态绑定与词法绑定的区别。当今的大部分编程语言使用词法绑定,并且在学习变量作用域与变量查找时也没有必要去了解它们之间的区别。
|
||||
|
||||
如此看来,Emacs Lisp 比较特殊因为动态绑定是默认选项,词法绑定需要显式启用。这里有一些历史遗留原因,但在实际使用中,你应该_时刻_启用词法绑定,因为它更快并且不容易出错。要启用词法绑定,只需将如下的注释行作为你的 Emacs Lisp 文件的第一行:
|
||||
|
||||
如此看来,Emacs Lisp 比较特殊因为动态绑定是默认选项,词法绑定需要显式启用。这里有一些历史遗留原因,但在实际使用中,你应该*时刻*启用词法绑定,因为它更快并且不容易出错。要启用词法绑定,只需将如下的注释行作为你的 Emacs Lisp 文件的第一行:
|
||||
|
||||
```
|
||||
`;;; -*- lexical-binding: t; -*-`
|
||||
;;; -*- lexical-binding: t; -*-
|
||||
```
|
||||
|
||||
另一种方式,你可以调用 `add-file-local-variable-prop-line`,在你选择将变量 `lexical-binding` 置为 `t` 后,会自动插入如上的注释行。
|
||||
@@ -105,15 +101,13 @@ GNU Emacs 是由 C 和 Emacs Lisp(Elisp,Lisp 编程语言的一种方言)
|
||||
|
||||
如你所知,`let` 用于临时建立局部绑定:
|
||||
|
||||
|
||||
```
|
||||
(let ((a "I'm a")
|
||||
(b "I'm b"))
|
||||
(message "Hello, %s. Hello %s" a b))
|
||||
```
|
||||
|
||||
接下来有趣的是——使用 `defcustom`、`defvar` 以及 `defconst` 定义的变量被称为_特殊变量_,不论词法绑定是否启用,它们都将使用动态绑定:
|
||||
|
||||
接下来有趣的是——使用 `defcustom`、`defvar` 以及 `defconst` 定义的变量被称为*特殊变量*,不论词法绑定是否启用,它们都将使用动态绑定:
|
||||
|
||||
```
|
||||
;;; -*- lexical-binding: t; -*-
|
||||
@@ -142,7 +136,6 @@ GNU Emacs 是由 C 和 Emacs Lisp(Elisp,Lisp 编程语言的一种方言)
|
||||
|
||||
这是另一个常见的示例,如何进行大小写敏感的搜索:
|
||||
|
||||
|
||||
```
|
||||
(let ((case-fold-search nil))
|
||||
(some-function-which-uses-search ...))
|
||||
@@ -154,26 +147,25 @@ GNU Emacs 是由 C 和 Emacs Lisp(Elisp,Lisp 编程语言的一种方言)
|
||||
|
||||
```
|
||||
(let ((vars ()))
|
||||
(mapatoms
|
||||
(lambda (cand)
|
||||
(when (and (boundp cand)
|
||||
(not (keywordp cand))
|
||||
(special-variable-p cand)
|
||||
(not (string-match "-"
|
||||
(symbol-name cand))))
|
||||
(push cand vars))))
|
||||
vars) ;; => (t obarray noninteractive debugger nil)
|
||||
(mapatoms
|
||||
(lambda (cand)
|
||||
(when (and (boundp cand)
|
||||
(not (keywordp cand))
|
||||
(special-variable-p cand)
|
||||
(not (string-match "-"
|
||||
(symbol-name cand))))
|
||||
(push cand vars))))
|
||||
vars) ;; => (t obarray noninteractive debugger nil)
|
||||
```
|
||||
|
||||
### 缓冲区局部变量
|
||||
|
||||
每个缓冲区都能够拥有变量的一个局部绑定。这就意味着对于任何变量,都会首先在当前缓冲区中查找缓冲区局部变量取代默认值。局部变量是 Emacs 中一个非常重要的特性,比如它们被主模式用来建立缓冲区范围内的行为与设置。
|
||||
|
||||
事实上你已经在本文中见过_缓冲区局部变量_——也就是将 `lexical-binding` 在缓冲区范围内设置为 `t` 的特殊注释行。在 Emacs 中,在特殊注释行中定义的缓冲区局部变量也被称为`文件局部变量`。
|
||||
事实上你已经在本文中见过*缓冲区局部变量*——也就是将 `lexical-binding` 在缓冲区范围内设置为 `t` 的特殊注释行。在 Emacs 中,在特殊注释行中定义的缓冲区局部变量也被称为*文件局部变量*。
|
||||
|
||||
任何的全局变量都可以用缓冲区局部变量来遮掩,比如上面定义的变量 `my-var`,你可用如下方式设置局部变量:
|
||||
|
||||
|
||||
```
|
||||
(setq-local my-var t)
|
||||
;; or (set (make-local-variable 'my-var) t)
|
||||
@@ -185,7 +177,6 @@ GNU Emacs 是由 C 和 Emacs Lisp(Elisp,Lisp 编程语言的一种方言)
|
||||
|
||||
因为局部变量意味着对缓冲区的定制,它们也就经常被用于模式钩子中。一个典型的例子如下所示:
|
||||
|
||||
|
||||
```
|
||||
(add-hook 'go-mode-hook
|
||||
(defun go-setup+ ()
|
||||
@@ -199,8 +190,7 @@ GNU Emacs 是由 C 和 Emacs Lisp(Elisp,Lisp 编程语言的一种方言)
|
||||
|
||||
这将设置 `go-mode` 缓冲区中 `M-x compile` 使用的编译命令。
|
||||
|
||||
另一个重要的方面就是一些变量会_自动_成为缓冲区局部变量。这也就意味着当你使用 `setq` 设置这样一个变量时,它会针对当前缓冲区设置局部绑定。这个特性不应该被经常使用,因为这种隐式的行为并不好。不过如果你想的话,你可以使用如下方法创建自动局部变量:
|
||||
|
||||
另一个重要的方面就是一些变量会*自动*成为缓冲区局部变量。这也就意味着当你使用 `setq` 设置这样一个变量时,它会针对当前缓冲区设置局部绑定。这个特性不应该被经常使用,因为这种隐式的行为并不好。不过如果你想的话,你可以使用如下方法创建自动局部变量:
|
||||
|
||||
```
|
||||
(defvar-local my-automatical-local-var t)
|
||||
@@ -213,9 +203,7 @@ GNU Emacs 是由 C 和 Emacs Lisp(Elisp,Lisp 编程语言的一种方言)
|
||||
|
||||
Emacs 是一个强大的编辑器,并且随着你的定制它将变得更加强大。现在,你知道了 Elisp 是如何处理变量的,以及你应如何在你自己的脚本与配置中使用它们。
|
||||
|
||||
* * *
|
||||
|
||||
_本篇文章此前采用 CC BY-NC-SA 4.0 许可证发布在 [With-Emacs][7] 上,经过修改(带有合并请求)并在作者允许的情况下重新发布。_
|
||||
*本篇文章此前采用 CC BY-NC-SA 4.0 许可证发布在 [With-Emacs][7] 上,经过修改(带有合并请求)并在作者允许的情况下重新发布。*
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@@ -224,7 +212,7 @@ via: https://opensource.com/article/20/3/variables-emacs
|
||||
作者:[Clemens Radermacher][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[cycoe](https://github.com/cycoe)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
@@ -0,0 +1,329 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (Zioyi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12149-1.html)
|
||||
[#]: subject: (12 Linux Commands to Have Some Fun in the Terminal)
|
||||
[#]: via: (https://itsfoss.com/funny-linux-commands/)
|
||||
[#]: author: (Community https://itsfoss.com/author/itsfoss/)
|
||||
|
||||
12 个有趣的 Linux 终端命令
|
||||
======
|
||||
|
||||
> 你觉得 Linux 终端里只有无趣的工作吗?那你一定不知道下面这些有趣的 Linux 命令吧。
|
||||
|
||||
Linux 终端是用来完成复杂的工作的,我们有很多有用的 [linux 命令奇技淫巧][1]来帮助你。
|
||||
|
||||
但是,你知道你还可以用终端来做很多有趣的事吗?如果你不知道,没关系,大多数 Linux 用户也都只把终端视为一个用来管理系统和开发工作的交互界面。
|
||||
|
||||
然而,如果你知道这里有些你可以在终端玩的[基于终端的游戏][2]和 [ASCII 码游戏][3],你一定会大吃一惊。
|
||||
|
||||
在这篇文章中,我将会探索一些有趣的、可笑的、荒谬的命令来让你可以在终端中找点乐子!
|
||||
|
||||
### 用这些命令在 Linux 终端中找点乐子
|
||||
|
||||
![][4]
|
||||
|
||||
你可能会觉得这些命令荒谬或没用,但是有一些还是可以被好好利用的。
|
||||
|
||||
我已经放上了 Ubuntu/Debian 的安装指令,如果你使用基于 Ubuntu 的发行版,请确保[启用 universe 仓库][5],因为大多数命令不在主仓库中。
|
||||
|
||||
如果你使用 Arch、Fedora、SUSE、Solus 或者其他非 Ubuntu 的发行版,请使用你的发行版包管理工具去安装这些有趣的 Linux 命令。
|
||||
|
||||
#### 1、在终端开一辆火车
|
||||
|
||||
让我们坐上火车,来一场说走就走的旅行的,没错,就是字面意思!
|
||||
|
||||
`sl` 命令可以让你在终端运行一辆火车。
|
||||
|
||||
![][6]
|
||||
|
||||
安装方法:
|
||||
|
||||
```
|
||||
sudo apt install sl
|
||||
```
|
||||
|
||||
完成后,你只要在终端输入下面的命令就可以开始:
|
||||
|
||||
```
|
||||
sl
|
||||
```
|
||||
|
||||
很精彩,对吧?但等等,我们还没结束!你还可以让你的火车飞起来,只要加上参数 `-F`,波特先生,请飞吧:
|
||||
|
||||
```
|
||||
sl -F
|
||||
```
|
||||
|
||||
这样会让火车长出翅膀飞出终端窗口!
|
||||
|
||||
#### 2、给你的 Linux 终端加上黑客帝国效果
|
||||
|
||||
还记得科幻电影[黑客帝国][7]吗?终端里掉落的绿色字符成为了黑客帝国的标志形象。
|
||||
|
||||
你也可以在你的 Linux 电脑里有这样的黑客帝国数字雨!你只需要安装 `cmatric` 然后在终端输入它就行。
|
||||
|
||||
![][8]
|
||||
|
||||
在 Debian/Ubuntu Linux 上安装 cmatrix:
|
||||
|
||||
```
|
||||
sudo apt install cmatrix
|
||||
```
|
||||
|
||||
现在,你要做的就是输入下面的命令,在终端就会有黑客帝国屏幕了:
|
||||
|
||||
```
|
||||
cmatrix
|
||||
```
|
||||
|
||||
按下 `Ctrl+C` 来停止它,黑客先生。
|
||||
|
||||
#### 3、燃起来
|
||||
|
||||
拿好灭火器,因为接下来你要在你的终端里点火了!
|
||||
|
||||
![][11]
|
||||
|
||||
想安装它,你要输入:
|
||||
|
||||
```
|
||||
sudo apt install libaa-bin
|
||||
```
|
||||
|
||||
完成后,你输入下面的命令,你的终端就会燃起一团火焰:
|
||||
|
||||
```
|
||||
aafire
|
||||
```
|
||||
|
||||
按下 `Ctrl+C` 来停止它。
|
||||
|
||||
#### 4、幸运饼干命令
|
||||
|
||||
想知道你的运气怎样但身边没有幸运饼干?
|
||||
|
||||
别担心,你只需在终端打出 `fortune` 然后按下回车。终端将会随机显示出一个幸运语,就像你从幸运饼干里得到的一样。
|
||||
|
||||
![][12]
|
||||
|
||||
安装它:
|
||||
|
||||
```
|
||||
sudo apt install fortune
|
||||
```
|
||||
|
||||
完成后,只要在命令行打出下面的内容,你就会知道你的运气怎样:
|
||||
|
||||
```
|
||||
fortune
|
||||
```
|
||||
|
||||
这是一个你可以实际使用的命令。你可以用它作为每日消息,这样在多用户环境下,每个用户登录后都会得到一个“幸运饼干”。
|
||||
|
||||
你也可以把它添加到 `bashrc` 文件,这样当你登进终端你就会看到了。
|
||||
|
||||
#### 5、宠物爱好者?这是给你准备的
|
||||
|
||||
`oneko` 是一个有趣的命令,可以把你的光标变成一只老鼠,然后创造一只好奇的猫,一旦你移动光标,就会来追你。这不仅局限于终端。当猫追逐光标时,你可以继续工作。
|
||||
|
||||
如果你家里有孩子这一定很有趣。
|
||||
|
||||
![][13]
|
||||
|
||||
用下面的命令安装 `oneko`:
|
||||
|
||||
```
|
||||
sudo apt install oneko
|
||||
```
|
||||
|
||||
用下面的命令运行它:
|
||||
|
||||
```
|
||||
oneko
|
||||
```
|
||||
|
||||
如果你不喜欢猫,喜欢狗,输入:
|
||||
|
||||
```
|
||||
oneko -dog
|
||||
```
|
||||
|
||||
它有很多种小宠物,你可以用 `oneko -help` 获取信息。按下 `Ctrl+C` 终止它。
|
||||
|
||||
#### 6、有个小兄弟在看着你
|
||||
|
||||
`xeyes` 是一个很小的 GUI 程序,它可以绘制出一双眼睛一直盯着你!它会不断跟随你的鼠标光标,运行命令自己看看!
|
||||
|
||||
![][14]
|
||||
|
||||
你可以用下面命令安装:
|
||||
|
||||
```
|
||||
sudo apt install xeyes
|
||||
```
|
||||
|
||||
然后这样用它:
|
||||
|
||||
```
|
||||
xeyes
|
||||
```
|
||||
|
||||
按下 `Ctrl+C` 终止它。
|
||||
|
||||
#### 7、让终端帮你讲话
|
||||
|
||||
打开你的扬声器,你来试试这个命令,[eSpeak][15] 是一个有趣的命令,它可以让你的终端说话。是的,你没听错。
|
||||
|
||||
先安装这个包:
|
||||
|
||||
```
|
||||
sudo apt install espeak
|
||||
```
|
||||
|
||||
接下来,你只需要输入在命令行中输入你想听到的话:
|
||||
|
||||
```
|
||||
espeak "Type what your computer says"
|
||||
```
|
||||
|
||||
无论你在双引号里面填什么,你的电脑都会复述出来!它就像[在 Linux 中的 echo 命令][16],但不是打印出来,而是说出来。
|
||||
|
||||
#### 8、Toilet(但与洗手间无关)
|
||||
|
||||
这听起来有点奇怪,是的。但是,这只是一个命令,用来将文本转换成大的 ASCII 字符。
|
||||
|
||||
![][17]
|
||||
|
||||
用这个命令安装 `toilet`:
|
||||
|
||||
```
|
||||
sudo apt install toilet
|
||||
```
|
||||
|
||||
完成后,你只需输入:
|
||||
|
||||
```
|
||||
toilet sample text you want
|
||||
```
|
||||
|
||||
我也不知道为啥这个小程序叫 Toilet。
|
||||
|
||||
#### 9、那个牛说什么?
|
||||
|
||||
`cowsay` 是一个在终端中用 ASCII 字符展示出一头牛的命令。通过这个命令,你可以控制牛说出你想说的话。
|
||||
|
||||
别纠结声音,它只展示文本(就是你看漫画书一样)。
|
||||
|
||||
![Cowsay Cowthink][18]
|
||||
|
||||
安装 `cowsay`:
|
||||
|
||||
```
|
||||
sudo apt install cowsay
|
||||
```
|
||||
|
||||
安装完成后,你只要输入:
|
||||
|
||||
```
|
||||
cowsay "your text"
|
||||
```
|
||||
|
||||
无论你在双引号里填什么,你的牛都会说!我看到一些系统管理员用它来展示每天的消息。你也可以这样,你甚至可以把它和 `fortune` 命令结合。
|
||||
|
||||
#### 10、旗帜
|
||||
|
||||
`banner` 命令与 `toilet` 命令相似,但它限制最多只能打印 10 个字符。
|
||||
|
||||
![][19]
|
||||
|
||||
你可以这样安装 `banner` 命令:
|
||||
|
||||
```
|
||||
sudo apt install sysvbanner
|
||||
```
|
||||
|
||||
然后这样运行:
|
||||
|
||||
```
|
||||
banner "Welcome"
|
||||
```
|
||||
|
||||
替换双引号里的内容,你将会得到你想要的展示内容。
|
||||
|
||||
#### 11、Yes
|
||||
|
||||
![][20]
|
||||
|
||||
`yes` 命令帮助你在循环中自动响应直到终止命令。这个命令将会一直打印相同的内容。如果你想快速生成大量垃圾文本,那么此命令将像超级按钮一样工作。
|
||||
|
||||
你也可以使用它为命令提供 `yes` 应答(如果提示应答时)。例如,`apt upgrade` 命令会要求你确认,你可以像这样使用它:
|
||||
|
||||
```
|
||||
yes | sudo apt upgrade
|
||||
```
|
||||
|
||||
你不需要安装任何包,`yes` 命令已经存在了。
|
||||
|
||||
想要终止 `yes` 命令循环,只需按下 `CTRL+C`。
|
||||
|
||||
#### 12、得到一个新的身份
|
||||
|
||||
要生成一个随机的假身份吗?我推荐你用 `rig` 命令。你在终端运行它,就会生成一个假的身份。
|
||||
|
||||
![][21]
|
||||
|
||||
用这个命令安装 `rig`:
|
||||
|
||||
```
|
||||
sudo apt install rig
|
||||
```
|
||||
|
||||
只需像这样输入:
|
||||
|
||||
```
|
||||
rig
|
||||
```
|
||||
|
||||
它可能被用在脚本或者 web 应用中展示随机信息,但我自己还没做过什么。
|
||||
|
||||
### 结尾
|
||||
|
||||
我希望你会喜欢这个有趣的 Linux 命令列表。你最喜欢哪个命令呢?你还知道其他有趣的命令吗?请在评论部分与我们分享。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/funny-linux-commands/
|
||||
|
||||
作者:[Srimanta Koley][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[Zioyi](https://github.com/Zioyi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/itsfoss/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/linux-command-tricks/
|
||||
[2]: https://itsfoss.com/best-command-line-games-linux/
|
||||
[3]: https://itsfoss.com/best-ascii-games/
|
||||
[4]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/04/fun-linux-commands.png?ssl=1
|
||||
[5]: https://itsfoss.com/ubuntu-repositories/
|
||||
[6]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/04/sl-command.jpg?ssl=1
|
||||
[7]: https://en.wikipedia.org/wiki/The_Matrix
|
||||
[8]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/04/matrix-screen-command.png?ssl=1
|
||||
[9]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2015/12/Star-Wars-Linux-Terminal-2.png?fit=732%2C462&ssl=1
|
||||
[10]: https://itsfoss.com/star-wars-linux/
|
||||
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/04/fire-command.png?ssl=1
|
||||
[12]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/04/fortune-command.jpg?ssl=1
|
||||
[13]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/04/oneko-command.jpg?ssl=1
|
||||
[14]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/04/xeyes-command.jpg?ssl=1
|
||||
[15]: https://itsfoss.com/espeak-text-speech-linux/
|
||||
[16]: https://linuxhandbook.com/echo-command/
|
||||
[17]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/04/toilet-command.jpg?ssl=1
|
||||
[18]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/04/cowsay-cowthink.jpg?ssl=1
|
||||
[19]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/04/banner-command.jpg?ssl=1
|
||||
[20]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/04/yes-yourtext.jpg?ssl=1
|
||||
[21]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/04/rig-command.jpg?ssl=1
|
||||
[22]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/03/srimanta.jpg?ssl=1
|
||||
@@ -0,0 +1,78 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (The rebirth of Mapzen, new projects bolster PyTorch, faster AI object detection, and other open source news)
|
||||
[#]: via: (https://opensource.com/article/20/4/news-march-25)
|
||||
[#]: author: (Scott Nesbitt https://opensource.com/users/scottnesbitt)
|
||||
|
||||
The rebirth of Mapzen, new projects bolster PyTorch, faster AI object detection, and other open source news
|
||||
======
|
||||
Catch up on the biggest open source headlines from the past two weeks.
|
||||
![][1]
|
||||
|
||||
In this edition of our open source news roundup, we take a look at the rebirth of Mapzen, two new projects to bolster PyTorch, new open source object detection software, and more!
|
||||
|
||||
### Mapzen makes a comeback
|
||||
|
||||
While its technology is used by open source projects like OpenStreetMap and by firms like Foursquare, open source mapping company Mapzen couldn't sustain itself as a business. Mapzen initially closed its doors in 2018, but it has [a new lease on life][2] with the support of the Linux Foundation.
|
||||
|
||||
As a project under the Urban Computing Foundation (UCF), Mapzen "encompasses six independent projects and communities involved in developing a truly open platform for mapping, search, navigation and transit data." Being under the UCF's umbrella enables Mapzen's developers to "collaborate on and build a common set of open-source tools connecting cities, autonomous vehicles, and smart infrastructure." They can also tap such UCF members as Google, IBM, and the University of California San Diego for support. Mapzen projects are available under their [GitHub organization][3].
|
||||
|
||||
### New open source projects to bolster PyTorch
|
||||
|
||||
PyTorch, the open source machine learning framework originating out of Facebook, has been getting a lot of love lately from both its creator and from AWS. The two firms have [released open source projects to bolster PyTorch][4].
|
||||
|
||||
Facebook is sharing TorchServe, "a model-serving framework for PyTorch that will make it easier for developers to put their models into production." AWS's contribution is TorchElastic, "a library that makes it easier for developers to build fault-tolerant training jobs on Kubernetes clusters." PyTorch's product manager Joe Spisak [told VentureBeat][5] that by using the two projects developers can run "training over a number of nodes without the training job actually failing; it will just continue gracefully, and once those nodes come back online, it can basically restart the training."
|
||||
|
||||
You can find the code for [TorchServe][6] and [TorchElastic][7] on GitHub.
|
||||
|
||||
### Microsoft and Huazhong University release object detection AI
|
||||
|
||||
One of the more difficult tasks facing artificial intelligence systems is to accurately detect and identify objects in photos and videos. Researchers from Microsoft and China's Huazhong University have [released an open source tool][8] that does the job quickly and efficiently.
|
||||
|
||||
Called Fair Multi-Object Tracking (FairMOT for short), the tool "outperforms state-of-the-art models on public data sets at 30 frames per second" (almost normal video speed). It took researches about 30 hours to train the software using data from the MOT Challenge, which is "a framework for validating people-tracking algorithms." The team behind FairMOT believe that the tool can be used in "industries ranging from elder care to security, and perhaps be used to track the spread of illnesses like COVID-19."
|
||||
|
||||
You can view the source code and training models for FairMOT in [this GitHub repository][9].
|
||||
|
||||
#### In other news
|
||||
|
||||
* [Will a small open-source effort from Japan disrupt the autonomous space?][10]
|
||||
* [Google open-sources data set to train and benchmark AI sound separation models][11]
|
||||
* [Docker builds open source community around Compose Specification][12]
|
||||
* [Sophos Sandboxie is now available as an open-source tool][13]
|
||||
* [PyCon has moved to an online-only event and is available now][14]
|
||||
|
||||
|
||||
|
||||
Thanks, as always, to Opensource.com staff members and [Correspondents][15] for their help this week.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/4/news-march-25
|
||||
|
||||
作者:[Scott Nesbitt][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/scottnesbitt
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/weekly_news_roundup_tv.png?itok=tibLvjBd
|
||||
[2]: https://www.zdnet.com/article/mapzen-open-source-mapping-project-revived-under-the-urban-computing-foundation/
|
||||
[3]: https://github.com/mapzen/
|
||||
[4]: https://techcrunch.com/2020/04/21/aws-and-facebook-launch-an-open-source-model-server-for-pytorch/
|
||||
[5]: https://venturebeat.com/2020/04/21/facebook-partners-with-aws-on-pytorch-1-5-upgrades-like-torchserve-for-model-serving/
|
||||
[6]: https://github.com/pytorch/serve
|
||||
[7]: https://github.com/pytorch/elastic
|
||||
[8]: https://venturebeat.com/2020/04/08/researchers-open-source-state-of-the-art-object-tracking-ai/
|
||||
[9]: https://github.com/ifzhang/FairMOT
|
||||
[10]: https://www.forbes.com/sites/rahulrazdan/2020/04/04/will-a-small-open-source-effort-from-japan-disrupt-the--autonomous-space-/#6e6819f01cc5
|
||||
[11]: https://venturebeat.com/2020/04/09/google-open-sources-data-set-to-train-and-benchmark-ai-sound-separation-models/
|
||||
[12]: https://sdtimes.com/softwaredev/docker-builds-open-source-community-around-compose-specification/
|
||||
[13]: https://securityaffairs.co/wordpress/101397/malware/sandboxie-sandbox-open-source.html
|
||||
[14]: https://us.pycon.org/2020/online/
|
||||
[15]: https://opensource.com/correspondent-program
|
||||
@@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (Zioyi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
||||
@@ -0,0 +1,307 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (20 Linux Command Tips and Tricks That Will Save You A Lot of Time)
|
||||
[#]: via: (https://itsfoss.com/linux-command-tricks/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
20 Linux Command Tips and Tricks That Will Save You A Lot of Time
|
||||
======
|
||||
|
||||
_**Brief**: Here are some tiny but useful Linux commands, terminal tricks and shortcuts that will save you a lot of time while working with Linux command line._
|
||||
|
||||
Have you ever encountered a moment when you see your colleague using some simple Linux commands for tasks that took you several keystrokes? And when you saw that you were like, “Wow! I didn’t know it could have been done that easily”.
|
||||
|
||||
In this article, I’ll show you some pro Linux command tricks that will save you a lot of time and in some cases, from plenty of frustration. Not only your friends or colleagues will ‘wow’ at you, it will also help you increase your productivity as you will need fewer keystrokes and even fewer mouse clicks.
|
||||
|
||||
It’s not that these are Linux tips for beginners only. Chances are that even experienced Linux users will find some hidden gems that they were not aware despite using Linux for all these years.
|
||||
|
||||
In any case, you [learn Linux][1] by experience, be it your own or someone else’s :)
|
||||
|
||||
### Cool Linux terminal tricks to save time and increase productivity
|
||||
|
||||
![][2]
|
||||
|
||||
You might already know a few of these Linux command tips or perhaps all of it. In either case, you are welcome to share your favorite tricks in the comment section.
|
||||
|
||||
Some of these tips also depend on how the shell is configured. Let’s begin!
|
||||
|
||||
#### 0\. Using tab for autocompletion
|
||||
|
||||
I’ll start with something really obvious and yet really important: tab completion.
|
||||
|
||||
When you are starting to type something in Linux terminal, you can hit the tab key and it will suggest all the possible options that start with string you have typed so far.
|
||||
|
||||
For example, if you are trying to copy a file named my_best_file_1.txt, you can just type ‘cp m’ and hit tab to see the possible options.
|
||||
|
||||
![Use tab for auto-completion][3]
|
||||
|
||||
You can use tab in completing commands as well.
|
||||
|
||||
[irp posts=”16244″ name=”Difference Between apt and apt-get Explained”]
|
||||
|
||||
#### 1\. Switch back to the last working directory
|
||||
|
||||
Suppose you end up in a long directory path and then you move to another directory in a totally different path. And then you realize that you have to go back to the previous directory you were in. In this case, all you need to do is to type this command:
|
||||
|
||||
```
|
||||
cd -
|
||||
```
|
||||
|
||||
This will put you back in the last working directory. You don’t need to type the long directory path or copy paste it anymore.
|
||||
|
||||
![Easily switch between directories][4]
|
||||
|
||||
#### 2\. Go back to home directory
|
||||
|
||||
This is way too obvious. You can use the command below to move to your home directory from anywhere in Linux command-line:
|
||||
|
||||
```
|
||||
cd ~
|
||||
```
|
||||
|
||||
However, you can also use just cd to go back to home directory:
|
||||
|
||||
```
|
||||
cd
|
||||
```
|
||||
|
||||
Most modern Linux distributions have the shell pre-configured for this command. Saves you at least two keystrokes here.
|
||||
|
||||
![Move to Home as quickly as possible][5]
|
||||
|
||||
#### 3\. List the contents of a directory
|
||||
|
||||
You must be guessing what’s the trick in the command for listing the contents of a directory. Everyone knows to use the ls -l for this purpose.
|
||||
|
||||
And that’s the thing. Most people use ls -l to list the contents of the directory, whereas the same can be done with the following command:
|
||||
|
||||
```
|
||||
ll
|
||||
```
|
||||
|
||||
Again, this depends on the Linux distributions and shell configuration, but chances are that you’ll be able to use it in most Linux distributions.
|
||||
|
||||
![Using ll instead of ls -l][6]
|
||||
|
||||
#### 4\. Running multiple commands in one single command
|
||||
|
||||
Suppose, you have to run several commands one after another. Do you wait for the first command to finish running and then execute the next one?
|
||||
|
||||
You can use the ‘;’ separator for this purpose. This way, you can run a number of commands in one line. No need to wait for the previous commands to finish their business.
|
||||
|
||||
```
|
||||
command_1; command_2; command_3
|
||||
```
|
||||
|
||||
#### 5\. Running multiple commands in one single command only if the previous command was successful
|
||||
|
||||
In the previous command, you saw how to run several commands in one single command to save time. But what if you have to make sure that commands don’t fail?
|
||||
|
||||
Imagine a situation where you want to build a code and then if the build was successful, run the make?
|
||||
|
||||
You can use && separator for this case. && makes sure that the next command will only run when the previous command was successful.
|
||||
|
||||
```
|
||||
command_1 && command_2
|
||||
```
|
||||
|
||||
A good example of this command is when you use sudo apt update && sudo apt upgrade to upgrade your system.
|
||||
|
||||
#### 6\. Easily search and use the commands that you had used in the past
|
||||
|
||||
Imagine a situation where you used a long command couple of minutes/hours ago and you have to use it again. Problem is that you cannot remember the exact command anymore.
|
||||
|
||||
Reverse search is your savior here. You can search for the command in the history using a search term.
|
||||
|
||||
Just use the keys ctrl+r to initiate reverse search and type some part of the command. It will look up into the history and will show you the commands that matches the search term.
|
||||
|
||||
```
|
||||
ctrl+r search_term
|
||||
```
|
||||
|
||||
By default, it will show just one result. To see more results matching your search term, you will have to use ctrl+r again and again. To quit reverse search, just use Ctrl+C.
|
||||
|
||||
![Reverse search in command history][7]
|
||||
|
||||
Note that in some Bash shells, you can also use Page Up and Down key with your search term and it will autocomplete the command.
|
||||
|
||||
#### 7\. Unfreeze your Linux terminal from accidental Ctrl+S
|
||||
|
||||
You probably are habitual of using Ctrl+S for saving. But if you use that in Linux terminal, you’ll have a frozen terminal.
|
||||
|
||||
Don’t worry, you don’t have to close the terminal, not anymore. Just use Ctrl+Q and you can use the terminal again.
|
||||
|
||||
```
|
||||
ctrl+Q
|
||||
```
|
||||
|
||||
#### 8\. Move to beginning or end of line
|
||||
|
||||
Suppose you are typing a long command and midway you realize that you had to change something at the beginning. You would use several left arrow keystrokes to move to the start of the line. And similarly for going to the end of the line.
|
||||
|
||||
You can use Home and End keys here of course but alternatively, you can use Ctrl+A to go to the beginning of the line and Ctrl+E to go to the end.
|
||||
|
||||
![Move to the beginning or end of the line][8]
|
||||
|
||||
I find it more convenient than using the home and end keys, especially on my laptop.
|
||||
|
||||
#### 9\. Reading a log file in real time
|
||||
|
||||
In situations where you need to analyze the logs while the application is running, you can use the tail command with -f option.
|
||||
|
||||
```
|
||||
tail -f path_to_Log
|
||||
```
|
||||
|
||||
You can also use the regular grep options to display only those lines that are meaningful to you:
|
||||
|
||||
```
|
||||
tail -f path_to_log | grep search_term
|
||||
```
|
||||
|
||||
You can also use the option F here. This will keep the tail running even if the log file is deleted. So if the log file is created again, tail will continue logging.
|
||||
|
||||
#### 10\. Reading compressed logs without extracting
|
||||
|
||||
Server logs are usually gzip compressed to save disk space. It creates an issue for the developer or sysadmin analyzing the logs. You might have to [scp][9] it to your local and then extract it to access the files because, at times, you don’t have write permission to extract the logs.
|
||||
|
||||
Thankfully, z commands save you in such situations. z commands provide alternatives of the regular commands that you use to deal with log files such as less, cat, grep etc.
|
||||
|
||||
So you get zless, zcat, zgrep etc and you don’t even have to explicitly extract the compressed files. Please refer to my earlier article about [using z commands to real compressed logs][10] in detail.
|
||||
|
||||
This was one of the secret finds that won me a coffee from my colleague.
|
||||
|
||||
#### 11\. Use less to read files
|
||||
|
||||
To see the contents of a file, cat is not the best option especially if it is a big file. cat command will display the entire file on your screen.
|
||||
|
||||
You can use Vi, Vim or other terminal based text editors but if you just want to read a file, less command is a far better choice.
|
||||
|
||||
```
|
||||
less path_to_file
|
||||
```
|
||||
|
||||
You can search for terms inside less, move by page, display with line numbers etc.
|
||||
|
||||
#### 12\. Reuse the last item from the previous command with !$
|
||||
|
||||
Using the argument of the previous command comes handy in many situations.
|
||||
|
||||
Say you have to create a directory and then go into the newly created directory. There you can use the !$ options.
|
||||
|
||||
![Use !$ to use the argument of last command][11]
|
||||
|
||||
A better way to do the same is to use alt+. . You can use . a number times to shuffle between the options of the last commands.
|
||||
|
||||
#### 13\. Reuse the previous command in present command with !!
|
||||
|
||||
You can call the entire previous command with !!. This comes particularly useful when you have to run a command and realize that it needs root privileges.
|
||||
|
||||
A quick sudo !! saves plenty of keystrokes here.
|
||||
|
||||
![Use !! to use last command as an argument][12]
|
||||
|
||||
#### 14\. Using alias to fix typos
|
||||
|
||||
You probably already know what is an alias command in Linux. What you can do is, to use them to fix typos.
|
||||
|
||||
For example, you might often mistype grep as gerp. If you put an alias in your bashrc in this fashion:
|
||||
|
||||
```
|
||||
alias gerp=grep
|
||||
```
|
||||
|
||||
This way you won’t have to retype the command again.
|
||||
|
||||
#### 15\. Copy Paste in Linux terminal
|
||||
|
||||
This one is slightly ambiguous because it depends on Linux distributions and terminal applications. But in general, you should be able to copy paste commands with these shortcuts:
|
||||
|
||||
* Select the text for copying and right click for paste (works in Putty and other Windows SSH clients)
|
||||
* Select the text for copying and middle click (scroll button on the mouse) for paste
|
||||
* Ctrl+Shift+C for copy and Ctrl+Shift+V for paste
|
||||
|
||||
|
||||
|
||||
#### 16\. Kill a running command/process
|
||||
|
||||
This one is perhaps way too obvious. If there is a command running in the foreground and you want to exit it, you can press Ctrl+C to stop that running command.
|
||||
|
||||
#### 17\. Using yes command for commands or scripts that need interactive response
|
||||
|
||||
If there are some commands or scripts that need user interaction and you know that you have to enter Y each time it requires an input, you can use Yes command.
|
||||
|
||||
Just use it in the below fashion:
|
||||
|
||||
```
|
||||
yes | command_or_script
|
||||
```
|
||||
|
||||
#### 18\. Empty a file without deleting it
|
||||
|
||||
If you just want to empty the contents of a text file without deleting the file itself, you can use a command similar to this:
|
||||
|
||||
```
|
||||
> filename
|
||||
```
|
||||
|
||||
#### 19\. Find if there are files containing a particular text
|
||||
|
||||
There are multiple ways to search and find in Linux command line. But in the case when you just want to see if there are files that contain a particular text, you can use this command:
|
||||
|
||||
```
|
||||
grep -Pri Search_Term path_to_directory
|
||||
```
|
||||
|
||||
I highly advise mastering find command though.
|
||||
|
||||
#### 20\. Using help with any command
|
||||
|
||||
I’ll conclude this article with one more obvious and yet very important ‘trick’, using help with a command or a command line tool.
|
||||
|
||||
Almost all command and command line tool come with a help page that shows how to use the command. Often using help will tell you the basic usage of the tool/command.
|
||||
|
||||
Just use it in this fashion:
|
||||
|
||||
```
|
||||
command_tool --help
|
||||
```
|
||||
|
||||
#### Your favorite Linux command line tricks?
|
||||
|
||||
I have deliberately not included commands like [fuck][13] because those are not standard commands that you’ll find everywhere. The tricks discussed here should be usable almost in all Linux distributions and shell without the need of installing a new tool.
|
||||
|
||||
I would also suggest [using alias command in Linux][14] to replace complicated commands with a simple. Saves a lot of time.
|
||||
|
||||
I know that there are more Linux command tricks to save time in the terminal. Why not share some of your experiences with Linux and do share your best trick with rest of the community here? The comment section below is at your disposal.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/linux-command-tricks/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/learn-linux-for-free/
|
||||
[2]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2017/08/Linux-Command-Tricks-Save-Time.jpeg?resize=800%2C450&ssl=1
|
||||
[3]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2017/08/Linux-Command-tricks-to-save-time-8.png?ssl=1
|
||||
[4]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2017/08/Linux-Command-tricks-to-save-time-1.png?ssl=1
|
||||
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2017/08/Linux-Command-tricks-to-save-time-2.png?ssl=1
|
||||
[6]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2017/08/Linux-Command-tricks-to-save-time-3.png?ssl=1
|
||||
[7]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2017/08/Linux-Command-tricks-to-save-time-4.png?ssl=1
|
||||
[8]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2017/08/Linux-Command-tricks-to-save-time-5.png?ssl=1
|
||||
[9]: http://www.hypexr.org/linux_scp_help.php
|
||||
[10]: https://itsfoss.com/read-compressed-log-files-linux/
|
||||
[11]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2017/08/Linux-Command-tricks-to-save-time-6.png?ssl=1
|
||||
[12]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2017/08/Linux-Command-tricks-to-save-time-7.png?ssl=1
|
||||
[13]: https://github.com/nvbn/thefuck
|
||||
[14]: https://linuxhandbook.com/linux-alias-command/
|
||||
@@ -1,129 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (qfzy1233)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Bodhi Linux 5.1 Review: Slightly Different Lightweight Linux)
|
||||
[#]: via: (https://itsfoss.com/bodhi-linux-review/)
|
||||
[#]: author: (John Paul https://itsfoss.com/author/john/)
|
||||
|
||||
Bodhi Linux 5.1 Review: Slightly Different Lightweight Linux
|
||||
======
|
||||
|
||||
Bodhi Linux is a [lightweight Linux distribution][1] based on Ubuntu. Unlike most other distributions, Bodhi uses its own Moksha desktop and focuses on providing you a minimal setup to run on older computers.
|
||||
|
||||
### What is Bodhi Linux?
|
||||
|
||||
![Bodhi Start Page][2]
|
||||
|
||||
[Bodhi Linux][3] was first introduced in 2011. It is designed with “[minimalism, resource efficiency, and user choice][4]” in mind. The devs strove to provide a “[system that is functional but not bloated][5]“. As such, it uses the lightweight Moksha Desktop and has only the basic applications preinstalled. The idea is to give the user a stable platform to build the system that they want. It is based on the latest Ubuntu LTS.
|
||||
|
||||
### Moksha Desktop
|
||||
|
||||
![Bodhi Desktop][6]
|
||||
|
||||
Originally Bodhi shipped with the [Enlightenment desktop environment][7]. Bodhi Linux has long been known as the “Enlightened” Linux distro. In fact, the word ‘bodhi’ is based on the Sanskrit word for “enlightenment”.
|
||||
|
||||
However, that changed when Enlightenment 18 was released. The release was in such bad shape that it was not included in Bodhi. Enlightenment 19 was released and fixed some of the problems, but still had issues.
|
||||
|
||||
After trying to work with the Enlightenment dev team and getting nowhere, the Bodhi devs [forked][8] Enlightenment 17 in 2015. The new desktop environment would be named [Moksha][9], which is based on the Sanskrit word for “emancipation, liberation, or release”. You can find the code for it on [GitHub][10].
|
||||
|
||||
### What is new in 5.1.0?
|
||||
|
||||
[Subscribe to our YouTube channel for more Linux videos][11]
|
||||
|
||||
[Bodhi 5.1.0][12] is the first release in two years and the second release to be based on Ubuntu 18.04. Besides updating packages, it also has new default icons and theme. This release makes several changes to the default applications. Leafpad comes preinstalled instead of epad and [GNOME Web][13] (also known as Epiphany) replaces [Midori][14]). The eepDater system updater was removed.
|
||||
|
||||
There are currently [four different versions][15] of Bodhi 5.1.0 available to [download][16]: Standard, Hwe, Legacy, and AppPack.
|
||||
|
||||
* Standard will work for systems made in the last decade. It does not push kernel updates.
|
||||
* Hwe (Hardware Enablement) edition is new to the Bodhi family and is designed to include support for newer hardware and will received kernel updates. The 5.1 release features the 5.3.0-42 kernel.
|
||||
* Legacy is the only edition that is 32-bit. It uses the “older 4.9.0-6-686 Linux kernel that is optimized for old (15+ years old) hardware. This kernel also does not include the PAE extension which is not supported on many older systems.”
|
||||
* The AppPack edition is for those who want a fully-loaded system out of the box and comes with many applications preinstalled.
|
||||
|
||||
|
||||
|
||||
### System Requirements for Bodhi Linux
|
||||
|
||||
Minimum system requirement
|
||||
|
||||
* 500 MHz processor
|
||||
* 256 MB of RAM
|
||||
* 5 GB of drive space
|
||||
|
||||
|
||||
|
||||
Recommended system requirement
|
||||
|
||||
* 1.0 GHz processor
|
||||
* 512 MB of RAM
|
||||
* 10 GB of drive space
|
||||
|
||||
|
||||
|
||||
### Experiencing Bodhi Linux
|
||||
|
||||
![Old Bodhi Linux][17]
|
||||
|
||||
Since it is based on Ubuntu, installing Bodhi was very simple. After I signed into Bodhi, I was surprised by the new theme and icon set. The last time I installed Bodhi (including 5.0 a couple of months ago) I thought that it needed a new look. There was nothing really wrong with the previous theme, but it looked like something from the early 2000. The new theme gives it a more modern look.
|
||||
|
||||
![Bodhi Linux 5.1][18]
|
||||
|
||||
I was also glad to see that Midori had been replaced by GNOME Web. I’m not a fan of [Midori browser][19]. It always seemed too minimal for me. (However, that might change in the future with [Midori Next][20].) Web felt more like the web browser I need. Most importantly it comes with Firefox Sync, so I can keep all of my bookmarks and passwords synced.
|
||||
|
||||
Unlike many Linux distros, Bodhi doesn’t really come with a stand-alone software center. Instead, if you click the AppCenter icon it opens the browser and navigates to the [AppCenter p][21][a][21][ge][21] of the Bodhi website. Here apps are sorted by category. Most of them are [lightweight applications][22].
|
||||
|
||||
![Bodhi Linux Appcenter][23]
|
||||
|
||||
If you click on one of the pages and click “Install”, Bodhi will install it (after to type in your passwords). This is achieved using a neat little program named [apturl][24] that “is a very simple way to install a software package from a web browser”. It’s pretty slick and I wish more Ubuntu-based distros would use it.
|
||||
|
||||
Overall, I like the Moksha desktop. It adheres to the desktop metaphor we have seen for decades (and which I am most comfortable with). It stays out of your way but is very easy to change and modify. The only thing I miss is that the application menu doesn’t open when I hit the super key. But I guess you can’t have everything in life.
|
||||
|
||||
### Final Thoughts
|
||||
|
||||
I was pleasantly surprised by this recent release of Bodhi Linux. In the past, I’ve played with it from time to time. I always liked it, but this last release has been the best so far. In a way, they have broken free of the idea that Bodhi is only for older system by adding support for newer kernels.
|
||||
|
||||
If you are looking for a change of scenery while staying close to the world of Ubuntu give [Bodhi Linux][3] a try.
|
||||
|
||||
Have you ever used Bodhi Linux? What is your favorite Ubuntu-based distro? Please let us know in the comments below.
|
||||
|
||||
If you found this article interesting, please take a minute to share it on social media, Hacker News or [Reddit][25].
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/bodhi-linux-review/
|
||||
|
||||
作者:[John Paul][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/john/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/lightweight-linux-beginners/
|
||||
[2]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/03/bodhi-start-page.png?resize=800%2C500&ssl=1
|
||||
[3]: https://www.bodhilinux.com/
|
||||
[4]: https://www.bodhilinux.com/w/wiki/
|
||||
[5]: https://www.bodhilinux.com/w/what-is-bodhi-linux/
|
||||
[6]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/03/bodhi-desktop.jpg?resize=800%2C500&ssl=1
|
||||
[7]: https://www.enlightenment.org/start
|
||||
[8]: https://www.bodhilinux.com/2015/04/28/introducing-the-moksha-desktop/
|
||||
[9]: https://www.bodhilinux.com/moksha-desktop/
|
||||
[10]: https://github.com/JeffHoogland/moksha
|
||||
[11]: https://www.youtube.com/c/itsfoss?sub_confirmation=1
|
||||
[12]: https://www.bodhilinux.com/2020/03/25/bodhi-linux-5-1-0-released/
|
||||
[13]: https://wiki.gnome.org/Apps/Web/
|
||||
[14]: https://en.wikipedia.org/wiki/Midori_(web_browser
|
||||
[15]: https://www.bodhilinux.com/w/selecting-the-correct-iso-image/
|
||||
[16]: https://www.bodhilinux.com/download/
|
||||
[17]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/03/bodhi.png?resize=800%2C400&ssl=1
|
||||
[18]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/04/bodhi-Linux-5-1-screenshot.jpg?ssl=1
|
||||
[19]: https://itsfoss.com/midori-browser/
|
||||
[20]: https://www.midori-browser.org/2020/01/15/midori-next-come-on-yarovi-we-can/
|
||||
[21]: https://www.bodhilinux.com/a/
|
||||
[22]: https://itsfoss.com/lightweight-alternative-applications-ubuntu/
|
||||
[23]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/03/Bodhi-Linux-AppCenter.png?resize=800%2C500&ssl=1
|
||||
[24]: https://wiki.ubuntu.com/AptUrl
|
||||
[25]: https://reddit.com/r/linuxusersgroup
|
||||
215
sources/tech/20200425 Inlining optimisations in Go.md
Normal file
215
sources/tech/20200425 Inlining optimisations in Go.md
Normal file
@@ -0,0 +1,215 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Inlining optimisations in Go)
|
||||
[#]: via: (https://dave.cheney.net/2020/04/25/inlining-optimisations-in-go)
|
||||
[#]: author: (Dave Cheney https://dave.cheney.net/author/davecheney)
|
||||
|
||||
Inlining optimisations in Go
|
||||
======
|
||||
|
||||
This is a post about how the Go compiler implements inlining and how this optimisation affects your Go code.
|
||||
|
||||
_n.b._ This article focuses on _gc_, the de facto Go compiler from [golang.org][1]. The concepts discussed apply broadly to other Go compilers like gccgo and llgo but may differ in implementation and efficacy.
|
||||
|
||||
### What is inlining?
|
||||
|
||||
Inlining is the act of combining smaller functions into their respective callers. In the early days of computing this optimisation was typically performed by hand. Nowadays inlining is one of a class of fundamental optimisations performed automatically during the compilation process.
|
||||
|
||||
### Why is inlining important?
|
||||
|
||||
Inlining is important for two reasons. The first is it removes the overhead of the function call itself. The second is it permits the compiler to more effectively apply other optimisation strategies.
|
||||
|
||||
#### Function call overhead
|
||||
|
||||
Calling a function[1][2] in any language carries a cost. There are the overheads of marshalling parameters into registers or onto the stack (depending on the ABI) and reversing the process on return. Invoking a function call involves jumping the program counter from one point in the instruction stream to another which can cause a pipeline stall. Once inside the function there is usually some preamble required to prepare a new stack frame for the function to execute and a similar epilogue needed to retire the frame before returning to the caller.
|
||||
|
||||
In Go a function call carries additional costs to support dynamic stack growth. On entry the amount of stack space available to the goroutine is compared to the amount required for the function. If insufficient stack space is available, the preamble jumps into the runtime logic that grows the stack by copying it to a new, larger, location. Once this is done the runtime jumps back to the start of the original function, the stack check is performed again, which now passes, and the call continues. In this way goroutines can start with a small stack allocation which grows only when needed.[2][3]
|
||||
|
||||
This check is cheap–only a few instructions–and because goroutine stacks grows geometrically the check rarely fails. Thus, the branch prediction unit inside a modern processor can hide the cost of the stack check by assuming it will always be successful. In the case where the processor mis-predicts the stack check and has to discard the work done while it was executing speculatively, the cost of the pipeline stall is relatively small compared to the cost of the work needed for the runtime to grow a goroutines stack.
|
||||
|
||||
While the overhead of the generic and Go specific components of each function call are well optimised by modern processors using speculative execution techniques, those overheads cannot be entirely eliminated, thus each function call carries with it a performance cost over and above the time it takes to perform useful work. As a function call’s overhead is fixed, smaller functions pay a larger cost relative to larger ones because they tend to do less useful work per invocation.
|
||||
|
||||
The solution to eliminating these overheads must therefore be to eliminate the function call itself, which the Go compiler does, under certain conditions, by replacing the call to a function with the contents of the function. This is known as _inlining_ because it brings the body of the function in line with its caller.
|
||||
|
||||
#### Improved optimisation opportunities
|
||||
|
||||
Dr. Cliff Click describes inlining as _the_ optimisation performed by modern compilers as it forms the basis for optimisations like constant proportion and dead code elimination. In effect, inlining allows the compiler to _see_ _furthe_r, allowing it to observe, in the context that a particular function is being called, logic that can be further simplified or eliminated entirely. As inlining can be applied recursively optimisation decisions can be made not only in the context of each individual function, but also applied to the chain of functions in a call path.
|
||||
|
||||
### Inlining in action
|
||||
|
||||
The effects of inlining can be demonstrated with this small example
|
||||
|
||||
```
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
//go:noinline
|
||||
func max(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
var Result int
|
||||
|
||||
func BenchmarkMax(b *testing.B) {
|
||||
var r int
|
||||
for i := 0; i < b.N; i++ {
|
||||
r = max(-1, i)
|
||||
}
|
||||
Result = r
|
||||
}
|
||||
```
|
||||
|
||||
Running this benchmark gives the following result:[3][4]
|
||||
|
||||
```
|
||||
% go test -bench=.
|
||||
BenchmarkMax-4 530687617 2.24 ns/op
|
||||
```
|
||||
|
||||
The cost of `max(-1, i)` is around 2.24 nanoseconds on my 2015 MacBook Air. Now let’s remove the `//go:noinline` pragma and see the result:
|
||||
|
||||
```
|
||||
% go test -bench=.
|
||||
BenchmarkMax-4 1000000000 0.514 ns/op
|
||||
```
|
||||
|
||||
From 2.24 ns to 0.51 ns, or according to `benchstat`, a 78% improvement.
|
||||
|
||||
```
|
||||
% benchstat {old,new}.txt
|
||||
name old time/op new time/op delta
|
||||
Max-4 2.21ns ± 1% 0.49ns ± 6% -77.96% (p=0.000 n=18+19)
|
||||
```
|
||||
|
||||
Where did these improvements come from?
|
||||
|
||||
First, the removal of the function call and associated preamble[4][5] was a major contributor. Pulling the contents of `max` into its caller reduced the number of instructions executed by the processor and eliminated several branches.
|
||||
|
||||
Now the contents of `max` are visible to the compiler as it optimises `BenchmarkMax` it can make some additional improvements. Consider that once `max` is inlined, this is what the body of `BenchmarkMax` looks like to the compiler:
|
||||
|
||||
```
|
||||
func BenchmarkMax(b *testing.B) {
|
||||
var r int
|
||||
for i := 0; i < b.N; i++ {
|
||||
if -1 > i {
|
||||
r = -1
|
||||
} else {
|
||||
r = i
|
||||
}
|
||||
}
|
||||
Result = r
|
||||
}
|
||||
```
|
||||
|
||||
Running the benchmark again we see our manually inlined version performs as well as the version inlined by the compiler
|
||||
|
||||
```
|
||||
% benchstat {old,new}.txt
|
||||
name old time/op new time/op delta
|
||||
Max-4 2.21ns ± 1% 0.48ns ± 3% -78.14% (p=0.000 n=18+18)
|
||||
```
|
||||
|
||||
Now the compiler has access to the result of inlining `max` into `BenchmarkMax` it can apply optimisation passes which were not possible before. For example, the compiler has noted that `i` is initialised to `0` and only incremented so any comparison with `i` can assume `i` will never be negative. Thus, the condition `-1 > i` will never be true.[5][6]
|
||||
|
||||
Having proved that `-1 > i` will never be true, the compiler can simplify the code to
|
||||
|
||||
```
|
||||
func BenchmarkMax(b *testing.B) {
|
||||
var r int
|
||||
for i := 0; i < b.N; i++ {
|
||||
if false {
|
||||
r = -1
|
||||
} else {
|
||||
r = i
|
||||
}
|
||||
}
|
||||
Result = r
|
||||
}
|
||||
```
|
||||
|
||||
and because the branch is now a constant, the compiler can eliminate the unreachable path leaving it with
|
||||
|
||||
```
|
||||
func BenchmarkMax(b *testing.B) {
|
||||
var r int
|
||||
for i := 0; i < b.N; i++ {
|
||||
r = i
|
||||
}
|
||||
Result = r
|
||||
}
|
||||
```
|
||||
|
||||
Thus, through inlining and the optimisations it unlocks, the compiler has reduced the expression `r = max(-1, i)` to simply `r = i`.
|
||||
|
||||
### The limits of inlining
|
||||
|
||||
In this article I’ve discussed, so called, _leaf_ inlining; the act of inlining a function at the bottom of a call stack into its direct caller. Inlining is a recursive process, once a function has been inlined into its caller, the compiler may inline the resulting code into _its_ caller, as so on. For example, this code
|
||||
|
||||
```
|
||||
func BenchmarkMaxMaxMax(b *testing.B) {
|
||||
var r int
|
||||
for i := 0; i < b.N; i++ {
|
||||
r = max(max(-1, i), max(0, i))
|
||||
}
|
||||
Result = r
|
||||
}
|
||||
```
|
||||
|
||||
runs as fast as the previous example as the compiler is able to repeatedly apply the optimisations outlined above to reduce the code to the same `r = i` expression.
|
||||
|
||||
In the next article I’ll discuss an alternative inlining strategy when the Go compiler wishes to inline a function in the middle of a call stack. Finally I’ll discuss the limits that the compiler is prepared to go to to inline code, and which Go constructs are currently beyond its capability.
|
||||
|
||||
1. In Go, a method is just a function with a predefined formal parameter, the receiver. The relative costs of calling a free function vs a invoking a method, assuming that method is not called through an interface, are the same.[][7]
|
||||
2. Up until Go 1.14 the stack check preamble was also used by the garbage collector to stop the world by setting all active goroutine’s stacks to zero, forcing them to trap into the runtime the next time they made a function call. This system was [recently replaced][8] with a mechanism which allowed the runtime to pause an goroutine without waiting for it to make a function call.[][9]
|
||||
3. I’m using the `//go:noinline` pragma to prevent the compiler from inlining `max`. This is because I want to isolate the effects of inlining on `max` rather than disabling optimisations globally with `-gcflags='-l -N'`. I go into detail about the `//go:` comments in [this presentation][10].[][11]
|
||||
4. You can check this for yourself by comparing the output of `go test -bench=. -gcflags=-S` with and without the `//go:noinline` annotation.[][12]
|
||||
5. You can check this yourself with the `-gcflags=-d=ssa/prove/debug=on` flag.[][13]
|
||||
|
||||
|
||||
|
||||
#### Related posts:
|
||||
|
||||
1. [Five things that make Go fast][14]
|
||||
2. [Why is a Goroutine’s stack infinite ?][15]
|
||||
3. [How to write benchmarks in Go][16]
|
||||
4. [Go’s hidden #pragmas][17]
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://dave.cheney.net/2020/04/25/inlining-optimisations-in-go
|
||||
|
||||
作者:[Dave Cheney][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://dave.cheney.net/author/davecheney
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://github.com/golang/go
|
||||
[2]: tmp.gBQ2tEtMHc#easy-footnote-bottom-1-4053 (In Go, a method is just a function with a predefined formal parameter, the receiver. The relative costs of calling a free function vs a invoking a method, assuming that method is not called through an interface, are the same.)
|
||||
[3]: tmp.gBQ2tEtMHc#easy-footnote-bottom-2-4053 (Up until Go 1.14 the stack check preamble was also used by the garbage collector to stop the world by setting all active goroutine’s stacks to zero, forcing them to trap into the runtime the next time they made a function call. This system was <a href="https://github.com/golang/proposal/blob/master/design/24543-non-cooperative-preemption.md">recently replaced</a> with a mechanism which allowed the runtime to pause an goroutine without waiting for it to make a function call.)
|
||||
[4]: tmp.gBQ2tEtMHc#easy-footnote-bottom-3-4053 (I’m using the <code>//go:noinline</code> pragma to prevent the compiler from inlining <code>max</code>. This is because I want to isolate the effects of inlining on <code>max</code> rather than disabling optimisations globally with <code>-gcflags='-l -N'</code>. I go into detail about the <code>//go:</code> comments in <a href="https://dave.cheney.net/2018/01/08/gos-hidden-pragmas">this presentation</a>.)
|
||||
[5]: tmp.gBQ2tEtMHc#easy-footnote-bottom-4-4053 (You can check this for yourself by comparing the output of <code>go test -bench=. -gcflags=-S</code> with and without the <code>//go:noinline</code> annotation.)
|
||||
[6]: tmp.gBQ2tEtMHc#easy-footnote-bottom-5-4053 (You can check this yourself with the <code>-gcflags=-d=ssa/prove/debug=on</code> flag.)
|
||||
[7]: tmp.gBQ2tEtMHc#easy-footnote-1-4053
|
||||
[8]: https://github.com/golang/proposal/blob/master/design/24543-non-cooperative-preemption.md
|
||||
[9]: tmp.gBQ2tEtMHc#easy-footnote-2-4053
|
||||
[10]: https://dave.cheney.net/2018/01/08/gos-hidden-pragmas
|
||||
[11]: tmp.gBQ2tEtMHc#easy-footnote-3-4053
|
||||
[12]: tmp.gBQ2tEtMHc#easy-footnote-4-4053
|
||||
[13]: tmp.gBQ2tEtMHc#easy-footnote-5-4053
|
||||
[14]: https://dave.cheney.net/2014/06/07/five-things-that-make-go-fast (Five things that make Go fast)
|
||||
[15]: https://dave.cheney.net/2013/06/02/why-is-a-goroutines-stack-infinite (Why is a Goroutine’s stack infinite ?)
|
||||
[16]: https://dave.cheney.net/2013/06/30/how-to-write-benchmarks-in-go (How to write benchmarks in Go)
|
||||
[17]: https://dave.cheney.net/2018/01/08/gos-hidden-pragmas (Go’s hidden #pragmas)
|
||||
@@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (qfzy1233)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Bodhi Linux 5.1 Review: Slightly Different Lightweight Linux)
|
||||
[#]: via: (https://itsfoss.com/bodhi-linux-review/)
|
||||
[#]: author: (John Paul https://itsfoss.com/author/john/)
|
||||
|
||||
Bodhi Linux 5.1 一览: 略有不同的轻量化 Linux
|
||||
======
|
||||
|
||||
Bodhi Linux 是一个基于 Ubuntu 的[轻量级Linux发行版][1]。与其他大多数发行版不同,Bodhi 使用自己的 Moksha 桌面,并专注于为你提供在旧计算机上运行的最简设置。
|
||||
|
||||
### 什么是 Bodhi Linux?
|
||||
|
||||
![Bodhi Start Page][2]
|
||||
|
||||
[Bodhi Linux][3] 最早于2011年推出。它以“[简约、高效和用户自定义][4]”为设计理念。开发人员旨在提供一个“[功能正常但不臃肿的系统][5]”。因此,它使用轻量级的Moksha 桌面,只预装了基本的应用程序。这一做法是为了给用户一个稳定的平台来构建他们想要的系统。它基于最新版的 Ubuntu 长期支持版本。
|
||||
|
||||
### Moksha 桌面
|
||||
|
||||
![Bodhi Desktop][6]
|
||||
|
||||
起初菩提是随着[ Enlightenment 桌面环境][7]一起发布的。Bodhi Linux 一直被认为是“开明的”Linux发行版。事实上,“Bodhi”这个词是基于梵文的“开悟”。
|
||||
|
||||
然而,当 Enlightenment 18版本发布以后,这一切都改变了。该版本是如此的糟糕,它并没有集成 Bodhi 。Enlightenment 19 被发布并修复了一些问题,但仍然存在一些问题。
|
||||
|
||||
在尝试与 Enlightenment 开发团队合作却毫无进展之后,Bodhi 开发者在2015年复刻了[8]Enlightenment 17。新的桌面环境被命名为[Moksha][9],它是基于梵文单词“解脱、解放或释放”。你可以在[GitHub][10]上找到它的代码。
|
||||
|
||||
### 5.1.0有什么新特性?
|
||||
|
||||
[订阅我们的YouTube频道来观看更多的Linux视频][11]
|
||||
|
||||
[Bodhi 5.1.0][12] 是两年内的第一个版本,也是基于 Ubuntu 18.04 的第二个版本。除了更新包,它还有新的默认图标和主题。该版本对默认应用程序做了几处更改。预装版 Leafpad 取代了 epad 并且 [GNOME Web][13] (也被称为Epiphany)代替了[Midori][14])。删除了eepDater系统更新器。
|
||||
|
||||
目前有[四个不同的版本][15]的菩提5.1.0提供[下载][16]: 标准版(Standard),硬件支持版(Hwe), 兼容版(Legacy), 和软件包版(AppPack).
|
||||
|
||||
* 标准适用于过去十年内电脑配置。它不推送内核更新。
|
||||
* 硬件支持版Hwe (Hardware Enablement)是 Bodhi 新的家族设计包括支持更新的硬件和将收到内核更新。5.1版本的使用的是5.3.0-42内核。
|
||||
* 兼容版是唯一的32位版本。它使用“较旧的4.9.0-6-686 Linux内核,该内核针对旧的(15年以上)硬件进行了优化”。这个内核也不包括PAE扩展,这是许多老系统不支持的。”
|
||||
* 软件包版是为那些想要一个开箱即用并预装了许多应用程序的全负载系统的人准备的。
|
||||
|
||||
|
||||
|
||||
### Bodhi Linux 的系统要求
|
||||
|
||||
最低系统要求
|
||||
|
||||
* 500 MHz 处理器
|
||||
* 256 MB 内存
|
||||
* 5 GB 的硬盘存储空间
|
||||
|
||||
|
||||
|
||||
推荐系统要求
|
||||
|
||||
* 1.0 GHz 处理器
|
||||
* 512 MB 内存
|
||||
* 10 GB 的硬盘存储空间
|
||||
|
||||
|
||||
|
||||
### Bodhi Linux 的体验
|
||||
|
||||
![Old Bodhi Linux][17]
|
||||
|
||||
由于它是基于 Ubuntu 的,安装 Bodhi 非常简单。当我登录到 Bodhi 后,我对新的主题和图标设置感到惊讶。上次我安装 Bodhi (包括几个月前的5.0)时,我认为它需要一个新的外观。之前的主题并没有什么问题,但看起来像是2000年初的东西。新的主题使它看起来更具现代感。
|
||||
|
||||
![Bodhi Linux 5.1][18]
|
||||
|
||||
我也很高兴看到 Midori 浏览器被 GNOME Web 所取代。我不是[Midori 浏览器][19]的粉丝。对我来说,它总是显得功能太少了。(不过,随着[Midori Next][20]的推出,这种情况可能会改变。)Web更像是我需要的Web浏览器。最重要的是它带有Firefox同步功能,这样我就可以同步我所有的书签和密码了。
|
||||
|
||||
与许多 Linux 发行版不同,Bodhi 并没有一个独立的软件中心。相反,如果你点击 AppCenter 图标,它会打开浏览器,并导航到 Bodhi 网站的软件中心页面[AppCenter page][21]。这里的应用程序是按类别排序的。它们中的大多数是[轻量级应用程序][22]。
|
||||
|
||||
![Bodhi Linux Appcenter][23]
|
||||
|
||||
如果你点击其中一个页面并点击“安装”,Bodhi 会开始它的安装(在你输入密码之后)。这是通过一个名为[apturl][24]的小程序实现的,它是“源自web浏览器安装软件包的一种非常简单的方法”。它非常灵巧,我希望更多基于ubuntu的发行版使用它。
|
||||
|
||||
总的来说,我喜欢 Moksha 桌面。它坚持我们几十年来看到的桌面风格(这是我最喜欢的)。它不干涉你,却很容易改变和定制。我唯一怀念的是,当我点击超级键时,应用程序菜单不打开。但我猜你不可能拥有生活中的一切。
|
||||
|
||||
### 结语
|
||||
|
||||
我对最近发布的 Bodhi Linux 感到十分惊喜。过去,我经常折腾它。并且我一直很喜欢它,但最近的这个版本是迄今为止最好的。在某种程度上,他们通过增加对新内核的支持,打破了Bodhi只适用于旧系统的想法。
|
||||
|
||||
如果你想在拥有 Ubuntu 体验的同时改善一下视觉体验,那就试试[Bodhi Linux][3]吧。
|
||||
|
||||
你用过 Bodhi Linux 吗?你最喜欢的基于ubuntu的发行版是什么?请在下面的评论中告诉我们。
|
||||
|
||||
如果你觉得这篇文章很有趣,请花点时间在社交媒体、Hacker News或其他网站上分享 [Reddit][25].
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/bodhi-linux-review/
|
||||
|
||||
作者:[John Paul][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/john/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/lightweight-linux-beginners/
|
||||
[2]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/03/bodhi-start-page.png?resize=800%2C500&ssl=1
|
||||
[3]: https://www.bodhilinux.com/
|
||||
[4]: https://www.bodhilinux.com/w/wiki/
|
||||
[5]: https://www.bodhilinux.com/w/what-is-bodhi-linux/
|
||||
[6]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/03/bodhi-desktop.jpg?resize=800%2C500&ssl=1
|
||||
[7]: https://www.enlightenment.org/start
|
||||
[8]: https://www.bodhilinux.com/2015/04/28/introducing-the-moksha-desktop/
|
||||
[9]: https://www.bodhilinux.com/moksha-desktop/
|
||||
[10]: https://github.com/JeffHoogland/moksha
|
||||
[11]: https://www.youtube.com/c/itsfoss?sub_confirmation=1
|
||||
[12]: https://www.bodhilinux.com/2020/03/25/bodhi-linux-5-1-0-released/
|
||||
[13]: https://wiki.gnome.org/Apps/Web/
|
||||
[14]: https://en.wikipedia.org/wiki/Midori_(web_browser
|
||||
[15]: https://www.bodhilinux.com/w/selecting-the-correct-iso-image/
|
||||
[16]: https://www.bodhilinux.com/download/
|
||||
[17]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/03/bodhi.png?resize=800%2C400&ssl=1
|
||||
[18]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/04/bodhi-Linux-5-1-screenshot.jpg?ssl=1
|
||||
[19]: https://itsfoss.com/midori-browser/
|
||||
[20]: https://www.midori-browser.org/2020/01/15/midori-next-come-on-yarovi-we-can/
|
||||
[21]: https://www.bodhilinux.com/a/
|
||||
[22]: https://itsfoss.com/lightweight-alternative-applications-ubuntu/
|
||||
[23]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/03/Bodhi-Linux-AppCenter.png?resize=800%2C500&ssl=1
|
||||
[24]: https://wiki.ubuntu.com/AptUrl
|
||||
[25]: https://reddit.com/r/linuxusersgroup
|
||||
@@ -1,343 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (Zioyi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (12 Linux Commands to Have Some Fun in the Terminal)
|
||||
[#]: via: (https://itsfoss.com/funny-linux-commands/)
|
||||
[#]: author: (Community https://itsfoss.com/author/itsfoss/)
|
||||
|
||||
12个有趣的Linux终端命令
|
||||
======
|
||||
|
||||
_**你觉得Linux终端里只有无趣的工作吗?那你一定不知道下面这些有趣的Linux命令吧。**_
|
||||
|
||||
Linux终端是用来完成复杂的工作的,我们有很多有用的[linux命令奇技淫巧][1]来帮助你。
|
||||
|
||||
但是,你知道你还可以用终端来做很多有趣的是吗?如果你不知道,没关系,大多数Linux用户也都只把终端视为一个用来管理系统和执行任务的交互接口。
|
||||
|
||||
然而,如果你知道这里有些你可以在终端玩的[基于终端的游戏][2]和[ASCII码游戏][3],你一定会大吃一惊。
|
||||
|
||||
在这篇文章中,我将会探索一些有趣的、可笑的、荒谬的命令来让你可以在终端中找点乐子!
|
||||
|
||||
### 用这些命令在Linux终端中找点乐子
|
||||
|
||||
![][4]
|
||||
|
||||
你可能会觉得这些命令荒谬或没用,但是有一些还是可以被好好利用的。
|
||||
|
||||
我已经添加了Ubuntu/Debian的安装组件,如果你使用基于Ubuntu的发行版,请确保[启用通用仓库][5]因为大多数命令不在主仓库中。
|
||||
|
||||
如果你使用Arch、Fedora、SUSE、Solus或者其他非Ubuntu的发行版,请使用你的发行版包管理工具去安装这些有趣的Linux命令。
|
||||
|
||||
#### 1\. 在终端开一辆火车
|
||||
|
||||
让我们坐上火车,来一场说走就走的旅行的,没错,就是字面意思!
|
||||
|
||||
sl命令可以让你在终端运行一辆火车。
|
||||
|
||||
![][6]
|
||||
|
||||
安装方法:
|
||||
|
||||
```
|
||||
sudo apt install sl
|
||||
```
|
||||
|
||||
完成后,你只要在终端输入下面的命令就可以开始
|
||||
|
||||
```
|
||||
sl
|
||||
```
|
||||
|
||||
很精彩,对吧?但等等,我们还没结束!你还可以让你的火车飞起来,只要加上参数-F,Magic:
|
||||
|
||||
```
|
||||
sl -F
|
||||
```
|
||||
|
||||
**这样会让火车长出翅膀飞出终端窗口!**
|
||||
|
||||
#### 2\. 给你的Linux终端加上矩阵效果
|
||||
|
||||
还记得科幻电影[黑客帝国][7]吗?掉落在终端的绿字变成一个矩阵符号。
|
||||
|
||||
你也可以在你的Linux电脑里有这样的矩阵数字雨!你只需要安装**cmatric**然后在终端输入它就行。
|
||||
|
||||
![][8]
|
||||
|
||||
在Debian/Ubuntu Linux上安装cmatrix:
|
||||
|
||||
```
|
||||
sudo apt install cmatrix
|
||||
```
|
||||
|
||||
现在,你要做的就是输入下面的命令,在终端就会有矩阵屏幕了:
|
||||
|
||||
```
|
||||
cmatrix
|
||||
```
|
||||
|
||||
按住Ctrl+C来停止它,黑客先生。
|
||||
|
||||
**推荐阅读:**
|
||||
|
||||
![][9]
|
||||
|
||||
#### [通过Telnet在Linux终端看星际大战][10]
|
||||
|
||||
在Linux终端看星际大战。
|
||||
|
||||
#### 3\. 让这里着火
|
||||
|
||||
拿好灭火器因为接下来你要在你的终端里点火了!
|
||||
|
||||
![][11]
|
||||
|
||||
想安装它,你要输入:
|
||||
|
||||
```
|
||||
sudo apt install libaa-bin
|
||||
```
|
||||
|
||||
完成后,你输入下面的命令,你的终端就会燃起一团火焰:
|
||||
|
||||
```
|
||||
aafire
|
||||
```
|
||||
|
||||
按住Ctril+C来停止它。
|
||||
|
||||
#### 4\. 幸运饼干命令
|
||||
|
||||
想知道你的运气怎样但身边没有幸运饼干?
|
||||
|
||||
别担心,你只需在终端打出“fortune”然后按下回车。终端将会显示出一个你的幸运语就像你从幸运饼干里得到的一样。
|
||||
|
||||
![][12]
|
||||
|
||||
安装它:
|
||||
|
||||
```
|
||||
sudo apt install fortune
|
||||
```
|
||||
|
||||
完成后,只要在命令行打出下面的内容,你就会知道你的运气怎样:
|
||||
|
||||
```
|
||||
fortune
|
||||
```
|
||||
|
||||
这是一个你可以实际去使用的命令。你可以用它作为每日消息,这样在多用户环境下,每个用户登录后都会得到一个“幸运饼干”。
|
||||
|
||||
你也可以把它添加到bashrc文件,这样当你登进终端你就会看到了。
|
||||
|
||||
#### 5\. 宠物爱好者?这是给你准备的
|
||||
|
||||
Oneko是一个有趣的命令,可以把你的光标变成一只老鼠,然后创造一只猫,一旦你移动光标,就会来追你。这不仅局限于终端。当猫追逐光标时,你可以继续工作。
|
||||
|
||||
如果你家里有孩子这一定很有趣。
|
||||
|
||||
![][13]
|
||||
|
||||
用下面的命令安装Oneko
|
||||
|
||||
```
|
||||
sudo apt install oneko
|
||||
```
|
||||
|
||||
用下面的命令运行它:
|
||||
|
||||
```
|
||||
oneko
|
||||
```
|
||||
|
||||
如果你不喜欢猫,喜欢狗,输入:
|
||||
|
||||
```
|
||||
oneko -dog
|
||||
```
|
||||
|
||||
这里有很多种小宠物,你可以用oneko -help获取信息。用Ctrl+C终止它。
|
||||
|
||||
#### 6\. 有个小兄弟在看着你
|
||||
|
||||
Xeyes是一个很小的GUI程序,它可以绘制出一双眼睛一直盯着你!它会不断跟随您的鼠标光标,运行命令自己看看!
|
||||
|
||||
![][14]
|
||||
|
||||
你可以用下面命令安装:
|
||||
|
||||
```
|
||||
sudo apt install xeyes
|
||||
```
|
||||
|
||||
然后这样用它:
|
||||
|
||||
```
|
||||
xeyes
|
||||
```
|
||||
|
||||
按住Ctrl+C终止它。
|
||||
|
||||
#### 7\. Let the terminal speak for you
|
||||
#### 7\. 让终端帮你讲话
|
||||
|
||||
打开你的扬声器,你来试试这个命令,[eSpeak][15]是一个有趣的命令,它可以让你的终端说话。是的,你没听错。
|
||||
|
||||
先安装这个包:
|
||||
|
||||
```
|
||||
sudo apt install espeak
|
||||
```
|
||||
|
||||
接下来,你只需要输入在命令行中输入你想听到的话:
|
||||
|
||||
```
|
||||
espeak "Type what your computer says"
|
||||
```
|
||||
|
||||
无论你在双引号里面填什么,你的电脑都会复述出来!它就像[在Linux中的echo命令][16],但不是打印出来,而是说出来。
|
||||
|
||||
#### 8\. 卫生间(但它不能洗衣服)
|
||||
|
||||
这听起来有点奇怪,是的。但是,这只是一个命令,用来将文本转换成大的ASCII字符。
|
||||
|
||||
![][17]
|
||||
|
||||
用这个命令安装toilet:
|
||||
|
||||
```
|
||||
sudo apt install toilet
|
||||
```
|
||||
|
||||
完成后,你只需输入:
|
||||
|
||||
```
|
||||
toilet sample text you want
|
||||
```
|
||||
|
||||
我也不知道为啥这个小程序叫卫生间。
|
||||
|
||||
#### 9\. 那个牛说什么?
|
||||
|
||||
Cowsay是一个在终端中用ASCII字符展示出一头牛的命令。通过这个命令,你可以控制牛说出你想说的话。
|
||||
|
||||
别纠结声音,它只展示文本(就是你看漫画书一样)。
|
||||
|
||||
![Cowsay Cowthink][18]
|
||||
|
||||
安装**cowsay**:
|
||||
|
||||
```
|
||||
sudo apt install cowsay
|
||||
```
|
||||
|
||||
安装完成后,你只要输入:
|
||||
|
||||
```
|
||||
cowsay "your text"
|
||||
```
|
||||
|
||||
无论你在双引号里填什么,你的牛都会说!我看到一些系统管理员用它来展示每天的消息。你也可以这样,你甚至可以把它和fortune命令结合。
|
||||
|
||||
#### 10\. Banner命令
|
||||
|
||||
banner命令与toilet命令相似,但它限制最多只能打印10个字符。
|
||||
|
||||
![][19]
|
||||
|
||||
你可以这样安装banner命令:
|
||||
|
||||
```
|
||||
sudo apt install sysvbanner
|
||||
```
|
||||
|
||||
然后这样运行:
|
||||
|
||||
```
|
||||
banner "Welcome"
|
||||
```
|
||||
|
||||
替换双引号里的内容,你将会得到你想要的展示内容。
|
||||
|
||||
#### 11\. Yes命令
|
||||
|
||||
![][20]
|
||||
|
||||
yes命令帮助你在循环中自动响应直到终止命令。这个命令将会一直打印相同的内容。如果你想快速生成大量垃圾文本,那么此命令将像超级按钮一样工作。
|
||||
|
||||
你也可以使用它为命令提供“yes”(如果提示)。例如,apt upgrade命令会要求你确认,你可以像这样使用它:
|
||||
|
||||
```
|
||||
yes | sudo apt upgrade
|
||||
```
|
||||
|
||||
你不需要安装任何包,Yes命令已经存在了。
|
||||
|
||||
想要终止yes命令循环,只需按住**CTRL+C**。
|
||||
|
||||
#### 12\. 得到一个新的身份
|
||||
|
||||
要生成一个随机的假身份吗?我推荐你用rig命令。你在终端运行它,就会生成一个假的身份。
|
||||
|
||||
![][21]
|
||||
|
||||
用这个命令安装rig:
|
||||
|
||||
```
|
||||
sudo apt install rig
|
||||
```
|
||||
|
||||
只需像这样输入:
|
||||
|
||||
```
|
||||
rig
|
||||
```
|
||||
|
||||
它可能被用在脚本或者web应用中展示随机信息,但我自己还没做过什么。
|
||||
|
||||
**结尾**
|
||||
|
||||
我希望你会喜欢这个有趣的Linux命令列表。你最喜欢哪个命令呢?你还知道其他有趣的命令吗?请在评论部分与我们分享。
|
||||
|
||||
![][22]
|
||||
|
||||
### Srimanta Koley
|
||||
|
||||
Srimanta是一位热情的作家、发行者、开源爱好者,非常喜欢与技术相关的所有内容。他喜欢读书,特别是90年的书!
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/funny-linux-commands/
|
||||
|
||||
作者:[Community][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[Zioyi](https://github.com/Zioyi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/itsfoss/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/linux-command-tricks/
|
||||
[2]: https://itsfoss.com/best-command-line-games-linux/
|
||||
[3]: https://itsfoss.com/best-ascii-games/
|
||||
[4]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/04/fun-linux-commands.png?ssl=1
|
||||
[5]: https://itsfoss.com/ubuntu-repositories/
|
||||
[6]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/04/sl-command.jpg?ssl=1
|
||||
[7]: https://en.wikipedia.org/wiki/The_Matrix
|
||||
[8]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/04/matrix-screen-command.png?ssl=1
|
||||
[9]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2015/12/Star-Wars-Linux-Terminal-2.png?fit=732%2C462&ssl=1
|
||||
[10]: https://itsfoss.com/star-wars-linux/
|
||||
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/04/fire-command.png?ssl=1
|
||||
[12]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/04/fortune-command.jpg?ssl=1
|
||||
[13]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/04/oneko-command.jpg?ssl=1
|
||||
[14]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/04/xeyes-command.jpg?ssl=1
|
||||
[15]: https://itsfoss.com/espeak-text-speech-linux/
|
||||
[16]: https://linuxhandbook.com/echo-command/
|
||||
[17]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/04/toilet-command.jpg?ssl=1
|
||||
[18]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/04/cowsay-cowthink.jpg?ssl=1
|
||||
[19]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/04/banner-command.jpg?ssl=1
|
||||
[20]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/04/yes-yourtext.jpg?ssl=1
|
||||
[21]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/04/rig-command.jpg?ssl=1
|
||||
[22]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/03/srimanta.jpg?ssl=1
|
||||
@@ -7,28 +7,28 @@
|
||||
[#]: via: (https://www.2daygeek.com/linux-unix-check-network-interfaces-names-nic-speed-ip-mac-address/)
|
||||
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
|
||||
|
||||
How to Check the Available Network Interfaces, Associated IP Addresses, MAC Addresses, and Interface Speed on Linux
|
||||
如何在 Linux 上检查可用的网络接口、关联的 IP 地址、MAC 地址和接口速度
|
||||
======
|
||||
|
||||
By default when you set up the server you will configure the primary network interface.
|
||||
默认在设置服务器时,你将配置主网络接口。
|
||||
|
||||
This is part of the build work that everyone does.
|
||||
这是每个人所做的构建工作的一部分。
|
||||
|
||||
Sometimes you may need to configure an additional network interface for several reasons.
|
||||
有时出于各种原因,你可能需要配置额外的网络接口。
|
||||
|
||||
This could be a network bonding/teaming or high availability or a separate interface for application requirements or backups.
|
||||
这可以是网络绑定/团队合作或高可用性,也可以是用于应用需求或备份的单独接口。
|
||||
|
||||
To do so, you need to know how many interfaces your computer has and their speed to configure it.
|
||||
为此,你需要知道计算机有多少接口以及它们的配置速度。
|
||||
|
||||
There are many commands to check for available network interfaces, but we only use the IP command.
|
||||
有许多命令可检查可用的网络接口,但是我们仅使用 IP 命令。
|
||||
|
||||
Later we will write a separate article with all these tools.
|
||||
稍后,我们将使用所有这些工具编写单独的文章。
|
||||
|
||||
In this tutorial, we will show you the Available Network Interface Card (NIC) information, such as the interface name, associated IP address, MAC address, and interface speed.
|
||||
在本教程中,我们将向你显示可用网络网卡(NIC)信息,例如接口名称、关联的 IP 地址、MAC 地址和接口速度。
|
||||
|
||||
### What’s IP Command
|
||||
### 什么是 IP 命令
|
||||
|
||||
**[IP command][1]** is similar to ifconfig, which is used to for assigning Static IP Address, Route & Default Gateway, etc.,
|
||||
**[IP 命令][1]**类似于 ifconfig, 用于分配静态 IP 地址、路由和默认网关等。
|
||||
|
||||
```
|
||||
# ip a
|
||||
@@ -45,17 +45,17 @@ In this tutorial, we will show you the Available Network Interface Card (NIC) in
|
||||
valid_lft forever preferred_lft forever
|
||||
```
|
||||
|
||||
### What’s ethtool Command
|
||||
### 什么是 ethtool 命令
|
||||
|
||||
The ethtool is used to query or control network driver and hardware settings.
|
||||
ethtool 用于查询或控制网络驱动或硬件设置。
|
||||
|
||||
```
|
||||
# ethtool eth0
|
||||
```
|
||||
|
||||
### 1) How to Check the Available Network Interfaces on Linux Using the IP Command
|
||||
### 1)如何在 Linux 上使用 IP 命令检查可用的网络接口
|
||||
|
||||
When you run the IP command without any arguments, it gives you plenty of information, but if you only need the available network interfaces, use the following customized IP command.
|
||||
在不带任何参数的情况下运行 IP 命令时,它会提供大量信息,但是,如果仅需要可用的网络接口,请使用以下定制的 IP 命令。
|
||||
|
||||
```
|
||||
# ip a |awk '/state UP/{print $2}'
|
||||
@@ -64,9 +64,9 @@ eth0:
|
||||
eth1:
|
||||
```
|
||||
|
||||
### 2) How to Check the IP Address of a Network Interface on Linux Using the IP Command
|
||||
### 2)如何在 Linux 上使用 IP 命令检查网络接口的 IP 地址
|
||||
|
||||
If you only want to see which IP address is assigned to which interface, use the following customized IP command.
|
||||
如果只想查看 IP 地址分配给了哪个接口,请使用以下定制的 IP 命令。
|
||||
|
||||
```
|
||||
# ip -o a show | cut -d ' ' -f 2,7
|
||||
@@ -78,18 +78,18 @@ lo 127.0.0.1/8
|
||||
192.168.1.102/24
|
||||
```
|
||||
|
||||
### 3) How to Check the Network Interface Card MAC Address on Linux Using the IP Command
|
||||
### 3)如何在 Linux 上使用 IP 命令检查网卡的 MAC 地址
|
||||
|
||||
If you only want to see the network interface name and the corresponding MAC address, use the following format.
|
||||
如果只想查看网络接口名称和相应的 MAC 地址,请使用以下格式。
|
||||
|
||||
To check a specific network interface MAC address.
|
||||
检查特定的网络接口的 MAC 地址。
|
||||
|
||||
```
|
||||
# ip link show dev eth0 |awk '/link/{print $2}'
|
||||
00:00:00:55:43:5c
|
||||
```
|
||||
|
||||
To check MAC address for all network interface.
|
||||
检查所有网络接口的 MAC 地址。
|
||||
|
||||
```
|
||||
# vi /opt/scripts/mac-addresses.sh
|
||||
@@ -102,7 +102,7 @@ ethtool -P $output
|
||||
done
|
||||
```
|
||||
|
||||
Run the below shell script to get the MAC address for multiple network interfaces.
|
||||
运行下面的 shell 脚本获取多个网络接口的 MAC 地址。
|
||||
|
||||
```
|
||||
# sh /opt/scripts/mac-addresses.sh
|
||||
@@ -113,11 +113,11 @@ eth1:
|
||||
Permanent address: 00:00:00:55:43:5d
|
||||
```
|
||||
|
||||
### 4) How to Check the Network Interface Port Speed on Linux Using the ethtool Command
|
||||
### 4)如何在 Linux 上使用 ethtool 命令检查网络接口速度
|
||||
|
||||
If you want to check the network interface port speed on Linux, use the ethtool command.
|
||||
如果要在 Linux 上检查网络接口速度,请使用 ethtool 命令。
|
||||
|
||||
To check the speed of a particular network interface port.
|
||||
检查特定网络接口的速度。
|
||||
|
||||
```
|
||||
# ethtool eth0 |grep "Speed:"
|
||||
@@ -125,7 +125,7 @@ To check the speed of a particular network interface port.
|
||||
Speed: 10000Mb/s
|
||||
```
|
||||
|
||||
To check the port speed for all network interfaces.
|
||||
检查所有网络接口速度。
|
||||
|
||||
```
|
||||
# vi /opt/scripts/port-speed.sh
|
||||
@@ -138,7 +138,7 @@ ethtool $output |grep "Speed:"
|
||||
done
|
||||
```
|
||||
|
||||
Run the below shell script to get the port speed for multiple network interfaces.
|
||||
运行以下 shell 脚本获取多个网络接口速度。
|
||||
|
||||
```
|
||||
# sh /opt/scripts/port-speed.sh
|
||||
@@ -149,9 +149,9 @@ eth1:
|
||||
Speed: 10000Mb/s
|
||||
```
|
||||
|
||||
### 5) Shell Script to Verify Network Interface Card Information
|
||||
### 5)验证网卡信息的 Shell 脚本
|
||||
|
||||
This **[shell script][2]** allows you to gather all of the above information, such as network interface names, IP addresses of network interfaces, MAC addresses of network interfaces, and the speed of a network interface port.
|
||||
通过此 **[shell 脚本][2]**,你可以收集上述所有信息,例如网络接口名称、网络接口的 IP 地址,网络接口的 MAC 地址以及网络接口的速度。
|
||||
|
||||
```
|
||||
# vi /opt/scripts/nic-info.sh
|
||||
@@ -168,7 +168,7 @@ ethtool $iname |grep "Speed:"
|
||||
done
|
||||
```
|
||||
|
||||
Run the below shell script to check network card information.
|
||||
运行以下 shell 脚本检查网卡信息。
|
||||
|
||||
```
|
||||
# sh /opt/scripts/nic-info.sh
|
||||
@@ -191,7 +191,7 @@ via: https://www.2daygeek.com/linux-unix-check-network-interfaces-names-nic-spee
|
||||
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
Reference in New Issue
Block a user