Merge pull request #35 from LCTT/master

update
This commit is contained in:
MjSeven 2018-06-16 22:48:40 +08:00 committed by GitHub
commit a6b7002182
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 555 additions and 572 deletions

View File

@ -1,7 +1,11 @@
机器人学影响 CIO 角色的 3 种方式
======
> 机器人流程自动化如何影响 CIO ?考虑这些可能。
![配图](https://enterprisersproject.com/sites/default/files/styles/620x350/public/cio_ai.png?itok=toMIgELj)
随着 2017 即将结束,许多 CIO 们的 2018 年目标也将确定。或许你们将参与到机器人流程自动化RPA中。多年以来RPA 对许多公司来说只是一个可望不可及的概念。但是随着组织被迫变得越来越敏捷高效RPA 所具有的潜在优势开始受到重视。
随着 2017 的结束,许多 CIO 们的 2018 年目标也将确定。或许你们将参与到机器人流程自动化RPA中。多年以来RPA 对许多公司来说只是一个可望不可及的概念。但是随着组织被迫变得越来越敏捷高效RPA 所具有的潜在优势开始受到重视。
根据 Redwood Sofeware 和 Sapio Research 的最新 [研究报告][1]IT 决策者们相信,未来 5 年有 59% 的业务可以被自动化处理,从而产生新的速度和效率,并且消减相应的重复性的人工工作量的岗位。但是,目前在相应岗位上没有实施 RPA 的公司中,有 20% 的公司员工超过 1000 人。
@ -43,7 +47,7 @@ via: https://enterprisersproject.com/article/2017/11/3-ways-robotics-affects-cio
作者:[Dennis Walsh][a]
译者:[qhwdw](https://github.com/qhwdw)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -160,7 +160,7 @@ func main() {
router.Handle("GET", "/api/auth_user", authRequired(getAuthUser))
addr := fmt.Sprintf(":%d", config.port)
log.Printf("starting server at %s 🚀\n", config.appURL)
log.Printf("starting server at %s \n", config.appURL)
log.Fatalf("could not start server: %v\n", http.ListenAndServe(addr, router))
}
@ -220,7 +220,7 @@ go build
```
我们在目录中有了一个 “passwordless-demo”但是你的目录中可能与示例不一样`go build` 将创建一个同名的可执行文件。如果你没有关闭前面的 cockroach 节点,并且你正确配置了 `SMTP_USERNAME` 和 `SMTP_PASSWORD` 变量,你将看到命令 `starting server at http://localhost/ 🚀` 没有错误输出。
我们在目录中有了一个 “passwordless-demo”但是你的目录中可能与示例不一样`go build` 将创建一个同名的可执行文件。如果你没有关闭前面的 cockroach 节点,并且你正确配置了 `SMTP_USERNAME` 和 `SMTP_PASSWORD` 变量,你将看到命令 `starting server at http://localhost/ ` 没有错误输出。
#### 请求 JSON 的中间件
@ -764,7 +764,7 @@ func fetchUser(ctx context.Context, id string) (User, error) {
如果你在 mailtrap 上点击之后出现有关 `脚本运行被拦截,因为文档的框架是沙箱化的,并且没有设置 'allow-scripts' 权限` 的问题,你可以尝试右键点击 “在新标签中打开链接“。这样做是安全的,因为邮件内容是 [沙箱化的][10]。我在 `localhost` 上有时也会出现这个问题,但是我认为你一旦以 `https://` 方式部署到服务器上应该不会出现这个问题了。
如果有任何问题,请在我的 [GitHub repo][11] 留言或者提交 PRs 👍
如果有任何问题,请在我的 [GitHub repo][11] 留言或者提交 PRs
以后,我为这个 API 写了一个客户端作为这篇文章的[第二部分][13]。

View File

@ -0,0 +1,163 @@
如何装载/卸载 Linux 内核模块
===============
> 找到并装载内核模块以解决外设问题。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_computer_development_programming.png?itok=4OM29-82)
本文来自 Manning 出版的 [Linux in Action][1] 的第 15 章。
Linux 使用内核模块管理硬件外设。 我们来看看它是如何工作的。
运行中的 Linux 内核是您不希望被破坏的东西之一。毕竟,内核是驱动计算机所做的一切工作的软件。考虑到在一个运行的系统上必须同时管理诸多细节,最好能让内核尽可能的减少分心,专心的完成它的工作。但是,如果对计算环境进行任何微小的更改都需要重启整个系统,那么插入一个新的网络摄像头或打印机就可能会严重影响您的工作流程。每次添加设备时都必须重新启动,以使系统识别它,这效率很低。
为了在稳定性和可用性之间达成有效的平衡Linux 将内核隔离,但是允许您通过可加载内核模块 (LKM) 实时添加特定的功能。如下图所示,您可以将模块视为软件的一部分,它告诉内核在哪里找到一个设备以及如何使用它。反过来,内核使设备对用户和进程可用,并监视其操作。
![Kernel modules][3]
*内核模块充当设备和 Linux 内核之间的转换器。*
虽然你可以自己编写模块来完全按照你喜欢的方式来支持一个设备但是为什么要这样做呢Linux 模块库已经非常强大,通常不需要自己去实现一个模块。 而绝大多数时候Linux 会自动加载新设备的模块,而您甚至不知道它。
不过,有时候,出于某种原因,它本身并不会自动进行。(你肯定不想让那个招聘经理不耐烦地一直等待你的笑脸加入视频面试。)为了帮助你解决问题,你需要更多地了解内核模块,特别是,如何找到运行你的外设的实际模块,然后如何手动激活它。
### 查找内核模块
按照公认的约定,内核模块是位于 `/lib/modules/` 目录下的具有 .ko内核对象扩展名的文件。 然而,在你找到这些文件之前,你还需要选择一下。因为在引导时你需要从版本列表中选择其一加载,所以支持您选择的特定软件(包括内核模块)必须存在某处。 那么,`/lib/modules/` 就是其中之一。 你会发现目录里充满了每个可用的 Linux 内核版本的模块; 例如:
```
$ ls /lib/modules
4.4.0-101-generic
4.4.0-103-generic
4.4.0-104-generic
```
在我的电脑上运行的内核是版本号最高的版本4.4.0-104-generic但不能保证这对你来说是一样的内核经常更新。 如果您将要在一个运行的系统上使用模块完成一些工作的话,你需要确保您找到正确的目录树。
好消息:有一个可靠的窍门。相对于通过名称来识别目录,并希望能够找到正确的目录,你可以使用始终指向使用的内核名称的系统变量。 您可以使用 `uname -r` `-r` 从系统信息中指定通常显示的内核版本号)来调用该变量:
```
$ uname -r
4.4.0-104-generic
```
通过这些信息,您可以使用称为命令替换的过程将 `uname` 并入您的文件系统引用中。 例如,要导航到正确的目录,您需要将其添加到 `/lib/modules` 。 要告诉 Linux “uname” 不是一个文件系统中的位置,请将 `uname` 部分用反引号括起来,如下所示:
```
$ ls /lib/modules/`uname -r`
build modules.alias modules.dep modules.softdep
initrd modules.alias.bin modules.dep.bin modules.symbols
kernel modules.builtin modules.devname modules.symbols.bin
misc modules.builtin.bin modules.order vdso
```
你可以在 `kernel/` 目录下的子目录中找到大部分模块。 花几分钟时间浏览这些目录,了解事物的排列方式和可用内容。 这些文件名通常会让你知道它们是什么。
```
$ ls /lib/modules/`uname -r`/kernel
arch crypto drivers fs kernel lib mm
net sound ubuntu virt zfs
```
这是查找内核模块的一种方法;实际上,这是一种快速的方式。 但这不是唯一的方法。 如果你想获得完整的集合,你可以使用 `lsmod` 列出所有当前加载的模块以及一些基本信息。 这个截断输出的第一列(在这里列出的太多了)是模块名称,后面是文件大小和数量,然后是每个模块的名称:
```
$ lsmod
[...]
vboxdrv 454656 3 vboxnetadp,vboxnetflt,vboxpci
rt2x00usb 24576 1 rt2800usb
rt2800lib 94208 1 rt2800usb
[...]
```
到底有多少?好吧,我们再运行一次 `lsmod ` ,但是这一次将输出管道输送到 `wc -l` 看一下一共多少行:
```
$ lsmod | wc -l
113
```
这是已加载的模块。 总共有多少个? 运行 `modprobe -c` 并计算这些行将给我们这个数字:
```
$ modprobe -c | wc -l
33350
```
有 33,350 个可用模块!? 看起来好像有人多年来一直在努力为我们提供软件来驱动我们的物理设备。
注意:在某些系统中,您可能会遇到自定义的模块,这些模块要么在 `/etc/modules` 文件中使用独特的条目进行引用,要么在 `/etc/modules-load.d/` 下的配置文件中。这些模块很可能是本地开发项目的产物,可能涉及前沿实验。不管怎样,知道你看到的是什么总是好的。
这就是如何找到模块的方法。 如果出于某种原因,它不会自行加载,您的下一个工作就是弄清楚如何手动加载未激活的模块。
### 手动加载内核模块
在加载内核模块之前,逻辑上您必须确认它存在。在这之前,你需要知道它叫什么。要做到这一点,有时需要兼有魔法和运气以及在线文档作者的辛勤工作的帮助。
我将通过描述一段时间前遇到的问题来说明这个过程。在一个晴朗的日子里,出于某种原因,笔记本电脑上的 WiFi 接口停止工作了。就这样。也许是软件升级把它搞砸了。谁知道呢?我运行了 `lshw -c network` ,得到了这个非常奇怪的信息:
```
network UNCLAIMED
    AR9485 Wireless Network Adapter
```
Linux 识别到了接口Atheros AR9485但将其列为未声明。 那么,正如他们所说的那样,“当情况变得严峻时,就会在互联网上进行艰难的搜索。” 我搜索了一下 atheros ar9 linux 模块,在浏览了一页又一页五年前甚至是十年前的页面后,它们建议我自己写个模块或者放弃吧,然后我终于发现(最起码 Ubuntu 16.04)有一个可以工作的模块。 它的名字是 ath9k 。
是的! 这场战斗胜券在握!向内核添加模块比听起来容易得多。 要仔细检查它是否可用,可以针对模块的目录树运行 `find`,指定 `-type f` 来告诉 Linux 您正在查找文件,然后将字符串 `ath9k` 和星号一起添加以包含所有以你的字符串打头的文件:
```
$ find /lib/modules/$(uname -r) -type f -name ath9k*
/lib/modules/4.4.0-97-generic/kernel/drivers/net/wireless/ath/ath9k/ath9k_common.ko
/lib/modules/4.4.0-97-generic/kernel/drivers/net/wireless/ath/ath9k/ath9k.ko
/lib/modules/4.4.0-97-generic/kernel/drivers/net/wireless/ath/ath9k/ath9k_htc.ko
/lib/modules/4.4.0-97-generic/kernel/drivers/net/wireless/ath/ath9k/ath9k_hw.ko
```
再一步,加载模块:
```
# modprobe ath9k
```
就是这样。无启动,没烦恼。
这里还有一个示例,向您展示如何使用已经崩溃的运行模块。曾经有一段时间,我使用罗技网络摄像头和一个特定的软件会使摄像头在下次系统启动前无法被任何其他程序访问。有时我需要在不同的应用程序中打开相机,但没有时间关机重新启动。(我运行了很多应用程序,在引导之后将它们全部准备好需要一些时间。)
由于这个模块可能是运行的,所以使用 `lsmod` 来搜索 video 这个词应该给我一个关于相关模块名称的提示。 实际上,它比提示更好:用 video 这个词描述的唯一模块是 uvcvideo如下所示
```
$ lsmod | grep video
uvcvideo 90112 0
videobuf2_vmalloc 16384 1 uvcvideo
videobuf2_v4l2 28672 1 uvcvideo
videobuf2_core 36864 2 uvcvideo,videobuf2_v4l2
videodev 176128 4 uvcvideo,v4l2_common,videobuf2_core,videobuf2_v4l2
media 24576 2 uvcvideo,videodev
```
有可能是我自己的操作导致了崩溃,我想我可以挖掘更深一点,看看我能否以正确的方式解决问题。但结果你知道的;有时你不关心理论,只想让设备工作。 所以我用 `rmmod` 杀死了 `uvcvideo` 模块,然后用 `modprobe` 重新启动它,一切都好:
```
# rmmod uvcvideo
# modprobe uvcvideo
```
再一次:不重新启动。没有其他的后续影响。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/5/how-load-or-unload-linux-kernel-module
作者:[David Clinton][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[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/dbclinton
[1]:https://www.manning.com/books/linux-in-action?a_aid=bootstrap-it&a_bid=4ca15fc9&chan=opensource
[2]:/file/397906
[3]:https://opensource.com/sites/default/files/uploads/kernels.png "Kernel modules"

View File

@ -0,0 +1,116 @@
Vim-plug极简 Vim 插件管理器
======
![](https://www.ostechnix.com/wp-content/uploads/2018/06/vim-plug-720x340.png)
当没有插件管理器时Vim 用户必须手动下载 tarball 包形式的插件,并将它们解压到 `~/.vim` 目录中。在少量插件的时候可以。但当他们安装更多的插件时,就会变得一团糟。所有插件文件分散在单个目录中,用户无法找到哪个文件属于哪个插件。此外,他们无法找到他们应该删除哪个文件来卸载插件。这时 Vim 插件管理器就可以派上用场。插件管理器将安装插件的文件保存在单独的目录中,因此管理所有插件变得非常容易。我们几个月前已经写了关于 [Vundle][1] 的文章。今天,我们将看到又一个名为 “Vim-plug” 的 Vim 插件管理器。
Vim-plug 是一个自由、开源、速度非常快的、极简的 vim 插件管理器。它可以并行地安装或更新插件。你还可以回滚更新。它创建<ruby>浅层克隆<rt>shallow clone</rt></ruby>最小化磁盘空间使用和下载时间。它支持按需加载插件以加快启动时间。其他值得注意的特性是支持分支/标签/提交、post-update 钩子、支持外部管理的插件等。
### 安装
安装和使用起来非常容易。你只需打开终端并运行以下命令:
```
$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
```
Neovim 用户可以使用以下命令安装 Vim-plug
```
$ curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
```
### 用法
#### 安装插件
要安装插件,你必须如下所示首先在 Vim 配置文件中声明它们。一般 Vim 的配置文件是 `~/.vimrc`Neovim 的配置文件是 `~/.config/nvim/init.vim`。请记住,当你在配置文件中声明插件时,列表应该以 `call plug#begin(PLUGIN_DIRECTORY)` 开始,并以 `plug#end()` 结束。
例如,我们安装 “lightline.vim” 插件。为此,请在 `~/.vimrc` 的顶部添加以下行。
```
call plug#begin('~/.vim/plugged')
Plug 'itchyny/lightline.vim'
call plug#end()
```
在 vim 配置文件中添加上面的行后,通过输入以下命令重新加载:
```
:source ~/.vimrc
```
或者,只需重新加载 Vim 编辑器。
现在,打开 vim 编辑器:
```
$ vim
```
使用以下命令检查状态:
```
:PlugStatus
```
然后输入下面的命令,然后按回车键安装之前在配置文件中声明的插件。
```
:PlugInstall
```
#### 更新插件
要更新插件,请运行:
```
:PlugUpdate
```
更新插件后,按下 `d` 查看更改。或者,你可以之后输入 `:PlugDiff`
#### 审查插件
有时,更新的插件可能有新的 bug 或无法正常工作。要解决这个问题,你可以简单地回滚有问题的插件。输入 `:PlugDiff` 命令,然后按回车键查看上次 `:PlugUpdate`的更改,并在每个段落上按 `X` 将每个插件回滚到更新前的前一个状态。
#### 删除插件
删除一个插件删除或注释掉你以前在你的 vim 配置文件中添加的 `plug` 命令。然后,运行 `:source ~/.vimrc` 或重启 Vim 编辑器。最后,运行以下命令卸载插件:
```
:PlugClean
```
该命令将删除 vim 配置文件中所有未声明的插件。
#### 升级 Vim-plug
要升级vim-plug本身请输入
```
:PlugUpgrade
```
如你所见,使用 Vim-plug 管理插件并不难。它简化了插件管理。现在去找出你最喜欢的插件并使用 Vim-plug 来安装它们。
就是这些了。我将很快在这里发布另一个有趣的话题。在此之前,请继续关注我们。
干杯!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/vim-plug-a-minimalist-vim-plugin-manager/
作者:[SK][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[geekpi](https://github.com/geekpi)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.ostechnix.com/author/sk/
[1]:https://linux.cn/article-9416-1.html

View File

@ -1,3 +1,4 @@
Translating by qhwdw
Operating a Kubernetes network
============================================================

View File

@ -1,3 +1,4 @@
Translating by qhwdw
Learn Blockchains by Building One
======

View File

@ -1,3 +1,4 @@
Translating by qhwdw
How to improve ROI on automation: 4 tips
======

View File

@ -1,3 +1,4 @@
Translating by qhwdw
Token ERC Comparison for Fungible Tokens Blockchainers
======
“The good thing about standards is that there are so many to choose from.” [_Andrew S. Tanenbaum_][1]

View File

@ -1,3 +1,4 @@
Translating by qhwdw
The Cost of Cloud Computing
============================================================

View File

@ -1,3 +1,4 @@
Translating by qhwdw
Simple Load Balancing with DNS on Linux
======

View File

@ -1,246 +0,0 @@
translating
The Linux Filesystem Explained
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/search.jpg?itok=7hj0YYjF)
Back in 1996 I learned how to install software on my spanking new Linux before really understanding the topography of the filesystem. This turned out to be a problem, not so much for programs, because they would just magically work even though I hadn't a clue of where the actual executable files landed. The problem was the documentation.
You see, back then, Linux was not the intuitive, user-friendly system it is today. You had to read a lot. You had to know things about the frequency rate of your CRT monitor and the ins and outs of your noisy dial-up modem, among hundreds of other things. I soon realized I would need to spend some time getting a handle on how the directories were organized and what all their exotic names like /etc (not for miscellaneous files), /usr (not for user files), and /*bin *(not a trash can) meant.
This tutorial will help you get up to speed faster than I did.
### Structure
It makes sense to explore the Linux filesystem from a terminal window, not because the author is a grumpy old man and resents new kids and their pretty graphical tools -- although there is some truth to that -- but because a terminal, despite being text-only, has better tools to show the map of Linux's directory tree.
In fact, that is the name of the first tool you'll install to help you on the way: _tree_. If you are using Ubuntu or Debian, you can do:
```
sudo apt install tree
```
On Red Hat or Fedora, do:
```
sudo dnf install tree
```
For SUSE/openSUSE use `zypper`:
```
sudo zypper install tree
```
For Arch-like distros (Manjaro, Antergos, etc.) use:
```
sudo pacman -S tree
```
... and so on.
Once installed, stay in your terminal window and run _tree_ like this:
```
tree /
```
`The /` in the instruction above refers to the _root_ directory. The root directory is the one from which all other directories branch off from. When you run `tree` and tell it to start with _/_ , you will see the whole directory tree, all directories and all the subdirectories in the whole system, with all their files, fly by.
If you have been using your system for some time, this may take a while, because, even if you haven't generated many files yourself, a Linux system and its apps are always logging, cacheing, and storing temporal files. The number of entries in the file system can grow quite quickly.
Don't feel overwhelmed, though. Instead, try this:
```
tree -L 1 /
```
And you should see what is shown in Figure 1.
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/f01_tree01.png?itok=aGKzzC0C)
The instruction above can be translated as " _show me only the 1st Level of the directory tree starting at / (root)_ ". The `-L` option tells `tree` how many levels down you want to see.
Most Linux distributions will show you the same or a very similar layout to what you can see in the image above. This means that even if you feel confused now, master this, and you will have a handle on most, if not all, Linux installations in the whole wide world.
To get you started on the road to mastery, let's look at what each directory is used for. While we go through each, you can peek at their contents using ls.
### Directories
From top to bottom, the directories you are seeing are as follows.
#### _/bin_
_/bin_ is the directory that contains _bin_ aries, that is, some of the applications and programs you can run. You will find the _ls_ program mentioned above in this directory, as well as other basic tools for making and removing files and directories, moving them around, and so on. There are more _bin_ directories in other parts of the file system tree, but we'll be talking about those in a minute.
#### _/boot_
The _/boot_ directory contains files required for starting your system. Do I have to say this? Okay, I'll say it: **DO NOT TOUCH!**. If you mess up one of the files in here, you may not be able to run your Linux and it is a pain to repair. On the other hand, don't worry too much about destroying your system by accident: you have to have superuser privileges to do that.
#### _/dev_
_/dev_ contains _dev_ ice files. Many of these are generated at boot time or even on the fly. For example, if you plug in a new webcam or a USB pendrive into your machine, a new device entry will automagically pop up here.
#### _/etc_
_/etc_ is the directory where names start to get confusing. _/etc_ gets its name from the earliest Unixes and it was literally "et cetera" because it was the dumping ground for system files administrators were not sure where else to put.
Nowadays, it would be more appropriate to say that _etc_ stands for "Everything to configure," as it contains most, if not all system-wide configuration files. For example, the files that contain the name of your system, the users and their passwords, the names of machines on your network and when and where the partitions on your hard disks should be mounted are all in here. Again, if you are new to Linux, it may be best if you don't touch too much in here until you have a better understanding of how things work.
#### _/home_
_/home_ is where you will find your users' personal directories. In my case, under _/home_ there are two directories: _/home/paul_ , which contains all my stuff; and _/home/guest_ , in case anybody needs to borrow my computer.
#### _/lib_
_/lib_ is where _lib_ raries live. Libraries are files containing code that your applications can use. They contain snippets of code that applications use to draw windows on your desktop, control peripherals, or send files to your hard disk.
There are more _lib_ directories scattered around the file system, but this one, the one hanging directly off of _/_ is special in that, among other things, it contains the all-important kernel modules. The kernel modules are drivers that make things like your video card, sound card, WiFi, printer, and so on, work.
#### _/media_
The _/media_ directory is where external storage will be automatically mounted when you plug it in and try to access it. As opposed to most of the other items on this list, _/media_ does not hail back to 1970s, mainly because inserting and detecting storage (pendrives, USB hard disks, SD cards, external SSDs, etc) on the fly, while a computer is running, is a relatively new thing.
#### _/mnt_
The _/mnt_ directory, however, is a bit of remnant from days gone by. This is where you would manually mount storage devices or partitions. It is not used very often nowadays.
#### _/opt_
The _/opt_ directory is often where software you compile (that is, you build yourself from source code and do not install from your distribution repositories) sometimes lands. Applications will end up in the _/opt/bin_ directory and libraries in the _/opt/lib_ directory.
A slight digression: another place where applications and libraries end up in is _/usr/local_ , When software gets installed here, there will also be _/usr/local/bin_ and _/usr/local/lib_ directories. What determines which software goes where is how the developers have configured the files that control the compilation and installation process.
#### _/proc_
_/proc_ , like _/dev_ is a virtual directory. It contains information about your computer, such as information about your CPU and the kernel your Linux system is running. As with _/dev_ , the files and directories are generated when your computer starts, or on the fly, as your system is running and things change.
#### _/root_
_/root_ is the home directory of the superuser (also known as the "Administrator") of the system. It is separate from the rest of the users' home directories BECAUSE YOU ARE NOT MEANT TO TOUCH IT. Keep your own stuff in you own directories, people.
#### _/run_
_/run_ is another new directory. System processes use it to store temporary data for their own nefarious reasons. This is another one of those DO NOT TOUCH folders.
#### _/sbin_
_/sbin_ is similar to _/bin_ , but it contains applications that only the superuser (hence the initial _s_ ) will need. You can use these applications with the `sudo` command that temporarily concedes you superuser powers on many distributions. _/sbin_ typically contains tools that can install stuff, delete stuff and format stuff. As you can imagine, some of these instructions are lethal if you use them improperly, so handle with care.
#### _/usr_
The _/usr_ directory was where users' home directories were originally kept back in the early days of UNIX. However, now _/home_ is where users kept their stuff as we saw above. These days, _/usr_ contains a mish-mash of directories which in turn contain applications, libraries, documentation, wallpapers, icons and a long list of other stuff that need to be shared by applications and services.
You will also find _bin_ , _sbin_ and _lib_ directories in _/usr_. What is the difference with their root-hanging cousins? Not much nowadays. Originally, the _/bin_ directory (hanging off of root) would contain very basic commands, like `ls`, `mv` and `rm`; the kind of commands that would come pre-installed in all UNIX/Linux installations, the bare minimum to run and maintain a system. _/usr/bin_ on the other hand would contain stuff the users would install and run to use the system as a work station, things like word processors, web browsers, and other apps.
But many modern Linux distributions just put everything into _/usr/bin_ and have _/bin_ point to _/usr/bin_ just in case erasing it completely would break something. So, while Debian, Ubuntu and Mint still keep _/bin_ and _/usr/bin_ (and _/sbin_ and _/usr/sbin_ ) separate; others, like Arch and its derivatives just have one "real" directory for binaries, _/usr/bin_ , and the rest or _*bin_ s are "fake" directories that point to _/usr/bin_.
#### _/srv_
The _/srv_ directory contains data for servers. If you are running a web server from your Linux box, your HTML files for your sites would go into _/srv/http_ (or _/srv/www_ ). If you were running an FTP server, your files would go into _/srv/ftp_.
#### _/sys_
_/sys_ is another virtual directory like _/proc_ and _/dev_ and also contains information from devices connected to your computer.
In some cases you can also manipulate those devices. I can, for example, change the brightness of the screen of my laptop by modifying the value stored in the _/sys/devices/pci0000:00/0000:00:02.0/drm/card1/card1-eDP-1/intel_backlight/brightness_ file (on your machine you will probably have a different file). But to do that you have to become superuser. The reason for that is, as with so many other virtual directories, messing with the contents and files in _/sys_ can be dangerous and you can trash your system. DO NOT TOUCH until you are sure you know what you are doing.
#### _/tmp_
_/tmp_ contains temporary files, usually placed there by applications that you are running. The files and directories often (not always) contain data that an application doesn't need right now, but may need later on. So, to free up RAM, it gets stored here.
You can also use _/tmp_ to store your own temporary files -- _/tmp_ is one of the few directories hanging of _/_ which you can actually interact with without becoming superuser. The problem is that applications sometimes don't come back to retrieve and delete files and directories and _/tmp_ can often end up eating up space on your hard disk, filling it up with junk. Later on in this series we'll see how to clean it up.
#### _/var_
_/var_ was originally given its name because its contents was deemed _variable_ , in that it changed frequently. Today it is a bit of a misnomer because there are many other directories that also contain data that changes frequently, especially the virtual directories we saw above.
Be that as it may, _/var_ contains things like logs in the _/var/log_ subdirectories. Logs are files that register events that happen on the system. If something fails in the kernel, it will be logged in a file in _/var/log_ ; if someone tries to break into your computer from outside, your firewall will also log the attempt here. It also contains _spools_ for tasks. These "tasks" can be the jobs you send to a shared printer when you have to wait because another user is printing a long document, or mail that is waiting to be delivered to users on the system.
Your system may have some more directories we haven't mentioned above. In the screenshot, for example, there is a _/snap_ directory. That's because the shot was captured on an Ubuntu system. Ubuntu has recently incorporated [snap][1] packages as a way of distributing software. The _/snap_ directory contains all the files and the software installed from snaps.
### Digging Deeper
That is the root directory covered, but many of the subdirectories lead to their own set of files and subdirectories. Figure 2 gives you an overall idea of what the basic file system tree looks like (the image is kindly supplied under a CC By-SA license by Paul Gardner) and [Wikipedia has a break down with a summary of what each directory is used for][2].
![filesystem][4]
Figure 2: Standard Unix filesystem hierarchy.
[Used with permission][5]
Paul Gardner
To explore the filesystem yourself, use the `cd` command:
```
cd
```
will take you to the directory of your choice ( _cd_ stands for _change directory_.
If you get confused,
```
pwd
```
will always tell you where you ( _pwd_ stands for _print working directory_ ). Also,
```
cd
```
with no options or parameters, will take you back to your own home directory, where things are safe and cosy.
Finally,
```
cd ..
```
will take you up one level, getting you one level closer to the _/_ root directory. If you are in _/usr/share/wallpapers_ and run `cd ..`, you will move up to _/usr/share_.
To see what a directory contains, use
```
ls
```
or simply
```
ls
```
to list the contents of the directory you are in right now.
And, of course, you always have `tree` to get an overview of what lays within a directory. Try it on _/usr/share_ \-- there is a lot of interesting stuff in there.
### Conclusion
Although there are minor differences between Linux distributions, the layout for their filesystems are mercifully similar. So much so that you could say: once you know one, you know them all. And the best way to know the filesystem is to explore it. So go forth with `tree`, `ls`, and `cd` into uncharted territory.
You cannot damage your filesystem just by looking at it, so move from one directory to another and take a look around. Soon you'll discover that the Linux filesystem and how it is laid out really makes a lot of sense, and you will intuitively know where to find apps, documentation, and other resources.
Learn more about Linux through the free ["Introduction to Linux" ][6]course from The Linux Foundation and edX.
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/learn/intro-to-linux/2018/4/linux-filesystem-explained
作者:[PAUL BROWN][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.linux.com/users/bro66
[1]:https://www.ubuntu.com/desktop/snappy
[2]:https://en.wikipedia.org/wiki/Unix_filesystem#Conventional_directory_layout
[3]:https://www.linux.com/files/images/standard-unix-filesystem-hierarchypng
[4]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/standard-unix-filesystem-hierarchy.png?itok=CVqmyk6P (filesystem)
[5]:https://www.linux.com/licenses/category/used-permission
[6]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux

View File

@ -1,3 +1,4 @@
Translating by qhwdw
Passwordless Auth: Client
======
Time to continue with the [passwordless auth][1] posts. Previously, we wrote an HTTP service in Go that provided with a passwordless authentication API. Now, we are gonna code a JavaScript client for it.

View File

@ -1,3 +1,4 @@
Translating by qhwdw
How insecure is your router?
======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/locks_keys_bridge_paris.png?itok=Bp0dsEc9)

View File

@ -1,3 +1,4 @@
translating by amwps290
How to clean up your data in the command line
======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc_520x292_opendata_0613mm.png?itok=UIjD_jhK)

View File

@ -1,3 +1,4 @@
Translating by qhwdw
Turn Your Raspberry Pi into a Tor Relay Node
======

View File

@ -0,0 +1,257 @@
# Linux文件系统详解
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/search.jpg?itok=7hj0YYjF)
早在1996年在真正理解文件系统的结构之前我就学会了如何在我崭新的 Linux 上安装软件。这是一个问题,但不是程序的问题,因为即使我不知道实际的可执行文件在哪里,它们也会神奇地工作。问题在于文档。
你看那时候Linux 不是像今天这样直观,用户友好的系统。 你必须读很多东西。 你必须知道你的 CRT 显示器的频率以及拨号调制解调器的噪音来龙去脉,以及其他数以百计的事情。 我很快就意识到我需要花一些时间来掌握目录的组织方式以及 /etc不用于其他文件/usr不是用于用户文件和 /*bin * 不是垃圾桶)的意思。
本教程将帮助您加快速度,比我做得更快。
### 结构
从终端窗口探索 Linux 文件系统是有道理的,这并不是因为作者是一个脾气暴躁的老人,并且对新孩子和他们漂亮的图形工具不以为然——尽管有一些事实——但是因为终端,尽管是文本——只有更好的工具才能显示 Linux 目录树的结构。
事实上,这是您将安装的第一个工具的名称:*tree*。如果你正在使用 Ubuntu 或 Debian ,你可以:
```
sudo apt install tree
```
在 Red Hat 或 Fedora :
```
sudo dnf install tree
```
对于 SUSE/openSUSE 可以使用 `zypper`
```
sudo zypper install tree
```
对于使用 Arch ManjaroAntergos等等使用
```
sudo pacman -S tree
```
...等等。
一旦安装好,在终端窗口运行 *tree* 命令:
```
tree /
```
上述指令中的 `/` 指的是根目录。系统中的其他目录都是从根目录分支而出,当你运行 `tree` 命令,并且告诉它从根目录开始,那么你就可以看到整个目录树,系统中的所有目录及其子目录,还有他们的文件。
如果您已经使用您的系统有一段时间了这可能需要一段时间因为即使您自己还没有生成很多文件Linux系统及其应用程序总是记录、缓存和存储临时文件。文件系统中的条目数量可以快速增长。
不过,不要感到不知所措。 相反,试试这个:
```
tree -L 1 /
```
您应该看到如图 1 所示。
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/f01_tree01.png?itok=aGKzzC0C)
上面的指令可以翻译为“只显示以 /(根目录) 开头的目录树的第一级”。 `-L` 选项告诉树你想看到多少层目录。
大多数 Linux 发行版都会向您显示与您在上图中看到的相同或非常类似的结构。 这意味着,即使你现在感到困惑,掌握这一点,你将掌握大部分(如果不是全部的话)整个世界的 Linux 文件系统。
为了让您开始走上掌握之路,让我们看看每个目录的用途。 当我们查看每一个目录的时候,你可以使用 *ls* 来查看他们的内容。
### 目录
从上到下,你所看到的目录如下
#### _/bin_
*/bin* 目录是包含一些二进制文件的目录,即可以运行的一些应用程序。 你会在这个目录中找到上面提到的 *ls* 程序,以及用于新建和删除文件和目录,移动它们基本工具。还有其他一些程序,等等, 文件系统树的其他部分有更多的 *bin* 目录,但我们将在一分钟内讨论这些目录。
#### _/boot_
*/boot* 目录包含启动系统所需的文件。 我必须要说吗? 好吧,我会说:**不要动它** 如果你在这里弄乱了其中一个文件,你可能无法运行你的 Linux修复破坏的系统是非常痛苦的一件事。 另一方面,不要太担心无意中破坏系统:您必须拥有超级用户权限才能执行此操作。
#### _/dev_
*/dev* 目录包含设备文件。 其中许多是在启动时或甚至在运行时生成的。 例如,如果您将新的网络摄像头或 USB 随身碟连接到您的机器中,则会自动弹出一个新的设备条目。
#### _/etc_
*/etc* 的目录名称会让人变得非常的困惑。*/etc* 从最早的 Unixes 系统中得到它的名称,它的字面意思是 “et cetera” ,因为它是系统文件管理员不确定在哪里放置文件的垃圾场。
现在,说 */etc* 是“要配置的所有内容”更为恰当,因为它包含大部分(如果不是全部的话)系统配置文件。 例如,包含系统名称,用户及其密码,网络上计算机名称以及硬盘上分区的安装位置和时间的文件都在这里。 再说一遍,如果你是 Linux 的新手,最好是不要在这里接触太多,直到你对系统的工作有更好的理解。
#### _/home_
*/home* 是您可以找到用户个人目录的地方。 在我的情况下,*/home* 下有两个目录:*/home/paul*,其中包含我所有的东西;另外一个目录是 */home/guest* 目录,以防有人需要使用我的电脑。
#### _/lib_
*/lib* 是库文件所在的地方。 库是包含应用程序可以使用的代码文件。 它们包含应用程序用于在桌面上绘制窗口,控制外围设备或将文件发送到硬盘的代码片段。
在文件系统周围散布着更多的 *lib* 目录,但是这个直接挂载在 / 的 */lib* 目录是特殊的,除此之外,它包含了所有重要的内核模块。 内核模块是使您的视频卡声卡WiFi打印机等工作的驱动程序。
#### _/media_
*/media* 目录中,当您插入外部存储并试图访问它时,将自动挂载它。与此列表中的大多数其他项目不同,*/media* 并不追溯到 1970 年代,主要是因为当计算机正在运行而动态地插入和检测存储( U 盘, USB 硬盘SD卡外部 SSD 等),这是最近才发生的事。
#### _/mnt_
然而,*/mnt* 目录是一些过去的残余。这是您手动挂载存储设备或分区的地方。现在不常用了。
#### _/opt_
*/opt* 目录通常是您编译软件(即,您从源代码构建,并不是从您的系统的软件库中安装软件)的地方。应用程序最终会出现在 */opt/bin* 目录,库会在 */opt/lib* 目录中出现。
稍微的题外话:应用程序和库的另一个地方是 */usr/local*,在这里安装软件时,也会有 */usr/local/bin**/usr/local/lib* 目录。开发人员如何配置文件来控制编译和安装过程,这就决定了软件安装到哪个地方。
#### _/proc_
*/proc*,就像 */dev* 是一个虚拟目录。它包含有关您的计算机的信息,例如关于您的 CPU 和您的 Linux 系统正在运行的内核的信息。与 */dev* 一样,文件和目录是在计算机启动或运行时生成的,因为您的系统正在运行且会发生变化。
#### _/root_
*/root* 是系统的超级用户(也称为“管理员”)的主目录。 它与其他用户的主目录是分开的,因为您打算去动它。 所以把自己的东西放在你自己的目录中,伙计们。
#### _/run_
*/run* 是另一个新目录。系统进程出于自己的邪恶原因使用它来存储临时数据。这是另一个不要动它的文件夹例子。
#### _/sbin_
*/sbin* 与 */bin* 类似,但它包含的应用程序只有超级用户(即首字母的 s )才需要。您可以使用 `sudo` 命令使用这些应用程序,该命令暂时允许您在许多发行版上拥有超级用户权限。*/sbin* 目录通常包含可以安装、删除和格式化内容的工具。你可以想象,如果你使用不当,这些指令中有一些是致命的,所以要小心处理。
#### _/usr_
*/usr* 目录是在 UNIX 早期用户的主目录被保留的地方。然而,正如我们上面看到的,现在 */home* 是用户保存他们的东西的地方。如今,*/usr* 包含了大量目录,而这些目录又包含了应用程序、库、文档、壁纸、图标和许多其他需要应用程序和服务共享的内容。
您还可以在 */usr* 目录下找到 */bin**/sbin**/lib* 目录,他们与挂载到根目录下的那些有什么区别呢?现在的区别不是很大。在早期,/bin 目录(挂载在根目录下的)只会包含一些基本的命令,例如 *ls**mv* 和 *rm* ;这是一些在安装系统的时候就会预装的一些命令,用于维护系统的一个基本的命令。 而 */usr/bin* 目录则包含了用户自己安装和用于工作的软件,例如文字处理器,浏览器和一些其他的软件。
但是许多现代的 Linux 发行版只是把所有的东西都放到 */usr/bin* 中,并让 */bin* 指向 */usr/bin*以防彻底删除它会破坏某些东西。因此Debian、Ubuntu 和 Mint 仍然保持 */bin**/usr/bin* (和 */sbin**/usr/sbin* )分离;其他的,比如 Arch 和它衍生版,只是有一个二进制的“真实”目录,*/usr/bin*,其余的或 *bin 是指向 */usr/ bin* 的“假”目录。
#### _/srv_
*/srv* 目录包含服务器的数据。 如果您正在 Linux 机器上运行 Web 服务器,您网站的 HTML文件将放到 */srv/http*(或 */srv/www*)。 如果您正在运行 FTP 服务器,则您的文件将放到 */srv/ftp*
#### _/sys_
*/sys* 是另一个类似 */proc**/dev* 的虚拟目录,它还包含连接到计算机的设备的信息。
在某些情况下,您还可以操纵这些设备。 例如,我可以通过修改存储在 /sys/devices/pci0000:00/0000:00:02.0/drm/card1/card1-eDP-1/intel_backlight/brightness 中的值来更改笔记本电脑屏幕的亮度(在你的机器上你可能会有不同的文件)。但要做到这一点,你必须成为超级用户。原因是,与许多其他虚拟目录一样,在 */sys* 中打乱内容和文件可能是危险的,您可能会破坏系统。直到你确信你知道你在做什么。否则不要动它。
#### _/tmp_
*/tmp* 包含临时文件,通常由正在运行的应用程序放置。文件和目录通常(并非总是)包含应用程序现在不需要但以后可能需要的数据。为了释放内存,它被存储在这里。
您还可以使用 */tmp* 来存储您自己的临时文件—— /tmp 是挂载到根目录下您可以在不成为超级用户的情况下与它进行实际交互少数目录之一。问题是,应用程序有时不会回来检索和删除文件和目录,而且 */tmp* 常常会耗尽硬盘上的空间,使其塞满垃圾。在本系列的后面,我们将看到如何清理它。
#### _/var_
*/var* 最初被命名是因为它的内容被认为是可变的,因为它经常变化。今天,它有点用词不当,因为还有许多其他目录也包含频繁更改的数据,特别是我们上面看到的虚拟目录。
不管怎样,*/var* 目录包含了类似 */var/log* 子目录的日志文件。日志是记录系统中发生的事件的文件。如果内核中出现了什么问题,它将被记录到 */var/log* 文件中;如果有人试图从外部侵入您的计算机,您的防火墙也将记录尝试。它还包含用于任务的假脱机程序。这些“任务”可以是您在不得不等待时发送给共享打印机的任务,因为另一个用户正在打印一个长文档,或者是等待发送给系统上的用户的邮件。
您的系统可能还有一些我们上面没有提到的目录。例如,在屏幕截图中,有一个 */snap* 目录。这是因为这张截图是在Ubuntu系统上截取的。Ubuntu 最近将 [snap][1] 包作为一种分发软件的方式。*/snap* 目录包含所有文件和从 snaps 安装的软件。
### 更深入的研究
这里仅仅谈了根目录,但是许多子目录都指向它们自己的一组文件和子目录。图 2 给出了基本文件系统的总体概念(图片是在 Paul Gardner 的 CC BY-SA 许可下提供的),[Wikipedia 对每个目录的用途进行了总结][2]。
![filesystem][4]
图 2标准 Unix 文件系统
[许可][5]
Paul Gardner
要自行探索文件系统,请使用 `cd` 命令:
```
cd
```
将带您到您所选择的目录( *cd* 代表更改目录)。
如果你不知道你在哪儿,
```
pwd
```
*pwd* 会告诉你,你到底在哪里,( *pwd* 代表打印工作目录 ),同时
```
cd
```
*cd* 命令在没有任何选项或者参数的时候,将会直接带你到你自己的主目录,这是一个安全舒适的地方。
最后,
```
cd ..
```
*cd ..* 将会带你到上一层目录,会使你更加接近根目录,如果你在 */usr/share/wallpapers* 目录,然后你执行 `cd ..` 命令,你将会跳转到 `/usr/share` 目录
要查看目录里有什么内容,使用
```
ls
```
或这简单的使用
```
l
```
列出你所在目录的内容。
当然,您总是可以使用 `tree` 来获得目录中内容的概述。在 */usr/share* 上试试——里面有很多有趣的东西。
### 总结
尽管 Linux 发行版之间存在细微差别,但它们的文件系统的布局非常相似。 你可以这么说:一旦你认识一个,你就会知道他们。 知道文件系统的最好方法就是探索它。 因此,伴随 `tree` `ls` 和 `cd` 进入未知的领域吧。
您不能仅仅通过查看文件系统就破坏文件系统,因此请从一个目录移动到另一个目录并进行浏览。 很快你就会发现 Linux 文件系统及其布局的确很有意义,并且你会直观地知道在哪里可以找到应用程序,文档和其他资源。
通过 Linux 基金会和 edX 免费的 “[Linux入门][6]” 课程了解更多有关 Linux 的信息。
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/learn/intro-to-linux/2018/4/linux-filesystem-explained
作者:[PAUL BROWN][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[amwps290](https://github.com/amwps290)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.linux.com/users/bro66
[1]:https://www.ubuntu.com/desktop/snappy
[2]:https://en.wikipedia.org/wiki/Unix_filesystem#Conventional_directory_layout
[3]:https://www.linux.com/files/images/standard-unix-filesystem-hierarchypng
[4]:https://www.linux.com/sites/lcom/files/styles/rendered_file/public/standard-unix-filesystem-hierarchy.png?itok=CVqmyk6P "filesystem"
[5]:https://www.linux.com/licenses/category/used-permission
[6]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux

View File

@ -1,201 +0,0 @@
# 装载/卸载 Linux 内核模块
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_computer_development_programming.png?itok=4OM29-82)
本文来自 Manning 出版的 [Linux in Action][1] 的第 15 章。
Linux 使用内核模块管理硬件外设。 我们来看看它是如何工作的。
运行中的 Linux 内核是您不希望破坏的东西之一。毕竟,内核是驱动计算机所做的一切的软件。考虑到在一个运行的系统上必须同时管理诸多细节,最好能让内核尽可能的减少分心,专心的完成它的工作。但是,如果在不重新启动整个系统的情况下,对计算环境进行任何微小的更改都是不可能的,那么插入一个新的网络摄像头或打印机可能会对您的工作流程造成严重的破坏。每次添加设备时都必须重新启动,以使系统识别它,这效率很低。
为了在稳定性和可用性之间建立一个有效的平衡Linux 将内核隔离,但是允许您通过可加载内核模块 (LKMs) 实时添加特定的功能。如下图所示,您可以将模块视为软件的一部分,它告诉内核在哪里找到一个设备以及如何使用它。反过来,内核使设备对用户和进程可用,并监视其操作。
![Kernel modules][3]
内核模块充当设备和 Linux 内核之间的转换器。
没有什么能够阻止你编写你自己的模块来完全按照你喜欢的方式来支持一个设备,但是为什么呢? Linux 模块库已经非常强大,通常不需要自己去实现一个模块。 而绝大多数时候Linux 会自动加载新设备的模块,而您甚至不知道它。
不过,有时候,出于某种原因,它本身并不会运行。 (你不想让那个招聘经理不耐烦地等待你的笑脸加入视频会议面试时间太长。)为了帮助你解决问题,你需要更多地了解内核模块,特别是 ,如何找到运行你的外设的实际模块,然后如何手动激活它。
### 查找内核模块
按照公认的约定,模块是位于 `/lib/modules/` 目录下的具有 .ko内核对象扩展名的文件。 然而,在你一直导航到这些文件之前,你可能不得不做出选择。 因为在引导时你需要从加载发行版列表中选择一个选项,所以支持您选择的特定软件(包括内核模块)必须存在某处。 那么,`/lib/modules/` 就是其中之一。 你会发现目录里充满了每个可用的 Linux 内核版本的模块; 例如:
```
$ ls /lib/modules
4.4.0-101-generic
4.4.0-103-generic
4.4.0-104-generic
```
在我的电脑上运行的内核是版本号最高的版本4.4.0-104-generic但不能保证这对你来说是一样的内核经常更新。 如果您将要在一个运行的系统上对你想要使用的模块做一些工作的话,则需要确保您拥有正确的目录树。
`uname -r` `-r` 指定了系统信息中的内核版本号):
```
$ uname -r
4.4.0-104-generic
```
好消息:有一个可靠的窍门。 不通过名称来识别目录,并希望能够找到正确的目录,而是使用始终指向使用的内核名称的系统变量。 您可以使用(从系统信息中指定通常显示的内核版本号)来调用该变量:
通过这些信息,您可以使用称为命令替换的过程将 `uname` 并入您的文件系统引用中。 例如,要导航到正确的目录,您需要将其添加到 `/lib/modules` 。 要告诉 Linux “uname” 不是文件系统的位置,请将 `uname` 部分用反引号括起来,如下所示:
```
$ ls /lib/modules/`uname -r`
build   modules.alias        modules.dep      modules.softdep
initrd  modules.alias.bin    modules.dep.bin  modules.symbols
kernel  modules.builtin      modules.devname  modules.symbols.bin
misc    modules.builtin.bin  modules.order    vdso
```
你可以在 `kernel/` 目录下的子目录中找到大部分模块。 花几分钟时间浏览这些目录,了解事物的排列方式和可用内容。 这些文件名通常会让你知道你在看什么。
```
$ ls /lib/modules/`uname -r`/kernel
arch  crypto  drivers  fs  kernel  lib  mm
net  sound  ubuntu  virt  zfs
```
这是查找内核模块的一种方法; 实际上,这是一种快速的方式。 但这不是唯一的方法。 如果你想获得完整的集合,你可以使用 `lsmod` 列出所有当前加载的模块以及一些基本信息。 这个截断输出的第一列(在这里列出的太多了)是模块名称,后面是文件大小和数量,然后是每个模块的名称:
```
$ lsmod
[...]
vboxdrv          454656  3 vboxnetadp,vboxnetflt,vboxpci
rt2x00usb        24576  1 rt2800usb
rt2800lib        94208  1 rt2800usb
[...]
```
到底有多少?好吧,我们再运行一次 `lsmod ` ,但是这一次将输出管道输送到 `wc -l` 看一下一共多少行:
```
$ lsmod | wc -l
113
```
那些是加载的模块。 总共有多少个? 运行 `modprobe -c` 并计算这些行将给我们这个数字:
```
$ modprobe -c | wc -l
33350
```
有33,350个可用模块 看起来好像有人多年来一直在努力为我们提供软件来驱动我们的物理设备。
注意:在某些系统中,您可能会遇到自定义的模块,这些模块在 `/etc/modules` 文件中使用其唯一条目进行引用,也可以作为保存到 `/etc/modules-load.d/` 的配置文件。这些模块很可能是本地开发项目的产物,可能涉及前沿实验。不管怎样,知道你在看什么是好事。
这就是你如何找到模块。 如果出于某种原因,它不会自行运行,您的下一个工作就是弄清楚如何手动加载非活动模块。
### 手动加载内核模块
在加载内核模块之前,逻辑上您必须确认它的存在。在这之前,你需要知道它叫什么。要做到这一点,有时需要同样的魔法和运气以及在线文档作者的辛勤工作的帮助。
我将通过描述一段时间前遇到的问题来说明这个过程。在一个晴朗的日子里,出于某种原因,笔记本电脑上的 WiFi 接口停止工作了。就这样。也许是软件升级把它搞砸了。谁知道呢?我运行了 `lshw -c network` ,得到了这个非常奇怪的信息:
```
network UNCLAIMED
    AR9485 Wireless Network Adapter
```
Linux 识别到了接口Atheros AR9485但将其列为未声明。 那么,正如他们所说的那样,“当情况变得严峻时,就会在互联网上进行艰难的搜索。” 我搜索了一下 atheros ar9 linux 模块,在浏览了 5 页甚至是 10 年前的页面后,它们建议自己写模块或者放弃,然后我终于发现(使用 Ubuntu 16.04 至少)存在一个工作模块。 它的名字是 ath9k 。
是的! 这场战斗胜券在握! 向内核添加模块比听起来容易得多。 要仔细检查它是否可用,可以针对模块的目录树运行 `find`,指定 `-type f` 来告诉 Linux 您正在查找文件,然后将字符串 `ath9k` 和星号一起添加以包含所有以你的字符串打头的文件:
```
$ find /lib/modules/$(uname -r) -type f -name ath9k*
/lib/modules/4.4.0-97-generic/kernel/drivers/net/wireless/ath/ath9k/ath9k_common.ko
/lib/modules/4.4.0-97-generic/kernel/drivers/net/wireless/ath/ath9k/ath9k.ko
/lib/modules/4.4.0-97-generic/kernel/drivers/net/wireless/ath/ath9k/ath9k_htc.ko
/lib/modules/4.4.0-97-generic/kernel/drivers/net/wireless/ath/ath9k/ath9k_hw.ko
```
再一步,加载模块:
```
# modprobe ath9k
```
就是这样。没有重新启动。没有大惊小怪。
这里还有一个示例,向您展示如何使用已经崩溃的运行模块。曾经有一段时间,我使用罗技网络摄像头和一个特定的软件会使摄像头在下次系统启动前无法被任何其他程序访问。有时我需要在不同的应用程序中打开相机,但没有时间关机重新启动。(我运行了很多应用程序,在引导之后将它们全部准备好需要一些时间。)
由于这个模块可能是运行的,所以使用 `lsmod` 来搜索视频这个词应该给我一个关于相关模块名称的提示。 实际上,它比提示更好:用 video 这个词描述的唯一模块是 uvcvideo如下所示
```
$ lsmod | grep video
uvcvideo               90112  0
videobuf2_vmalloc      16384  1 uvcvideo
videobuf2_v4l2         28672  1 uvcvideo
videobuf2_core         36864  2 uvcvideo,videobuf2_v4l2
videodev              176128  4 uvcvideo,v4l2_common,videobuf2_core,videobuf2_v4l2
media                  24576  2 uvcvideo,videodev
```
有可能是我自己的操作导致了崩溃,我想我可以挖掘更深一点,看看我能否以正确的方式解决问题。 但你知道它是如何的; 有时你不关心理论,只想让设备工作。 所以我用 `rmmod` 杀死了 `uvcvideo` 模块,然后用 `modprobe` 重新启动它,一切都好:
```
# rmmod uvcvideo
# modprobe uvcvideo
```
再一次:不重新启动。没有其他的后续影响。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/5/how-load-or-unload-linux-kernel-module
作者:[David Clinto][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[amwps290](https://github.com/amwps290)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://opensource.com/users/dbclinton
[1]:https://www.manning.com/books/linux-in-action?a_aid=bootstrap-it&amp;a_bid=4ca15fc9&amp;chan=opensource
[2]:/file/397906
[3]:https://opensource.com/sites/default/files/uploads/kernels.png "Kernel modules"

View File

@ -1,120 +0,0 @@
Vim-plug极简 Vim 插件管理器
======
![](https://www.ostechnix.com/wp-content/uploads/2018/06/vim-plug-720x340.png)
当没有插件管理器时Vim 用户必须手动下载 tarball 包的插件并将它们解压到 **~/.vim** 目录中。在少量插件的时候可以。当他们安装更多的插件时,就会变得一团糟。所有插件文件分散在单个目录中,用户无法找到哪个文件属于哪个插件。此外,他们无法找到他们应该删除哪个文件来卸载插件。这时 Vim 插件管理器就可以派上用场。插件管理器将安装插件的文件保存在单独的目录中,因此管理所有插件变得非常容易。我们几个月前已经写了关于 [**Vundle**][1] 的文章。今天,我们将看到又一个名为 **“Vim-plug”** 的 Vim 插件管理器。
Vim-plug 是一个免费、开源、速度非常快的、极简的 vim 插件管理器。它可以并行安装或更新插件。你还可以回滚更新。它创建浅层克隆以最小化磁盘空间使用和下载时间。它支持按需加载插件以加快启动时间。其他值得注意的特性是分支/标签/提交支持、post-update hook、支持外部管理的插件等。
### Vim-plug一个极简的 Vim 插件管理器
#### **安装**
安装和使用起来非常容易。你只需打开终端并运行以下命令:
```
$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
```
Neovim 用户可以使用以下命令安装 Vim-plug
```
$ curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
```
#### 用法
**安装插件**
要安装插件,你必须如下所示首先在 Vim 配置文件中声明它们。一般 Vim 的配置文件是 **~/.vimrc**Neovim 的配置文件是 **~/.config/nvim/init.vim**。请记住,当你在配置文件中声明插件时,列表应该以 **call plug#begin(PLUGIN_DIRECTORY)** 开始,并以 **plug#end()** 结束。
例如,我们安装 “lightline.vim” 插件。为此,请在 **~/.vimrc** 的顶部添加以下行。
```
call plug#begin('~/.vim/plugged')
Plug 'itchyny/lightline.vim'
call plug#end()
```
在 vim 配置文件中添加上面的行后,通过输入以下命令重新加载:
```
:source ~/.vimrc
```
或者,只需重新加载 Vim 编辑器。
现在,打开 vim 编辑器:
```
$ vim
```
使用以下命令检查状态:
```
:PlugStatus
```
然后输入下面的命令,然后按 ENTER 键安装之前在配置文件中声明的插件。
```
:PlugInstall
```
**更新插件**
要更新插件,请运行:
```
:PlugUpdate
```
更新插件后,按下 **d** 查看更改。或者,你可以之后输入 **:PlugDiff**。
**审查插件**
有时,更新的插件可能有新的 bug 或无法正常工作。要解决这个问题,你可以简单地回滚有问题的插件。输入 **:PlugDiff** 命令,然后按 ENTER 键查看上次 **:PlugUpdate**的更改,并在每个段落上按 **X** 将每个插件回滚到更新前的前一个状态。
**删除插件**
删除一个插件删除或注释掉你以前在你的 vim 配置文件中添加的 **plug** 命令。然后,运行 **:source ~/.vimrc** 或重启 Vim 编辑器。最后,运行以下命令卸载插件:
```
:PlugClean
```
该命令将删除 vim 配置文件中所有未声明的插件。
**升级 Vim-plug**
要升级vim-plug本身请输入
```
:PlugUpgrade
```
如你所见,使用 Vim-plug 管理插件并不难。它简化了插件管理。现在去找出你最喜欢的插件并使用 Vim-plug 来安装它们。
**建议阅读:**
就是这些了。我将很快在这里发布另一个有趣的话题。在此之前,请继续关注 OSTechNix。
干杯!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/vim-plug-a-minimalist-vim-plugin-manager/
作者:[SK][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.ostechnix.com/author/sk/
[1]:https://www.ostechnix.com/manage-vim-plugins-using-vundle-linux/