mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-27 02:30:10 +08:00
commit
43cf586b9c
published
20140403 Easily Install Android Studio in Ubuntu And Linux Mint.md20141106 System Calls Make the World Go Round.md20170628 Notes on BPF and eBPF.md20171129 5 best practices for getting started with DevOps.md20171213 Will DevOps steal my job-.md20171220 Containers without Docker at Red Hat.md20180208 Python Global, Local and Nonlocal variables (With Examples).md20180220 How slowing down made me a better leader.md20180314 How to measure particulate matter with a Raspberry Pi.md20180317 How To Edit Multiple Files Using Vim Editor.md20180325 Could we run Python 2 and Python 3 code in the same VM with no code changes.md20180326 4 command line note-taking applications for Linux.md20180407 The Shuf Command Tutorial With Examples For Beginners.md20180409 A Kernel Module That Forcibly Shutdown Your System.md20180412 BUILDING GO PROJECTS WITH DOCKER ON GITLAB CI.md20180412 How To Check User Created Date On Linux.md20180413 Finding what you-re looking for on Linux.md20180420 How to start developing on Java in Fedora.md
sources
talk
20180128 Being open about data privacy.md20180206 Why Linux is better than Windows or macOS for security.md20180328 College student reflects on getting started in open source.md20180412 Easily Run And Integrate AppImage Files With AppImageLauncher.md
tech
20171221 A Commandline Food Recipes Manager.md20180327 How to build a digital pinhole camera with a Raspberry Pi.md20180425 Enhance your Python with an interactive shell.md20180426 Continuous Profiling of Go programs.md20180427 How to Compile a Linux Kernel.md20180430 Easily Search And Install Google Web Fonts In Linux.md20180430 Reset a lost root password in under 5 minutes.md20180501 How To Use Vim Editor To Input Text Anywhere.md20180503 How to build container images with Buildah.md20180504 A Beginners Guide To Cron Jobs.md20180507 4 Firefox extensions to install now.md20180507 A reading list for Linux and open source fans.md20180507 How To Improve Application Startup Time In Linux.md20180507 Systemd Services- Beyond Starting and Stopping.md20180509 4MLinux Revives Your Older Computer [Review].md
translated
talk
tech
20141106 System Calls Make the World Go Round.md20170213 Getting Started with Taskwarrior.md20180208 Python Global, Local and Nonlocal variables (With Examples).md20180327 How to build a digital pinhole camera with a Raspberry Pi.md20180413 Finding what you-re looking for on Linux.md20180425 Enhance your Python with an interactive shell.md20180430 Easily Search And Install Google Web Fonts In Linux.md20180430 Reset a lost root password in under 5 minutes.md20180501 How To Use Vim Editor To Input Text Anywhere.md20180502 zzupdate - Single Command To Upgrade Ubuntu.md20180503 How to build container images with Buildah.md
@ -1,5 +1,6 @@
|
||||
在 Ubuntu 和 Linux Mint 中轻松安装 Android Studio
|
||||
======
|
||||
|
||||
[Android Studio][1] 是谷歌自己的 Android 开发 IDE,是带 ADT 插件的 Eclipse 的不错替代品。Android Studio 可以通过源代码安装,但在这篇文章中,我们将看到**如何在 Ubuntu 18.04、16.04 和相应的 Linux Mint 变体**中安装 Android Studio。
|
||||
|
||||
在继续安装 Android Studio 之前,请确保你已经[在 Ubuntu 中安装了 Java][2]。
|
||||
@ -13,28 +14,31 @@
|
||||
![Install Android Studio in Ubuntu from Software Center][4]
|
||||
|
||||
如果你在软件中心安装 Android Studio 时看到错误,则可以使用[ Snap 命令][5] 安装 Android Studio。
|
||||
|
||||
```
|
||||
sudo snap install android-studio --classic
|
||||
|
||||
```
|
||||
|
||||
非常简单!
|
||||
|
||||
### 另一种方式 1:在 Ubuntu 中使用 umake 安装 Android Studio
|
||||
|
||||
你也可以使用 Ubuntu Developer Tools Center,现在称为 [Ubuntu Make][6],轻松安装 Android Studio。Ubuntu Make 提供了一个命令行工具来安装各种开发工具、IDE等。Ubuntu Make 在 Ubuntu 仓库中就有。
|
||||
你也可以使用 Ubuntu Developer Tools Center,现在称为 [Ubuntu Make][6],轻松安装 Android Studio。Ubuntu Make 提供了一个命令行工具来安装各种开发工具和 IDE 等。Ubuntu Make 在 Ubuntu 仓库中就有。
|
||||
|
||||
要安装 Ubuntu Make,请在终端中使用以下命令:
|
||||
|
||||
`sudo apt-get install ubuntu-make`
|
||||
```
|
||||
sudo apt-get install ubuntu-make
|
||||
```
|
||||
|
||||
安装 Ubuntu Make 后,请使用以下命令在 Ubuntu 中安装 Android Studio:
|
||||
|
||||
```
|
||||
umake android
|
||||
|
||||
```
|
||||
|
||||
在安装过程中它会给你的几个选项。我认为你可以处理。如果你决定卸载 Android Studio,则可以按照以下方式使用相同的 umake 工具:
|
||||
|
||||
```
|
||||
umake android --remove
|
||||
|
||||
@ -45,11 +49,11 @@ umake android --remove
|
||||
感谢 [Paolo Ratolo][7],我们有一个 PPA,可用于 Ubuntu 16.04、14.04、Linux Mint 和其他基于 Ubuntu 的发行版中轻松安装 Android Studio。请注意,它将下载大约 650MB 的数据。请注意你的互联网连接以及数据费用(如果有的话)。
|
||||
|
||||
打开一个终端并使用以下命令:
|
||||
|
||||
```
|
||||
sudo apt-add-repository ppa:paolorotolo/android-studio
|
||||
sudo apt-get update
|
||||
sudo apt-get install android-studio
|
||||
|
||||
```
|
||||
|
||||
这不容易吗?虽然从源代码安装程序很有趣,但拥有这样的 PPA 总是不错的。我们看到了如何安装 Android Studio,现在来看看如何卸载它。
|
||||
@ -57,17 +61,16 @@ sudo apt-get install android-studio
|
||||
### 卸载 Android Studio:
|
||||
|
||||
如果你还没有安装 PPA Purge:
|
||||
|
||||
```
|
||||
sudo apt-get install ppa-purge
|
||||
|
||||
```
|
||||
|
||||
现在使用 PPA Purge 来清除已安装的 PPA:
|
||||
|
||||
```
|
||||
sudo apt-get remove android-studio
|
||||
|
||||
sudo ppa-purge ppa:paolorotolo/android-studio
|
||||
|
||||
```
|
||||
|
||||
就是这些了。我希望这能够帮助你**在 Ubuntu 和 Linux Mint 上安装 Android Studio**。在运行 Android Studio 之前,请确保[在 Ubuntu 中安装了Java][8]。在类似的文章中,我建议你阅读[如何安装和配置 Ubuntu SDK ][9]和[如何在 Ubuntu 中轻松安装 Microsoft Visual Studio][10]。
|
||||
@ -81,7 +84,7 @@ via: https://itsfoss.com/install-android-studio-ubuntu-linux/
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
197
published/20141106 System Calls Make the World Go Round.md
Normal file
197
published/20141106 System Calls Make the World Go Round.md
Normal file
@ -0,0 +1,197 @@
|
||||
系统调用,让世界转起来!
|
||||
=====================
|
||||
|
||||
|
||||
我其实不想将它分解开给你看,用户应用程序其实就是一个可怜的<ruby>瓮中大脑<rt>brain in a vat</rt></ruby>:
|
||||
|
||||

|
||||
|
||||
它与外部世界的*每个*交流都要在内核的帮助下通过**系统调用**才能完成。一个应用程序要想保存一个文件、写到终端、或者打开一个 TCP 连接,内核都要参与。应用程序是被内核高度怀疑的:认为它到处充斥着 bug,甚至是个充满邪恶想法的脑子。
|
||||
|
||||
这些系统调用是从一个应用程序到内核的函数调用。出于安全考虑,它们使用了特定的机制,实际上你只是调用了内核的 API。“<ruby>系统调用<rt>system call</rt></ruby>”这个术语指的是调用由内核提供的特定功能(比如,系统调用 `open()`)或者是调用途径。你也可以简称为:**syscall**。
|
||||
|
||||
这篇文章讲解系统调用,系统调用与调用一个库有何区别,以及在操作系统/应用程序接口上的刺探工具。如果彻底了解了应用程序借助操作系统发生的哪些事情,那么就可以将一个不可能解决的问题转变成一个快速而有趣的难题。
|
||||
|
||||
那么,下图是一个运行着的应用程序,一个用户进程:
|
||||
|
||||

|
||||
|
||||
它有一个私有的 [虚拟地址空间][2]—— 它自己的内存沙箱。整个系统都在它的地址空间中(即上面比喻的那个“瓮”),程序的二进制文件加上它所使用的库全部都 [被映射到内存中][3]。内核自身也映射为地址空间的一部分。
|
||||
|
||||
下面是我们程序 `pid` 的代码,它通过 [getpid(2)][4] 直接获取了其进程 id:
|
||||
|
||||
|
||||
```
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
pid_t p = getpid();
|
||||
printf("%d\n", p);
|
||||
}
|
||||
```
|
||||
|
||||
*pid.c [download][1]*
|
||||
|
||||
|
||||
在 Linux 中,一个进程并不是一出生就知道它的 PID。要想知道它的 PID,它必须去询问内核,因此,这个询问请求也是一个系统调用:
|
||||
|
||||

|
||||
|
||||
它的第一步是开始于调用 C 库的 [getpid()][5],它是系统调用的一个*封装*。当你调用一些函数时,比如,`open(2)`、`read(2)` 之类,你是在调用这些封装。其实,对于大多数编程语言在这一块的原生方法,最终都是在 libc 中完成的。
|
||||
|
||||
封装为这些基本的操作系统 API 提供了方便,这样可以保持内核的简洁。*所有的内核代码*运行在特权模式下,有 bug 的内核代码行将会产生致命的后果。能在用户模式下做的任何事情都应该在用户模式中完成。由库来提供友好的方法和想要的参数处理,像 `printf(3)` 这样。
|
||||
|
||||
我们拿一个 web API 进行比较,内核的封装方式可以类比为构建一个尽可能简单的 HTTP 接口去提供服务,然后提供特定语言的库及辅助方法。或者也可能有一些缓存,这就是 libc 的 `getpid()` 所做的:首次调用时,它真实地去执行了一个系统调用,然后,它缓存了 PID,这样就可以避免后续调用时的系统调用开销。
|
||||
|
||||
一旦封装完成,它做的第一件事就是进入了<ruby>~~超空间~~<rt>hyperspace</rt></ruby>:内核。这种转换机制因处理器架构设计不同而不同。在 Intel 处理器中,参数和 [系统调用号][6] 是 [加载到寄存器中的][7],然后,运行一个 [指令][8] 将 CPU 置于 [特权模式][9] 中,并立即将控制权转移到内核中的全局系统调用 [入口][10]。如果你对这些细节感兴趣,David Drysdale 在 LWN 上有两篇非常好的文章([其一][11],[其二][12])。
|
||||
|
||||
内核然后使用这个系统调用号作为进入 [`sys_call_table`][14] 的一个 [索引][13],它是一个函数指针到每个系统调用实现的数组。在这里,调用了 [`sys_getpid`][15]:
|
||||
|
||||

|
||||
|
||||
在 Linux 中,系统调用大多数都实现为架构无关的 C 函数,有时候这样做 [很琐碎][16],但是通过内核优秀的设计,系统调用机制被严格隔离。它们是工作在一般数据结构中的普通代码。嗯,除了*完全偏执*的参数校验以外。
|
||||
|
||||
一旦它们的工作完成,它们就会正常*返回*,然后,架构特定的代码会接手转回到用户模式,封装将在那里继续做一些后续处理工作。在我们的例子中,[getpid(2)][17] 现在缓存了由内核返回的 PID。如果内核返回了一个错误,另外的封装可以去设置全局 `errno` 变量。这些细节可以让你知道 GNU 是怎么处理的。
|
||||
|
||||
如果你想要原生的调用,glibc 提供了 [syscall(2)][18] 函数,它可以不通过封装来产生一个系统调用。你也可以通过它来做一个你自己的封装。这对一个 C 库来说,既不神奇,也不特殊。
|
||||
|
||||
这种系统调用的设计影响是很深远的。我们从一个非常有用的 [strace(1)][19] 开始,这个工具可以用来监视 Linux 进程的系统调用(在 Mac 上,参见 [dtruss(1m)][20] 和神奇的 [dtrace][21];在 Windows 中,参见 [sysinternals][22])。这是对 `pid` 程序的跟踪:
|
||||
|
||||
```
|
||||
~/code/x86-os$ strace ./pid
|
||||
|
||||
execve("./pid", ["./pid"], [/* 20 vars */]) = 0
|
||||
brk(0) = 0x9aa0000
|
||||
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
|
||||
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7767000
|
||||
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
|
||||
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
|
||||
fstat64(3, {st_mode=S_IFREG|0644, st_size=18056, ...}) = 0
|
||||
mmap2(NULL, 18056, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7762000
|
||||
close(3) = 0
|
||||
|
||||
[...snip...]
|
||||
|
||||
getpid() = 14678
|
||||
fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 1), ...}) = 0
|
||||
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7766000
|
||||
write(1, "14678\n", 614678
|
||||
) = 6
|
||||
exit_group(6) = ?
|
||||
```
|
||||
|
||||
输出的每一行都显示了一个系统调用、它的参数,以及返回值。如果你在一个循环中将 `getpid(2)` 运行 1000 次,你就会发现始终只有一个 `getpid()` 系统调用,因为,它的 PID 已经被缓存了。我们也可以看到在格式化输出字符串之后,`printf(3)` 调用了 `write(2)`。
|
||||
|
||||
`strace` 可以开始一个新进程,也可以附加到一个已经运行的进程上。你可以通过不同程序的系统调用学到很多的东西。例如,`sshd` 守护进程一天都在干什么?
|
||||
|
||||
```
|
||||
~/code/x86-os$ ps ax | grep sshd
|
||||
12218 ? Ss 0:00 /usr/sbin/sshd -D
|
||||
|
||||
~/code/x86-os$ sudo strace -p 12218
|
||||
Process 12218 attached - interrupt to quit
|
||||
select(7, [3 4], NULL, NULL, NULL
|
||||
|
||||
[
|
||||
... nothing happens ...
|
||||
No fun, it's just waiting for a connection using select(2)
|
||||
If we wait long enough, we might see new keys being generated and so on, but
|
||||
let's attach again, tell strace to follow forks (-f), and connect via SSH
|
||||
]
|
||||
|
||||
~/code/x86-os$ sudo strace -p 12218 -f
|
||||
|
||||
[lots of calls happen during an SSH login, only a few shown]
|
||||
|
||||
[pid 14692] read(3, "-----BEGIN RSA PRIVATE KEY-----\n"..., 1024) = 1024
|
||||
[pid 14692] open("/usr/share/ssh/blacklist.RSA-2048", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
|
||||
[pid 14692] open("/etc/ssh/blacklist.RSA-2048", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
|
||||
[pid 14692] open("/etc/ssh/ssh_host_dsa_key", O_RDONLY|O_LARGEFILE) = 3
|
||||
[pid 14692] open("/etc/protocols", O_RDONLY|O_CLOEXEC) = 4
|
||||
[pid 14692] read(4, "# Internet (IP) protocols\n#\n# Up"..., 4096) = 2933
|
||||
[pid 14692] open("/etc/hosts.allow", O_RDONLY) = 4
|
||||
[pid 14692] open("/lib/i386-linux-gnu/libnss_dns.so.2", O_RDONLY|O_CLOEXEC) = 4
|
||||
[pid 14692] stat64("/etc/pam.d", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
|
||||
[pid 14692] open("/etc/pam.d/common-password", O_RDONLY|O_LARGEFILE) = 8
|
||||
[pid 14692] open("/etc/pam.d/other", O_RDONLY|O_LARGEFILE) = 4
|
||||
```
|
||||
|
||||
看懂 SSH 的调用是块难啃的骨头,但是,如果搞懂它你就学会了跟踪。能够看到应用程序打开的是哪个文件是有用的(“这个配置是从哪里来的?”)。如果你有一个出现错误的进程,你可以 `strace` 它,然后去看它通过系统调用做了什么?当一些应用程序意外退出而没有提供适当的错误信息时,你可以去检查它是否有系统调用失败。你也可以使用过滤器,查看每个调用的次数,等等:
|
||||
|
||||
```
|
||||
~/code/x86-os$ strace -T -e trace=recv curl -silent www.google.com. > /dev/null
|
||||
|
||||
recv(3, "HTTP/1.1 200 OK\r\nDate: Wed, 05 N"..., 16384, 0) = 4164 <0.000007>
|
||||
recv(3, "fl a{color:#36c}a:visited{color:"..., 16384, 0) = 2776 <0.000005>
|
||||
recv(3, "adient(top,#4d90fe,#4787ed);filt"..., 16384, 0) = 4164 <0.000007>
|
||||
recv(3, "gbar.up.spd(b,d,1,!0);break;case"..., 16384, 0) = 2776 <0.000006>
|
||||
recv(3, "$),a.i.G(!0)),window.gbar.up.sl("..., 16384, 0) = 1388 <0.000004>
|
||||
recv(3, "margin:0;padding:5px 8px 0 6px;v"..., 16384, 0) = 1388 <0.000007>
|
||||
recv(3, "){window.setTimeout(function(){v"..., 16384, 0) = 1484 <0.000006>
|
||||
```
|
||||
|
||||
我鼓励你在你的操作系统中的试验这些工具。把它们用好会让你觉得自己有超能力。
|
||||
|
||||
但是,足够有用的东西,往往要让我们深入到它的设计中。我们可以看到那些用户空间中的应用程序是被严格限制在它自己的虚拟地址空间里,运行在 Ring 3(非特权模式)中。一般来说,只涉及到计算和内存访问的任务是不需要请求系统调用的。例如,像 [strlen(3)][23] 和 [memcpy(3)][24] 这样的 C 库函数并不需要内核去做什么。这些都是在应用程序内部发生的事。
|
||||
|
||||
C 库函数的 man 页面所在的节(即圆括号里的 `2` 和 `3`)也提供了线索。节 2 是用于系统调用封装,而节 3 包含了其它 C 库函数。但是,正如我们在 `printf(3)` 中所看到的,库函数最终可以产生一个或者多个系统调用。
|
||||
|
||||
如果你对此感到好奇,这里是 [Linux][25] (也有 [Filippo 的列表][26])和 [Windows][27] 的全部系统调用列表。它们各自有大约 310 和 460 个系统调用。看这些系统调用是非常有趣的,因为,它们代表了*软件*在现代的计算机上能够做什么。另外,你还可能在这里找到与进程间通讯和性能相关的“宝藏”。这是一个“不懂 Unix 的人注定最终还要重新发明一个蹩脚的 Unix ” 的地方。(LCTT 译注:原文 “Those who do not understand Unix are condemned to reinvent it,poorly。” 这句话是 [Henry Spencer][35] 的名言,反映了 Unix 的设计哲学,它的一些理念和文化是一种技术发展的必须结果,看似糟糕却无法超越。)
|
||||
|
||||
与 CPU 周期相比,许多系统调用花[很长的时间][28]去执行任务,例如,从一个硬盘驱动器中读取内容。在这种情况下,调用进程在底层的工作完成之前一直*处于休眠状态*。因为,CPU 运行的非常快,一般的程序都因为 **I/O 的限制**在它的生命周期的大部分时间处于休眠状态,等待系统调用返回。相反,如果你跟踪一个计算密集型任务,你经常会看到没有任何的系统调用参与其中。在这种情况下,[top(1)][29] 将显示大量的 CPU 使用。
|
||||
|
||||
在一个系统调用中的开销可能会是一个问题。例如,固态硬盘比普通硬盘要快很多,但是,操作系统的开销可能比 I/O 操作本身的开销 [更加昂贵][30]。执行大量读写操作的程序可能就是操作系统开销的瓶颈所在。[向量化 I/O][31] 对此有一些帮助。因此要做 [文件的内存映射][32],它允许一个程序仅访问内存就可以读或写磁盘文件。类似的映射也存在于像视频卡这样的地方。最终,云计算的经济性可能导致内核消除或最小化用户模式/内核模式的切换。
|
||||
|
||||
最终,系统调用还有益于系统安全。一是,无论如何来历不明的一个二进制程序,你都可以通过观察它的系统调用来检查它的行为。这种方式可能用于去检测恶意程序。例如,我们可以记录一个未知程序的系统调用的策略,并对它的异常行为进行报警,或者对程序调用指定一个白名单,这样就可以让漏洞利用变得更加困难。在这个领域,我们有大量的研究,和许多工具,但是没有“杀手级”的解决方案。
|
||||
|
||||
这就是系统调用。很抱歉这篇文章有点长,我希望它对你有用。接下来的时间,我将写更多(短的)文章,也可以在 [RSS][33] 和 [Twitter][34] 关注我。这篇文章献给 glorious Clube Atlético Mineiro。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via:https://manybutfinite.com/post/system-calls/
|
||||
|
||||
作者:[Gustavo Duarte][a]
|
||||
译者:[qhwdw](https://github.com/qhwdw)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://duartes.org/gustavo/blog/about/
|
||||
[1]:https://manybutfinite.com/code/x86-os/pid.c
|
||||
[2]:https://manybutfinite.com/post/anatomy-of-a-program-in-memory
|
||||
[3]:https://manybutfinite.com/post/page-cache-the-affair-between-memory-and-files/
|
||||
[4]:http://linux.die.net/man/2/getpid
|
||||
[5]:https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/getpid.c;h=937b1d4e113b1cff4a5c698f83d662e130d596af;hb=4c6da7da9fb1f0f94e668e6d2966a4f50a7f0d85#l49
|
||||
[6]:https://github.com/torvalds/linux/blob/v3.17/arch/x86/syscalls/syscall_64.tbl#L48
|
||||
[7]:https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/x86_64/sysdep.h;h=4a619dafebd180426bf32ab6b6cb0e5e560b718a;hb=4c6da7da9fb1f0f94e668e6d2966a4f50a7f0d85#l139
|
||||
[8]:https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/x86_64/sysdep.h;h=4a619dafebd180426bf32ab6b6cb0e5e560b718a;hb=4c6da7da9fb1f0f94e668e6d2966a4f50a7f0d85#l179
|
||||
[9]:https://manybutfinite.com/post/cpu-rings-privilege-and-protection
|
||||
[10]:https://github.com/torvalds/linux/blob/v3.17/arch/x86/kernel/entry_64.S#L354-L386
|
||||
[11]:http://lwn.net/Articles/604287/
|
||||
[12]:http://lwn.net/Articles/604515/
|
||||
[13]:https://github.com/torvalds/linux/blob/v3.17/arch/x86/kernel/entry_64.S#L422
|
||||
[14]:https://github.com/torvalds/linux/blob/v3.17/arch/x86/kernel/syscall_64.c#L25
|
||||
[15]:https://github.com/torvalds/linux/blob/v3.17/kernel/sys.c#L800-L809
|
||||
[16]:https://github.com/torvalds/linux/blob/v3.17/kernel/sys.c#L800-L859
|
||||
[17]:http://linux.die.net/man/2/getpid
|
||||
[18]:http://linux.die.net/man/2/syscall
|
||||
[19]:http://linux.die.net/man/1/strace
|
||||
[20]:https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/dtruss.1m.html
|
||||
[21]:http://dtrace.org/blogs/brendan/2011/10/10/top-10-dtrace-scripts-for-mac-os-x/
|
||||
[22]:http://technet.microsoft.com/en-us/sysinternals/bb842062.aspx
|
||||
[23]:http://linux.die.net/man/3/strlen
|
||||
[24]:http://linux.die.net/man/3/memcpy
|
||||
[25]:https://github.com/torvalds/linux/blob/v3.17/arch/x86/syscalls/syscall_64.tbl
|
||||
[26]:https://filippo.io/linux-syscall-table/
|
||||
[27]:http://j00ru.vexillium.org/ntapi/
|
||||
[28]:https://manybutfinite.com/post/what-your-computer-does-while-you-wait/
|
||||
[29]:http://linux.die.net/man/1/top
|
||||
[30]:http://danluu.com/clwb-pcommit/
|
||||
[31]:http://en.wikipedia.org/wiki/Vectored_I/O
|
||||
[32]:https://manybutfinite.com/post/page-cache-the-affair-between-memory-and-files/
|
||||
[33]:http://feeds.feedburner.com/GustavoDuarte
|
||||
[34]:http://twitter.com/food4hackers
|
||||
[35]:https://en.wikipedia.org/wiki/Henry_Spencer
|
@ -7,17 +7,16 @@
|
||||
|
||||
我想在讨论的基础上去写一些笔记,因为,我觉得它超级棒!
|
||||
|
||||
这是 [幻灯片][9] 和一个 [pdf][10]。这个 pdf 非常好,结束的位置有一些链接,在 PDF 中你可以直接点击这个链接。
|
||||
开始前,这里有个 [幻灯片][9] 和一个 [pdf][10]。这个 pdf 非常好,结束的位置有一些链接,在 PDF 中你可以直接点击这个链接。
|
||||
|
||||
### 什么是 BPF?
|
||||
|
||||
在 BPF 出现之前,如果你想去做包过滤,你必须拷贝所有进入用户空间的包,然后才能去过滤它们(使用 “tap”)。
|
||||
在 BPF 出现之前,如果你想去做包过滤,你必须拷贝所有的包到用户空间,然后才能去过滤它们(使用 “tap”)。
|
||||
|
||||
这样做存在两个问题:
|
||||
|
||||
1. 如果你在用户空间中过滤,意味着你将拷贝所有进入用户空间的包,拷贝数据的代价是很昂贵的。
|
||||
|
||||
2. 使用的过滤算法很低效
|
||||
1. 如果你在用户空间中过滤,意味着你将拷贝所有的包到用户空间,拷贝数据的代价是很昂贵的。
|
||||
2. 使用的过滤算法很低效。
|
||||
|
||||
问题 #1 的解决方法似乎很明显,就是将过滤逻辑移到内核中。(虽然具体实现的细节并没有明确,我们将在稍后讨论)
|
||||
|
||||
@ -35,12 +34,11 @@
|
||||
|
||||
### 为什么 BPF 要工作在内核中
|
||||
|
||||
这里的关键点是,包仅仅是个字节的数组。BPF 程序是运行在这些字节的数组上。它们不允许有循环(loops),但是,它们 _可以_ 有聪明的办法知道 IP 包头(IPv6 和 IPv4 长度是不同的)以及基于它们的长度来找到 TCP 端口
|
||||
这里的关键点是,包仅仅是个字节的数组。BPF 程序是运行在这些字节的数组之上。它们不允许有循环(loop),但是,它们 _可以_ 有聪明的办法知道 IP 包头(IPv6 和 IPv4 长度是不同的)以及基于它们的长度来找到 TCP 端口:
|
||||
|
||||
```
|
||||
x = ip_header_length
|
||||
port = *(packet_start + x + port_offset)
|
||||
|
||||
```
|
||||
|
||||
(看起来不一样,其实它们基本上都相同)。在这个论文/幻灯片上有一个非常详细的虚拟机的描述,因此,我不打算解释它。
|
||||
@ -48,13 +46,9 @@ port = *(packet_start + x + port_offset)
|
||||
当你运行 `tcpdump host foo` 后,这时发生了什么?就我的理解,应该是如下的过程。
|
||||
|
||||
1. 转换 `host foo` 为一个高效的 DAG 规则
|
||||
|
||||
2. 转换那个 DAG 规则为 BPF 虚拟机的一个 BPF 程序(BPF 字节码)
|
||||
|
||||
3. 发送 BPF 字节码到 Linux 内核,由 Linux 内核验证它
|
||||
|
||||
4. 编译这个 BPF 字节码程序为一个原生(native)代码。例如, [在 ARM 上是 JIT 代码][1] 以及为 [x86][2] 的机器码
|
||||
|
||||
4. 编译这个 BPF 字节码程序为一个<ruby>原生<rt>native</rt></ruby>代码。例如,这是个[ARM 上的 JIT 代码][1] 以及 [x86][2] 的机器码
|
||||
5. 当包进入时,Linux 运行原生代码去决定是否过滤这个包。对于每个需要去处理的包,它通常仅需运行 100 - 200 个 CPU 指令就可以完成,这个速度是非常快的!
|
||||
|
||||
### 现状:eBPF
|
||||
@ -63,19 +57,15 @@ port = *(packet_start + x + port_offset)
|
||||
|
||||
关于 eBPF 的一些事实是:
|
||||
|
||||
* eBPF 程序有它们自己的字节码语言,并且从那个字节码语言编译成内核原生代码,就像 BPF 程序
|
||||
|
||||
* eBPF 程序有它们自己的字节码语言,并且从那个字节码语言编译成内核原生代码,就像 BPF 程序一样
|
||||
* eBPF 运行在内核中
|
||||
|
||||
* eBPF 程序不能随心所欲的访问内核内存。而是通过内核提供的函数去取得一些受严格限制的所需要的内容的子集。
|
||||
|
||||
* eBPF 程序不能随心所欲的访问内核内存。而是通过内核提供的函数去取得一些受严格限制的所需要的内容的子集
|
||||
* 它们 _可以_ 与用户空间的程序通过 BPF 映射进行通讯
|
||||
|
||||
* 这是 Linux 3.18 的 `bpf` 系统调用
|
||||
|
||||
### kprobes 和 eBPF
|
||||
|
||||
你可以在 Linux 内核中挑选一个函数(任意函数),然后运行一个你写的每次函数被调用时都运行的程序。这样看起来是不是很神奇。
|
||||
你可以在 Linux 内核中挑选一个函数(任意函数),然后运行一个你写的每次该函数被调用时都运行的程序。这样看起来是不是很神奇。
|
||||
|
||||
例如:这里有一个 [名为 disksnoop 的 BPF 程序][12],它的功能是当你开始/完成写入一个块到磁盘时,触发它执行跟踪。下图是它的代码片断:
|
||||
|
||||
@ -92,45 +82,37 @@ b.attach_kprobe(event="blk_mq_start_request", fn_name="trace_start")
|
||||
|
||||
```
|
||||
|
||||
从根本上来说,它声明一个 BPF 哈希(它的作用是当请求开始/完成时,这个程序去触发跟踪),一个名为 `trace_start` 的函数将被编译进 BPF 字节码,然后附加 `trace_start` 到内核函数 `blk_start_request` 上。
|
||||
本质上它声明一个 BPF 哈希(它的作用是当请求开始/完成时,这个程序去触发跟踪),一个名为 `trace_start` 的函数将被编译进 BPF 字节码,然后附加 `trace_start` 到内核函数 `blk_start_request` 上。
|
||||
|
||||
这里使用的是 `bcc` 框架,它可以使你写的 Python 化的程序去生成 BPF 代码。你可以在 [https://github.com/iovisor/bcc][13] 找到它(那里有非常多的示例程序)。
|
||||
这里使用的是 `bcc` 框架,它可以让你写 Python 式的程序去生成 BPF 代码。你可以在 [https://github.com/iovisor/bcc][13] 找到它(那里有非常多的示例程序)。
|
||||
|
||||
### uprobes 和 eBPF
|
||||
|
||||
因为我知道你可以附加 eBPF 程序到内核函数上,但是,我不知道你能否将 eBPF 程序附加到用户空间函数上!那会有更多令人激动的事情。这是 [在 Python 中使用一个 eBPF 程序去计数 malloc 调用的示例][14]。
|
||||
因为我知道可以附加 eBPF 程序到内核函数上,但是,我不知道能否将 eBPF 程序附加到用户空间函数上!那会有更多令人激动的事情。这是 [在 Python 中使用一个 eBPF 程序去计数 malloc 调用的示例][14]。
|
||||
|
||||
### 附加 eBPF 程序时应该考虑的事情
|
||||
|
||||
* 带 XDP 的网卡(我之前写过关于这方面的文章)
|
||||
|
||||
* tc egress/ingress (在网络栈上)
|
||||
|
||||
* kprobes(任意内核函数)
|
||||
|
||||
* uprobes(很明显,任意用户空间函数??像带符号的任意 C 程序)
|
||||
|
||||
* uprobes(很明显,任意用户空间函数??像带调试符号的任意 C 程序)
|
||||
* probes 是为 dtrace 构建的名为 “USDT probes” 的探针(像 [这些 mysql 探针][3])。这是一个 [使用 dtrace 探针的示例程序][4]
|
||||
|
||||
* [JVM][5]
|
||||
|
||||
* 跟踪点
|
||||
|
||||
* seccomp / landlock 安全相关的事情
|
||||
|
||||
* 更多的事情
|
||||
* 等等
|
||||
|
||||
### 这个讨论超级棒
|
||||
|
||||
在幻灯片里有很多非常好的链接,并且在 iovisor 仓库里有个 [LINKS.md][15]。现在已经很晚了,但是,很快我将写我的第一个 eBPF 程序了!
|
||||
在幻灯片里有很多非常好的链接,并且在 iovisor 仓库里有个 [LINKS.md][15]。虽然现在已经很晚了,但是我马上要去写我的第一个 eBPF 程序了!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://jvns.ca/blog/2017/06/28/notes-on-bpf---ebpf/
|
||||
|
||||
作者:[Julia Evans ][a]
|
||||
作者:[Julia Evans][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/) 荣誉推出
|
||||
|
@ -1,55 +1,55 @@
|
||||
5 个最佳实践开始你的 DevOps 之旅
|
||||
============================================================
|
||||
|
||||
### 想要实现 DevOps 但是不知道如何开始吗?试试这 5 个最佳实践吧。
|
||||
|
||||
> 想要实现 DevOps 但是不知道如何开始吗?试试这 5 个最佳实践吧。
|
||||
|
||||

|
||||
|
||||
Image by : [Andrew Magill][8]. Modified by Opensource.com. [CC BY 4.0][9]
|
||||
|
||||
想要采用 DevOps 的人通常会过早的被它的歧义性给吓跑,更不要说更加深入的使用了。当一些人开始使用 DevOps 的时候都会问:“如何开始使用呢?”,”怎么才算使用了呢?“。这 5 个最佳实践是很好的路线图来指导你的 DevOps 之旅。
|
||||
想要采用 DevOps 的人通常会过早的被它的歧义性给吓跑,更不要说更加深入的使用了。当一些人开始使用 DevOps 的时候都会问:“如何开始使用呢?”,”怎么才算使用了呢?“。这 5 个最佳实践是指导你的 DevOps 之旅的很好的路线图。
|
||||
|
||||
### 1\. 衡量所有的事情
|
||||
### 1、 衡量所有的事情
|
||||
|
||||
除非你能量化输出结果,否则你并不能确认你的努力能否使事情变得更好。新功能能否快速的输出给客户?有更少的漏洞泄漏给他们吗?出错了能快速应对和恢复吗?
|
||||
除非你能够量化输出结果,否则你并不能确认你的努力能否使事情变得更好。新功能能否快速的输出给客户?带给他们的缺陷更少吗?出错了能快速应对和恢复吗?
|
||||
|
||||
在你开始做任何修改之前,思考一下你切换到 DevOps 之后想要一些什么样的输出。随着你的 DevOps 之旅,将享受到服务的所有内容的丰富的实时报告,从这两个指标考虑一下:
|
||||
|
||||
* **上架时间** 衡量端到端,通常是面向客户的业务经验。这通常从一个功能被正式提出而开始,客户在产品中开始使用这个功能而结束。上架时间不是团队的主要指标;更加重要的是,当开发出一个有价值的新功能时,它表明了你完成业务的效率,为系统改进提供了一个机会。
|
||||
* **上架时间** 衡量端到端,通常是面向客户的业务经验。这通常从一个功能被正式提出而开始,客户在产品中开始使用这个功能而结束。上架时间不是工程团队的主要指标;更加重要的是,当开发出一个有价值的新功能时,它表明了你完成业务的效率,为系统改进提供了一个机会。
|
||||
|
||||
* **时间周期** 衡量工程团队的进度。从开始开发一个新功能开始,到在产品中运行需要多久?这个指标对于你理解团队的效率是非常有用的,为团队等级的提升提供了一个机会。
|
||||
* **时间周期** 衡量工程团队的进度。从开始开发一个新功能开始,到在产品环境中运行需要多久?这个指标对于你了解团队的效率是非常有用的,为团队层面的提升提供了一个机会。
|
||||
|
||||
### 2\. 放飞你的流程
|
||||
### 2、 放飞你的流程
|
||||
|
||||
DevOps 的成功需要团队布置一个定期流程并且持续提升它。这不总是有效的,但是必须是一个定期(希望有效)的流程。通常它有一些敏捷开发的味道,就像 Scrum 或者 Scrumban 一样;一些时候它也像精益开发。不论你用的什么方法,挑选一个正式的流程,开始使用它,并且做好这些基础。
|
||||
DevOps 的成功需要团队布置一个定期(但愿有效)流程并且持续提升它。这不总是有效的,但是必须是一个定期的流程。通常它有一些敏捷开发的味道,就像 Scrum 或者 Scrumban 一样;一些时候它也像精益开发。不论你用的什么方法,挑选一个正式的流程,开始使用它,并且做好这些基础。
|
||||
|
||||
定期检查和调整流程是 DevOps 成功的关键,抓住相关演示,团队回顾,每日会议的机会来提升你的流程。
|
||||
定期检查和调整流程是 DevOps 成功的关键,抓住相关演示、团队回顾、每日会议的机会来提升你的流程。
|
||||
|
||||
DevOps 的成功取决于大家一起有效的工作。团队的成员需要在一个有权改进的公共流程中工作。他们也需要定期找机会分享从这个流程中上游或下游的其他人那里学到的东西。
|
||||
|
||||
随着你构建成功。好的流程规范能帮助你的团队以很快的速度体会到 DevOps 其他的好处
|
||||
随着你构建成功,好的流程规范能帮助你的团队以很快的速度体会到 DevOps 其他的好处
|
||||
|
||||
尽管更多面向开发的团队采用 Scrum 是常见的,但是以运营为中心的团队(或者其他中断驱动的团队)可能选用一个更短期的流程,例如 Kanban。
|
||||
|
||||
### 3\. 可视化工作流程
|
||||
### 3、 可视化工作流程
|
||||
|
||||
这是很强大的,能够看到哪个人在给定的时间做哪一部分工作,可视化你的工作流程能帮助大家知道接下来应该做什么,流程中有多少工作以及流程中的瓶颈在哪里。
|
||||
|
||||
在你看到和衡量之前你并不能有效的限制流程中的工作。同样的,你也不能有效的排除瓶颈直到你清楚的看到它。
|
||||
|
||||
全部工作可视化能帮助团队中的成员了解他们在整个工作中的贡献。这样可以促进跨组织边界的关系建设,帮助您的团队更有效地协作,实现共同的成就感。
|
||||
|
||||
### 4\. 持续化所有的事情
|
||||
### 4、 持续化所有的事情
|
||||
|
||||
DevOps 应该是强制自动化的。然而罗马不是一日建成的。你应该注意的第一个事情应该是努力的持续集成(CI),但是不要停留到这里;紧接着的是持续交付(CD)以及最终的持续部署。
|
||||
DevOps 应该是强制自动化的。然而罗马不是一日建成的。你应该注意的第一个事情应该是努力的[持续集成(CI)][10],但是不要停留到这里;紧接着的是[持续交付(CD)][11]以及最终的持续部署。
|
||||
|
||||
持续部署的过程中是个注入自动测试的好时机。这个时候新代码刚被提交,你的持续部署应该运行测试代码来测试你的代码和构建成功的加工品。这个加工品经受流程的考验被产出直到最终被客户看到。
|
||||
持续部署的过程中是个注入自动测试的好时机。这个时候新代码刚被提交,你的持续部署应该运行测试代码来测试你的代码和构建成功的加工品。这个加工品经受流程的考验被产出,直到最终被客户看到。
|
||||
|
||||
另一个“持续”是不太引人注意的持续改进。一个简单的场景是每天询问你旁边的同事:“今天做些什么能使工作变得更好?”,随着时间的推移,这些日常的小改进融合到一起会引起很大的结果,你将很惊喜!但是这也会让人一直思考着如何改进。
|
||||
另一个“持续”是不太引人注意的持续改进。一个简单的场景是每天询问你旁边的同事:“今天做些什么能使工作变得更好?”,随着时间的推移,这些日常的小改进融合到一起会带来很大的结果,你将很惊喜!但是这也会让人一直思考着如何改进。
|
||||
|
||||
### 5\. Gherkinize
|
||||
### 5、 Gherkinize
|
||||
|
||||
促进组织间更有效的沟通对于成功的 DevOps 的系统思想至关重要。在程序员和业务员之间直接使用共享语言来描述新功能的需求文档对于沟通是个好办法。一个好的产品经理能在一天内学会 [Gherkin][12] 然后使用它构造出明确的英语来描述需求文档,工程师会使用 Gherkin 描述的需求文档来写功能测试,之后开发功能代码直到代码通过测试。这是一个简化的 [验收测试驱动开发][13](ATDD),这样就开始了你的 DevOps 文化和开发实践。
|
||||
促进组织间更有效的沟通对于成功的 DevOps 的系统思想至关重要。在程序员和业务员之间直接使用共享语言来描述新功能的需求文档对于沟通是个好办法。一个好的产品经理能在一天内学会 [Gherkin][12] 然后使用它以平实的英语构造出明确的描述需求文档,工程师会使用 Gherkin 描述的需求文档来写功能测试,之后开发功能代码直到代码通过测试。这是一个简化的 [验收测试驱动开发][13](ATDD),能够帮助你开始你的 DevOps 文化和开发实践。
|
||||
|
||||
### 开始你旅程
|
||||
|
||||
@ -60,15 +60,15 @@ DevOps 应该是强制自动化的。然而罗马不是一日建成的。你应
|
||||
|
||||
[][14]
|
||||
|
||||
Magnus Hedemark - Magnus 在IT行业已有20多年,并且一直热衷于技术。他目前是 nitedHealth Group 的 DevOps 工程师。在业余时间,Magnus 喜欢摄影和划独木舟。
|
||||
Magnus Hedemark - Magnus 在 IT 行业已有 20 多年,并且一直热衷于技术。他目前是 nitedHealth Group 的 DevOps 工程师。在业余时间,Magnus 喜欢摄影和划独木舟。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/17/11/5-keys-get-started-devops
|
||||
|
||||
作者:[Magnus Hedemark ][a]
|
||||
作者:[Magnus Hedemark][a]
|
||||
译者:[aiwhj](https://github.com/aiwhj)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,4 +1,4 @@
|
||||
DevOps 将让你失业?
|
||||
DevOps 会让你失业吗?
|
||||
======
|
||||
|
||||
>你是否担心工作中自动化将代替人?可能是对的,但是这并不是件坏事。
|
||||
@ -8,19 +8,19 @@ DevOps 将让你失业?
|
||||
|
||||
这是一个很正常的担心:DevOps 最终会让你失业?毕竟,DevOps 意味着开发人员做运营,对吗?DevOps 是自动化的。如果我的工作都自动化了,我去做什么?实行持续分发和容器化意味着运营已经过时了吗?对于 DevOps 来说,所有的东西都是代码:基础设施是代码、测试是代码、这个和那个都是代码。如果我没有这些技能怎么办?
|
||||
|
||||
[DevOps][1] 是一个即将到来的变化,将颠覆这一领域,狂热的拥挤者们正在谈论,如何使用 [三种方法][2] 去改变世界 —— 即 DevOps 的三大基础 —— 去推翻一个旧的世界。它是势不可档的。那么,问题来了 —— DevOps 将会让我失业吗?
|
||||
[DevOps][1] 是一个即将到来的变化,它将颠覆这一领域,狂热的拥挤者们正在谈论,如何使用 [三种方法][2] 去改变世界 —— 即 DevOps 的三大基础 —— 去推翻一个旧的世界。它是势不可档的。那么,问题来了 —— DevOps 将会让我失业吗?
|
||||
|
||||
### 第一个担心:再也不需要我了
|
||||
### 第一个担心:再也不需要我了
|
||||
|
||||
由于开发者来管理应用程序的整个生命周期,接受 DevOps 的理念很容易。容器化可能是影响这一想法的重要因素。当容器化在各种场景下铺开之后,它们被吹嘘成开发者构建、测试、和部署他们代码的一站式解决方案。DevOps 对于运营、测试、以及 QA 团队来说,有什么作用呢?
|
||||
由于开发者来管理应用程序的整个生命周期,接受 DevOps 的理念很容易。容器化可能是影响这一想法的重要因素。当容器化在各种场景下铺开之后,它们被吹嘘成开发者构建、测试和部署他们代码的一站式解决方案。DevOps 对于运营、测试、以及 QA 团队来说,有什么作用呢?
|
||||
|
||||
这源于对 DevOps 原则的误解。DevOps 的第一原则,或者第一方法是,_系统思考_ ,或者强调整体管理方法和了解应用程序或服务的整个生命周期。这并不意味着应用程序的开发者将学习和管理整个过程。相反,是拥有各个专业和技能的人共同合作,以确保成功。让开发者对这一过程完全负责的作法,几乎是将开发者置于使用者的对立面—— 本质上就是 “将鸡蛋放在了一个篮子里”。
|
||||
这源于对 DevOps 原则的误解。DevOps 的第一原则,或者第一方法是,<ruby>系统思考<rt>Systems Thinking</rt></ruby>,或者强调整体管理方法和了解应用程序或服务的整个生命周期。这并不意味着应用程序的开发者将学习和管理整个过程。相反,是拥有各个专业和技能的人共同合作,以确保成功。让开发者对这一过程完全负责的作法,几乎是将开发者置于使用者的对立面 —— 本质上就是 “将鸡蛋放在了一个篮子里”。
|
||||
|
||||
在 DevOps 中有一个为你保留的专门职位。就像将一个受过传统教育的、拥有线性回归和二分查找知识的软件工程师,被用去写一些 Ansible playbooks 和 Docker 文件,这是一种浪费。而对于那些拥有高级技能,知道如何保护一个系统和优化数据库执行的系统管理员,被浪费在写一些 CSS 和设计用户流这样的工作上。写代码、做测试、和维护应用程序的高效团队一般是跨学科、跨职能的、拥有不同专业技术和背景的人组成的混编团队。
|
||||
|
||||
### 第二个担心:我的工作将被自动化
|
||||
|
||||
或许是,或许不是,DevOps 可能在有时候是自动化的同义词。当自动化构建、测试、部署、监视、以及提醒等事项,已经占据了整个应用程序生命周期管理的时候,还会给我们剩下什么工作呢?这种对自动化的关注可能与第二个方法有关:_放大反馈循环_。DevOps 的第二个方法是在团队和部署的应用程序之间,采用相反的方向优先处理快速反馈 —— 从监视和维护部署、测试、开发、等等,通过强调,使反馈更加重要并且可操作。虽然这第二种方式与自动化并不是特别相关,许多自动化工具团队在它们的部署流水线中使用,以促进快速提醒和快速行动,或者基于对使用者的支持业务中产生的反馈来改进。传统的做法是靠人来完成的,这就可以理解为什么自动化可能会导致未来一些人失业的焦虑了。
|
||||
或许是,或许不是,DevOps 可能在有时候是自动化的同义词。当自动化构建、测试、部署、监视,以及提醒等事项,已经占据了整个应用程序生命周期管理的时候,还会给我们剩下什么工作呢?这种对自动化的关注可能与第二个方法有关:<ruby>放大反馈循环<rt>Amplify Feedback Loops</rt></ruby>。DevOps 的第二个方法是在团队和部署的应用程序之间,采用相反的方向优先处理快速反馈 —— 从监视和维护部署、测试、开发、等等,通过强调,使反馈更加重要并且可操作。虽然这第二种方式与自动化并不是特别相关,许多自动化工具团队在它们的部署流水线中使用,以促进快速提醒和快速行动,或者基于对使用者的支持业务中产生的反馈来改进。传统的做法是靠人来完成的,这就可以理解为什么自动化可能会导致未来一些人失业的焦虑了。
|
||||
|
||||
自动化只是一个工具,它并不能代替人。聪明的人使用它来做一些重复的工作,不去开发智力和创造性的财富,而是去按红色的 “George Jetson” 按钮是一种极大的浪费。让每天工作中的苦活自动化,意味着有更多的时间去解决真正的问题和即将到来的创新的解决方案。人类需要解决更多的 “怎么做和为什么” 问题,而计算机只能处理 “复制和粘贴”。
|
||||
|
||||
@ -28,17 +28,17 @@ DevOps 将让你失业?
|
||||
|
||||
### 第三个担心:我没有这些技能怎么办
|
||||
|
||||
"我怎么去继续做这些事情?我不懂如何自动化。现在所有的工作都是代码 —— 我不是开发人员,我不会做 DevOps 中写代码的工作“,第三个担心是一种不自信的担心。由于文化的改变,是的,团队将也会要求随之改变,一些人可能担心,他们缺乏继续做他们工作的技能。
|
||||
“我怎么去继续做这些事情?我不懂如何自动化。现在所有的工作都是代码 —— 我不是开发人员,我不会做 DevOps 中写代码的工作”,第三个担心是一种不自信的担心。由于文化的改变,是的,团队将也会要求随之改变,一些人可能担心,他们缺乏继续做他们工作的技能。
|
||||
|
||||
然而,大多数人或许已经比他们所想的更接近。Dockerfile 是什么,或者像 Puppet 或 Ansible 配置管理是什么,但是环境即代码,系统管理员已经写了 shell 脚本和 Python 程序去处理他们重复的任务。学习更多的知识并使用已有的工具处理他们的更多问题 —— 编排、部署、维护即代码 —— 尤其是当从繁重的手动任务中解放出来,专注于成长时。
|
||||
然而,大多数人或许已经比他们所想的更接近。Dockerfile 是什么,或者像 Puppet 或 Ansible 配置管理是什么,这就是环境即代码,系统管理员已经写了 shell 脚本和 Python 程序去处理他们重复的任务。学习更多的知识并使用已有的工具处理他们的更多问题 —— 编排、部署、维护即代码 —— 尤其是当从繁重的手动任务中解放出来,专注于成长时。
|
||||
|
||||
在 DevOps 的使用者中去回答这第三个担心,第三个方法是:_一种不断实验和学习的文化_。尝试、失败、并从错误中吸取教训而不是责怪它们的能力,是设计出更有创意的解决方案的重要因素。第三个方法是为前两个方法授权—— 允许快速检测和修复问题,并且开发人员可以自由地尝试和学习,其它的团队也是如此。从未使用过配置管理或者写过自动供给基础设施程序的运营团队也要自由尝试并学习。测试和 QA 团队也要自由实现新测试流水线,并且自动批准和发布新流程。在一个拥抱学习和成长的文化中,每个人都可以自由地获取他们需要的技术,去享受工作带来的成功和喜悦。
|
||||
在 DevOps 的使用者中去回答这第三个担心,第三个方法是:<ruby>一种不断实验和学习的文化<rt>A Culture of Continual Experimentation and Learning</ruby>。尝试、失败,并从错误中吸取教训而不是责怪它们的能力,是设计出更有创意的解决方案的重要因素。第三个方法是为前两个方法授权 —— 允许快速检测和修复问题,并且开发人员可以自由地尝试和学习,其它的团队也是如此。从未使用过配置管理或者写过自动供给基础设施程序的运营团队也要自由尝试并学习。测试和 QA 团队也要自由实现新测试流水线,并且自动批准和发布新流程。在一个拥抱学习和成长的文化中,每个人都可以自由地获取他们需要的技术,去享受工作带来的成功和喜悦。
|
||||
|
||||
### 结束语
|
||||
|
||||
在一个行业中,任何可能引起混乱的实践或变化都会产生担心和不确定,DevOps 也不例外。对自己工作的担心是对成百上千的文章和演讲的合理回应,其中列举了无数的实践和技术,而这些实践和技术正致力于授权开发者对行业的各个方面承担职责。
|
||||
|
||||
然而,事实上,DevOps 是 "[一个跨学科的沟通实践,致力于研究构建、进化、和运营快速变化的弹性系统][3]"。 DevOps 意味着终结 ”筒仓“,但并不专业化。它是受委托去做苦差事的自动化系统,解放你,让你去做人类更擅长做的事:思考和想像。并且,如果你愿意去学习和成长,它将不会终结你解决新的、挑战性的问题的机会。
|
||||
然而,事实上,DevOps 是 “[一个跨学科的沟通实践,致力于研究构建、进化、和运营快速变化的弹性系统][3]”。 DevOps 意味着终结 “筒仓”,但并不专业化。它是受委托去做苦差事的自动化系统,解放你,让你去做人类更擅长做的事:思考和想像。并且,如果你愿意去学习和成长,它将不会终结你解决新的、挑战性的问题的机会。
|
||||
|
||||
DevOps 会让你失业吗?会的,但它同时给你提供了更好的工作。
|
||||
|
||||
@ -48,7 +48,7 @@ via: https://opensource.com/article/17/12/will-devops-steal-my-job
|
||||
|
||||
作者:[Chris Collins][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/) 荣誉推出
|
||||
|
@ -1,71 +1,72 @@
|
||||
Red Hat 的去 Docker 化容器实践
|
||||
======
|
||||
|
||||
最近几年,开源项目Docker (已更名为[Moby][1]) 在容器普及化方面建树颇多。然而,它的功能特性不断集中到一个单一、庞大的系统,该系统由具有 root 权限运行的守护进程 `dockerd` 管控,这引发了人们的焦虑。对这些焦虑的阐述,具有代表性的是 Red Hat 公司的容器团队负责人 Dan Walsh 在 [KubeCon \+ CloudNativecon][3] 会议中的[演讲][2]。Walsh讲述了他的容器团队目前的工作方向,即使用一系列更小、可协同工作的组件替代 Docker。他的战斗口号是”拒绝臃肿的守护进程“,理由是与公认的 Unix 哲学相违背。
|
||||
最近几年,开源项目 Docker (已更名为[Moby][1]) 在容器普及化方面建树颇多。然而,它的功能特性不断集中到一个单一、庞大的系统,该系统由具有 root 权限运行的守护进程 `dockerd` 管控,这引发了人们的焦虑。对这些焦虑的阐述,具有代表性的是 Red Hat 公司的容器团队负责人 Dan Walsh 在 [KubeCon + CloudNativecon][3] 会议中的[演讲][2]。Walsh 讲述了他的容器团队目前的工作方向,即使用一系列更小、可协同工作的组件替代 Docker。他的战斗口号是“拒绝臃肿的守护进程”,理由是与公认的 Unix 哲学相违背。
|
||||
|
||||
### Docker 模块化实践
|
||||
|
||||
就像我们在[早期文献][4]中看到的那样,容器的基础操作不复杂:你首先拉取一个容器镜像,利用该镜像创建一个容器,最后启动这个容器。除此之外,你要懂得如何构建镜像并推送至镜像仓库。大多数人在上述这些步骤中使用 Docker,但其实 Docker 并不是唯一的选择,目前的可替换选择是 `rkt`。rkt引发了一系列标准的创建,包括运行时标准 CRI,镜像标准 OCI 及网络标准 CNI 等。遵守这些标准的后端,如 [CRI-O][5] 和 Docker,可以与 [Kubernetes][6] 为代表的管理软件协同工作。
|
||||
就像我们在[早期文献][4]中看到的那样,容器的基础操作不复杂:你首先拉取一个容器镜像,利用该镜像创建一个容器,最后启动这个容器。除此之外,你要懂得如何构建镜像并推送至镜像仓库。大多数人在上述这些步骤中使用 Docker,但其实 Docker 并不是唯一的选择,目前的可替换选择是 `rkt`。rkt 引发了一系列标准的创建,包括运行时标准 CRI,镜像标准 OCI 及网络标准 CNI 等。遵守这些标准的后端,如 [CRI-O][5] 和 Docker,可以与 [Kubernetes][6] 为代表的管理软件协同工作。
|
||||
|
||||
这些标准促使 Red Hat 公司开发了一系列部分实现标准的”核心应用“供 Kubernetes 使用,例如 CRI-O 运行时。但 Kubernetes 提供的功能不足以满足 Red Hat公司的 [OpenShift][7] 项目所需。开发者可能需要构建容器并推送至镜像仓库,实现这些操作需要额外的一整套方案。
|
||||
这些标准促使 Red Hat 公司开发了一系列实现了部分标准的“核心应用”供 Kubernetes 使用,例如 CRI-O 运行时。但 Kubernetes 提供的功能不足以满足 Red Hat 公司的 [OpenShift][7] 项目所需。开发者可能需要构建容器并推送至镜像仓库,实现这些操作需要额外的一整套方案。
|
||||
|
||||
事实上,目前市面上已有多种构建容器的工具。来自 Sysdig 公司的 Michael Ducy 在[分会场][8]中回顾了 Docker 本身之外的8种镜像构建工具,而这也很可能不是全部的工具。Ducy 将理想的构建工具定义如下:可以用可重现的方式创建最小化镜像。最小化镜像并不包含操作系统,只包含应用本身及其依赖。Ducy 认为 [Distroless][9], [Smith][10] 及 [Source-to-Image][11] 都是很好的工具,可用于构建最小化镜像。Ducy 将最小化镜像称为”微容器“。
|
||||
事实上,目前市面上已有多种构建容器的工具。来自 Sysdig 公司的 Michael Ducy 在[分会场][8]中回顾了 Docker 本身之外的 8 种镜像构建工具,而这也很可能不是全部。Ducy 将理想的构建工具定义如下:可以用可重现的方式创建最小化镜像。最小化镜像并不包含操作系统,只包含应用本身及其依赖。Ducy 认为 [Distroless][9], [Smith][10] 及 [Source-to-Image][11] 都是很好的工具,可用于构建最小化镜像。Ducy 将最小化镜像称为“微容器”。
|
||||
|
||||
可重现镜像是指构建多次结果保持不变的镜像。为达到这个目标,Ducy 表示应该使用“宣告式”而不是“命令式”的方式。考虑到 Ducy 来自 Chef 配置管理工具领域,你应该能理解他的意思。Ducy 给出了符合标准的几个不错的实现,包括 [Ansible 容器][12], [Habitat][13], [nixos-容器][14]和 [Simth][10] 等,但你需要了解这些项目对应的编程语言。Ducy 额外指出 Habitat 构建的容器自带管理功能,如果你已经使用了systemd, Docker 或 Kubernetes 等外部管理工具,Habitat 的管理功能可能是冗余的。除此之外,我们还要提从 Docker 和 [Buildah][16] 项目诞生的新项目 [BuildKit][15], 它是 Red Hat 公司 [Atomic 工程][17]的一个组件。
|
||||
<ruby>可重现镜像<rt>reproducible container</rt></ruby>是指构建多次结果保持不变的镜像。为达到这个目标,Ducy 表示应该使用“宣告式”而不是“命令式”的方式。考虑到 Ducy 来自 Chef 配置管理工具领域,你应该能理解他的意思。Ducy 给出了符合标准的几个不错的实现,包括 [Ansible 容器][12]、 [Habitat][13]、 [nixos-容器][14]和 [Simth][10] 等,但你需要了解这些项目对应的编程语言。Ducy 额外指出 Habitat 构建的容器自带管理功能,如果你已经使用了 systemd、 Docker 或 Kubernetes 等外部管理工具,Habitat 的管理功能可能是冗余的。除此之外,我们还要提到从 Docker 和 [Buildah][16] 项目诞生的新项目 [BuildKit][15], 它是 Red Hat 公司 [Atomic 工程][17]的一个组件。
|
||||
|
||||
### 使用Buildah构建容器
|
||||
### 使用 Buildah 构建容器
|
||||
|
||||
![\[Buildah logo\]][18] Buildah 名称显然来自于 Walsh 风趣的 [Boston 口音][19]; 该工具的品牌宣传中充满了 Boston 风格,例如 logo 使用了 Boston 梗犬(如图所示)。该项目的实现思路与 Ducy 不同:为了构建容器,与其被迫使用宣告式配置管理的方案,不如构建一些简单工具,结合你最喜欢的配置管理工具使用。这样你可以如愿的使用命令行,例如使用 `cp` 命令代替 Docker 的自定义指令 `COPY` 。除此之外,你可以使用如下工具为容器提供内容:1) 配置管理工具,例如Ansible 或 Puppet;2) 操作系统相关或编程语言相关的安装工具,例如 APT 和 pip; 3) 其它系统。下面展示了基于通用 shell 命令的容器构建场景,其中只需要使用 `make` 命令即可为容器安装可执行文件。
|
||||
![\[Buildah logo\]][18]
|
||||
|
||||
Buildah 名称显然来自于 Walsh 风趣的 [波士顿口音][19]; 该工具的品牌宣传中充满了波士顿风格,例如 logo 使用了波士顿梗犬(如图所示)。该项目的实现思路与 Ducy 不同:为了构建容器,与其被迫使用宣告式配置管理的方案,不如构建一些简单工具,结合你最喜欢的配置管理工具使用。这样你可以如愿的使用命令行,例如使用 `cp` 命令代替 Docker 的自定义指令 `COPY` 。除此之外,你可以使用如下工具为容器提供内容:1) 配置管理工具,例如Ansible 或 Puppet;2) 操作系统相关或编程语言相关的安装工具,例如 APT 和 pip; 3) 其它系统。下面展示了基于通用 shell 命令的容器构建场景,其中只需要使用 `make` 命令即可为容器安装可执行文件。
|
||||
|
||||
```
|
||||
# 拉取基础镜像, 类似 Dockerfile 中的 FROM 命令
|
||||
buildah from redhat
|
||||
# 拉取基础镜像, 类似 Dockerfile 中的 FROM 命令
|
||||
buildah from redhat
|
||||
|
||||
# 挂载基础镜像, 在其基础上工作
|
||||
crt=$(buildah mount)
|
||||
ap foo $crt
|
||||
make install DESTDIR=$crt
|
||||
|
||||
# 下一步,生成快照
|
||||
buildah commit
|
||||
# 挂载基础镜像, 在其基础上工作
|
||||
crt=$(buildah mount)
|
||||
ap foo $crt
|
||||
make install DESTDIR=$crt
|
||||
|
||||
# 下一步,生成快照
|
||||
buildah commit
|
||||
```
|
||||
|
||||
有趣的是,基于这个思路,你可以复用主机环境中的构建工具,无需在镜像中安装这些依赖,故可以构建非常微小的镜像。通常情况下,构建容器镜像时需要在容器中安装目标应用的构建依赖。例如,从源码构建需要容器中有编译器工具链,这是因为构建并不在主机环境进行。大量的容器也包含了 `ps` 和 `bash` 这样的 Unix 命令,对微容器而言其实是多余的。开发者经常忘记或无法从构建好的容器中移除一些依赖,增加了不必要的开销和攻击面。
|
||||
|
||||
Buildah的模块化方案能够以非 root 方式进行部分构建;但`mount` 命令仍然需要 `CAP_SYS_ADMIN` 或 `等同 root 访问权限` 的能力,有一个 [issue][20] 试图解决该问题。但 Buildah 与 Docker [都有][21]同样的限制[22],即无法在容器内构建容器。对于 Docker,你需要使用“特权”模式运行容器,一些特殊的环境很难满足这个条件,例如 [GitLab 持续集成][23];即使满足该条件,配置也特别[繁琐][24]。
|
||||
Buildah 的模块化方案能够以非 root 方式进行部分构建;但`mount` 命令仍然需要 `CAP_SYS_ADMIN`,有一个 [工单][20] 试图解决该问题。但 Buildah 与 Docker [都有][21]同样的[限制][22],即无法在容器内构建容器。对于 Docker,你需要使用“特权”模式运行容器,一些特殊的环境很难满足这个条件,例如 [GitLab 持续集成][23];即使满足该条件,配置也特别[繁琐][24]。
|
||||
|
||||
手动提交的步骤可以对创建容器快照的时间节点进行细粒度控制。Dockerfile 每一行都会创建一个新的快照;相比而言,Buildah 的提交检查点都是事先选择好的,这可以减少不必要的快照并节省磁盘空间。这也有利于隔离私钥或密码等敏感信息,避免其出现在公共镜像中。
|
||||
|
||||
Docker 构建的镜像是非标准的、仅供其自身使用;相比而言,Buildah 提供[多种输出格式][25],其中包括符合 OCI 标准的镜像。为向后兼容,Buildah 提供 一个 `使用Dockerfile构建` 的命令,即 [`buildah bud`][26], 它可以解析标准的 Dockerfile。Buildah 提供 `enter` 命令直接查看镜像内部信息,`run` 命令启动一个容器。实现这些功能仅使用了 `runc` 在内的标准工具,无需在后台运行一个“臃肿的守护进程”。
|
||||
Docker 构建的镜像是非标准的、仅供其自身使用;相比而言,Buildah 提供[多种输出格式][25],其中包括符合 OCI 标准的镜像。为向后兼容,Buildah 提供了一个“使用 Dockerfile 构建”的命令,即 [`buildah bud`][26], 它可以解析标准的 Dockerfile。Buildah 提供 `enter` 命令直接查看镜像内部信息,`run` 命令启动一个容器。实现这些功能仅使用了 `runc` 在内的标准工具,无需在后台运行一个“臃肿的守护进程”。
|
||||
|
||||
Ducy 对 Buildah 表示质疑,认为采用非宣告性不利于可重现性。如果允许使用 shell 命令,可能产生很多预想不到的情况;例如,一个 shell 脚本下载了任意的可执行程序,但后续无法追溯文件的来源。shell 命令的执行受环境变量影响,执行结果可能大相径庭。与基于 shell 的工具相比,Puppet 或 Chef 这样的配置管理系统在理论上更加可靠,因为他们的设计初衷就是收敛于最终配置;事实上,可以通过配置管理系统调用 shell 命令。但 Walsh 对此提出反驳,认为已有的配置管理工具可以在 Buildah 的基础上工作,用户可以选择是否使用配置管理;这样更加符合“机制与策略分离”的经典 Unix 哲学。
|
||||
Ducy 对 Buildah 表示质疑,认为采用非宣告性不利于可重现性。如果允许使用 shell 命令,可能产生很多预想不到的情况;例如,一个 shell 脚本下载了任意的可执行程序,但后续无法追溯文件的来源。shell 命令的执行受环境变量影响,执行结果可能大相径庭。与基于 shell 的工具相比,Puppet 或 Chef 这样的配置管理系统在理论上更加可靠,因为它们的设计初衷就是收敛于最终配置;事实上,可以通过配置管理系统调用 shell 命令。但 Walsh 对此提出反驳,认为已有的配置管理工具可以在 Buildah 的基础上工作,用户可以选择是否使用配置管理;这样更加符合“机制与策略分离”的经典 Unix 哲学。
|
||||
|
||||
目前 Buildah 处于测试阶段,Red Hat 公司正努力将其集成到 OpenShift。我写这篇文章时已经测试过 Buildah,它缺少一些主题的文档,但基本可以稳定运行。尽管在错误处理方面仍有待提高,但它确实是一款值得你关注的容器工具。
|
||||
目前 Buildah 处于测试阶段,Red Hat 公司正努力将其集成到 OpenShift。我写这篇文章时已经测试过 Buildah,它缺少一些文档,但基本可以稳定运行。尽管在错误处理方面仍有待提高,但它确实是一款值得你关注的容器工具。
|
||||
|
||||
### 替换其它 Docker 命令行
|
||||
|
||||
Walsh 在其演讲中还简单介绍了 Redhat 公司 正在开发的另一个暂时叫做 [libpod][24] 的项目。项目名称来源于 Kubernetes 中的 “pod”, 在 Kubernetes 中 “pod” 用于分组主机内的容器,分享名字空间等。
|
||||
Walsh 在其演讲中还简单介绍了 Red hat 公司 正在开发的另一个暂时叫做 [libpod][24] 的项目。项目名称来源于 Kubernetes 中的 “pod”, 在 Kubernetes 中 “pod” 用于分组主机内的容器,分享名字空间等。
|
||||
|
||||
Libpod 提供 `kpod` 命令,用于直接检查和操作容器存储。Walsh 分析了该命令发挥作用的场景,例如 `dockerd` 停止响应或 Kubernetes 集群崩溃。基本上,`kpod` 独立地再次实现了 `docker` 命令行工具。`kpod ps` 返回运行中的容器列表,`kpod images` 返回镜像列表。事实上,[命令转换速查手册][28] 中给出了每一条 Docker 命令对应的 `kpod` 命令。
|
||||
|
||||
这种模块化实现的一个好处是,当你使用 `kpod run` 运行容器时,容器直接作为当前 shell 而不是 `dockerd` 的子进程启动。理论上,可以直接使用 systemd 启动容器,这样可以消除 `dockerd` 引入的冗余。这让[由套接字激活的容器][29]成为可能,但暂时基于 Docker 实现该特性[并不容易][30],[即使借助 Kubernetes][31] 也是如此。但我在测试过程中发现,使用 `kpod` 启动的容器有一些基础功能性缺失,具体而言是网络功能(!),相关实现在[活跃开发][32]过程中。
|
||||
这种模块化实现的一个好处是,当你使用 `kpod run` 运行容器时,容器直接作为当前 shell 而不是 `dockerd` 的子进程启动。理论上,可以直接使用 systemd 启动容器,这样可以消除 `dockerd` 引入的冗余。这让[由套接字激活的容器][29]成为可能,但暂时基于 Docker 实现该特性[并不容易][30],[即使借助 Kubernetes][31] 也是如此。但我在测试过程中发现,使用 `kpod` 启动的容器有一些基础功能性缺失,具体而言是网络功能(!),相关实现在[活跃开发][32]过程中。
|
||||
|
||||
我们最后提到的命令是 `push`。虽然上述命令已经足以满足本地使用容器的需求,但没有提到远程仓库,借助远程仓库开发者可以活跃地进行应用打包协作。仓库也是持续部署框架的核心组件。[skopeo][33] 项目用于填补这个空白,它是另一个 Atomic 成员项目,按其 `README` 文件描述,“包含容器镜像及镜像库的多种操作”。该项目的设计初衷是,在不用类似 `docker pull` 那样实际下载可能体积庞大的镜像的前提下,检查容器镜像的内容。Docker [拒绝加入][34] 检查功能,建议通过一个额外的工具实现该功能,这促成了 Skopeo 项目。除了`pull`,`push`,Skopeo现在还可以完成很多其它操作,例如在,不产生本地副本的情况下将镜像在不同的仓库中复制和转换。由于部分功能比较基础,可供其它项目使用,目前很大一部分 Skopeo 代码位于一个叫做 [containers/image][35] 的基础库。[Pivotal][36], Google的 [container-diff][37] ,`kpod push` 及 `buildah push` 都使用了该库。
|
||||
我们最后提到的命令是 `push`。虽然上述命令已经足以满足本地使用容器的需求,但没有提到远程仓库,借助远程仓库开发者可以活跃地进行应用打包协作。仓库也是持续部署框架的核心组件。[skopeo][33] 项目用于填补这个空白,它是另一个 Atomic 成员项目,按其 `README` 文件描述,“包含容器镜像及镜像库的多种操作”。该项目的设计初衷是,在不用类似 `docker pull` 那样实际去下载可能体积庞大的镜像的前提下,检查容器镜像的内容。Docker [拒绝加入][34] 检查功能,建议通过一个额外的工具实现该功能,这促成了 Skopeo 项目。除了 `pull`、`push`,Skopeo 现在还可以完成很多其它操作,例如在,不产生本地副本的情况下将镜像在不同的仓库中复制和转换。由于部分功能比较基础,可供其它项目使用,目前很大一部分 Skopeo 代码位于一个叫做 [containers/image][35] 的基础库。[Pivotal][36]、 Google 的 [container-diff][37] 、`kpod push` 及 `buildah push` 都使用了该库。
|
||||
|
||||
`kpod` 与 Kubernetes 并没有紧密的联系,故未来可能会更换名称(事实上,在本文刊发过程中,已经更名为 [`podman`][38]),毕竟 Red Hat 法务部门还没有明确其名称。该团队希望实现更多 pod 级别的命令,这样可以对多个容器进行操作,有点类似于 [`docker compose`][39] 实现的功能。但在这方面,[Kompose][40] 是更好的工具,可以通过 [复合 YAML 文件][41] 在 Kubernetes 集群中运行容器。按计划,我们不会实现类似于 [`swarm`] 的 Docker 命令,这部分功能最好由 Kubernetes 本身完成。
|
||||
`kpod` 与 Kubernetes 并没有紧密的联系,故未来可能会更换名称(事实上,在本文刊发过程中,已经更名为 [`podman`][38]),毕竟 Red Hat 法务部门还没有明确其名称。该团队希望实现更多 pod 级别的命令,这样可以对多个容器进行操作,有点类似于 [`docker compose`][39] 实现的功能。但在这方面,[Kompose][40] 是更好的工具,可以通过 [复合 YAML 文件][41] 在 Kubernetes 集群中运行容器。按计划,我们不会实现类似于 [`swarm`] 的 Docker 命令,这部分功能最好由 Kubernetes 本身完成。
|
||||
|
||||
目前看来,已经持续数年的 Docker 模块化努力终将硕果累累。但目前 `kpod` 处于快速迭代过程中,不太适合用于生产环境,但那些工具的众不同的设计理念让人很感兴趣,而且其中大部分的工具已经可以用于开发环境。目前只能通过编译源码的方式安装 libpod,但最终会提供各个发行版的二进制包。
|
||||
目前看来,已经持续数年的 Docker 模块化努力终将硕果累累。但目前 `kpod` 处于快速迭代过程中,不太适合用于生产环境,不过那些工具的与众不同的设计理念让人很感兴趣,而且其中大部分的工具已经可以用于开发环境。目前只能通过编译源码的方式安装 libpod,但最终会提供各个发行版的二进制包。
|
||||
|
||||
> 本文[最初发表][43]于 [Linux Weekly News][44]。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
链接: https://anarc.at/blog/2017-12-20-docker-without-docker/
|
||||
via: https://anarc.at/blog/2017-12-20-docker-without-docker/
|
||||
|
||||
作者:[À propos de moi][a]
|
||||
作者:[Anarcat][a]
|
||||
译者:[pinewall](https://github.com/pinewall)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -0,0 +1,198 @@
|
||||
初识 Python:全局、局部和非局部变量(带示例)
|
||||
======
|
||||
|
||||
### 全局变量
|
||||
|
||||
在 Python 中,在函数之外或在全局范围内声明的变量被称为全局变量。 这意味着,全局变量可以在函数内部或外部访问。
|
||||
|
||||
我们来看一个关于如何在 Python 中创建一个全局变量的示例。
|
||||
|
||||
#### 示例 1:创建全局变量
|
||||
|
||||
```python
|
||||
x = "global"
|
||||
|
||||
def foo():
|
||||
print("x inside :", x)
|
||||
|
||||
foo()
|
||||
print("x outside:", x)
|
||||
```
|
||||
|
||||
当我们运行代码时,将会输出:
|
||||
|
||||
```
|
||||
x inside : global
|
||||
x outside: global
|
||||
```
|
||||
|
||||
在上面的代码中,我们创建了 `x` 作为全局变量,并定义了一个 `foo()` 来打印全局变量 `x`。 最后,我们调用 `foo()` 来打印x的值。
|
||||
|
||||
倘若你想改变一个函数内的 `x` 的值该怎么办?
|
||||
|
||||
```python
|
||||
x = "global"
|
||||
|
||||
def foo():
|
||||
x = x * 2
|
||||
print(x)
|
||||
foo()
|
||||
```
|
||||
|
||||
当我们运行代码时,将会输出:
|
||||
|
||||
```
|
||||
UnboundLocalError: local variable 'x' referenced before assignment
|
||||
```
|
||||
|
||||
输出显示一个错误,因为 Python 将 `x` 视为局部变量,而 `x` 没有在 `foo()` 内部定义。
|
||||
|
||||
为了运行正常,我们使用 `global` 关键字,查看 [PythonGlobal 关键字][1]以便了解更多。
|
||||
|
||||
### 局部变量
|
||||
|
||||
在函数体内或局部作用域内声明的变量称为局部变量。
|
||||
|
||||
#### 示例 2:访问作用域外的局部变量
|
||||
|
||||
```python
|
||||
def foo():
|
||||
y = "local"
|
||||
|
||||
foo()
|
||||
print(y)
|
||||
```
|
||||
|
||||
当我们运行代码时,将会输出:
|
||||
|
||||
```
|
||||
NameError: name 'y' is not defined
|
||||
```
|
||||
|
||||
输出显示了一个错误,因为我们试图在全局范围内访问局部变量 `y`,而局部变量只能在 `foo()` 函数内部或局部作用域内有效。
|
||||
|
||||
我们来看一个关于如何在 Python 中创建一个局部变量的例子。
|
||||
|
||||
#### 示例 3:创建一个局部变量
|
||||
|
||||
通常,我们在函数内声明一个变量来创建一个局部变量。
|
||||
|
||||
```python
|
||||
def foo():
|
||||
y = "local"
|
||||
print(y)
|
||||
|
||||
foo()
|
||||
```
|
||||
|
||||
当我们运行代码时,将会输出:
|
||||
|
||||
```
|
||||
local
|
||||
```
|
||||
|
||||
让我们来看看前面的问题,其中x是一个全局变量,我们想修改 `foo()` 内部的 `x`。
|
||||
|
||||
### 全局变量和局部变量
|
||||
|
||||
在这里,我们将展示如何在同一份代码中使用全局变量和局部变量。
|
||||
|
||||
#### 示例 4:在同一份代码中使用全局变量和局部变量
|
||||
|
||||
```python
|
||||
x = "global"
|
||||
|
||||
def foo():
|
||||
global x
|
||||
y = "local"
|
||||
x = x * 2
|
||||
print(x)
|
||||
print(y)
|
||||
|
||||
foo()
|
||||
```
|
||||
|
||||
当我们运行代码时,将会输出(LCTT 译注:原文中输出结果的两个 `global` 有空格,正确的是没有空格):
|
||||
```
|
||||
globalglobal
|
||||
local
|
||||
```
|
||||
|
||||
在上面的代码中,我们将 `x` 声明为全局变量,将 `y` 声明为 `foo()` 中的局部变量。 然后,我们使用乘法运算符 `*` 来修改全局变量 `x`,并打印 `x` 和 `y`。
|
||||
|
||||
在调用 `foo()` 之后,`x` 的值变成 `globalglobal`了(LCTT 译注:原文同样有空格,正确的是没有空格),因为我们使用 `x * 2` 打印两次 `global`。 之后,我们打印局部变量y的值,即 `local` 。
|
||||
|
||||
#### 示例 5:具有相同名称的全局变量和局部变量
|
||||
|
||||
```python
|
||||
x = 5
|
||||
|
||||
def foo():
|
||||
x = 10
|
||||
print("local x:", x)
|
||||
|
||||
foo()
|
||||
print("global x:", x)
|
||||
```
|
||||
|
||||
当我们运行代码时,将会输出:
|
||||
|
||||
```
|
||||
local x: 10
|
||||
global x: 5
|
||||
```
|
||||
|
||||
在上面的代码中,我们对全局变量和局部变量使用了相同的名称 `x`。 当我们打印相同的变量时却得到了不同的结果,因为这两个作用域内都声明了变量,即 `foo()` 内部的局部作用域和 `foo()` 外面的全局作用域。
|
||||
|
||||
当我们在 `foo()` 内部打印变量时,它输出 `local x: 10`,这被称为变量的局部作用域。
|
||||
|
||||
同样,当我们在 `foo()` 外部打印变量时,它输出 `global x: 5`,这被称为变量的全局作用域。
|
||||
|
||||
### 非局部变量
|
||||
|
||||
非局部变量用于局部作用域未定义的嵌套函数。 这意味着,变量既不能在局部也不能在全局范围内。
|
||||
|
||||
我们来看一个关于如何在 Python 中创建一个非局部变量的例子。(LCTT 译者注:原文为创建全局变量,疑为笔误)
|
||||
|
||||
我们使用 `nonlocal` 关键字来创建非局部变量。
|
||||
|
||||
#### 例 6:创建一个非局部变量
|
||||
|
||||
```python
|
||||
def outer():
|
||||
x = "local"
|
||||
|
||||
def inner():
|
||||
nonlocal x
|
||||
x = "nonlocal"
|
||||
print("inner:", x)
|
||||
|
||||
inner()
|
||||
print("outer:", x)
|
||||
|
||||
outer()
|
||||
```
|
||||
|
||||
当我们运行代码时,将会输出:
|
||||
|
||||
```
|
||||
inner: nonlocal
|
||||
outer: nonlocal
|
||||
```
|
||||
|
||||
在上面的代码中有一个嵌套函数 `inner()`。 我们使用 `nonlocal` 关键字来创建非局部变量。`inner()` 函数是在另一个函数 `outer()` 的作用域中定义的。
|
||||
|
||||
注意:如果我们改变非局部变量的值,那么变化就会出现在局部变量中。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.programiz.com/python-programming/global-local-nonlocal-variables
|
||||
|
||||
作者:[programiz][a]
|
||||
译者:[Flowsnow](https://github.com/Flowsnow)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.programiz.com/
|
||||
[1]:https://www.programiz.com/python-programming/global-keyword
|
@ -1,6 +1,8 @@
|
||||
放慢速度是如何使我变得更好的领导者
|
||||
放慢速度如何使我变成更好的领导者
|
||||
======
|
||||
|
||||
> 开放式领导和耐心、倾听一样重要,它们都是关于执行的。
|
||||
|
||||

|
||||
|
||||
在我职业生涯的早期,我认为我能做的最重要的事情就是行动。如果我的老板说跳,我的回答是“跳多高?”
|
||||
@ -9,15 +11,15 @@
|
||||
|
||||
实行开放式领导需要培养耐心和倾听技能,我需要在[最佳行动计划上进行合作,而不仅仅是最快的计划][2]。它还为我提供了一些工具,以解释 [为什么我会对某人说“不”][3] (或者,也许是“不是现在”),这样我就能以透明和自信的方式领导。
|
||||
|
||||
如果你正在进行软件开发和实践 scrum 中,那么下面的观点可能会引起你的共鸣:在 sprint 计划和 sprint 演示中,耐心和倾听经理的表现和它的技能一样重要。(译注: scrum 是迭代式增量软件开发过程,通常用于敏捷软件开发。 sprint 计划和 sprint 演示是其中的两个术语。)忘掉它们,你会减少你能够产生的影响。
|
||||
如果你正在进行软件开发和实践 scrum 中,那么下面的观点可能会引起你的共鸣:在 sprint 计划和 sprint 演示中,耐心和倾听经理的表现和它的技能一样重要。(LCTT 译注: scrum 是迭代式增量软件开发过程,通常用于敏捷软件开发。 sprint 计划和 sprint 演示是其中的两个术语。)忘掉它们,你会减少你能够产生的影响。
|
||||
|
||||
### 专注于耐心
|
||||
|
||||
专注和耐心并不总是容易的。通常,我发现自己正坐在会议上,用行动项目填满我的笔记本时,我一般会思考:“我们可以简单地对 x 和 y 进行改进”。然后我记得事情不是那么线性的。(译者注:这句话感觉翻译得并不通顺)
|
||||
专注和耐心并不总是容易的。通常,我发现自己正坐在会议上,用行动项目填满我的笔记本时,我一般会思考:“我们只要做了某事,另外一件事就会得到改善”。然后我记得事物不是那么线性发展的。
|
||||
|
||||
我需要考虑可能影响情况的其他因素。暂停下来从多个人和资源中获取数据可以帮我充实策略,以确保出组织长期成功。它还帮助我确定那些短期的里程碑,这些里程碑应该会让我负责生产的业务完成交付。
|
||||
我需要考虑可能影响情况的其他因素。暂停下来从多个人和资源中获取数据可以帮我充实策略,以确保组织长期成功。它还帮助我确定那些短期的里程碑,这些里程碑应该可以让我负责生产的业务完成交付。
|
||||
|
||||
这里有一个很好的例子,以前耐心不是我认为应该拥有的东西,而这又是如何影响了我的表现。当我在北卡罗来纳州工作时,我与一个在亚利桑那州的人共事。我们没有使用视频会议技术,所以当我们交谈时我没有看到她的肢体语言。然而当我负责为我领导的项目交付结果时,她是确保我获得足够支持的两个人之一。
|
||||
这里有一个很好的例子,以前耐心不是我认为应该拥有、以及影响我的表现的东西。当我在北卡罗来纳州工作时,我与一个在亚利桑那州的人共事。我们没有使用视频会议技术,所以当我们交谈时我没有看到她的肢体语言。然而当我负责为我领导的项目交付结果时,她是确保我获得足够支持的两个人之一。
|
||||
|
||||
无论出于何种原因,当我与她交谈时,当她要求我做某件事时,我做了。她会为我的绩效评估提供意见,所以我想确保她高兴。那时,我还不够成熟不懂得其实没必要非要讨她开心;我的重点应该放在其他绩效指标上。我本应该花更多的时间倾听并与她合作,而不是在她还在说话的时候拿起第一个“行动项目”并开始工作。
|
||||
|
||||
@ -35,7 +37,7 @@
|
||||
|
||||
我最终对她有一些反馈。 下次我们一起工作时,我不想在六个月后听到反馈意见。 我想早些时候和更频繁地听到反馈意见,以便我能够尽早从错误中学习。 关于这项工作的持续讨论是任何团队都应该发生的事情。
|
||||
|
||||
当我成为一名管理者和领导者时,我坚持要求我的团队达到相同的标准:计划,制定计划并反思。 重复。 不要让外力造成的麻烦让你偏离你需要实施的计划。 将工作分成小的增量,以便反思和调整计划。 正如 Daniel Goleman 写道:“把注意力放在需要的地方是领导力的一个主要任务。” 不要害怕面对这个挑战。
|
||||
当我成为一名管理者和领导者时,我坚持要求我的团队达到相同的标准:计划,执行计划并反思。 重复。 不要让外力造成的麻烦让你偏离你需要实施的计划。 将工作分成小的增量,以便反思和调整计划。 正如 Daniel Goleman 写道:“把注意力放在需要的地方是领导力的一个主要任务。” 不要害怕面对这个挑战。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -43,7 +45,7 @@ via: [https://opensource.com/open-organization/18/2/open-leadership-patience-lis
|
||||
|
||||
作者:[Angela Robertson][a]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,134 +1,120 @@
|
||||
如何使用树莓派测定颗粒物
|
||||
如何使用树莓派测定颗粒物(PM 2.5)
|
||||
======
|
||||
|
||||
> 使用两个简单的硬件设备和几行代码构建一个空气质量探测器。
|
||||
|
||||

|
||||
|
||||
我们在东南亚的学校定期测定空气中的颗粒物。这里的测定值非常高,尤其是在二到五月之间,干燥炎热、土地干旱等各种因素都对空气质量产生了不利的影响。我将会在这篇文章中展示如何使用树莓派来测定颗粒物。
|
||||
|
||||
### 什么是颗粒物?
|
||||
|
||||
颗粒物就是粉尘或者空气中的微小颗粒。其中 PM10 和 PM2.5 之间的差别就是 PM10 指的是粒径小于10微米的颗粒,而 PM2.5 指的是粒径小于2.5微米的颗粒。在粒径小于2.5微米的的情况下,由于它们能被吸入肺泡中并且对呼吸系统造成影响,因此颗粒越小,对人的健康危害越大。
|
||||
颗粒物就是粉尘或者空气中的微小颗粒。其中 PM10 和 PM2.5 之间的差别就是 PM10 指的是粒径小于 10 微米的颗粒,而 PM2.5 指的是粒径小于 2.5 微米的颗粒。在粒径小于 2.5 微米的的情况下,由于它们能被吸入肺泡中并且对呼吸系统造成影响,因此颗粒越小,对人的健康危害越大。
|
||||
|
||||
世界卫生组织的建议[颗粒物浓度][1]是:
|
||||
|
||||
* 年均 PM10 不高于20 µg/m³
|
||||
* 年均 PM2.5 不高于10 µg/m³
|
||||
* 不允许超标时,日均 PM10 不高于50 µg/m³
|
||||
* 不允许超标时,日均 PM2.5 不高于25 µg/m³
|
||||
* 年均 PM10 不高于 20 µg/m³
|
||||
* 年均 PM2.5 不高于 10 µg/m³
|
||||
* 不允许超标时,日均 PM10 不高于 50 µg/m³
|
||||
* 不允许超标时,日均 PM2.5 不高于 25 µg/m³
|
||||
|
||||
以上数值实际上是低于大多数国家的标准的,例如欧盟对于 PM10 所允许的年均值是不高于40 µg/m³。
|
||||
以上数值实际上是低于大多数国家的标准的,例如欧盟对于 PM10 所允许的年均值是不高于 40 µg/m³。
|
||||
|
||||
### 什么是空气质量指数(AQI, Air Quality Index)?
|
||||
### 什么是<ruby>空气质量指数<rt>Air Quality Index</rt></ruby>(AQI)?
|
||||
|
||||
空气质量指数按照颗粒物的测定值来评价空气质量的好坏,然而由于各国之间的计算方式有所不同,这个指数并没有统一的标准。维基百科上关于[空气质量指数][2]的词条对此给出了一个概述。我们学校则以[美国环境保护协会][3](EPA, Environment Protection Agency)建立的分类法来作为依据。
|
||||
空气质量指数是按照颗粒物的测定值来评价空气质量的好坏,然而由于各国之间的计算方式有所不同,这个指数并没有统一的标准。维基百科上关于[空气质量指数][2]的词条对此给出了一个概述。我们学校则以<ruby>[美国环境保护协会][3]<rt>Environment Protection Agency</rt></ruby>(EPA)建立的分类法来作为依据。
|
||||
|
||||
![空气质量指数][5]
|
||||
|
||||
空气质量指数
|
||||
*空气质量指数*
|
||||
|
||||
### 测定颗粒物需要哪些准备?
|
||||
|
||||
测定颗粒物只需要以下两种器材:
|
||||
|
||||
* 树莓派(款式不限,最好带有 WiFi)
|
||||
* SDS011 颗粒物传感器
|
||||
|
||||
|
||||
|
||||
![颗粒物传感器][7]
|
||||
|
||||
颗粒物传感器
|
||||
*颗粒物传感器*
|
||||
|
||||
如果是只带有 Micro USB的树莓派Zero W,那还需要一根连接到标准 USB 端口的适配线,只需要20美元,而传感器则自带适配串行接口的 USB 适配器。
|
||||
如果是只带有 Micro USB 的树莓派 Zero W,那还需要一根连接到标准 USB 端口的适配线,只需要 20 美元,而传感器则自带适配串行接口的 USB 适配器。
|
||||
|
||||
### 安装过程
|
||||
|
||||
对于树莓派,只需要下载对应的 Raspbian Lite 镜像并且[写入到 Micro SD 卡][8]上就可以了(网上很多教程都有介绍如何设置 WLAN 连接,我就不细说了)。
|
||||
|
||||
如果要使用 SSH,那还需要在启动分区建立一个名为 `ssh` 的空文件。树莓派的 IP 通过路由器或者 DHCP 服务器获取,随后就可以通过 SSH 登录到树莓派了(默认密码是 raspberry):
|
||||
|
||||
```
|
||||
$ ssh pi@192.168.1.5
|
||||
|
||||
```
|
||||
|
||||
首先我们需要在树莓派上安装一下这些包:
|
||||
|
||||
```
|
||||
$ sudo apt install git-core python-serial python-enum lighttpd
|
||||
|
||||
```
|
||||
|
||||
在开始之前,我们可以用 `dmesg` 来获取 USB 适配器连接的串行接口:
|
||||
|
||||
```
|
||||
$ dmesg
|
||||
|
||||
[ 5.559802] usbcore: registered new interface driver usbserial
|
||||
|
||||
[ 5.559930] usbcore: registered new interface driver usbserial_generic
|
||||
|
||||
[ 5.560049] usbserial: USB Serial support registered for generic
|
||||
|
||||
[ 5.569938] usbcore: registered new interface driver ch341
|
||||
|
||||
[ 5.570079] usbserial: USB Serial support registered for ch341-uart
|
||||
|
||||
[ 5.570217] ch341 1–1.4:1.0: ch341-uart converter detected
|
||||
|
||||
[ 5.575686] usb 1–1.4: ch341-uart converter now attached to ttyUSB0
|
||||
|
||||
```
|
||||
|
||||
在最后一行,可以看到接口 `ttyUSB0`。然后我们需要写一个 Python 脚本来读取传感器的数据并以 JSON 格式存储,在通过一个 HTML 页面就可以把数据展示出来了。
|
||||
|
||||
### 在树莓派上读取数据
|
||||
|
||||
首先创建一个传感器实例,每5分钟读取一次传感器的数据,持续30秒,这些数值后续都可以调整。在每两次测定的间隔,我们把传感器调到睡眠模式以延长它的使用寿命(厂商认为元件的寿命大约8000小时)。
|
||||
首先创建一个传感器实例,每 5 分钟读取一次传感器的数据,持续 30 秒,这些数值后续都可以调整。在每两次测定的间隔,我们把传感器调到睡眠模式以延长它的使用寿命(厂商认为元件的寿命大约 8000 小时)。
|
||||
|
||||
我们可以使用以下命令来下载 Python 脚本:
|
||||
|
||||
```
|
||||
$ wget -O /home/pi/aqi.py https://raw.githubusercontent.com/zefanja/aqi/master/python/aqi.py
|
||||
|
||||
```
|
||||
|
||||
另外还需要执行以下两条命令来保证脚本正常运行:
|
||||
|
||||
```
|
||||
$ sudo chown pi:pi /var/wwww/html/
|
||||
|
||||
$ echo[] > /var/wwww/html/aqi.json
|
||||
|
||||
$ sudo chown pi:pi /var/www/html/
|
||||
$ echo '[]' > /var/www/html/aqi.json
|
||||
```
|
||||
|
||||
下面就可以执行脚本了:
|
||||
|
||||
```
|
||||
$ chmod +x aqi.py
|
||||
|
||||
$ chmod +x aqi.p
|
||||
$ ./aqi.py
|
||||
|
||||
PM2.5:55.3, PM10:47.5
|
||||
|
||||
PM2.5:55.5, PM10:47.7
|
||||
|
||||
PM2.5:55.7, PM10:47.8
|
||||
|
||||
PM2.5:53.9, PM10:47.6
|
||||
|
||||
PM2.5:53.6, PM10:47.4
|
||||
|
||||
PM2.5:54.2, PM10:47.3
|
||||
|
||||
…
|
||||
|
||||
```
|
||||
|
||||
### 自动化执行脚本
|
||||
|
||||
只需要使用诸如 crontab 的服务,我们就不需要每次都手动启动脚本了。按照以下命令打开 crontab 文件:
|
||||
|
||||
```
|
||||
$ crontab -e
|
||||
|
||||
```
|
||||
|
||||
在文件末尾添加这一行:
|
||||
|
||||
```
|
||||
@reboot cd /home/pi/ && ./aqi.py
|
||||
|
||||
```
|
||||
|
||||
现在我们的脚本就会在树莓派每次重启后自动执行了。
|
||||
@ -138,17 +124,14 @@ $ crontab -e
|
||||
我们在前面已经安装了一个轻量级的 web 服务器 `lighttpd`,所以我们需要把 HTML、JavaScript、CSS 文件放置在 `/var/www/html` 目录中,这样就能通过电脑和智能手机访问到相关数据了。执行下面的三条命令,可以下载到对应的文件:
|
||||
|
||||
```
|
||||
$ wget -O /var/wwww/html/index.html https://raw.githubusercontent.com/zefanja/aqi/master/html/index.html
|
||||
|
||||
$ wget -O /var/wwww/html/aqi.js https://raw.githubusercontent.com/zefanja/aqi/master/html/aqi.js
|
||||
|
||||
$ wget -O /var/wwww/html/style.css https://raw.githubusercontent.com/zefanja/aqi/master/html/style.css
|
||||
|
||||
$ wget -O /var/www/html/index.html https://raw.githubusercontent.com/zefanja/aqi/master/html/index.html
|
||||
$ wget -O /var/www/html/aqi.js https://raw.githubusercontent.com/zefanja/aqi/master/html/aqi.js
|
||||
$ wget -O /var/www/html/style.css https://raw.githubusercontent.com/zefanja/aqi/master/html/style.css
|
||||
```
|
||||
|
||||
在 JavaScript 文件中,实现了打开 JSON 文件、提取数据、计算空气质量指数的过程,随后页面的背景颜色将会根据 EPA 的划分标准而变化。
|
||||
|
||||
你只需要用浏览器访问树莓派的地址,就可以看到当前颗粒物浓度值等数据了。[http://192.168.1.5:][9]
|
||||
你只需要用浏览器访问树莓派的地址,就可以看到当前颗粒物浓度值等数据了: [http://192.168.1.5:][9]
|
||||
|
||||
这个页面比较简单而且可扩展,比如可以添加一个展示过去数小时历史数据的表格等等。
|
||||
|
||||
@ -158,7 +141,7 @@ $ wget -O /var/wwww/html/style.css https://raw.githubusercontent.com/zefanja/aqi
|
||||
|
||||
在资金相对紧张的情况下,树莓派是一种选择。除此以外,还有很多可以用来测定颗粒物的应用,包括室外固定装置、移动测定设备等等。我们学校则同时采用了这两种:固定装置在室外测定全天颗粒物浓度,而移动测定设备在室内检测空调过滤器的效果。
|
||||
|
||||
[Luftdaten.info][12]提供了一个如何设计类似的传感器的介绍,其中的软件效果出众,而且因为它没有使用树莓派,所以硬件更是小巧。
|
||||
[Luftdaten.info][12] 提供了一个如何设计类似的传感器的介绍,其中的软件效果出众,而且因为它没有使用树莓派,所以硬件更是小巧。
|
||||
|
||||
对于学生来说,设计一个颗粒物传感器确实算得上是一个优秀的课外项目。
|
||||
|
||||
@ -170,7 +153,7 @@ via: https://opensource.com/article/18/3/how-measure-particulate-matter-raspberr
|
||||
|
||||
作者:[Stephan Tetzel][a]
|
||||
译者:[HankChow](https://github.com/HankChow)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,41 +1,40 @@
|
||||
如何使用 Vim 编辑器编辑多个文件
|
||||
如何使用 Vim 编辑多个文件
|
||||
======
|
||||
|
||||

|
||||
|
||||
|
||||
有时候,您可能需要修改多个文件,或要将一个文件的内容复制到另一个文件中。在图形用户界面中,您可以在任何图形文本编辑器(如 gedit)中打开文件,并使用 CTRL + C 和 CTRL + V 复制和粘贴内容。在命令行模式下,您不能使用这种编辑器。不过别担心,只要有 vim 编辑器就有办法。在本教程中,我们将学习使用 Vim 编辑器同时编辑多个文件。相信我,很有意思哒。
|
||||
有时候,您可能需要修改多个文件,或要将一个文件的内容复制到另一个文件中。在图形用户界面中,您可以在任何图形文本编辑器(如 gedit)中打开文件,并使用 `CTRL + C` 和 `CTRL + V` 复制和粘贴内容。在命令行模式下,您不能使用这种编辑器。不过别担心,只要有 `vim` 编辑器就有办法。在本教程中,我们将学习使用 `vim` 编辑器同时编辑多个文件。相信我,很有意思哒。
|
||||
|
||||
### 安装 Vim
|
||||
|
||||
Vim 编辑器可在大多数 Linux 发行版的官方软件仓库中找到,所以您可以用默认的软件包管理器来安装它。例如,在 Arch Linux 及其变体上,您可以使用如下命令:
|
||||
|
||||
```
|
||||
$ sudo pacman -S vim
|
||||
|
||||
```
|
||||
|
||||
在 Debian 和 Ubuntu 上:
|
||||
|
||||
```
|
||||
$ sudo apt-get install vim
|
||||
|
||||
```
|
||||
|
||||
在 RHEL 和 CentOS 上:
|
||||
|
||||
```
|
||||
$ sudo yum install vim
|
||||
|
||||
```
|
||||
|
||||
在 Fedora 上:
|
||||
|
||||
```
|
||||
$ sudo dnf install vim
|
||||
|
||||
```
|
||||
|
||||
在 openSUSE 上:
|
||||
|
||||
```
|
||||
$ sudo zypper install vim
|
||||
|
||||
```
|
||||
|
||||
### 使用 Linux 的 Vim 编辑器同时编辑多个文件
|
||||
@ -44,7 +43,8 @@ $ sudo zypper install vim
|
||||
|
||||
#### 方法一
|
||||
|
||||
有两个文件,即 **file1.txt** 和 **file2.txt**,带有一堆随机单词:
|
||||
有两个文件,即 `file1.txt` 和 `file2.txt`,带有一堆随机单词:
|
||||
|
||||
```
|
||||
$ cat file1.txt
|
||||
ostechnix
|
||||
@ -59,53 +59,52 @@ line2
|
||||
line3
|
||||
line4
|
||||
line5
|
||||
|
||||
```
|
||||
|
||||
现在,让我们同时编辑这两个文件。请运行:
|
||||
|
||||
```
|
||||
$ vim file1.txt file2.txt
|
||||
|
||||
```
|
||||
|
||||
Vim 将按顺序显示文件的内容。首先显示第一个文件的内容,然后显示第二个文件,依此类推。
|
||||
|
||||
![][2]
|
||||
|
||||
**在文件中切换**
|
||||
##### 在文件中切换
|
||||
|
||||
要移至下一个文件,请键入:
|
||||
|
||||
```
|
||||
:n
|
||||
|
||||
```
|
||||
|
||||
![][3]
|
||||
|
||||
要返回到前一个文件,请键入:
|
||||
|
||||
```
|
||||
:N
|
||||
|
||||
```
|
||||
|
||||
如果有任何未保存的更改,Vim 将不允许您移动到下一个文件。要保存当前文件中的更改,请键入:
|
||||
|
||||
```
|
||||
ZZ
|
||||
|
||||
```
|
||||
|
||||
请注意,是两个大写字母 ZZ(SHIFT + zz)。
|
||||
请注意,是两个大写字母 `ZZ`(`SHIFT + zz`)。
|
||||
|
||||
要放弃更改并移至上一个文件,请键入:
|
||||
|
||||
```
|
||||
:N!
|
||||
|
||||
```
|
||||
|
||||
要查看当前正在编辑的文件,请键入:
|
||||
|
||||
```
|
||||
:buffers
|
||||
|
||||
```
|
||||
|
||||
![][4]
|
||||
@ -114,57 +113,59 @@ ZZ
|
||||
|
||||
![][5]
|
||||
|
||||
要切换到下一个文件,请输入 **:buffer**,后跟缓冲区编号。例如,要切换到第一个文件,请键入:
|
||||
要切换到下一个文件,请输入 `:buffer`,后跟缓冲区编号。例如,要切换到第一个文件,请键入:
|
||||
|
||||
```
|
||||
:buffer 1
|
||||
|
||||
```
|
||||
|
||||
![][6]
|
||||
|
||||
**打开其他文件进行编辑**
|
||||
##### 打开其他文件进行编辑
|
||||
|
||||
目前我们正在编辑两个文件,即 file1.txt 和 file2.txt。我想打开另一个名为 **file3.txt** 的文件进行编辑。
|
||||
目前我们正在编辑两个文件,即 `file1.txt` 和 `file2.txt`。我想打开另一个名为 `file3.txt` 的文件进行编辑。
|
||||
|
||||
您会怎么做?这很容易。只需键入 `:e`,然后输入如下所示的文件名即可:
|
||||
|
||||
您会怎么做?这很容易。只需键入 **:e**,然后输入如下所示的文件名即可:
|
||||
```
|
||||
:e file3.txt
|
||||
|
||||
```
|
||||
|
||||
![][7]
|
||||
|
||||
现在你可以编辑 file3.txt 了。
|
||||
现在你可以编辑 `file3.txt` 了。
|
||||
|
||||
要查看当前正在编辑的文件数量,请键入:
|
||||
|
||||
```
|
||||
:buffers
|
||||
|
||||
```
|
||||
|
||||
![][8]
|
||||
|
||||
请注意,对于使用 **:e** 打开的文件,您无法使用 **:n** 或 **:N** 进行切换。要切换到另一个文件,请输入 **:buffer**,然后输入文件缓冲区编号。
|
||||
请注意,对于使用 `:e` 打开的文件,您无法使用 `:n` 或 `:N` 进行切换。要切换到另一个文件,请输入 `:buffer`,然后输入文件缓冲区编号。
|
||||
|
||||
**将一个文件的内容复制到另一个文件中**
|
||||
##### 将一个文件的内容复制到另一个文件中
|
||||
|
||||
您已经知道了如何同时打开和编辑多个文件。有时,您可能想要将一个文件的内容复制到另一个文件中。这也是可以做到的。切换到您选择的文件,例如,假设您想将 file1.txt 的内容复制到 file2.txt 中:
|
||||
您已经知道了如何同时打开和编辑多个文件。有时,您可能想要将一个文件的内容复制到另一个文件中。这也是可以做到的。切换到您选择的文件,例如,假设您想将 `file1.txt` 的内容复制到 `file2.txt` 中:
|
||||
|
||||
|
||||
首先,请切换到 `file1.txt`:
|
||||
|
||||
首先,请切换到 file1.txt:
|
||||
```
|
||||
:buffer 1
|
||||
|
||||
```
|
||||
|
||||
将光标移动至在想要复制的行的前面,并键入**yy** 以抽出(复制)该行。然后,移至 file2.txt:
|
||||
将光标移动至在想要复制的行的前面,并键入`yy` 以抽出(复制)该行。然后,移至 `file2.txt`:
|
||||
|
||||
```
|
||||
:buffer 2
|
||||
|
||||
```
|
||||
|
||||
将光标移至要从 file1.txt 粘贴复制行的位置,然后键入 **p**。例如,您想要将复制的行粘贴到 line2 和 line3 之间,请将鼠标光标置于行前并键入 **p**。
|
||||
将光标移至要从 `file1.txt` 粘贴复制行的位置,然后键入 `p`。例如,您想要将复制的行粘贴到 `line2` 和 `line3` 之间,请将鼠标光标置于行前并键入 `p`。
|
||||
|
||||
输出示例:
|
||||
|
||||
```
|
||||
line1
|
||||
line2
|
||||
@ -172,54 +173,54 @@ ostechnix
|
||||
line3
|
||||
line4
|
||||
line5
|
||||
|
||||
```
|
||||
|
||||
![][9]
|
||||
|
||||
要保存当前文件中所做的更改,请键入:
|
||||
|
||||
```
|
||||
ZZ
|
||||
|
||||
```
|
||||
|
||||
再次提醒,是两个大写字母 ZZ(SHIFT + z)。
|
||||
再次提醒,是两个大写字母 ZZ(`SHIFT + z`)。
|
||||
|
||||
保存所有文件的更改并退出 vim 编辑器,键入:
|
||||
|
||||
```
|
||||
:wq
|
||||
|
||||
```
|
||||
|
||||
同样,您可以将任何文件的任何行复制到其他文件中。
|
||||
|
||||
**将整个文件内容复制到另一个文件中**
|
||||
##### 将整个文件内容复制到另一个文件中
|
||||
|
||||
我们知道如何复制一行,那么整个文件的内容呢?也是可以的。比如说,您要将 file1.txt 的全部内容复制到 file2.txt 中。
|
||||
我们知道如何复制一行,那么整个文件的内容呢?也是可以的。比如说,您要将 `file1.txt` 的全部内容复制到 `file2.txt` 中。
|
||||
|
||||
先打开 `file2.txt`:
|
||||
|
||||
先打开 file2.txt:
|
||||
```
|
||||
$ vim file2.txt
|
||||
|
||||
```
|
||||
|
||||
如果文件已经加载,您可以通过输入以下命令切换到 file2.txt:
|
||||
如果文件已经加载,您可以通过输入以下命令切换到 `file2.txt`:
|
||||
|
||||
```
|
||||
:buffer 2
|
||||
|
||||
```
|
||||
|
||||
将光标移动到您想要粘贴 file1.txt 内容的位置。我想在 file2.txt 的第 5 行之后粘贴 file1.txt 的内容,所以我将光标移动到第 5 行。然后,键入以下命令并按回车键:
|
||||
将光标移动到您想要粘贴 `file1.txt` 的内容的位置。我想在 `file2.txt` 的第 5 行之后粘贴 `file1.txt` 的内容,所以我将光标移动到第 5 行。然后,键入以下命令并按回车键:
|
||||
|
||||
```
|
||||
:r file1.txt
|
||||
|
||||
```
|
||||
|
||||
![][10]
|
||||
|
||||
这里,**r** 代表 **read**。
|
||||
这里,`r` 代表 “read”。
|
||||
|
||||
现在您会看到 `file1.txt` 的内容被粘贴在 `file2.txt` 的第 5 行之后。
|
||||
|
||||
现在您会看到 file1.txt 的内容被粘贴在 file2.txt 的第 5 行之后。
|
||||
```
|
||||
line1
|
||||
line2
|
||||
@ -231,107 +232,103 @@ open source
|
||||
technology
|
||||
linux
|
||||
unix
|
||||
|
||||
```
|
||||
|
||||
![][11]
|
||||
|
||||
要保存当前文件中的更改,请键入:
|
||||
|
||||
```
|
||||
ZZ
|
||||
|
||||
```
|
||||
|
||||
要保存所有文件的所有更改并退出 vim 编辑器,请输入:
|
||||
|
||||
```
|
||||
:wq
|
||||
|
||||
```
|
||||
|
||||
#### 方法二
|
||||
|
||||
另一种同时打开多个文件的方法是使用 **-o** 或 **-O** 标志。
|
||||
另一种同时打开多个文件的方法是使用 `-o` 或 `-O` 标志。
|
||||
|
||||
要在水平窗口中打开多个文件,请运行:
|
||||
|
||||
```
|
||||
$ vim -o file1.txt file2.txt
|
||||
|
||||
```
|
||||
|
||||
![][12]
|
||||
|
||||
要在窗口之间切换,请按 **CTRL-w w**(即按 **CTRL + w** 并再次按 **w**)。或者,您可以使用以下快捷方式在窗口之间移动:
|
||||
|
||||
* **CTRL-w k** – 上面的窗口
|
||||
* **CTRL-w j** – 下面的窗口
|
||||
|
||||
要在窗口之间切换,请按 `CTRL-w w`(即按 `CTRL + w` 并再次按 `w`)。或者,您可以使用以下快捷方式在窗口之间移动:
|
||||
|
||||
* `CTRL-w k` – 上面的窗口
|
||||
* `CTRL-w j` – 下面的窗口
|
||||
|
||||
要在垂直窗口中打开多个文件,请运行:
|
||||
|
||||
```
|
||||
$ vim -O file1.txt file2.txt file3.txt
|
||||
|
||||
```
|
||||
|
||||
![][13]
|
||||
|
||||
要在窗口之间切换,请按 **CTRL-w w**(即按 **CTRL + w** 并再次按 **w**)。或者,使用以下快捷方式在窗口之间移动:
|
||||
|
||||
* **CTRL-w l** – 左面的窗口
|
||||
* **CTRL-w h** – 右面的窗口
|
||||
|
||||
要在窗口之间切换,请按 `CTRL-w w`(即按 `CTRL + w` 并再次按 `w`)。或者,使用以下快捷方式在窗口之间移动:
|
||||
|
||||
* `CTRL-w l` – 左面的窗口
|
||||
* `CTRL-w h` – 右面的窗口
|
||||
|
||||
其他的一切都与方法一的描述相同。
|
||||
|
||||
例如,要列出当前加载的文件,请运行:
|
||||
|
||||
```
|
||||
:buffers
|
||||
|
||||
```
|
||||
|
||||
在文件之间切换:
|
||||
|
||||
```
|
||||
:buffer 1
|
||||
|
||||
```
|
||||
|
||||
打开其他文件,请键入:
|
||||
|
||||
```
|
||||
:e file3.txt
|
||||
|
||||
```
|
||||
|
||||
将文件的全部内容复制到另一个文件中:
|
||||
|
||||
```
|
||||
:r file1.txt
|
||||
|
||||
```
|
||||
|
||||
方法二的唯一区别是,只要您使用 **ZZ** 保存对当前文件的更改,文件将自动关闭。然后,您需要依次键入 **:wq ** 来关闭文件。但是,如果您按照方法一进行操作,输入 **:wq** 时,所有更改将保存在所有文件中,并且所有文件将立即关闭。
|
||||
方法二的唯一区别是,只要您使用 `ZZ` 保存对当前文件的更改,文件将自动关闭。然后,您需要依次键入 `:wq` 来关闭文件。但是,如果您按照方法一进行操作,输入 `:wq` 时,所有更改将保存在所有文件中,并且所有文件将立即关闭。
|
||||
|
||||
有关更多详细信息,请参阅手册页。
|
||||
|
||||
```
|
||||
$ man vim
|
||||
|
||||
```
|
||||
|
||||
|
||||
**建议阅读:**
|
||||
### 建议阅读
|
||||
|
||||
您现在掌握了如何在 Linux 中使用 vim 编辑器编辑多个文件。正如您所见,编辑多个文件并不难。Vim 编辑器还有更强大的功能。我们接下来会提供更多关于 Vim 编辑器的内容。
|
||||
|
||||
再见!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/how-to-edit-multiple-files-using-vim-editor/
|
||||
|
||||
作者:[SK][a]
|
||||
译者:[jessie-pang](https://github.com/jessie-pang)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,4 +1,4 @@
|
||||
我们可以在同一个虚拟机中运行 Python 2 和 Python 3 代码而不需要更改代码吗?
|
||||
我们可以在同一个虚拟机中运行 Python 2 和 3 代码而不需要更改代码吗?
|
||||
=====
|
||||
|
||||
从理论上来说,可以。Zed Shaw 说过一句著名的话,如果不行,那么 Python 3 一定不是图灵完备的。但在实践中,这是不现实的,我将通过给你们举几个例子来说明原因。
|
||||
@ -6,9 +6,8 @@
|
||||
### 对于字典(dict)来说,这意味着什么?
|
||||
|
||||
让我们来想象一台拥有 Python 6 的虚拟机,它可以读取 Python 3.6 编写的 `module3.py`。但是在这个模块中,它可以导入 Python 2.7 编写的 `module2.py`,并成功使用它,没有问题。这显然是实验代码,但假设 `module2.py` 包含以下的功能:
|
||||
|
||||
```
|
||||
|
||||
|
||||
def update_config_from_dict(config_dict):
|
||||
items = config_dict.items()
|
||||
while items:
|
||||
@ -28,14 +27,13 @@ def update_in_place(config_dict):
|
||||
del config_dict[k]
|
||||
elif new_value != v:
|
||||
config_dict[k] = v
|
||||
|
||||
```
|
||||
|
||||
现在,当我们想从 `module3` 中调用这些函数时,我们遇到了一个问题:Python 3.6 中的字典类型与 Python 2.7 中的字典类型不同。在 Python 2 中,dicts 是无序的,它们的 `.keys()`, `.values()`, `.items()` 方法返回了正确的序列,这意味着调用 `.items()` 会在字典中创建状态的副本。在 Python 3 中,这些方法返回字典当前状态的动态视图。
|
||||
现在,当我们想从 `module3` 中调用这些函数时,我们遇到了一个问题:Python 3.6 中的字典类型与 Python 2.7 中的字典类型不同。在 Python 2 中,字典是无序的,它们的 `.keys()`, `.values()`, `.items()` 方法返回了正确的序列,这意味着调用 `.items()` 会在字典中创建状态的副本。在 Python 3 中,这些方法返回字典当前状态的动态视图。
|
||||
|
||||
这意味着如果 `module3` 调用 `module2.update_config_from_dict(some_dictionary)`,它将无法运行,因为 Python 3 中 `dict.items()` 返回的值不是一个列表,并且没有 `.pop()` 方法。反过来也是如此。如果 `module3` 调用 `module2.config_to_dict()`,它可能会返回一个 Python 2 的字典。现在调用 `.items()` 突然返回一个列表,所以这段代码无法正常工作(这对 Python 3 字典来说工作正常):
|
||||
```
|
||||
|
||||
```
|
||||
def main(cmdline_options):
|
||||
d = module2.config_to_dict()
|
||||
items = d.items()
|
||||
@ -45,7 +43,6 @@ def main(cmdline_options):
|
||||
d[k] = v
|
||||
for k, v in items:
|
||||
print(f'Config with cmdline overrides: {k}={v}')
|
||||
|
||||
```
|
||||
|
||||
最后,使用 `module2.update_in_place()` 会失败,因为 Python 3 中 `.items()` 的值现在不允许在迭代过程中改变。
|
||||
@ -54,7 +51,7 @@ def main(cmdline_options):
|
||||
|
||||
### Python 应该神奇地知道类型并会自动转换!
|
||||
|
||||
为什么拥有 Python 6 的虚拟机无法识别 Python 3 的代码,在 Python 2 中调用 `some_dict.keys()` 时,我们还有别的意思吗?好吧,Python 不知道代码的作者在编写代码时,她所认为的 `some_dict` 应该是什么。代码中没有任何内容表明它是否是一个字典。在 Python 2 中没有类型注释,因为它们是可选的,即使在 Python 3 中,大多数代码也不会使用它们。
|
||||
为什么我们的 Python 6 的虚拟机无法识别 Python 3 的代码,在 Python 2 中调用 `some_dict.keys()` 时,我们还有别的意思吗?好吧,Python 不知道代码的作者在编写代码时,她所认为的 `some_dict` 应该是什么。代码中没有任何内容表明它是否是一个字典。在 Python 2 中没有类型注释,因为它们是可选的,即使在 Python 3 中,大多数代码也不会使用它们。
|
||||
|
||||
在运行时,当你调用 `some_dict.keys()` 的时候,Python 只是简单地在对象上查找一个属性,该属性恰好隐藏在 `some_dict` 名下,并试图在该属性上运行 `__call__()`。这里有一些关于方法绑定,描述符,slots 等技术问题,但这是它的核心。我们称这种行为为“鸭子类型”。
|
||||
|
||||
@ -62,33 +59,33 @@ def main(cmdline_options):
|
||||
|
||||
### 好的,让我们在运行时做出这个决定
|
||||
|
||||
Python 6 的虚拟机可以通过标记每个属性查找来实现这一点,信息是“来自 py2 的调用”或“来自 py3 的调用”,并使对象发送正确的属性。这会让事情变得很慢,并且使用更多的内存。这将要求我们使用用户代码使用的代理将两种版本的给定类型保留在内存中。我们需要将这些对象的状态同步到用户背后,使工作加倍。毕竟,新字典的内存表示与 Python 2 不同。
|
||||
Python 6 的虚拟机可以标记每个属性,通过查找“来自 py2 的调用”或“来自 py3 的调用”的信息来实现这一点,并使对象发送正确的属性。这会让它变得很慢,并且使用更多的内存。这将要求我们在内存中保留两种版本的代码,并通过代理来使用它们。我们需要加倍付出努力,在用户背后同步这些对象的状态。毕竟,新字典的内存表示与 Python 2 不同。
|
||||
|
||||
如果你在思考字典问题,考虑 Python 3 中的 Unicode 字符串和 Python 2 中的字节(byte)字符串的所有问题。
|
||||
如果你已经被字典问题绕晕了,那么再想想 Python 3 中的 Unicode 字符串和 Python 2 中的字节(byte)字符串的各种问题吧。
|
||||
|
||||
### 一切都会丢失吗?Python 3 不能运行旧代码?
|
||||
### 没有办法了吗?Python 3 根本就不能运行旧代码吗?
|
||||
|
||||
一切都不会丢失。每天都会有项目移植到 Python 3。将 Python 2 代码移植到两个版本的 Python 上推荐方法是在代码上运行 [Python-Modernize][1]。它会捕获那些在 Python 3 上不起作用的代码,并使用 [six][2] 库将其替换,以便它在 Python 2 和 Python 3 上运行。这是对 `2to3` 的改编,它正在生成 Python 3-only 代码。`Modernize` 是首选,因为它提供了更多的增量迁移路线。所有的这些在 Python 文档中的 [Porting Python 2 Code to Python 3][3]文档中都有很好的概述。
|
||||
不会。每天都会有项目移植到 Python 3。将 Python 2 代码移植到两个版本的 Python 上推荐方法是在你的代码上运行 [Python-Modernize][1]。它会捕获那些在 Python 3 上不起作用的代码,并使用 [six][2] 库将其替换,以便它在 Python 2 和 Python 3 上运行。这是 `2to3` 的一个改编版本,用于生成仅针对 Python 3 代码。`Modernize` 是首选,因为它提供了更多的增量迁移路线。所有的这些在 Python 文档中的 [Porting Python 2 Code to Python 3][3]文档中都有很好的概述。
|
||||
|
||||
但是,等一等,你不是说 Python 6 的虚拟机不能自动执行此操作吗?对。`Modernize` 查看你的代码,并试图猜测哪些是安全的。它会做出一些不必要的改变,还会错过其他必要的改变。但是,它不会帮助你处理字符串。如果你的代码没有保留“来自外部的二进制数据”和“流程中的文本数据”之间的界限,那么这种转换并非微不足道。
|
||||
但是,等一等,你不是说 Python 6 的虚拟机不能自动执行此操作吗?对。`Modernize` 查看你的代码,并试图猜测哪些是安全的。它会做出一些不必要的改变,还会错过其他必要的改变。但是,它不会帮助你处理字符串。如果你的代码没有在“来自外部的二进制数据”和“流程中的文本数据”之间保持界限,那么这种转换就不会那么轻易。
|
||||
|
||||
因此,迁移大项目不能自动完成,并且涉及人类进行测试,发现问题并修复它们。它工作吗?是的,我曾帮助[将一百万行代码迁移到 Python 3][4],并且交换没有造成事故。这一举措重获了我们服务器内存的 1/3,并使代码运行速度提高了 12%。那是在 Python 3.5 上,但是 Python 3.6 的速度要快得多,根据你的工作量,你甚至可以达到 [4 倍加速][5]。
|
||||
因此,大项目的迁移不能自动完成,并且需要人类进行测试,发现问题并修复它们。它工作吗?是的,我曾帮助[将一百万行代码迁移到 Python 3][4],并且这种切换没有造成事故。这一举措让我们重新获得了 1/3 的服务器内存,并使代码运行速度提高了 12%。那是在 Python 3.5 上,但是 Python 3.6 的速度要快得多,根据你的工作量,你甚至可以达到 [4 倍加速][5]。
|
||||
|
||||
### 亲爱的 Zed
|
||||
|
||||
hi,伙计,我关注你已经超过 10 年了。我一直在观察,当你感到沮丧的时候,你对 Mongrel 没有任何信任,尽管 Rails 生态系统几乎全部都在上面运行。当你重新设计它并开始 Mongrel 2 项目时,我一直在观察。我一直在关注你使用 Fossil 这一令人惊讶的举动。随着你发布 “Rails 是一个贫民窟”的帖子,我看到你突然离开了 Ruby 社区。当你开始编写 “Learn Python The Hard Way” 并且开始推荐它时,我感到非常兴奋。2013 年我在 [DjangoCon Europe][6] 见过你,我们谈了很多关于绘画,唱歌和倦怠的内容。关于[这张你的照片][7]是我在 Instagram 上的第一篇文章。
|
||||
hi,伙计,我关注你已经超过 10 年了。我一直在观察,当你感到沮丧的时候,你对 Mongrel 没有任何信任,尽管 Rails 生态系统几乎全部都在上面运行。当你重新设计它并开始 Mongrel 2 项目时,我一直在观察。我一直在关注你使用 Fossil 这一令人惊讶的举动。随着你发布 “Rails 是一个贫民窟”的帖子,我看到你突然离开了 Ruby 社区。当你开始编写《笨方法学 Python》并且开始推荐它时,我感到非常兴奋。2013 年我在 [DjangoCon Europe][6] 见过你,我们谈了很多关于绘画,唱歌和倦怠的内容。[你的这张照片][7]是我在 Instagram 上的第一个帖子。
|
||||
|
||||
你几乎把另一个“贫民区”的行动与 [“反对 Python 3” 案例][8] 文章拉到一起。我认为你本意是好的,但是这篇文章引起了很多混乱,包括许多人认为你认为 Python 3 不是图灵完整的。我花了好几个小时让人们相信,你是在开玩笑。但是,鉴于你对 Python 学习方式的重大贡献,我认为这是值得的。特别是你为 Python 3 更新了你的书。感谢你做这件事。如果我们社区中真的有人要求因你的帖子为由将你和你的书列入黑名单,把他们请出去。这是一个双输的局面,这是错误的。
|
||||
你几乎把另一个“贫民区”的行动与 [“反对 Python 3” 案例][8] 文章拉到一起。我认为你本意是好的,但是这篇文章引起了很多混淆,包括许多人觉得你认为 Python 3 不是图灵完整的。我花了好几个小时让人们相信,你是在开玩笑。但是,鉴于你对《笨方法学 Python》的重大贡献,我认为这是值得的。特别是你为 Python 3 更新了你的书。感谢你做这件事。如果我们社区中真的有人因你的帖子为由要求将你和你的书列入黑名单,而请他们出去。这是一个双输的局面,这是错误的。
|
||||
|
||||
在记录中,没有一个核心 Python 开发人员认为 Python 2 到 Python 3 的转换过程会顺利而且计划得当,[包括 Guido van Rossum][9]。真的,可以看那个视频,这有点事后诸葛亮的意思了。从这个意义上说,我们实际上是积极地相互认同的。如果我们再做一次,它会看起来不一样。但在这一点上,[在 2020 年 1 月 1 日,Python 2 将会到达终结][10]。大多数第三方库已经支持 Python 3,甚至开始发布只支持 Python 3 版本(参见[Django][11]或 [科学项目关于 Python 3 的声明][12])。
|
||||
说实话,没有一个核心 Python 开发人员认为 Python 2 到 Python 3 的转换过程会顺利而且计划得当,[包括 Guido van Rossum][9]。真的,可以看那个视频,这有点事后诸葛亮的意思了。从这个意义上说,*我们实际上是积极地相互认同的*。如果我们再做一次,它会看起来不一样。但在这一点上,[在 2020 年 1 月 1 日,Python 2 将会到达终结][10]。大多数第三方库已经支持 Python 3,甚至开始发布只支持 Python 3 的版本(参见 [Django][11] 或 [科学项目关于 Python 3 的声明][12])。
|
||||
|
||||
我们也积极地就另一件事达成一致。就像你于 Mongrel 一样,Python 核心开发人员是志愿者,他们的工作没有得到报酬。我们大多数人在这个项目上投入了大量的时间和精力,因此[我们自然而然敏感][13]于那些对他们的贡献不屑一顾和激烈的评论。特别是如果这个信息既攻击目前的事态,又要求更多的自由劳动。
|
||||
我们也积极地就另一件事达成一致。就像你于 Mongrel 一样,Python 核心开发人员是志愿者,他们的工作没有得到报酬。我们大多数人在这个项目上投入了大量的时间和精力,因此[我们自然而然敏感][13]于那些对他们的贡献不屑一顾和激烈的评论。特别是如果这个信息既攻击目前的事态,又要求更多的自由贡献。
|
||||
|
||||
我希望到 2018 年你会让忘记 2016 发布的帖子,有一堆好的反驳。[我特别喜欢 eevee][14](译注:eevee 是一个为 Blender 设计的渲染器)。它特别针对“一起运行 Python 2 和 Python 3 ”的场景,这是不现实的,就像在同一个虚拟机中运行 Ruby 1.8 和 Ruby 2.x 一样,或者像 Lua 5.3 和 Lua 5.1 同时运行一样。你甚至不能用 libc.so.6 运行针对 libc.so.5 编译的 C 二进制文件。然而,我发现最令人惊讶的是,你声称 Python 核心开发者是“有目的地”创造诸如 2to3 之类的破坏工具,这些由 Guido 创建,其最大利益就是让每个人尽可能顺利,快速地迁移。我很高兴你在之后的帖子中放弃了这个说法,但是你必须意识到你会激怒那些阅读原始版本的人。对蓄意伤害的指控最好有强有力的证据支持。
|
||||
我希望到 2018 年你会让忘记 2016 发布的帖子,有一堆好的反驳。[我特别喜欢 eevee][14](LCTT 译注:eevee 是一个为 Blender 设计的渲染器)。它特别针对“一起运行 Python 2 和 Python 3 ”的场景,这是不现实的,就像在同一个虚拟机中运行 Ruby 1.8 和 Ruby 2.x 一样,或者像 Lua 5.3 和 Lua 5.1 同时运行一样。你甚至不能用 libc.so.6 运行针对 libc.so.5 编译的 C 二进制文件。然而,我发现最令人惊讶的是,你声称 Python 核心开发者是“有目的地”创造诸如 2to3 之类的破坏工具,这些由 Guido 创建,其最大利益就是让每个人尽可能顺利,快速地迁移。我很高兴你在之后的帖子中放弃了这个说法,但是你必须意识到你会激怒那些阅读了原始版本的人。对蓄意伤害的指控最好有强有力的证据支持。
|
||||
|
||||
但看起来你仍然会这样做。[就在今天][15]你说 Python 核心开发者“忽略”尝试解决 API 的问题,特别是 `six`。正如我上面写的那样,Python 文档中的官方移植指南涵盖了 “six”。更重要的是,`six` 是由 Python 2.7 的发布管理者 Benjamin Peterson 编写。很多人学会了编程,这要归功于你,而且由于你在网上有大量的粉丝,人们会阅读这样的推文,他们会相信它的价值,这是有害的。
|
||||
但看起来你仍然会这样做。[就在今天][15]你说 Python 核心开发者“忽略”尝试解决 API 的问题,特别是 `six`。正如我上面写的那样,Python 文档中的官方移植指南涵盖了 `six`。更重要的是,`six` 是由 Python 2.7 的发布管理者 Benjamin Peterson 编写。很多人学会了编程,这要归功于你,而且由于你在网上有大量的粉丝,人们会阅读这样的推文,他们会相信它的价值,这是有害的。
|
||||
|
||||
我有一个建议,让我们把 “Python 3 管理不善”的争议搁置起来。Python 2 正在死亡,这个过程会很慢,并且它是丑陋而血腥的,但它是一条单行道。争论那些没有用。相反,让我们专注于我们现在可以做什么来使 Python 3.8 比其他任何 Python 版本更好。也许你更喜欢看外面的角色,但作为这个社区的成员,你会更有影响力。请说“我们”而不是“他们”。
|
||||
我有一个建议,让我们把 “Python 3 管理不善”的争议搁置起来。Python 2 正在死亡,这个过程会很慢,并且它是丑陋而血腥的,但它是一条单行道。争论那些没有用。相反,让我们专注于我们现在可以做什么来使 Python 3.8 比其他任何 Python 版本更好。也许你更喜欢看外面的角色,但作为这个社区的成员,你会更有影响力。请说“我们”而不是“他们”。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -96,9 +93,9 @@ hi,伙计,我关注你已经超过 10 年了。我一直在观察,当你
|
||||
via: http://lukasz.langa.pl/13/could-we-run-python-2-and-python-3-code-same-vm/
|
||||
|
||||
作者:[Łukasz Langa][a]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,32 +1,41 @@
|
||||
Linux 下的 4 个命令行笔记记录程序
|
||||
======
|
||||
4 个 Linux 下的命令行笔记程序
|
||||
===============
|
||||
|
||||
> 这些工具可以让你在 Linux 命令行下简单而有效地记录笔记和保存信息。
|
||||
|
||||

|
||||
当你需要保存代码段或 URL、想法或引用时,可能会启动文本编辑器或使用[桌面][1]或[基于 Web 的] [2]笔记记录工具。但那些不是你唯一的选择。如果你在终端窗口中工作,则可以使用 Linux 命令行下的许多笔记记录工具之一。
|
||||
|
||||
当你需要保存代码段或 URL、想法或引用时,可能会启动文本编辑器或使用[桌面][1]或[基于 Web 的][2]笔记记录工具。但那些不是你唯一的选择。如果你在终端窗口中工作,则可以使用 Linux 命令行下的许多笔记记录工具之一。
|
||||
|
||||
我们来看看这四个程序。
|
||||
|
||||
### tnote
|
||||
|
||||
[tnote][3] 使在终端窗口中记笔记很简单 - 几乎太简单了。
|
||||

|
||||
|
||||
tnote 是一个 Python 脚本。首次启动时,它会要求你输入密码和口令来加密存储笔记的[ SQLite 数据库][4]。完成之后,按 “A” 创建一个笔记。输入你的笔记,然后按 CTRL-D 保存。
|
||||
[tnote][3] 使在终端窗口中记笔记很简单 —— 几乎太简单了。
|
||||
|
||||
一旦你有几个(或多个)笔记,你可以查看它们或搜索特定的笔记,单词或短语或标签。tnote 不包含很多功能,但它确实实现了任务。
|
||||
tnote 是一个 Python 脚本。首次启动时,它会要求你输入密码和口令来加密存储笔记的 [SQLite 数据库][4]。完成之后,按 `A` 创建一个笔记。输入你的笔记,然后按 `CTRL-D` 保存。
|
||||
|
||||
一旦你有几个(或多个)笔记,你可以查看它们或搜索特定的笔记,单词或短语或标签。tnote 没有很多功能,但它确实实现了任务。
|
||||
|
||||
### Terminal Velocity
|
||||
|
||||
如果你使用的是 Mac OS,你可能会看到一个名为 [Notational Velocity][5] 的流行开源笔记程序,这是一种记录笔记的简单有效方法。[Terminal Velocity][6] 在将 Notational Velocity 体验带入命令行方面做得很好。
|
||||

|
||||
|
||||
如果你使用过 Mac OS,你可能会看到一个名为 [Notational Velocity][5] 的流行开源笔记程序,这是一种记录笔记的简单有效方法。[Terminal Velocity][6] 在将 Notational Velocity 体验带入命令行方面做得很好。
|
||||
|
||||
Terminal Velocity 打开你的默认文本编辑器(由你的 `.profile` 或 `.bashrc` 文件中的 `$EDITOR` 变量设置)。输入你的笔记,然后保存。该笔记出现在 Terminal Velocity 窗口的列表中。
|
||||
|
||||
使用键盘上的箭头键滚动查看你的笔记列表。要查看或编辑笔记,请按 Enter 键。如果你有一长串笔记,则可以在 `Find or Create` 字段中输入笔记标题的前几个字符以缩小列表的范围。在那里滚动笔记并按下 Enter 键将其打开。
|
||||
使用键盘上的箭头键滚动查看你的笔记列表。要查看或编辑笔记,请按回车键。如果你有一长串笔记,则可以在 `Find or Create` 字段中输入笔记标题的前几个字符以缩小列表的范围。在那里滚动笔记并按下回车键将其打开。
|
||||
|
||||
### pygmynote
|
||||
|
||||

|
||||
|
||||
在本文中的四个应用中,[pygmynote][7] 可能是最不用户友好的。然而,它是最灵活的。
|
||||
|
||||
像 tnote 一样,pygmynote 将你的笔记和附件保存在 SQLite 数据库中。当你启动它时,pygmynote 看起来并不特别有用。在任何时候,输入 `help` 并按下 Enter 键获取命令列表。
|
||||
像 tnote 一样,pygmynote 将你的笔记和附件保存在 SQLite 数据库中。当你启动它时,pygmynote 看起来并不特别有用。在任何时候,输入 `help` 并按下回车键获取命令列表。
|
||||
|
||||
你可以添加、编辑、查看和搜索笔记,并在笔记中添加[标签][8]。标签使找到笔记更容易,特别是如果你有很多笔记的时候。
|
||||
|
||||
@ -34,6 +43,8 @@ pygmynote 的灵活性在于它能够将附件添加到笔记中。这些附件
|
||||
|
||||
### jrnl
|
||||
|
||||

|
||||
|
||||
[jrnl][9] 是这里的一个奇怪应用。正如你可能从它的名字中猜到的那样,jrnl 意在成为一种日记工具。但这并不意味着你不能记笔记。 jrnl 做得很好。
|
||||
|
||||
当你第一次启动 jrnl 时,它会询问你想把文件 `journal.txt` (它存储你的笔记)保存的位置以及是否需要密码保护。如果你决定添加密码,那么你在应用内的操作都需要输入密码。
|
||||
@ -50,7 +61,7 @@ via: https://opensource.com/article/18/3/command-line-note-taking-applications
|
||||
|
||||
作者:[Scott Nesbitt][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,12 +1,14 @@
|
||||
给初学者看的 Shuf 命令教程
|
||||
给初学者看的 shuf 命令教程
|
||||
======
|
||||
|
||||

|
||||
Shuf 命令用于在类 Unix 操作系统中生成随机排列。使用 shuf 命令,我们可以随机打乱给定输入文件的行。Shuf 命令是 GNU Coreutils 的一部分,因此你不必担心安装问题。在这个简短的教程中,让我向你展示一些 shuf 命令的例子。
|
||||
|
||||
### 带例子的 Shuf 命令教程
|
||||
`shuf` 命令用于在类 Unix 操作系统中生成随机排列。使用 `shuf` 命令,我们可以随机打乱给定输入文件的行。`shuf` 命令是 GNU Coreutils 的一部分,因此你不必担心安装问题。在这个简短的教程中,让我向你展示一些 `shuf` 命令的例子。
|
||||
|
||||
### 带例子的 shuf 命令教程
|
||||
|
||||
我有一个名为 `ostechnix.txt` 的文件,内容如下:
|
||||
|
||||
我有一个名为 **ostechnix.txt** 的文件,内容如下。
|
||||
```
|
||||
$ cat ostechnix.txt
|
||||
line1
|
||||
@ -19,10 +21,10 @@ line7
|
||||
line8
|
||||
line9
|
||||
line10
|
||||
|
||||
```
|
||||
|
||||
现在让我们以随机顺序显示上面的行。为此,请运行:
|
||||
|
||||
```
|
||||
$ shuf ostechnix.txt
|
||||
line2
|
||||
@ -35,24 +37,24 @@ line4
|
||||
line6
|
||||
line9
|
||||
line3
|
||||
|
||||
```
|
||||
|
||||
看到了吗?上面的命令将名为 “ostechnix.txt” 中的行随机排列并输出了结果。
|
||||
看到了吗?上面的命令将名为 `ostechnix.txt` 中的行随机排列并输出了结果。
|
||||
|
||||
你可能想将输出写入另一个文件。例如,我想将输出保存到 `output.txt` 中。为此,请先创建 `output.txt`:
|
||||
|
||||
你可能想将输出写入另一个文件。例如,我想将输出保存到 **output.txt** 中。为此,请先创建 output.txt:
|
||||
```
|
||||
$ touch output.txt
|
||||
|
||||
```
|
||||
|
||||
然后,像下面使用 **-o** 标志将输出写入该文件。
|
||||
然后,像下面使用 `-o` 标志将输出写入该文件:
|
||||
|
||||
```
|
||||
$ shuf ostechnix.txt -o output.txt
|
||||
|
||||
```
|
||||
|
||||
上面的命令将随机随机打乱 ostechnix.txt 的内容并将输出写入 output.txt。你可以使用命令查看 output.txt 的内容:
|
||||
上面的命令将随机随机打乱 `ostechnix.txt` 的内容并将输出写入 `output.txt`。你可以使用命令查看 `output.txt` 的内容:
|
||||
|
||||
```
|
||||
$ cat output.txt
|
||||
|
||||
@ -66,17 +68,17 @@ line7
|
||||
line6
|
||||
line4
|
||||
line5
|
||||
|
||||
```
|
||||
|
||||
我只想显示文件中的任意一行。我该怎么做?很简单!
|
||||
|
||||
```
|
||||
$ shuf -n 1 ostechnix.txt
|
||||
line6
|
||||
|
||||
```
|
||||
|
||||
同样,我们可以选择前 “n” 个随机条目。以下命令将只显示前五个随机条目。
|
||||
同样,我们可以选择前 “n” 个随机条目。以下命令将只显示前五个随机条目:
|
||||
|
||||
```
|
||||
$ shuf -n 5 ostechnix.txt
|
||||
line10
|
||||
@ -84,10 +86,10 @@ line4
|
||||
line5
|
||||
line9
|
||||
line3
|
||||
|
||||
```
|
||||
|
||||
如下所示,我们可以直接使用 **-e** 标志传入输入,而不是从文件中读取行。
|
||||
如下所示,我们可以直接使用 `-e` 标志传入输入,而不是从文件中读取行:
|
||||
|
||||
```
|
||||
$ shuf -e line1 line2 line3 line4 line5
|
||||
line1
|
||||
@ -95,10 +97,10 @@ line3
|
||||
line5
|
||||
line4
|
||||
line2
|
||||
|
||||
```
|
||||
|
||||
你也可以传入数字:
|
||||
|
||||
```
|
||||
$ shuf -e 1 2 3 4 5
|
||||
3
|
||||
@ -106,25 +108,25 @@ $ shuf -e 1 2 3 4 5
|
||||
1
|
||||
4
|
||||
2
|
||||
|
||||
```
|
||||
|
||||
要快速在给定范围选择一个,请改用此命令。
|
||||
要快速在给定范围选择一个,请改用此命令:
|
||||
|
||||
```
|
||||
$ shuf -n 1 -e 1 2 3 4 5
|
||||
|
||||
```
|
||||
|
||||
或者,选择下面的任意三个随机数字。
|
||||
或者,选择下面的任意三个随机数字:
|
||||
|
||||
```
|
||||
$ shuf -n 3 -e 1 2 3 4 5
|
||||
3
|
||||
5
|
||||
1
|
||||
|
||||
```
|
||||
|
||||
我们也可以在特定范围内生成随机数。例如,要显示 1 到 10 之间的随机数,只需使用:
|
||||
|
||||
```
|
||||
$ shuf -i 1-10
|
||||
1
|
||||
@ -137,29 +139,26 @@ $ shuf -i 1-10
|
||||
3
|
||||
10
|
||||
5
|
||||
|
||||
```
|
||||
|
||||
有关更多详细信息,请参阅手册页。
|
||||
|
||||
```
|
||||
$ man shuf
|
||||
|
||||
```
|
||||
|
||||
今天就是这些。还有更多更好的东西。敬请关注!
|
||||
|
||||
干杯!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/the-shuf-command-tutorial-with-examples-for-beginners/
|
||||
|
||||
作者:[SK][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[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/) 荣誉推出
|
||||
|
@ -1,98 +1,103 @@
|
||||
强制关闭系统的内核模块
|
||||
强制关闭你的系统的内核模块
|
||||
======
|
||||
|
||||

|
||||
|
||||
我知道熬夜对健康不利。但谁在乎?多年来我一直是一只夜猫子。我通常在 12 点以后睡觉,有时在凌晨 1 点以后睡觉。第二天早上,我至少推迟三次闹钟,醒来后又累又有脾气。每天,我向自己保证早点睡觉,但最终会像平常一样晚睡。而且,这个循环还在继续!如果你和我一样,这有一个好消息。一个同学通宵开发了一个名为 **“Kgotobed”** 的内核模块,它迫使你在特定的时间上床睡觉。也就是说它会强制关闭你的系统。
|
||||
|
||||
我为什么要用这个?我有很多其他的选择。我可以设置一个 cron 作业来安排在特定时间关闭系统。我可以设置提醒或闹钟。我可以使用浏览器插件或软件。你可能会问!但是,它们都可以轻易忽略或绕过。Kgotobed 是你不能忽视的东西。**即使您是 root 用户也无法禁用**。是的,它会在指定的时间强制关闭你的系统。没有推迟选项。你不能推迟关机过程,也不能取消它。无论如何,系统都会在指定的时间停止运行。你被警告了!!
|
||||
你可能会问!我为什么要用这个?我有很多其他的选择。我可以设置一个 cron 作业来安排在特定时间关闭系统。我可以设置提醒或闹钟。我可以使用浏览器插件或软件。但是,它们都可以轻易忽略或绕过。Kgotobed 是你不能忽视的东西。**即使您是 root 用户也无法禁用**。是的,它会在指定的时间强制关闭你的系统。没有推迟选项。你不能推迟关机过程,也不能取消它。无论如何,系统都会在指定的时间停止运行。你被警告了!!
|
||||
|
||||
### 安装 Kgotobed
|
||||
|
||||
确保你已经安装了 **dkms**。它在大多数 Linux 发行版的默认仓库中都有。
|
||||
确保你已经安装了 `dkms`。它在大多数 Linux 发行版的默认仓库中都有。
|
||||
|
||||
例如在 Fedora 上,你可以使用以下命令安装它:
|
||||
|
||||
```
|
||||
$ sudo dnf install kernel-devel-$(uname -r) dkms
|
||||
|
||||
```
|
||||
|
||||
在 Debian、Ubuntu、linux Mint 上:
|
||||
|
||||
```
|
||||
$ sudo apt install dkms
|
||||
|
||||
```
|
||||
|
||||
安装完成后,git clone Kgotobed 项目。
|
||||
安装完成后,`git clone` Kgotobed 项目。
|
||||
|
||||
```
|
||||
$ git clone https://github.com/nikital/kgotobed.git
|
||||
|
||||
```
|
||||
|
||||
该命令会在当前工作目录中将所有 Kgotobed 仓库的内容克隆到名为 “kgotobed” 的文件夹中。cd 到该目录:
|
||||
该命令会在当前工作目录中将所有 Kgotobed 仓库的内容克隆到名为 `kgotobed` 的文件夹中。进入到该目录:
|
||||
|
||||
```
|
||||
$ cd kgotobed/
|
||||
|
||||
```
|
||||
|
||||
接着,使用命令安装 Kgotobed 驱动:
|
||||
|
||||
```
|
||||
$ sudo make install
|
||||
|
||||
```
|
||||
|
||||
上面的命令将 **kgotobed.ko** 模块注册到 **DKMS**(这样它会为每个你运行的内核重建)并在 **/usr/local/bin/** 目录下安装 **gotobed**,然后注册、启用并启动 kgotobed 服务。
|
||||
上面的命令将 `kgotobed.ko` 模块注册到 **DKMS**(这样它会为每个你运行的内核重建)并在 `/usr/local/bin/` 目录下安装 `gotobed`,然后注册、启用并启动 kgotobed 服务。
|
||||
|
||||
### 如何运行
|
||||
|
||||
默认情况下,Kgotobed 将睡前时间设置为 **1:00 AM**。也就是说,无论你在做什么,你的电脑都会在凌晨 1 点关机。
|
||||
|
||||
要查看当前的睡前时间,请运行:
|
||||
|
||||
```
|
||||
$ gotobed
|
||||
Current bedtime is 2018-04-10 01:00:00
|
||||
|
||||
```
|
||||
|
||||
要提前睡眠时间,例如 22:00(晚上 10 点),请运行:
|
||||
|
||||
```
|
||||
$ sudo gotobed 22:00
|
||||
[sudo] password for sk:
|
||||
Current bedtime is 2018-04-10 00:58:00
|
||||
Setting bedtime to 2018-04-09 22:00:00
|
||||
Bedtime will be in 2 hours 16 minutes
|
||||
|
||||
```
|
||||
|
||||
当你想早点睡觉时,这会很有帮助!
|
||||
|
||||
但是,你不能设置更晚的时间也就是凌晨 1 点以后。你无法卸载模块,并且调整系统时钟也无济于事。唯一的出路是重启!
|
||||
|
||||
要设置不同的默认时间,您需要自定义 **kgotobed.service**(通过编辑或使用 systemd 工具)。
|
||||
要设置不同的默认时间,您需要自定义 `kgotobed.service`(通过编辑或使用 systemd 工具)。
|
||||
|
||||
### 卸载 Kgotobed
|
||||
|
||||
对 Kgotobed 不满意?别担心!进入我们先前克隆的 “kgotobed” 文件夹,然后运行以下命令将其卸载。
|
||||
对 Kgotobed 不满意?别担心!进入我们先前克隆的 `kgotobed` 文件夹,然后运行以下命令将其卸载。
|
||||
|
||||
```
|
||||
$ sudo make uninstall
|
||||
|
||||
```
|
||||
|
||||
再一次,我警告你,即使你是 root 用户,也没有办法推迟或取消关机过程。你的系统将在指定的时间强制关闭。这并不适合每个人!当你在做一项重要任务时,它可能会让你疯狂。在这种情况下,请确保你已经不时地保存工作,或使用下面链接中的一些高级工具来帮助你在特定时间自动关闭、重启、暂停和休眠系统。
|
||||
|
||||
- [在特定时间自动关闭、重启、暂停和休眠系统](https://www.ostechnix.com/auto-shutdown-reboot-suspend-hibernate-linux-system-specific-time/)
|
||||
|
||||
就是这些了。希望你觉得这个指南有帮助。还有更好的东西。敬请关注!
|
||||
|
||||
干杯!
|
||||
|
||||
### 资源
|
||||
|
||||
- [Kgotobed GitHub 仓库](https://github.com/nikital/kgotobed)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/kgotobed-a-kernel-module-that-forcibly-shutdown-your-system/
|
||||
|
||||
作者:[SK][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[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/) 荣誉推出
|
||||
|
@ -1,11 +1,11 @@
|
||||
在 GITLAB CI 中使用 DOCKER 构建 GO 项目
|
||||
在 GitKab CI 中使用 Docker 构建 Go 项目
|
||||
===============================================
|
||||
|
||||
### 介绍
|
||||
|
||||
这篇文章是我在 CI 的 Docker 容器中构建 Go 项目的研究总结(特别是在 Gitlab 中)。我发现很难解决私有依赖问题(来自 Node/.NET 背景),因此这是我写这篇文章的主要原因。如果 Docker 镜像上存在任何问题或提交请求,请随时与我们联系。
|
||||
这篇文章是我在 CI 环境(特别是在 Gitlab 中)的 Docker 容器中构建 Go 项目的研究总结。我发现很难解决私有依赖问题(来自 Node/.NET 背景),因此这是我写这篇文章的主要原因。如果 Docker 镜像上存在任何问题或提交请求,请随时与我们联系。
|
||||
|
||||
### Dep
|
||||
### dep
|
||||
|
||||
由于 dep 是现在管理 Go 依赖关系的最佳选择,因此在构建前之前运行 `dep ensure`。
|
||||
|
||||
@ -18,50 +18,43 @@
|
||||
我第一次尝试使用 `golang:1.10`,但这个镜像没有:
|
||||
|
||||
* curl
|
||||
|
||||
* git
|
||||
|
||||
* make
|
||||
|
||||
* dep
|
||||
|
||||
* golint
|
||||
|
||||
我已经为我将不断更新的构建创建好了镜像([github][2] / [dockerhub][3]) - 但我不提供任何保证,因此你应该创建并管理自己的 Dockerhub。
|
||||
我已经创建好了用于构建的镜像([github][2] / [dockerhub][3]),我会保持更新,但我不提供任何担保,因此你应该创建并管理自己的 Dockerhub。
|
||||
|
||||
### 内部依赖关系
|
||||
|
||||
我们完全有能力创建一个有公共依赖关系的项目。但是如果你的项目依赖于另一个私人 gitlab 仓库呢?
|
||||
我们完全有能力创建一个有公共依赖关系的项目。但是如果你的项目依赖于另一个私人 Gitlab 仓库呢?
|
||||
|
||||
在本地运行 `dep ensure` 应该可以和你的 git 设置一起工作,但是一旦在 CI 上不适用,构建就会失败。
|
||||
|
||||
### Gitlab 权限模型
|
||||
#### Gitlab 权限模型
|
||||
|
||||
这是在[ Gitlab 8.12 中添加的][4],我们关心的最有用的功能是在构建期提供的 `CI_JOB_TOKEN` 环境变量。
|
||||
这是在 [Gitlab 8.12 中添加的][4],这个我们最关心的有用的功能是在构建期提供的 `CI_JOB_TOKEN` 环境变量。
|
||||
|
||||
这基本上意味着我们可以像这样克隆[依赖仓库][5]
|
||||
这基本上意味着我们可以像这样克隆[依赖仓库][5]:
|
||||
|
||||
```
|
||||
git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/myuser/mydependentrepo
|
||||
|
||||
```
|
||||
|
||||
然而,我们希望使这更友好一点,因为 dep 在试图拉取代码时不会奇迹般地添加凭据。
|
||||
然而,我们希望使这更友好一点,因为 `dep` 在试图拉取代码时不会奇迹般地添加凭据。
|
||||
|
||||
我们将把这一行添加到 `.gitlab-ci.yml` 的 `before_script` 部分。
|
||||
|
||||
```
|
||||
before_script:
|
||||
- echo -e "machine gitlab.com\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc
|
||||
|
||||
```
|
||||
|
||||
使用 `.netrc` 文件可以指定哪个凭证用于哪个服务器。这种方法可以避免每次从 Git 中拉取(或推送)时输入用户名和密码。密码以明文形式存储,因此你不应在自己的计算机上执行此操作。这实际用于 Git 在背后使用 `cURL`。 [在这里阅读更多][6]。
|
||||
|
||||
项目文件
|
||||
============================================================
|
||||
### 项目文件
|
||||
|
||||
### Makefile
|
||||
#### Makefile
|
||||
|
||||
虽然这是可选的,但我发现它使事情变得更容易。
|
||||
|
||||
@ -93,7 +86,7 @@ lint-all:
|
||||
|
||||
```
|
||||
|
||||
### .gitlab-ci.yml
|
||||
#### .gitlab-ci.yml
|
||||
|
||||
这是 Gitlab CI 魔术发生的地方。你可能想使用自己的镜像。
|
||||
|
||||
@ -132,7 +125,7 @@ build:
|
||||
|
||||
### 缺少了什么
|
||||
|
||||
我通常会用我的二进制文件构建 Docker 镜像,并将其推送到 Gitlab 容器注册器中。
|
||||
我通常会用我的二进制文件构建 Docker 镜像,并将其推送到 Gitlab 容器注册库中。
|
||||
|
||||
你可以看到我正在构建二进制文件并退出,你至少需要将该二进制文件(例如生成文件)存储在某处。
|
||||
|
||||
@ -140,9 +133,9 @@ build:
|
||||
|
||||
via: https://seandrumm.co.uk/blog/building-go-projects-with-docker-on-gitlab-ci/
|
||||
|
||||
作者:[ SEAN DRUMM][a]
|
||||
作者:[SEAN DRUMM][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,5 +1,6 @@
|
||||
如何在 Linux 上查看用户的创建日期
|
||||
======
|
||||
|
||||
你知道吗,如何在 Linux 系统上查看帐户的创建日期?如果知道,那么有些什么办法。
|
||||
|
||||
你成功了么?如果是的话,该怎么做?
|
||||
@ -12,19 +13,18 @@
|
||||
|
||||
可以使用以下 7 种方法进行验证。
|
||||
|
||||
* 使用 /var/log/secure
|
||||
* 使用 aureport 工具
|
||||
* 使用 .bash_logout
|
||||
* 使用 chage 命令
|
||||
* 使用 useradd 命令
|
||||
* 使用 passwd 命令
|
||||
* 使用 last 命令
|
||||
|
||||
|
||||
* 使用 `/var/log/secure`
|
||||
* 使用 `aureport` 工具
|
||||
* 使用 `.bash_logout`
|
||||
* 使用 `chage` 命令
|
||||
* 使用 `useradd` 命令
|
||||
* 使用 `passwd` 命令
|
||||
* 使用 `last` 命令
|
||||
|
||||
### 方式 1:使用 /var/log/secure
|
||||
|
||||
它存储所有安全相关的消息,包括身份验证失败和授权特权。它还会通过系统安全守护进程跟踪 sudo 登录、SSH 登录和其他错误记录。
|
||||
它存储所有安全相关的消息,包括身份验证失败和授权特权。它还会通过系统安全守护进程跟踪 `sudo` 登录、SSH 登录和其他错误记录。
|
||||
|
||||
```
|
||||
# grep prakash /var/log/secure
|
||||
Apr 12 04:07:18 centos.2daygeek.com useradd[21263]: new group: name=prakash, GID=501
|
||||
@ -32,24 +32,24 @@ Apr 12 04:07:18 centos.2daygeek.com useradd[21263]: new user: name=prakash, UID=
|
||||
Apr 12 04:07:34 centos.2daygeek.com passwd: pam_unix(passwd:chauthtok): password changed for prakash
|
||||
Apr 12 04:08:32 centos.2daygeek.com sshd[21269]: Accepted password for prakash from 103.5.134.167 port 60554 ssh2
|
||||
Apr 12 04:08:32 centos.2daygeek.com sshd[21269]: pam_unix(sshd:session): session opened for user prakash by (uid=0)
|
||||
|
||||
```
|
||||
|
||||
### 方式 2:使用 aureport 工具
|
||||
|
||||
aureport 工具可以根据记录在审计日志中的事件记录生成汇总和柱状报告。默认情况下,它会查询 /var/log/audit/ 目录中的所有 audit.log 文件来创建报告。
|
||||
`aureport` 工具可以根据记录在审计日志中的事件记录生成汇总和柱状报告。默认情况下,它会查询 `/var/log/audit/` 目录中的所有 `audit.log` 文件来创建报告。
|
||||
|
||||
```
|
||||
# aureport --auth | grep prakash
|
||||
46. 04/12/2018 04:08:32 prakash 103.5.134.167 ssh /usr/sbin/sshd yes 288
|
||||
47. 04/12/2018 04:08:32 prakash 103.5.134.167 ssh /usr/sbin/sshd yes 291
|
||||
|
||||
```
|
||||
|
||||
### 方式 3:使用 .bash_logout
|
||||
|
||||
家目录中的 .bash_logout 对 bash 有特殊的含义,它提供了一种在用户退出系统时执行命令的方式。
|
||||
家目录中的 `.bash_logout` 对 bash 有特殊的含义,它提供了一种在用户退出系统时执行命令的方式。
|
||||
|
||||
我们可以查看用户家目录中 `.bash_logout` 的更改日期。该文件是在用户第一次注销时创建的。
|
||||
|
||||
我们可以查看用户家目录中 .bash_logout 的更改日期。该文件是在用户第一次注销时创建的。
|
||||
```
|
||||
# stat /home/prakash/.bash_logout
|
||||
File: `/home/prakash/.bash_logout'
|
||||
@ -59,14 +59,14 @@ Access: (0644/-rw-r--r--) Uid: ( 501/ prakash) Gid: ( 501/ prakash)
|
||||
Access: 2017-03-22 20:15:00.000000000 -0400
|
||||
Modify: 2017-03-22 20:15:00.000000000 -0400
|
||||
Change: 2018-04-12 04:07:18.283000323 -0400
|
||||
|
||||
```
|
||||
|
||||
### 方式 4:使用 chage 命令
|
||||
|
||||
chage 代表 change age。该命令让用户管理密码过期信息。chage 命令更改密码更改时和上次密码更改日期之间的天数。
|
||||
`chage` 意即 “change age”。该命令让用户管理密码过期信息。`chage` 命令可以修改上次密码更改日期后需要更改密码的天数。
|
||||
|
||||
系统使用此信息来确定用户何时必须更改其密码。如果用户自帐户创建日期以来没有更改密码,这个就有用。
|
||||
|
||||
```
|
||||
# chage --list prakash
|
||||
Last password change : Apr 12, 2018
|
||||
@ -76,45 +76,44 @@ Account expires : never
|
||||
Minimum number of days between password change : 0
|
||||
Maximum number of days between password change : 99999
|
||||
Number of days of warning before password expires : 7
|
||||
|
||||
```
|
||||
|
||||
### 方式 5:使用 useradd 命令
|
||||
|
||||
useradd 命令用于在 Linux 中创建新帐户。默认情况下,它不会添加用户创建日期,我们必须使用 “Comment” 选项添加日期。
|
||||
`useradd` 命令用于在 Linux 中创建新帐户。默认情况下,它不会添加用户创建日期,我们必须使用 “备注” 选项添加日期。
|
||||
|
||||
```
|
||||
# useradd -m prakash -c `date +%Y/%m/%d`
|
||||
|
||||
# grep prakash /etc/passwd
|
||||
prakash:x:501:501:2018/04/12:/home/prakash:/bin/bash
|
||||
|
||||
```
|
||||
|
||||
### 方式 6:使用 passwd 命令
|
||||
|
||||
passwd 命令用于将密码分配给本地帐户或用户。如果用户在帐户创建后没有修改密码,那么可以使用 passwd 命令查看最后一次密码修改的日期。
|
||||
`passwd` 命令用于将密码分配给本地帐户或用户。如果用户在帐户创建后没有修改密码,那么可以使用 `passwd` 命令查看最后一次密码修改的日期。
|
||||
|
||||
```
|
||||
# passwd -S prakash
|
||||
prakash PS 2018-04-11 0 99999 7 -1 (Password set, MD5 crypt.)
|
||||
|
||||
```
|
||||
|
||||
### 方式 7:使用 last 命令
|
||||
|
||||
last 命令读取 /var/log/wtmp,并显示自该文件创建以来所有登录(和退出)用户的列表。
|
||||
`last` 命令读取 `/var/log/wtmp`,并显示自该文件创建以来所有登录(和退出)用户的列表。
|
||||
|
||||
```
|
||||
# last | grep "prakash"
|
||||
prakash pts/2 103.5.134.167 Thu Apr 12 04:08 still logged in
|
||||
|
||||
```
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/how-to-check-user-created-date-on-linux/
|
||||
|
||||
作者:[Prakash Subramanian][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[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/) 荣誉推出
|
||||
|
137
published/20180413 Finding what you-re looking for on Linux.md
Normal file
137
published/20180413 Finding what you-re looking for on Linux.md
Normal file
@ -0,0 +1,137 @@
|
||||
在 Linux 上寻找你正在寻找的东西
|
||||
=====
|
||||
|
||||
> 怎样在 Linux 系统上使用 find、locate、mlocate、which、 whereis、 whatis 和 apropos 命令寻找文件。
|
||||
|
||||

|
||||
|
||||
在 Linux 系统上找到你要找的文件或命令并不难, 有很多种方法可以寻找。
|
||||
|
||||
### find
|
||||
|
||||
最显然的无疑是 `find` 命令,并且 `find` 变得比过去几年更容易使用了。它过去需要一个搜索的起始位置,但是现在,如果你想将搜索限制在当下目录中,你还可以使用仅包含文件名或正则表达式的 `find` 命令。
|
||||
|
||||
```
|
||||
$ find e*
|
||||
empty
|
||||
examples.desktop
|
||||
```
|
||||
|
||||
这样,它就像 `ls` 命令一样工作,并没有做太多的搜索。
|
||||
|
||||
对于更专业的搜索,`find` 命令需要一个起点和一些搜索条件(除非你只是希望它提供该起点目录的递归列表)。命令 `find -type f` 从当前目录开始将递归列出所有常规文件,而 `find ~nemo -type f -empty` 将在 nemo 的主目录中找到空文件。
|
||||
|
||||
```
|
||||
$ find ~nemo -type f -empty
|
||||
/home/nemo/empty
|
||||
```
|
||||
|
||||
参见:[11 个好玩的 Linux 终端技巧][1]。
|
||||
|
||||
### locate
|
||||
|
||||
`locate` 命令的名称表明它与 `find` 命令基本相同,但它的工作原理完全不同。`find` 命令可以根据各种条件 —— 名称、大小、所有者、权限、状态(如空文件)等等选择文件并作为搜索选择深度,`locate` 命令通过名为 `/var/lib/mlocate/mlocate.db` 的文件查找你要查找的内容。该数据文件会定期更新,因此你刚创建的文件的位置它可能无法找到。如果这让你感到困扰,你可以运行 `updatedb` 命令立即获得更新。
|
||||
|
||||
```
|
||||
$ sudo updatedb
|
||||
```
|
||||
|
||||
### mlocate
|
||||
|
||||
`mlocate` 命令的工作类似于 `locate` 命令,它使用与 `locate` 相同的 `mlocate.db` 文件。
|
||||
|
||||
### which
|
||||
|
||||
`which` 命令的工作方式与 `find` 命令和 `locate` 命令有很大的区别。它使用你的搜索路径(`$PATH`)并检查其上的每个目录中具有你要查找的文件名的可执行文件。一旦找到一个,它会停止搜索并显示该可执行文件的完整路径。
|
||||
|
||||
`which` 命令的主要优点是它回答了“如果我输入此命令,将运行什么可执行文件?”的问题。它会忽略不可执行文件,并且不会列出系统上带有该名称的所有可执行文件 —— 列出的就是它找到的第一个。如果你想查找具有某个名称的所有可执行文件,则可以像这样运行 `find` 命令,但是要比非常高效 `which` 命令用更长的时间。
|
||||
|
||||
```
|
||||
$ find / -name locate -perm -a=x 2>/dev/null
|
||||
/usr/bin/locate
|
||||
/etc/alternatives/locate
|
||||
```
|
||||
|
||||
在这个 `find` 命令中,我们在寻找名为 “locate” 的所有可执行文件(任何人都可以运行的文件)。我们也选择了不要查看所有“拒绝访问”的消息,否则这些消息会混乱我们的屏幕。
|
||||
|
||||
### whereis
|
||||
|
||||
`whereis` 命令与 `which` 命令非常类似,但它提供了更多信息。它不仅仅是寻找可执行文件,它还寻找手册页(man page)和源文件。像 `which` 命令一样,它使用搜索路径(`$PATH`) 来驱动搜索。
|
||||
|
||||
```
|
||||
$ whereis locate
|
||||
locate: /usr/bin/locate /usr/share/man/man1/locate.1.gz
|
||||
```
|
||||
|
||||
### whatis
|
||||
|
||||
`whatis` 命令有其独特的使命。它不是实际查找文件,而是在手册页中查找有关所询问命令的信息,并从手册页的顶部提供该命令的简要说明。
|
||||
|
||||
```
|
||||
$ whatis locate
|
||||
locate (1) - find files by name
|
||||
```
|
||||
|
||||
如果你询问你刚刚设置的脚本,它不会知道你指的是什么,并会告诉你。
|
||||
|
||||
```
|
||||
$ whatis cleanup
|
||||
cleanup: nothing appropriate.
|
||||
```
|
||||
|
||||
### apropos
|
||||
|
||||
当你知道你想要做什么,但不知道应该使用什么命令来执行此操作时,`apropos` 命令很有用。例如,如果你想知道如何查找文件,那么 `apropos find` 和 `apropos locate` 会提供很多建议。
|
||||
|
||||
```
|
||||
$ apropos find
|
||||
File::IconTheme (3pm) - find icon directories
|
||||
File::MimeInfo::Applications (3pm) - Find programs to open a file by mimetype
|
||||
File::UserDirs (3pm) - find extra media and documents directories
|
||||
find (1) - search for files in a directory hierarchy
|
||||
findfs (8) - find a filesystem by label or UUID
|
||||
findmnt (8) - find a filesystem
|
||||
gst-typefind-1.0 (1) - print Media type of file
|
||||
ippfind (1) - find internet printing protocol printers
|
||||
locate (1) - find files by name
|
||||
mlocate (1) - find files by name
|
||||
pidof (8) - find the process ID of a running program.
|
||||
sane-find-scanner (1) - find SCSI and USB scanners and their device files
|
||||
systemd-delta (1) - Find overridden configuration files
|
||||
xdg-user-dir (1) - Find an XDG user dir
|
||||
$
|
||||
$ apropos locate
|
||||
blkid (8) - locate/print block device attributes
|
||||
deallocvt (1) - deallocate unused virtual consoles
|
||||
fallocate (1) - preallocate or deallocate space to a file
|
||||
IO::Tty (3pm) - Low-level allocate a pseudo-Tty, import constants.
|
||||
locate (1) - find files by name
|
||||
mlocate (1) - find files by name
|
||||
mlocate.db (5) - a mlocate database
|
||||
mshowfat (1) - shows FAT clusters allocated to file
|
||||
ntfsfallocate (8) - preallocate space to a file on an NTFS volume
|
||||
systemd-sysusers (8) - Allocate system users and groups
|
||||
systemd-sysusers.service (8) - Allocate system users and groups
|
||||
updatedb (8) - update a database for mlocate
|
||||
updatedb.mlocate (8) - update a database for mlocate
|
||||
whereis (1) - locate the binary, source, and manual page files for a...
|
||||
which (1) - locate a command
|
||||
```
|
||||
|
||||
### 总结
|
||||
|
||||
Linux 上可用于查找和识别文件的命令有很多种,但它们都非常有用。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3268768/linux/finding-what-you-re-looking-for-on-linux.html
|
||||
|
||||
作者:[Sandra Henry-Stocker][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.networkworld.com/author/Sandra-Henry_Stocker/
|
||||
[1]:http://www.networkworld.com/article/2926630/linux/11-pointless-but-awesome-linux-terminal-tricks.html#tk.nww-fsb
|
@ -2,38 +2,39 @@
|
||||
======
|
||||
|
||||

|
||||
Java 是世界上最流行的编程语言之一。它广泛用于开发物联网设备、Android 程序,Web 和企业应用。本文将提供使用 [OpenJDK][1] 安装和配置工作站的指南。
|
||||
|
||||
Java 是世界上最流行的编程语言之一。它广泛用于开发物联网设备、Android 程序、Web 和企业应用。本文将提供使用 [OpenJDK][1] 安装和配置工作站的指南。
|
||||
|
||||
### 安装编译器和工具
|
||||
|
||||
在 Fedora 中安装编译器或 Java Development Kit(JDK)很容易。在写这篇文章时,可以用 v8 和 v9。只需打开一个终端并输入:
|
||||
在 Fedora 中安装编译器或 Java Development Kit(JDK)很容易。在写这篇文章时,可以用 v8 和 v9 版本。只需打开一个终端并输入:
|
||||
|
||||
```
|
||||
sudo dnf install java-1.8.0-openjdk-devel
|
||||
|
||||
```
|
||||
|
||||
这安装 JDK v8。对于 v9,请输入:
|
||||
|
||||
```
|
||||
sudo dnf install java-9-openjdk-devel
|
||||
|
||||
```
|
||||
|
||||
对于需要其他工具和库(如 Ant 和 Maven)的开发人员,可以使用 **Java Development** 组。要安装套件,请输入:
|
||||
|
||||
```
|
||||
sudo dnf group install "Java Development"
|
||||
|
||||
```
|
||||
|
||||
要验证编译器是否已安装,请运行:
|
||||
|
||||
```
|
||||
javac -version
|
||||
|
||||
```
|
||||
|
||||
输出显示编译器版本,如下所示:
|
||||
|
||||
```
|
||||
javac 1.8.0_162
|
||||
|
||||
```
|
||||
|
||||
### 编译程序
|
||||
@ -41,49 +42,48 @@ javac 1.8.0_162
|
||||
你可以使用任何基本的文本编辑器(如 nano、vim 或 gedit)编写程序。这个例子提供了一个简单的 “Hello Fedora” 程序。
|
||||
|
||||
打开你最喜欢的文本编辑器并输入以下内容:
|
||||
|
||||
```
|
||||
public class HelloFedora {
|
||||
|
||||
|
||||
public static void main (String[] args) {
|
||||
System.out.println("Hello Fedora!");
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
将文件保存为 HelloFedora.java。在终端切换到包含该文件的目录并执行以下操作:
|
||||
将文件保存为 `HelloFedora.java`。在终端切换到包含该文件的目录并执行以下操作:
|
||||
|
||||
```
|
||||
javac HelloFedora.java
|
||||
|
||||
```
|
||||
|
||||
如果编译器遇到任何语法错误,它会发出错误。否则,它只会在下面显示 shell 提示符。
|
||||
|
||||
你现在应该有一个名为 HelloFedora 的文件,它是编译好的程序。使用以下命令运行它:
|
||||
你现在应该有一个名为 `HelloFedora` 的文件,它是编译好的程序。使用以下命令运行它:
|
||||
|
||||
```
|
||||
java HelloFedora
|
||||
|
||||
```
|
||||
|
||||
输出将显示:
|
||||
|
||||
```
|
||||
Hello Fedora!
|
||||
|
||||
```
|
||||
|
||||
### 安装集成开发环境(IDE)
|
||||
|
||||
有些程序可能更复杂,IDE 可以帮助顺利进行。Java 程序员有很多可用的 IDE,其中包括:
|
||||
|
||||
+ Geany,一个加载快速的基本 IDE,并提供内置模板
|
||||
+ Geany,一个快速加载的基本 IDE,并提供内置模板
|
||||
+ Anjuta
|
||||
+ GNOME Builder,已经在 Builder 的文章中介绍过 - 这是一个专门面向 GNOME 程序开发人员的新 IDE
|
||||
+ GNOME Builder,已经在 [Builder - 这是一个专门面向 GNOME 程序开发人员的新 IDE][6] 的文章中介绍过
|
||||
|
||||
然而,主要用 Java 编写的最流行的开源 IDE 之一是 [Eclipse][2]。 Eclipse 在官方仓库中有。要安装它,请运行以下命令:
|
||||
|
||||
```
|
||||
sudo dnf install eclipse-jdt
|
||||
|
||||
```
|
||||
|
||||
安装完成后,Eclipse 的快捷方式会出现在桌面菜单中。
|
||||
@ -93,9 +93,9 @@ sudo dnf install eclipse-jdt
|
||||
### 浏览器插件
|
||||
|
||||
如果你正在开发 Web 小程序并需要一个用于浏览器的插件,则可以使用 [IcedTea-Web][4]。像 OpenJDK 一样,它是开源的并易于在 Fedora 中安装。运行这个命令:
|
||||
|
||||
```
|
||||
sudo dnf install icedtea-web
|
||||
|
||||
```
|
||||
|
||||
从 Firefox 52 开始,Web 插件不再有效。有关详细信息,请访问 Mozilla 支持网站 [https://support.mozilla.org/en-US/kb/npapi-plugins?as=u&utm_source=inproduct][5]。
|
||||
@ -110,7 +110,7 @@ via: https://fedoramagazine.org/start-developing-java-fedora/
|
||||
作者:[Shaun Assam][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
@ -120,3 +120,4 @@ via: https://fedoramagazine.org/start-developing-java-fedora/
|
||||
[3]:http://help.eclipse.org/oxygen/nav/0
|
||||
[4]:https://icedtea.classpath.org/wiki/IcedTea-Web
|
||||
[5]:https://support.mozilla.org/en-US/kb/npapi-plugins?as=u&utm_source=inproduct
|
||||
[6]:https://fedoramagazine.org/builder-a-new-ide-specifically-for-gnome-app-developers-2/
|
@ -1,4 +1,4 @@
|
||||
Being open about data privacy
|
||||
Translating by FelixYFZ Being open about data privacy
|
||||
======
|
||||

|
||||
|
||||
|
@ -1,104 +0,0 @@
|
||||
fuzheng1998 translating
|
||||
|
||||
Why Linux is better than Windows or macOS for security
|
||||
======
|
||||
|
||||

|
||||
|
||||
Enterprises invest a lot of time, effort and money in keeping their systems secure. The most security-conscious might have a security operations center. They of course use firewalls and antivirus tools. They probably spend a lot of time monitoring their networks, looking for telltale anomalies that could indicate a breach. What with IDS, SIEM and NGFWs, they deploy a veritable alphabet of defenses.
|
||||
|
||||
But how many have given much thought to one of the cornerstones of their digital operations: the operating systems deployed on the workforce’s PCs? Was security even a factor when the desktop OS was selected?
|
||||
|
||||
This raises a question that every IT person should be able to answer: Which operating system is the most secure for general deployment?
|
||||
|
||||
We asked some experts what they think of the security of these three choices: Windows, the ever-more-complex platform that’s easily the most popular desktop system; macOS X, the FreeBSD Unix-based operating system that powers Apple Macintosh systems; and Linux, by which we mean all the various Linux distributions and related Unix-based systems.
|
||||
|
||||
### How we got here
|
||||
|
||||
One reason enterprises might not have evaluated the security of the OS they deployed to the workforce is that they made the choice years ago. Go back far enough and all operating systems were reasonably safe, because the business of hacking into them and stealing data or installing malware was in its infancy. And once an OS choice is made, it’s hard to consider a change. Few IT organizations would want the headache of moving a globally dispersed workforce to an entirely new OS. Heck, they get enough pushback when they move users to a new version of their OS of choice.
|
||||
|
||||
Still, would it be wise to reconsider? Are the three leading desktop OSes different enough in their approach to security to make a change worthwhile?
|
||||
|
||||
Certainly the threats confronting enterprise systems have changed in the last few years. Attacks have become far more sophisticated. The lone teen hacker that once dominated the public imagination has been supplanted by well-organized networks of criminals and shadowy, government-funded organizations with vast computing resources.
|
||||
|
||||
Like many of you, I have firsthand experience of the threats that are out there: I have been infected by malware and viruses on numerous Windows computers, and I even had macro viruses that infected files on my Mac. More recently, a widespread automated hack circumvented the security on my website and infected it with malware. The effects of such malware were always initially subtle, something you wouldn’t even notice, until the malware ended up so deeply embedded in the system that performance started to suffer noticeably. One striking thing about the infestations was that I was never specifically targeted by the miscreants; nowadays, it’s as easy to attack 100,000 computers with a botnet as it is to attack a dozen.
|
||||
|
||||
### Does the OS really matter?
|
||||
|
||||
The OS you deploy to your users does make a difference for your security stance, but it isn’t a sure safeguard. For one thing, a breach these days is more likely to come about because an attacker probed your users, not your systems. A [survey][1] of hackers who attended a recent DEFCON conference revealed that “84 percent use social engineering as part of their attack strategy.” Deploying a secure operating system is an important starting point, but without user education, strong firewalls and constant vigilance, even the most secure networks can be invaded. And of course there’s always the risk of user-downloaded software, extensions, utilities, plug-ins and other software that appears benign but becomes a path for malware to appear on the system.
|
||||
|
||||
And no matter which platform you choose, one of the best ways to keep your system secure is to ensure that you apply software updates promptly. Once a patch is in the wild, after all, the hackers can reverse engineer it and find a new exploit they can use in their next wave of attacks.
|
||||
|
||||
And don’t forget the basics. Don’t use root, and don’t grant guest access to even older servers on the network. Teach your users how to pick really good passwords and arm them with tools such as [1Password][2] that make it easier for them to have different passwords on every account and website they use.
|
||||
|
||||
Because the bottom line is that every decision you make regarding your systems will affect your security, even the operating system your users do their work on.
|
||||
|
||||
**[ To comment on this story, visit[Computerworld's Facebook page][3]. ]**
|
||||
|
||||
### Windows, the popular choice
|
||||
|
||||
If you’re a security manager, it is extremely likely that the questions raised by this article could be rephrased like so: Would we be more secure if we moved away from Microsoft Windows? To say that Windows dominates the enterprise market is to understate the case. [NetMarketShare][4] estimates that a staggering 88% of all computers on the internet are running a version of Windows.
|
||||
|
||||
If your systems fall within that 88%, you’re probably aware that Microsoft has continued to beef up security in the Windows system. Among its improvements have been rewriting and re-rewriting its operating system codebase, adding its own antivirus software system, improving firewalls and implementing a sandbox architecture, where programs can’t access the memory space of the OS or other applications.
|
||||
|
||||
But the popularity of Windows is a problem in itself. The security of an operating system can depend to a large degree on the size of its installed base. For malware authors, Windows provides a massive playing field. Concentrating on it gives them the most bang for their efforts.
|
||||
As Troy Wilkinson, CEO of Axiom Cyber Solutions, explains, “Windows always comes in last in the security world for a number of reasons, mainly because of the adoption rate of consumers. With a large number of Windows-based personal computers on the market, hackers historically have targeted these systems the most.”
|
||||
|
||||
It’s certainly true that, from Melissa to WannaCry and beyond, much of the malware the world has seen has been aimed at Windows systems.
|
||||
|
||||
### macOS X and security through obscurity
|
||||
|
||||
If the most popular OS is always going to be the biggest target, then can using a less popular option ensure security? That idea is a new take on the old — and entirely discredited — concept of “security through obscurity,” which held that keeping the inner workings of software proprietary and therefore secret was the best way to defend against attacks.
|
||||
|
||||
Wilkinson flatly states that macOS X “is more secure than Windows,” but he hastens to add that “macOS used to be considered a fully secure operating system with little chance of security flaws, but in recent years we have seen hackers crafting additional exploits against macOS.”
|
||||
|
||||
In other words, the attackers are branching out and not ignoring the Mac universe.
|
||||
|
||||
Security researcher Lee Muson of Comparitech says that “macOS is likely to be the pick of the bunch” when it comes to choosing a more secure OS, but he cautions that it is not impenetrable, as once thought. Its advantage is that “it still benefits from a touch of security through obscurity versus the still much larger target presented by Microsoft’s offering.”
|
||||
|
||||
Joe Moore of Wolf Solutions gives Apple a bit more credit, saying that “off the shelf, macOS X has a great track record when it comes to security, in part because it isn’t as widely targeted as Windows and in part because Apple does a pretty good job of staying on top of security issues.”
|
||||
|
||||
### And the winner is …
|
||||
|
||||
You probably knew this from the beginning: The clear consensus among experts is that Linux is the most secure operating system. But while it’s the OS of choice for servers, enterprises deploying it on the desktop are few and far between.
|
||||
|
||||
And if you did decide that Linux was the way to go, you would still have to decide which distribution of the Linux system to choose, and things get a bit more complicated there. Users are going to want a UI that seems familiar, and you are going to want the most secure OS.
|
||||
|
||||
As Moore explains, “Linux has the potential to be the most secure, but requires the user be something of a power user.” So, not for everyone.
|
||||
|
||||
Linux distros that target security as a primary feature include [Parrot Linux][5], a Debian-based distro that Moore says provides numerous security-related tools right out of the box.
|
||||
|
||||
Of course, an important differentiator is that Linux is open source. The fact that coders can read and comment upon each other’s work might seem like a security nightmare, but it actually turns out to be an important reason why Linux is so secure, says Igor Bidenko, CISO of Simplex Solutions. “Linux is the most secure OS, as its source is open. Anyone can review it and make sure there are no bugs or back doors.”
|
||||
|
||||
Wilkinson elaborates that “Linux and Unix-based operating systems have less exploitable security flaws known to the information security world. Linux code is reviewed by the tech community, which lends itself to security: By having that much oversight, there are fewer vulnerabilities, bugs and threats.”
|
||||
|
||||
That’s a subtle and perhaps counterintuitive explanation, but by having dozens — or sometimes hundreds — of people read through every line of code in the operating system, the code is actually more robust and the chance of flaws slipping into the wild is diminished. That had a lot to do with why PC World came right out and said Linux is more secure. As Katherine Noyes [explains][6], “Microsoft may tout its large team of paid developers, but it’s unlikely that team can compare with a global base of Linux user-developers around the globe. Security can only benefit through all those extra eyeballs.”
|
||||
|
||||
Another factor cited by PC World is Linux’s better user privileges model: Windows users “are generally given administrator access by default, which means they pretty much have access to everything on the system,” according to Noyes’ article. Linux, in contrast, greatly restricts “root.”
|
||||
|
||||
Noyes also noted that the diversity possible within Linux environments is a better hedge against attacks than the typical Windows monoculture: There are simply a lot of different distributions of Linux available. And some of them are differentiated in ways that specifically address security concerns. Security Researcher Lee Muson of Comparitech offers this suggestion for a Linux distro: “The[Qubes OS][7] is as good a starting point with Linux as you can find right now, with an [endorsement from Edward Snowden][8] massively overshadowing its own extremely humble claims.” Other security experts point to specialized secure Linux distributions such as [Tails Linux][9], designed to run securely and anonymously directly from a USB flash drive or similar external device.
|
||||
|
||||
### Building security momentum
|
||||
|
||||
Inertia is a powerful force. Although there is clear consensus that Linux is the safest choice for the desktop, there has been no stampede to dump Windows and Mac machines in favor of it. Nonetheless, a small but significant increase in Linux adoption would probably result in safer computing for everyone, because in market share loss is one sure way to get Microsoft’s and Apple’s attention. In other words, if enough users switch to Linux on the desktop, Windows and Mac PCs are very likely to become more secure platforms.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.computerworld.com/article/3252823/linux/why-linux-is-better-than-windows-or-macos-for-security.html
|
||||
|
||||
作者:[Dave Taylor][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.computerworld.com/author/Dave-Taylor/
|
||||
[1]:https://www.esecurityplanet.com/hackers/fully-84-percent-of-hackers-leverage-social-engineering-in-attacks.html
|
||||
[2]:http://www.1password.com
|
||||
[3]:https://www.facebook.com/Computerworld/posts/10156160917029680
|
||||
[4]:https://www.netmarketshare.com/operating-system-market-share.aspx?options=%7B%22filter%22%3A%7B%22%24and%22%3A%5B%7B%22deviceType%22%3A%7B%22%24in%22%3A%5B%22Desktop%2Flaptop%22%5D%7D%7D%5D%7D%2C%22dateLabel%22%3A%22Trend%22%2C%22attributes%22%3A%22share%22%2C%22group%22%3A%22platform%22%2C%22sort%22%3A%7B%22share%22%3A-1%7D%2C%22id%22%3A%22platformsDesktop%22%2C%22dateInterval%22%3A%22Monthly%22%2C%22dateStart%22%3A%222017-02%22%2C%22dateEnd%22%3A%222018-01%22%2C%22segments%22%3A%22-1000%22%7D
|
||||
[5]:https://www.parrotsec.org/
|
||||
[6]:https://www.pcworld.com/article/202452/why_linux_is_more_secure_than_windows.html
|
||||
[7]:https://www.qubes-os.org/
|
||||
[8]:https://twitter.com/snowden/status/781493632293605376?lang=en
|
||||
[9]:https://tails.boum.org/about/index.en.html
|
@ -1,3 +1,5 @@
|
||||
translating----geekpi
|
||||
|
||||
College student reflects on getting started in open source
|
||||
======
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
translating---geekpi
|
||||
|
||||
Easily Run And Integrate AppImage Files With AppImageLauncher
|
||||
======
|
||||
Did you ever download an AppImage file and you didn't know how to use it? Or maybe you know how to use it but you have to navigate to the folder where you downloaded the .AppImage file every time you want to run it, or manually create a launcher for it.
|
||||
|
@ -1,3 +1,5 @@
|
||||
translating---geekpi
|
||||
|
||||
HeRM’s - A Commandline Food Recipes Manager
|
||||
======
|
||||

|
||||
|
@ -1,150 +0,0 @@
|
||||
Translating by qhwdw
|
||||
How to build a digital pinhole camera with a Raspberry Pi
|
||||
======
|
||||
|
||||

|
||||
At the tail end of 2015, the Raspberry Pi Foundation surprised the world by releasing the diminutive [Raspberry Pi Zero][1]. What's more, they [gave it away for free][2] on the cover of the MagPi magazine. I immediately rushed out and trawled around several newsagents until I found the last two copies in the area. I wasn't sure what I would use them for, but I knew their small size would allow me to do interesting projects that a full-sized Pi could not satisfy.
|
||||
|
||||
|
||||
![Raspberry Pi Zero][4]
|
||||
|
||||
Raspberry Pi Zero from MagPi magazine. CC BY-SA.4.0.
|
||||
|
||||
Because of my interest in astrophotography, I had previously modified a Microsoft LifeCam Cinema HD webcam, stripping its case, lens, and infrared cut filter to expose the bare [CCD chip][5]. I used it with a custom-built case in place of an eyepiece in my Celestron telescope for astrophotography. It has captured incredible views of Jupiter, close-ups of craters on the Moon, and sunspots on the Sun (with suitable Baader safety film protection).
|
||||
|
||||
Even before that, I had turned my film SLR camera into a [pinhole camera][6] by drilling a hole in a body cap (the cap that protects a camera's internal workings when it doesn't have a lens attached) and covering it in a thin disc cut from a soda can, pierced with a needle to provide a pinhole. Quite by chance, one day this pinhole body cap was sitting on my desk next to the modified astrophotography webcam. I wondered whether the webcam had good enough low-light performance to capture an image from behind the pinhole body cap. It only took a minute with the [GNOME Cheese][7] application to verify that a pinhole webcam was indeed a viable idea.
|
||||
|
||||
From this seed of an idea, I had a way to use one of my Raspberry Pi Zeros! The pinhole cameras that people build are typically minimalistic, offering no controls other than the exposure duration and film's ISO rating. Digital cameras, by contrast, have 20 or more buttons and hundreds more settings buried in menus. My goal for the digital pinhole webcam was to stay true to pinhole photography traditions and build a minimalist device with no controls at all, not even exposure time.
|
||||
|
||||
The digital pinhole camera, created from a Raspberry Pi Zero, HD webcam, and empty powder compact, was the [first project][8] in an [ongoing series][9] of pinhole cameras I built. Here's how I made it.
|
||||
|
||||
### Hardware
|
||||
|
||||
Since I already had the Raspberry Pi Zero in hand, I needed a webcam for this project. Given that the Pi Zero retails for £4 in the UK, I wanted other parts of the project to be priced similarly. Spending £30 on a camera to use with a £4 computer board just feels unbalanced. The obvious answer was to head over to a well-known internet auction site and bid on some secondhand webcams. Soon, I'd acquired a generic HD resolution webcam for a mere £1 plus shipping. After a quick test to ensure it operated correctly with Fedora, I went about stripping the case to examine the size of the electronics.
|
||||
|
||||
|
||||
![Hercules DualPix HD webcam][11]
|
||||
|
||||
Hercules DualPix HD webcam, which would be gutted to extract the circuit board and CCD imaging sensor. CC BY-SA 4.0.
|
||||
|
||||
Next, I needed a case to house the camera. The Raspberry Pi Zero circuit board is a mere 65mm x 30mm x 5mm. The webcam's circuit board is even smaller, although it has a plastic mounting around the CCD chip to hold the lens in place. I looked around the house for a container that would fit the two tiny circuit boards. I discovered that my wife's powder compact was just wide enough to fit the Pi Zero circuit board. With a little fiddling, it looked as though I could squeeze the webcam board inside, too.
|
||||
|
||||
![Powder compact][13]
|
||||
|
||||
Powder compact that became the case for the pinhole camera. CC BY-SA 4.0.
|
||||
|
||||
I set out to strip the case off of the webcam by removing a handful of tiny screws to get at the innards. The size of a webcam's case gives little clue about the size of the circuit board inside or where the CCD is positioned. I was lucky that this webcam was small with a convenient layout. Since I was making a pinhole camera, I had to remove the lens to expose the bare CCD chip.
|
||||
|
||||
The plastic mounting was about 1cm high, which would be too tall to fit inside the powder compact. I could remove it entirely with a couple more screws on the rear of the circuit board, but I thought it would be useful to keep it to block light coming from gaps in the case, so I trimmed it down to 4mm high using a craft knife, then reattached it. I bent the legs on the LED to reduce its height. Finally, I chopped off a second plastic tube mounted over the microphone that funneled the sound, since I didn't intend to capture audio.
|
||||
|
||||
![Bare CCD chip][15]
|
||||
|
||||
With the lens removed, the bare CCD chip is visible. The cylindrical collar holds the lens in place and prevents light from the power LED from spoiling the image. CC BY-SA 4.0.
|
||||
|
||||
The webcam had a long USB cable with a full-size plug, while the Raspberry Pi Zero uses a Micro-USB socket, so I needed a USB-to-Micro-USB adapter. But, with the adapter plugged in, the Pi wouldn't fit inside the powder compact, nor would the 1m of USB cable. So I took a sharp knife to the Micro-USB adapter, cutting off its USB socket entirely and stripping plastic to reveal the metal tracks leading to the Micro-USB plug. I also cut the webcam's USB cable down to about 6cm and removed its outer sheaf and foil wrap to expose the four individual cable strands. I soldered them directly to the tracks on the Micro-USB plug. Now the webcam could be plugged into the Pi Zero, and the pair would still fit inside the powder compact case.
|
||||
|
||||
![Modified USB plugs][17]
|
||||
|
||||
The stripped-down Micro-USB plug with the webcam USB cable strands directly soldered onto the individual contact strips. The plug now protrudes only about 1cm from the Raspberry Pi Zero when attached. CC BY-SA 4.0.
|
||||
|
||||
Originally I thought this would be the end of my electrical design, but after testing, I realized I couldn't tell if the camera was capturing images or even powered on. I decided to use the Pi's GPIO pins to drive indicator LEDs. A yellow LED illuminates when the camera control software is running, and a green LED illuminates when the webcam is capturing an image. I connected BCM pins 17 and 18 to the positive leg of the LEDs via 300ohm current-limiting resistors, then connected both negative legs to a common ground pin.
|
||||
|
||||
![LEDs][19]
|
||||
|
||||
The LEDs are connected to GPIO pins BCM 17 and BCM 18, with a 300ohm resistor in series and a common ground. CC BY-SA 4.0.
|
||||
|
||||
Next, it was time to modify the powder compact. First, I removed the inner tray that holds the powder to free up space inside the case by cutting it off with a knife at its hinge. I was planning to run the Pi Zero on a portable USB power-bank battery, which wouldn't fit inside the case, so I cut a hole in the side of the case for the USB cable connector. The LEDs needed to be visible outside the case, so I used a 3mm drill bit to make two holes in the lid.
|
||||
|
||||
Then I used a 6mm drill bit to make a hole in the center of the bottom of the case, which I covered with a thin piece of metal and used a sewing needle to pierce a pinhole in its center. I made sure that only the very tip of the needle poked through, as inserting the entire needle would make the hole far too large. I used fine wet/dry sandpaper to smooth out the pinhole, then re-pierced it from the other side, again using only the tip of the needle. The goal with a pinhole camera is to get a clean, round hole with no deformations or ridges and that just barely lets light through. The smaller the hole, the sharper the images.
|
||||
|
||||
![Bottom of the case with the pinhole aperture][21]
|
||||
|
||||
The bottom of the case with the pinhole aperture. CC BY-SA 4.0.
|
||||
|
||||
All that remained was assembling the finished device. First I fixed the webcam circuit board in the case, using blue putty to hold it in position so the CCD was directly over the pinhole. Using putty allows me to easily reposition the CCD when I need to clean dust spots (and as insurance in case I put it in the wrong place). I placed the Raspberry Pi Zero board directly on top of the webcam board. To protect against electrical short circuits between the two boards, I covered the back of the Pi in several layers of electrical tape.
|
||||
|
||||
The [Raspberry Pi Zero][22] was such a perfect fit for the powder compact that it didn't need anything else to hold it in position, besides the USB cable for the battery that sticks out through the hole in the case. Finally, I poked the LEDs through the previously drilled holes and glued them into place. I added more electrical tape on the legs of the LEDs to prevent short circuits against the Pi Zero board when the lid is closed.
|
||||
|
||||
![Raspberry Pi Zero slotted into the case][24]
|
||||
|
||||
The Raspberry Pi Zero slotted into the case with barely 1mm of clearance at the edge. The hacked up Micro-USB plug connected to the webcam is next to the Micro-USB plug from the battery. CC BY-SA 4.0.
|
||||
|
||||
### Software
|
||||
|
||||
Computer hardware is useless without software to control it, of course. The Raspberry Pi Zero can run the same software as a full-sized Pi, but booting up a traditional [Raspbian OS][25] image is a very time-consuming process due to the Zero's slow CPU speed. A camera that takes more than a minute to turn on is a camera that will not get much real-world use. Furthermore, almost nothing that a full Raspbian OS runs is useful to this camera. Even if I disable all the redundant services launched at boot, it still takes unreasonably long to boot. I decided the only stock software I would use is a [U-Boot][26] bootloader and the Linux kernel. A custom written `init` binary mounts the root filesystem from the microSD card, loads the kernel modules needed to drive the webcam, populates `/dev`, and runs the application binary.
|
||||
|
||||
The application binary is another custom C program that does the core job of controlling the camera. First, it waits for the kernel driver to initialize the webcam, opens it, and initializes it via low-level `v4l ioctl` calls. The GPIO pins are configured to drive the LEDs by poking registers via `/dev/mem`.
|
||||
|
||||
With initialization out of the way, the camera goes into a loop. Each iteration captures a single frame from the webcam in JPEG format using default exposure settings, saves the image straight to the SD card, then sleeps for three seconds. This loop runs forever until the battery is unplugged. This nicely achieves the original goal, which was to create a digital camera with the simplicity on par with a typical analog pinhole camera.
|
||||
|
||||
[The code][27] for this custom userspace is made available under [GPLv3][28] or any later version. The Raspberry Pi Zero requires an ARMv6 binary, so I built it from an x86_64 host using the [QEMU ARM][29] emulator to run compilers from a `chroot` populated with the toolchain for the [Pignus][30] distro (a Fedora 23 port/rebuild for ARMv6). Both binaries were statically linked with [glibc][31], so they are self-contained. I built a custom RAMDisk containing the binaries and a few required kernel modules and copied it to the SD card, where the bootloader can find them.
|
||||
|
||||
![Completed camera][33]
|
||||
|
||||
The finished camera is entirely hidden inside the powder compact case. The only hint of something unusual is the USB cable coming out of the side. CC BY-SA 4.0.
|
||||
|
||||
### Taking photos
|
||||
|
||||
With both the hardware and software complete, it was time to see what the camera was capable of. Everyone is familiar with the excellent quality of images produced by modern digital cameras, whether professional DSLRs or mobile phones. It is important to reset expectations here to a more realistic level. The HD webcam captures 1280x1024 resolution (~1 megapixel). The CCD struggles to capture an image from the tiny amount of light allowed through the pinhole. The webcam automatically increases gain and exposure time to compensate, which results in very noisy images. The images also suffer from a very narrow dynamic range, as evidenced by a squashed histogram, which has to be stretched in post-processing to get true blacks and whites.
|
||||
|
||||
The best results are achieved by capturing images outside in daylight, as most interiors have insufficient illumination to register any kind of usable image. The CCD is only about 1cm in diameter, and it's just a few millimeters away from the pinhole, which creates a relatively narrow field of view. For example, in a selfie taken by holding the camera at arm's length, the person's head fills the entire frame. Finally, the images are in very soft focus, which is a defining characteristic of all pinhole cameras.
|
||||
|
||||
![Picture of houses taken with pinhole webcam][35]
|
||||
|
||||
Terraced houses in the street, London. CC BY-SA 4.0.
|
||||
|
||||
![Airport photo][37]
|
||||
|
||||
Farnborough airport, former terminal building. CC BY-SA 4.0.
|
||||
|
||||
Initially, I just used the camera to capture small numbers of still images. I later reduced the loop delay from three seconds to one second and used the camera used to capture sequences of images over many minutes. I rendered the images into time-lapse videos using [GStreamer.][38]
|
||||
|
||||
Here's a video I created with this process:
|
||||
|
||||
[][38]
|
||||
|
||||
Video of the walk from Bank to Waterloo along the Thames to unwind after a day's work. 1200 frames captured at 40 frames per minute animated at 20 frames per second.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/3/how-build-digital-pinhole-camera-raspberry-pi
|
||||
|
||||
作者:[Daniel Berrange][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/berrange
|
||||
[1]:https://www.raspberrypi.org/products/raspberry-pi-zero/
|
||||
[2]:https://opensource.com/users/node/24776
|
||||
[3]:https://opensource.com/file/390776
|
||||
[4]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-raspberrypizero.jpg?itok=1ry7Kx9m (Raspberry Pi Zero)
|
||||
[5]:https://en.wikipedia.org/wiki/Charge-coupled_device
|
||||
[6]:https://en.wikipedia.org/wiki/Pinhole_camera
|
||||
[7]:https://help.gnome.org/users/cheese/stable/
|
||||
[8]:https://pinholemiscellany.berrange.com/motivation/m-arcturus/
|
||||
[9]:https://pinholemiscellany.berrange.com/
|
||||
[10]:https://opensource.com/file/390756
|
||||
[11]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-hercules_dualpix_hd.jpg?itok=r858OM9_ (Hercules DualPix HD webcam)
|
||||
[12]:https://opensource.com/file/390771
|
||||
[13]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-powdercompact.jpg?itok=RZSwqCY7 (Powder compact)
|
||||
[14]:https://opensource.com/file/390736
|
||||
[15]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-bareccdchip.jpg?itok=IQzjZmED (Bare CCD chip)
|
||||
[17]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-usbs.jpg?itok=QJBkbI1F (Modified USB plugs)
|
||||
[19]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-_pi-zero-led.png?itok=oH4c2oCn (LEDs)
|
||||
[21]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-casebottom.jpg?itok=QjDMaWLi (Bottom of the case with the pinhole aperture)
|
||||
[22]:https://opensource.com/users/node/34916
|
||||
[24]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-pizeroincase.jpg?itok=cyUIvjjt (Raspberry Pi Zero slotted into the case)
|
||||
[25]:https://www.raspberrypi.org/downloads/raspbian/
|
||||
[26]:https://www.denx.de/wiki/U-Boot
|
||||
[27]:https://gitlab.com/berrange/pinholemiscellany/
|
||||
[28]:https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
[29]:https://wiki.qemu.org/Documentation/Platforms/ARM
|
||||
[30]:https://pignus.computer/
|
||||
[31]:https://www.gnu.org/software/libc/
|
||||
[33]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-completedcamera.jpg?itok=VYFaT-kA (Completed camera)
|
||||
[35]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-housesimage.jpg?itok=-_gtwn9N (Picture of houses taken with pinhole webcam)
|
||||
[37]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-farnboroughairportimage.jpg?itok=E829gg4F (Airport photo)
|
||||
[38]:https://gstreamer.freedesktop.org/modules/gst-ffmpeg.html
|
@ -1,95 +0,0 @@
|
||||
translating---geekpi
|
||||
|
||||
Enhance your Python with an interactive shell
|
||||
======
|
||||

|
||||
The Python programming language has become one of the most popular languages used in IT. One reason for this success is it can be used to solve a variety of problems. From web development to data science, machine learning to task automation, the Python ecosystem is rich in popular frameworks and libraries. This article presents some useful Python shells available in the Fedora packages collection to make development easier.
|
||||
|
||||
### Python Shell
|
||||
|
||||
The Python Shell lets you use the interpreter in an interactive mode. It’s very useful to test code or try a new library. In Fedora you can invoke the default shell by typing python3 in a terminal session. Some more advanced and enhanced shells are available to Fedora, though.
|
||||
|
||||
### IPython
|
||||
|
||||
IPython provides many useful enhancements to the Python shell. Examples include tab completion, object introspection, system shell access and command history retrieval. Many of these features are also used by the [Jupyter Notebook][1] , since it uses IPython underneath.
|
||||
|
||||
#### Install and run IPython
|
||||
```
|
||||
dnf install ipython3
|
||||
ipython3
|
||||
|
||||
```
|
||||
|
||||
Using tab completion prompts you with possible choices. This features comes in handy when you use an unfamiliar library.
|
||||
|
||||
![][2]
|
||||
|
||||
If you need more information, use the documentation by typing the ? command. For more details, you can use the ?? command.
|
||||
|
||||
![][3]
|
||||
|
||||
Another cool feature is the ability to execute a system shell command using the ! character. The result of the command can then be referenced in the IPython shell.
|
||||
|
||||
![][4]
|
||||
|
||||
A comprehensive list of IPython features is available in the [official documentation][5].
|
||||
|
||||
### bpython
|
||||
|
||||
bpython doesn’t do as much as IPython, but nonetheless it provides a useful set of features in a simple and lightweight package. Among other features, bpython provides:
|
||||
|
||||
* In-line syntax highlighting
|
||||
* Autocomplete with suggestions as you type
|
||||
* Expected parameter list
|
||||
* Ability to send or save code to a pastebin service or file
|
||||
|
||||
|
||||
|
||||
#### Install and run bpython
|
||||
```
|
||||
dnf install bpython3
|
||||
bpython3
|
||||
|
||||
```
|
||||
|
||||
As you type, bpython offers you choices to autocomplete your code.
|
||||
|
||||
![][6]
|
||||
|
||||
When you call a function or method, the expected parameters and the docstring are automatically displayed.
|
||||
|
||||
![][7]
|
||||
|
||||
Another neat feature is the ability to open the current bpython session in an external editor (Vim by default) using the function key F7. This is very useful when testing more complex programs.
|
||||
|
||||
For more details about configuration and features, consult the bpython [documentation][8].
|
||||
|
||||
### Conclusion
|
||||
|
||||
Using an enhanced Python shell is a good way to increase productivity. It gives you enhanced features to write a quick prototype or try out a new library. Are you using an enhanced Python shell? Feel free to mention it in the comment section below.
|
||||
|
||||
Photo by [David Clode][9] on [Unsplash][10]
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/enhance-python-interactive-shell/
|
||||
|
||||
作者:[Clément Verna][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://fedoramagazine.org/author/cverna/
|
||||
[1]:https://ipython.org/notebook.html
|
||||
[2]:https://fedoramagazine.org/wp-content/uploads/2018/03/ipython-tabcompletion.png
|
||||
[3]:https://fedoramagazine.org/wp-content/uploads/2018/03/ipyhton_doc1.png
|
||||
[4]:https://fedoramagazine.org/wp-content/uploads/2018/03/ipython_shell.png
|
||||
[5]:https://ipython.readthedocs.io/en/stable/overview.html#main-features-of-the-interactive-shell
|
||||
[6]:https://fedoramagazine.org/wp-content/uploads/2018/03/bpython1.png
|
||||
[7]:https://fedoramagazine.org/wp-content/uploads/2018/03/bpython2.png
|
||||
[8]:https://docs.bpython-interpreter.org/
|
||||
[9]:https://unsplash.com/photos/d0CasEMHDQs?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
||||
[10]:https://unsplash.com/search/photos/python?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
@ -1,3 +1,5 @@
|
||||
translating----geekpi
|
||||
|
||||
Continuous Profiling of Go programs
|
||||
============================================================
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
icecoobe translating
|
||||
|
||||
How to Compile a Linux Kernel
|
||||
======
|
||||
|
||||
|
@ -1,89 +0,0 @@
|
||||
translating---geekpi
|
||||
|
||||
Easily Search And Install Google Web Fonts In Linux
|
||||
======
|
||||
|
||||

|
||||
**Font Finder** is the Rust implementation of good old [**Typecatcher**][1], which is used to easily search and install Google web fonts from [**Google’s font archive**][2]. It helps you to install hundreds of free and open source fonts in your Linux desktop. In case you’re looking for beautiful fonts for your web projects and apps and whatever else, Font Finder can easily get them for you. It is free, open source GTK3 application written in Rust programming language. Unlike Typecatcher, which is written using Python, Font Finder can filter fonts by their categories, has zero Python runtime dependencies, and has much better performance and resource consumption.
|
||||
|
||||
In this brief tutorial, we are going to see how to install and use Font Finder in Linux.
|
||||
|
||||
### Install Font Finder
|
||||
|
||||
Since Fond Finder is written using Rust programming language, you need to install Rust in your system as described below.
|
||||
|
||||
After installing Rust, run the following command to install Font Finder:
|
||||
```
|
||||
$ cargo install fontfinder
|
||||
|
||||
```
|
||||
|
||||
Font Finder is also available as [**flatpak app**][3]. First install Flatpak in your system as described in the link below.
|
||||
|
||||
Then, install Font Finder using command:
|
||||
```
|
||||
$ flatpak install flathub io.github.mmstick.FontFinder
|
||||
|
||||
```
|
||||
|
||||
### Search And Install Google Web Fonts In Linux Using Font Finder
|
||||
|
||||
You can launch font finder either from the application launcher or run the following command to launch it.
|
||||
```
|
||||
$ flatpak run io.github.mmstick.FontFinder
|
||||
|
||||
```
|
||||
|
||||
This is how Font Finder default interface looks like.
|
||||
|
||||
![][5]
|
||||
|
||||
As you can see, Font Finder user interface is very simple. All Google web fonts are listed in the left pane and the preview of the respective font is given at the right pane. You can type any words in the preview box to view how the words will look like in the selected font. There is also a search box on the top left which allows you to quickly search for a font of your choice.
|
||||
|
||||
By default, Font Finder displays all type of fonts. You can, however, display the fonts by category-wise from the category drop-down box above the the search box.
|
||||
|
||||
![][6]
|
||||
|
||||
To install a font, just choose it and click the **Install** button on the top.
|
||||
|
||||
![][7]
|
||||
|
||||
You can test the newly installed fonts in any text processing applications.
|
||||
|
||||
![][8]
|
||||
|
||||
Similarly, to remove a font, just choose it from the Font Finder dashboard and click the **Uninstall** button. It’s that simple!
|
||||
|
||||
The Settings button (the gear button) on the top left corner provides the option to switch to dark preview.
|
||||
|
||||
![][9]
|
||||
|
||||
As you can see, Font Finder is very simple and does the job exactly as advertised in its home page. If you’re looking for an application to install Google web fonts, Font Finder is one such application.
|
||||
|
||||
And, that’s all for now. Hope this helps. More good stuffs to come. Stay tuned!
|
||||
|
||||
Cheers!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/font-finder-easily-search-and-install-google-web-fonts-in-linux/
|
||||
|
||||
作者:[SK][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.ostechnix.com/author/sk/
|
||||
[1]:https://www.ostechnix.com/install-google-web-fonts-ubuntu/
|
||||
[2]:https://fonts.google.com/
|
||||
[3]:https://flathub.org/apps/details/io.github.mmstick.FontFinder
|
||||
[4]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[5]:http://www.ostechnix.com/wp-content/uploads/2018/04/font-finder-1.png
|
||||
[6]:http://www.ostechnix.com/wp-content/uploads/2018/04/font-finder-2.png
|
||||
[7]:http://www.ostechnix.com/wp-content/uploads/2018/04/font-finder-3.png
|
||||
[8]:http://www.ostechnix.com/wp-content/uploads/2018/04/font-finder-5.png
|
||||
[9]:http://www.ostechnix.com/wp-content/uploads/2018/04/font-finder-4.png
|
@ -1,82 +0,0 @@
|
||||
translating---geekpi
|
||||
|
||||
Reset a lost root password in under 5 minutes
|
||||
======
|
||||
|
||||

|
||||
|
||||
A system administrator can easily reset passwords for users who have forgotten theirs. But what happens if the system administrator forgets the root password, or leaves the company? This guide will show you how to reset a lost or forgotten root password on a Red Hat-compatible system, including Fedora and CentOS, in less than 5 minutes.
|
||||
|
||||
Please note, if the entire system hard disk has been encrypted with LUKS, you would need to provide the LUKS password when prompted. Also, this procedure is applicable to systems running systemd which has been the default init system since Fedora 15, CentOS 7.14.04, and Red Hat Enterprise Linux 7.0.
|
||||
|
||||
First, you need to interrupt the boot process, so you'll need to turn the system on or restart it if it’s already powered on. The first step is tricky because the GRUB menu tends to flash very quickly on the screen. You may need to try this a few times until you are able to do it.
|
||||
|
||||
Press **e** on your keyboard when you see this screen:
|
||||
|
||||

|
||||
|
||||
If you've done this correctly, you should see a screen similar to this one:
|
||||
|
||||

|
||||
|
||||
Use your arrow keys to move to the Linux16 line:
|
||||
|
||||

|
||||
|
||||
Using your **del** key or your **backspace** key, remove `rhgb quiet` and replace with the following:
|
||||
|
||||
`rd.break enforcing=0`
|
||||
|
||||

|
||||
|
||||
Setting `enforcing=0` will allow you to avoid performing a complete system SELinux relabeling. Once the system is rebooted, you'll only have to restore the correct SELinux context for the `/etc/shadow` file. I'll show you how to do this too.
|
||||
|
||||
Press **Ctrl-x** to start.
|
||||
|
||||
**The system will now be in emergency mode.**
|
||||
|
||||
Remount the hard drive with read-write access:
|
||||
```
|
||||
# mount –o remount,rw /sysroot
|
||||
|
||||
```
|
||||
|
||||
Run `chroot` to access the system:
|
||||
```
|
||||
# chroot /sysroot
|
||||
|
||||
```
|
||||
|
||||
You can now change the root password:
|
||||
```
|
||||
# passwd
|
||||
|
||||
```
|
||||
|
||||
Type the new root password twice when prompted. If you are successful, you should see a message that reads " **all authentication tokens updated successfully**. "
|
||||
|
||||
Type **exit** twice to reboot the system.
|
||||
|
||||
Log in as root and restore the SELinux label to the `/etc/shadow` file.
|
||||
```
|
||||
# restorecon -v /etc/shadow
|
||||
|
||||
```
|
||||
|
||||
Turn SELinux back to enforcing mode:
|
||||
```
|
||||
# setenforce 1
|
||||
|
||||
```
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/4/reset-lost-root-password
|
||||
|
||||
作者:[Curt Warfield][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://opensource.com/users/rcurtiswarfield
|
@ -1,100 +0,0 @@
|
||||
How To Use Vim Editor To Input Text Anywhere
|
||||
======
|
||||
|
||||

|
||||
|
||||
Howdy Vim users! Today, I have come up with a good news to all of you. Say hello to **Vim-anywhere** , a simple script that allows you to use the Vim editor to input text anywhere in your Linux box. That means you can simply invoke your favorite Vim editor, type whatever you want and paste the text on any application or on a website. The text will be available in your clipboard until you restart your system. This utility is absolutely useful for those who love to use the Vim keybindings often in non-vim environment.
|
||||
|
||||
### Install Vim-anywhere in Linux
|
||||
|
||||
The Vim-anywhere utility will work on any GNOME based (or derivatives) Linux distributions. Also, make sure you have installed the following prerequisites.
|
||||
|
||||
* Curl
|
||||
* Git
|
||||
* gVim
|
||||
* xclip
|
||||
|
||||
|
||||
|
||||
For instance, you can those utilities in Ubuntu as shown below.
|
||||
```
|
||||
$ sudo apt install curl git vim-gnome xclip
|
||||
|
||||
```
|
||||
|
||||
Then, run the following command to install Vim-anywhere:
|
||||
```
|
||||
$ curl -fsSL https://raw.github.com/cknadler/vim-anywhere/master/install | bash
|
||||
|
||||
```
|
||||
|
||||
Vim-anywhere has been installed. Now let us see how to use it.
|
||||
|
||||
### Use Vim Editor To Input Text Anywhere
|
||||
|
||||
Let us say you need to create a word document. But you’re much more comfortable using Vim editor than LibreOffice writer. No problem, this is where Vim-anywhere comes in handy. It automates the entire process. It simply invokes the Vim editor, so you can write whatever you want in it and paste it in the .doc file.
|
||||
|
||||
Let me show you an example. Open LibreOffice writer or any graphical text editor of your choice. Then, open Vim-anywhere. To do so, simply press **CTRL+ALT+V**. It will open the gVim editor. Press “i” to switch to interactive mode and input the text. Once done, save and close it by typing **:wq**.
|
||||
|
||||
![][2]
|
||||
|
||||
The text will be available in the clipboard until you restart the system. After you closed the editor, your previous application is refocused. Just press **CTRL+P** to paste the text in it.
|
||||
|
||||
![][3]
|
||||
|
||||
It’s just an example. You can even use Vim-anywhere to write something on an annoying web form or any other applications. Once Vim-anywhere invoked, it will open a buffer. Close it and its contents are automatically copied to your clipboard and your previous application is refocused.
|
||||
|
||||
The vim-anywhere utility will create a temporary file in **/tmp/vim-anywhere** when invoked. These temporary files stick around until you restart your system, giving you a temporary history.
|
||||
```
|
||||
$ ls /tmp/vim-anywhere
|
||||
|
||||
```
|
||||
|
||||
You can re-open your most recent file using command:
|
||||
```
|
||||
$ vim $( ls /tmp/vim-anywhere | sort -r | head -n 1 )
|
||||
|
||||
```
|
||||
|
||||
**Update Vim-anywhere**
|
||||
|
||||
Run the following command to update Vim-anywhere:
|
||||
```
|
||||
$ ~/.vim-anywhere/update
|
||||
|
||||
```
|
||||
|
||||
**Change keyboard shotcut**
|
||||
|
||||
The default keybinding to invoke Vim-anywhere is CTRL+ALT+V. You can change it to any custom keybinding using gconf tool.
|
||||
```
|
||||
$ gconftool -t str --set /desktop/gnome/keybindings/vim-anywhere/binding <custom binding>
|
||||
|
||||
```
|
||||
|
||||
**Uninstall Vim-anywhere**
|
||||
|
||||
Some of you might think that opening Vim editor each time to input text and paste the text back to another application might be pointless and completely unnecessary.
|
||||
|
||||
If you don’t find this utility useful, simply uninstall it using command:
|
||||
```
|
||||
$ ~/.vim-anywhere/uninstall
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/how-to-use-vim-editor-to-input-text-anywhere/
|
||||
|
||||
作者:[SK][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.ostechnix.com/author/sk/
|
||||
[2]:http://www.ostechnix.com/wp-content/uploads/2018/05/vim-anywhere-1-1.png
|
||||
[3]:http://www.ostechnix.com/wp-content/uploads/2018/05/vim-anywhere-2.png
|
@ -1,137 +0,0 @@
|
||||
translating---geekpi
|
||||
|
||||
How to build container images with Buildah
|
||||
======
|
||||
|
||||

|
||||
|
||||
Project Atomic, through their efforts on the Open Container Initiative (OCI), have created a great tool called [Buildah][1]. Buildah helps with creating, building and updating container images supporting Docker formatted images as well as OCI compliant images.
|
||||
|
||||
Buildah handles building container images without the need to have a full container runtime or daemon installed. This particularly shines for setting up a continuous integration and continuous delivery pipeline for building containers.
|
||||
|
||||
Buildah makes the container’s filesystem directly available to the build host. Meaning that the build tooling is available on the host and not needed in the container image, keeping the build faster and the image smaller and safer. There are Buildah packages for CentOS, Fedora, and Debian.
|
||||
|
||||
### Installing Buildah
|
||||
|
||||
Since Fedora 26 Buildah can be installed using dnf.
|
||||
```
|
||||
$ sudo dnf install buildah -y
|
||||
|
||||
```
|
||||
|
||||
The current version of buildah is 0.16, which can be displayed by the following command.
|
||||
```
|
||||
$ buildah --version
|
||||
|
||||
```
|
||||
|
||||
### Basic commands
|
||||
|
||||
The first step needed to build a container image is to get a base image, this is done by the FROM statement in a Dockerfile. Buildah does handle this in a similar way.
|
||||
```
|
||||
$ sudo buildah from fedora
|
||||
|
||||
```
|
||||
|
||||
This command pulls the Fedora based image and stores it on the host. It is possible to inspect the images available on the host, by running the following.
|
||||
```
|
||||
$ sudo buildah images
|
||||
IMAGE ID IMAGE NAME CREATED AT SIZE
|
||||
9110ae7f579f docker.io/library/fedora:latest Mar 7, 2018 20:51 234.7 MB
|
||||
|
||||
```
|
||||
|
||||
After pulling the base image, a running container instance of this image is available, this is a “working-container”.
|
||||
|
||||
The following command displays the running containers.
|
||||
```
|
||||
$ sudo buildah containers
|
||||
CONTAINER ID BUILDER IMAGE ID IMAGE NAME
|
||||
CONTAINER NAME
|
||||
6112db586ab9 * 9110ae7f579f docker.io/library/fedora:latest fedora-working-container
|
||||
|
||||
```
|
||||
|
||||
Buildah also provides a very useful command to stop and remove all the containers that are currently running.
|
||||
```
|
||||
$ sudo buildah rm --all
|
||||
|
||||
```
|
||||
|
||||
The full list of command is available using the –help option.
|
||||
```
|
||||
$ buildah --help
|
||||
|
||||
```
|
||||
|
||||
### Building an Apache web server container image
|
||||
|
||||
Let’s see how to use Buildah to install an Apache web server on a Fedora base image, then copy a custom index.html to be served by the server.
|
||||
|
||||
First let’s create the custom index.html.
|
||||
```
|
||||
$ echo "Hello Fedora Magazine !!!" > index.html
|
||||
|
||||
```
|
||||
|
||||
Then install the httpd package inside the running container.
|
||||
```
|
||||
$ sudo buildah from fedora
|
||||
$ sudo buildah run fedora-working-container dnf install httpd -y
|
||||
|
||||
```
|
||||
|
||||
Let’s copy index.html to /var/www/html/.
|
||||
```
|
||||
$ sudo buildah copy fedora-working-container index.html /var/www/html/index.html
|
||||
|
||||
```
|
||||
|
||||
Then configure the container entrypoint to start httpd.
|
||||
```
|
||||
$ sudo buildah config --entrypoint "/usr/sbin/httpd -DFOREGROUND" fedora-working-container
|
||||
|
||||
```
|
||||
|
||||
Now to make the “working-container” available, the commit command saves the container to an image.
|
||||
```
|
||||
$ sudo buildah commit fedora-working-container hello-fedora-magazine
|
||||
|
||||
```
|
||||
|
||||
The hello-fedora-magazine image is now available, and can be pushed to a registry to be used.
|
||||
```
|
||||
$ sudo buildah images
|
||||
IMAGE ID IMAGE NAME CREATED
|
||||
AT SIZE
|
||||
9110ae7f579f docker.io/library/fedora:latest
|
||||
Mar 7, 2018 22:51 234.7 MB
|
||||
49bd5ec5be71 docker.io/library/hello-fedora-magazine:latest
|
||||
Apr 27, 2018 11:01 427.7 MB
|
||||
|
||||
```
|
||||
|
||||
It is also possible to use Buildah to test this image by running the following steps.
|
||||
```
|
||||
$ sudo buildah from --name=hello-magazine docker.io/library/hello-fedora-magazine
|
||||
|
||||
$ sudo buildah run hello-magazine
|
||||
|
||||
```
|
||||
|
||||
Accessing <http://localhost> will display “Hello Fedora Magazine !!!“
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/daemon-less-container-management-buildah/
|
||||
|
||||
作者:[Ashutosh Sudhakar Bhakare][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://fedoramagazine.org/author/ashutoshbhakare/
|
||||
[1]:https://github.com/projectatomic/buildah
|
230
sources/tech/20180504 A Beginners Guide To Cron Jobs.md
Normal file
230
sources/tech/20180504 A Beginners Guide To Cron Jobs.md
Normal file
@ -0,0 +1,230 @@
|
||||
A Beginners Guide To Cron Jobs
|
||||
======
|
||||
|
||||

|
||||
**Cron** is one of the most useful utility that you can find in any Unix-like operating system. It is used to schedule commands at a specific time. These scheduled commands or tasks are known as “Cron Jobs”. Cron is generally used for running scheduled backups, monitoring disk space, deleting files (for example log files) periodically which are no longer required, running system maintenance tasks and a lot more. In this brief guide, we will see the basic usage of Cron Jobs in Linux.
|
||||
|
||||
### The Beginners Guide To Cron Jobs
|
||||
|
||||
The typical format of a cron job is:
|
||||
```
|
||||
Minute(0-59) Hour(0-24) Day_of_month(1-31) Month(1-12) Day_of_week(0-6) Command_to_execute
|
||||
|
||||
```
|
||||
|
||||
Just memorize the cron job format or print the following illustration and keep it in your desk.
|
||||
|
||||
![][2]
|
||||
|
||||
In the above picture, the asterisks refers the specific blocks of time.
|
||||
|
||||
To display the contents of the **crontab** file of the currently logged in user:
|
||||
```
|
||||
$ crontab -l
|
||||
|
||||
```
|
||||
|
||||
To edit the current user’s cron jobs, do:
|
||||
```
|
||||
$ crontab -e
|
||||
|
||||
```
|
||||
|
||||
If it is the first time, you will be asked to editor to edit the jobs.
|
||||
```
|
||||
no crontab for sk - using an empty one
|
||||
|
||||
Select an editor. To change later, run 'select-editor'.
|
||||
1. /bin/nano <---- easiest
|
||||
2. /usr/bin/vim.basic
|
||||
3. /usr/bin/vim.tiny
|
||||
4. /bin/ed
|
||||
|
||||
Choose 1-4 [1]:
|
||||
|
||||
```
|
||||
|
||||
Choose any one that suits you. Here it is how a sample crontab file looks like.
|
||||
|
||||
![][3]
|
||||
|
||||
In this file, you need to add your cron jobs.
|
||||
|
||||
To edit the crontab of a different user, for example ostechnix, do:
|
||||
```
|
||||
$ crontab -u ostechnix -e
|
||||
|
||||
```
|
||||
|
||||
Let us see some examples.
|
||||
|
||||
To run a cron job **every minute** , the format should be like below.
|
||||
```
|
||||
* * * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
To run cron job every 5 minute, add the following in your crontab file.
|
||||
```
|
||||
*/5 * * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
To run a cron job at every quarter hour (every 15th minute), add this:
|
||||
```
|
||||
*/15 * * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
To run a cron job every hour at 30 minutes, run:
|
||||
```
|
||||
30 * * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
You can also define multiple time intervals separated by commas. For example, the following cron job will run three times every hour, at minutes 0, 5 and 10:
|
||||
```
|
||||
0,5,10 * * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a cron job every half hour:
|
||||
```
|
||||
*/30 * * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job every hour:
|
||||
```
|
||||
0 * * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job every 2 hours:
|
||||
```
|
||||
0 */2 * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job every day (It will run at 00:00):
|
||||
```
|
||||
0 0 * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job every day at 3am:
|
||||
```
|
||||
0 3 * * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job every sunday:
|
||||
```
|
||||
0 0 * * SUN <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Or,
|
||||
```
|
||||
0 0 * * 0 <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
It will run at exactly at 00:00 on Sunday.
|
||||
|
||||
Run a job on every day-of-week from Monday through Friday i.e every weekday:
|
||||
```
|
||||
0 0 * * 1-5 <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
The job will start at 00:00.
|
||||
|
||||
Run a job every month:
|
||||
```
|
||||
0 0 1 * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job at 16:15 on day-of-month 1:
|
||||
```
|
||||
15 16 1 * * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job at every quarter i.e on day-of-month 1 in every 3rd month:
|
||||
```
|
||||
0 0 1 */3 * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
Run a job on a specific month at a specific time:
|
||||
```
|
||||
5 0 * 4 * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
The job will start at 00:05 in April.
|
||||
|
||||
Run a job every 6 months:
|
||||
```
|
||||
0 0 1 */6 * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
This cron job will start at 00:00 on day-of-month 1 in every 6th month.
|
||||
|
||||
Run a job every year:
|
||||
```
|
||||
0 0 1 1 * <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
This cron job will start at 00:00 on day-of-month 1 in January.
|
||||
|
||||
We can also use the following strings to define job.
|
||||
|
||||
@reboot Run once, at startup. @yearly Run once a year. @annually (same as @yearly). @monthly Run once a month. @weekly Run once a week. @daily Run once a day. @midnight (same as @daily). @hourly Run once an hour.
|
||||
|
||||
For example, to run a job every time the server is rebooted, add this line in your crontab file.
|
||||
```
|
||||
@reboot <command-to-execute>
|
||||
|
||||
```
|
||||
|
||||
To remove all cron jobs for the current user:
|
||||
```
|
||||
$ crontab -r
|
||||
|
||||
```
|
||||
|
||||
There is also a dedicated website named [**crontab.guru**][4] for learning cron jobs examples. This site provides a lot of cron job examples.
|
||||
|
||||
For more details, check man pages.
|
||||
```
|
||||
$ man crontab
|
||||
|
||||
```
|
||||
|
||||
And, that’s all for now. At this point, you might have a basic understanding of cron jobs and how to use them in real time. More good stuffs to come. Stay tuned!!
|
||||
|
||||
Cheers!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/a-beginners-guide-to-cron-jobs/
|
||||
|
||||
作者:[SK][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.ostechnix.com/author/sk/
|
||||
[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[2]:http://www.ostechnix.com/wp-content/uploads/2018/05/cron-job-format-1.png
|
||||
[3]:http://www.ostechnix.com/wp-content/uploads/2018/05/cron-jobs-1.png
|
||||
[4]:https://crontab.guru/
|
75
sources/tech/20180507 4 Firefox extensions to install now.md
Normal file
75
sources/tech/20180507 4 Firefox extensions to install now.md
Normal file
@ -0,0 +1,75 @@
|
||||
4 Firefox extensions to install now
|
||||
======
|
||||

|
||||
As I mentioned in my [original article][1] on Firefox extensions, the web browser has become a critical component of the computing experience for many users. Modern browsers have evolved into powerful and extensible platforms, and extensions can add or modify their functionality. Extensions for Firefox are built using the WebExtensions API, a cross-browser development system.
|
||||
|
||||
In the first article, I asked readers: "Which extensions should you install?" To reiterate, that decision largely comes down to how you use your browser, your views on privacy, how much you trust extension developers, and other personal preferences. Since that article was published, one extension I recommended (Xmarks) has been discontinued. Additionally, that article received a ton of feedback that has been taken into account for this update.
|
||||
|
||||
Once again, I'd like to point out that browser extensions often require the ability to read and/or change everything on the web pages you visit. You should consider the ramifications of this very carefully. If an extension has modify access to all the web pages you visit, it could act as a keylogger, intercept credit card information, track you online, insert advertisements, and perform a variety of other nefarious activities. That doesn't mean every extension will surreptitiously do these things, but you should carefully consider the installation source, the permissions involved, your risk profile, and other factors before you install any extension. Keep in mind you can use profiles to manage how an extension impacts your attack surface—for example, using a dedicated profile with no extensions to perform tasks such as online banking.
|
||||
|
||||
With that in mind, here are four open source Firefox extensions you may want to consider.
|
||||
|
||||
### uBlock Origin
|
||||
|
||||
![ublock origin ad blocker screenshot][2]
|
||||
|
||||
My first recommendation remains unchanged. [uBlock Origin][3] is a fast, low memory, wide-spectrum blocker that allows you to not only block ads but also enforce your own content filtering. The default behavior of uBlock Origin is to block ads, trackers, and malware sites using multiple, predefined filter lists. From there it allows you to arbitrarily add lists and rules, or even lock down to a default-deny mode. Despite being powerful, the extension has proven to be efficient and performant. It continues to be updated regularly and is one of the best options available for this functionality.
|
||||
|
||||
### Privacy Badger
|
||||
|
||||
![privacy badger ad blocker][4]
|
||||
|
||||
My second recommendation also remains unchanged. If anything, privacy has been brought even more to the forefront since my previous article, making this extension an easy recommendation. As the name indicates, [Privacy Badger][5] is a privacy-focused extension that blocks ads and other third-party trackers. It's a project of the Electronic Freedom Foundation, which says:
|
||||
|
||||
> "Privacy Badger was born out of our desire to be able to recommend a single extension that would automatically analyze and block any tracker or ad that violated the principle of user consent; which could function well without any settings, knowledge, or configuration by the user; which is produced by an organization that is unambiguously working for its users rather than for advertisers; and which uses algorithmic methods to decide what is and isn't tracking."
|
||||
|
||||
Why is Privacy Badger on this list when the previous item may seem similar? A couple reasons. The first is that it fundamentally works differently than uBlock Origin. The second is that a practice of defense in depth is a sound policy to follow. Speaking of defense in depth, the EFF also maintains [HTTPS Everywhere][6] to automatically ensure https is used for many major websites. When you're installing Privacy Badger, you may want to consider HTTPS Everywhere as well.
|
||||
|
||||
In case you were starting to think this article was simply going to be a rehash of the last one, here's where my recommendations diverge.
|
||||
|
||||
### Bitwarden
|
||||
|
||||
![Bitwarden][7]
|
||||
|
||||
When recommending LastPass in the previous article, I mentioned it was likely going to be a controversial selection. That certainly proved true. Whether you should use a password manager at all—and if you do, whether you should choose one that has a browser plugin—is a hotly debated topic, and the answer very much depends on your personal risk profile. I asserted that most casual computer users should use one because it's much better than the most common alternative: using the same weak password everywhere. I still believe that.
|
||||
|
||||
[Bitwarden][8] has really matured since the last time I checked it out. Like LastPass, it is user-friendly, supports two-factor authentication, and is reasonably secure. Unlike LastPass, it is [open source][9]. It can be used with or without the browser plugin and supports importing from other solutions including LastPass. The core functionality is completely free, and there is a premium version that is $10/year.
|
||||
|
||||
### Vimium-FF
|
||||
|
||||
![Vimium][10]
|
||||
|
||||
[Vimium][11] is another open source extension that provides Firefox keyboard shortcuts for navigation and control in the spirit of Vim. They call it "The Hacker's Browser." Modifier keys are specified as **< c-x>**, **< m-x>**, and **< a-x>** for Ctrl+x, Meta+x, and Alt+x, respectively, and the defaults can be easily customized. Once you have Vimium installed, you can see this list of key bindings at any time by typing **?**. Note that if you prefer Emacs, there are also a couple of extensions for those keybindings as well. Either way, I think keyboard shortcuts are an underutilized productivity booster.
|
||||
|
||||
### Bonus: Grammarly
|
||||
|
||||
Not everyone is lucky enough to write a column on Opensource.com—although you should seriously consider writing for the site; if you have questions, are interested, or would like a mentor, reach out and let's chat. But even without a column to write, proper grammar is beneficial in a large variety of situations. Enter [Grammarly][12]. This extension is not open source, unfortunately, but it does make sure everything you type is clear, effective, and mistake-free. It does this by scanning your text for common and complex grammatical mistakes, spanning everything from subject-verb agreement to article use to modifier placement. Basic functionality is free, with a premium version with additional checks available for a monthly charge. I used it for this article and it caught multiple errors that my proofreading didn't.
|
||||
|
||||
Again, Grammarly is the only extension included on this list that is not open source, so if you know of a similar high-quality open source replacement, let us know in the comments.
|
||||
|
||||
These extensions are ones I've found useful and recommend to others. Let me know in the comments what you think of the updated recommendations.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/5/firefox-extensions
|
||||
|
||||
作者:[Jeremy Garcia][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://opensource.com/users/jeremy-garcia
|
||||
[1]:https://opensource.com/article/18/1/top-5-firefox-extensions
|
||||
[2]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/ublock.png?itok=_QFEbDmq (ublock origin ad blocker screenshot)
|
||||
[3]:https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/
|
||||
[4]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/images/life-uploads/privacy_badger_1.0.1.png?itok=qZXQeKtc (privacy badger ad blocker screenshot)
|
||||
[5]:https://www.eff.org/privacybadger
|
||||
[6]:https://www.eff.org/https-everywhere
|
||||
[7]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/bitwarden.png?itok=gZPrCYoi (Bitwarden)
|
||||
[8]:https://bitwarden.com/
|
||||
[9]:https://github.com/bitwarden
|
||||
[10]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/vimium.png?itok=QRESXjWG (Vimium)
|
||||
[11]:https://addons.mozilla.org/en-US/firefox/addon/vimium-ff/
|
||||
[12]:https://www.grammarly.com/
|
@ -0,0 +1,162 @@
|
||||
A reading list for Linux and open source fans
|
||||
======
|
||||
|
||||

|
||||
I recently asked our writer community to share with us what they're reading. These folks come from all different walks of life and roles in tech. What they have in common is that they are living and breathing Linux and open source every day.
|
||||
|
||||
Drink in this fantastic list. Many of them are free and available to download.
|
||||
|
||||
You may see books you've been meaning to get around to, books that are completely new to you, and some that feel like old friends.
|
||||
|
||||
We'd love to hear what you think of this list. Share with us in the comments below or on [Twitter][1] with #Linuxbooks #opensourcebooks.
|
||||
|
||||
### 17 books to add to your reading list
|
||||
|
||||
**Plus, a bonus fiction read.**
|
||||
|
||||
[23 Years of FreeDOS][2] by Jim Hall
|
||||
|
||||
Last year, the [FreeDOS][3] Project turned 23 years old. While there's nothing special about 23 years, the project decided to celebrate that milestone by sharing stories about how different people use or contribute to FreeDOS. The free, CC BY eBook is a collection of essays that describe the history of FreeDOS since 1994, and how people use FreeDOS today. (Recommendation and review by [Jim Hall][4])
|
||||
|
||||
[Eloquent JavaScript][5] by Marijn Haverbeke
|
||||
|
||||
This book teaches you how to write beautifully crafted programs using one of the most ubiquitous programming languages: [Javascript][6]. Learn the basics and advanced concepts of the language, and how to write programs that run in the browser or Node.js environment. The book also includes five fun projects so you can dive into actual programming while making a platform game or even writing your own programming language. (Recommendation and review by [Rahul Thakoor][7])
|
||||
|
||||
[_Forge Your Future with Open Source_][8] by VM (Vicky) Brasseur
|
||||
|
||||
If you're looking to contribute to open source, but you don't know how to start, this is the book for you. It covers how to find a project to join and how to make your first contributions. (Recommendation and review by [Ben Cotton][9])
|
||||
|
||||
[_Git for Teams_][10] by Emma Jane Hogbin Westby
|
||||
|
||||
Git is a widely-used version control system for individuals and teams alike, but its power means it can be complex. This book provides guidance on how to effectively use [git][11] in a team environment. For more, read our [in-depth review][12]. (Recommendation and review by [Ben Cotton][9])
|
||||
|
||||
[Getting to Yes][13] by Fisher, Ury, and Patton
|
||||
|
||||
The Harvard Negotiation Project, formed in the 1970s, was an academic effort involving economists, psychologists, sociologists, and political scientists to create a framework for negotiations which allows better outcomes for all involved. Their framework and techniques have been used in a diverse set of circumstances, including the Camp David Accords between Egypt and Israel in 1978.
|
||||
|
||||
Principled Negotiation involves understanding the real interests of the participants in a negotiation and using this knowledge to generate options acceptable to all. The same techniques can be used to resolve interpersonal issues, negotiations over cars and houses, discussions with insurance companies, and so on.
|
||||
|
||||
What does this have to do with open source software development? Everything in open source is a negotiation, in some sense. Submitting a bug report is outlining a position—that something does not work correctly—and requesting that someone reprioritize their work to fix it. A heated discussion on a mailing list over the right way to do something or a comment on a feature request is a negotiation, often with imperfect knowledge, about the scope and goals of the project.
|
||||
|
||||
Reframing these conversations as explorations, trying to understand why the other person is asking for something, and being transparent about the reasons why you believe another viewpoint to apply, can dramatically change your relationships and effectiveness working in an open source project. (Recommendation and review by [Dave Neary][14])
|
||||
|
||||
[Just for Fun: The Story of an Accidental Revolutionary][15] by Linus Torvalds et al.
|
||||
|
||||
Linux is an amazing and powerful operating system that spawned a movement to transparency and openness. And, the open source ethos that drives it flies in the face of traditional models of business and capital appreciation. In this book, learn about the genius of Linus the man and [Linux][16] the operating system. Get insight into the experiences that shaped Linus's life and fueled his transformation from a nerdy young man who enjoyed toying with his grandfather's clock to the master programmer of the world's predominant operating system. (Recommendation and review by [Don Watkins][17])
|
||||
|
||||
[Linux in a Month of Lunches][18] by Steven Ovadia
|
||||
|
||||
This book is designed to teach non-technical users how to use desktop [Linux][19] in about an hour a day. The book covers everything from choosing a desktop environment to installing software, to using Git. At the end of the month, readers can use Linux fulltime, replacing their other operating systems. (Recommendation and review by [Steven Ovadia][20])
|
||||
|
||||
[Linux in Action][21] by David Clinton
|
||||
|
||||
This book introduces serious Linux administration tools for anyone interested in getting more out of their tech, including IT professionals, developers, [DevOps][22] specialists, and more. Rather than teaching skills in isolation, the book is organized around practical projects like automating off-site data backups, securing a web server, and creating a VPN to safely connect an organization's resources. [Read more][23] by this author. (Recommendation and review by [David Clinton][24])
|
||||
|
||||
[Make: Linux for Makers][25] by Aaron Newcomb
|
||||
|
||||
This book is a must-read for anyone wanting to create and innovate with the [Raspberry Pi][26]. This book will have you up and operating your Raspberry Pi while at the same time understanding the nuances of it Raspbian Linux operating system. This is a masterful basic text that will help any maker unlock the potential of the Raspberry Pi. It’s concise and well written with a lot of fantastic illustrations and practical examples. (Recommendation by Jason Hibbets | Review by [Don Watkins][17])
|
||||
|
||||
[Managing Humans: Biting and Humorous Tales of a Software Engineering Manager][27] by Michael Lopp
|
||||
|
||||
Michael Lopp is better known by the nom de plume Rands, author of the popular blog [Rands in Repose][28]. This book is an edited, curated collection of blog posts, all related to the management of software development teams. What I love about the book and the blog, is that Rands starts from the fundamental principle that the most complex part of software development is human interactions. The book covers a range of topics about reading a group, understanding the personalities that make it up, and figuring out how to get the best out of everyone.
|
||||
|
||||
These things are universal, and as an open source community manager, I come across them all the time. How do you know if someone might be burning out? How do you run a good meeting? How do you evolve the culture of a project and team as it grows? How much process is the right amount? Regardless of the activity, questions like these arise all the time, and Rands's irreverent, humorous take is educational and entertaining. (Recommendation and review by [Dave Neary][14])
|
||||
|
||||
[Open Sources: Voices from the Open Source Revolution][29] (O'Reilly, 1999)
|
||||
|
||||
This book is a must-read for all open source enthusiasts. Linus Torvalds, Eric S. Raymond, Richard Stallman, Michael Tiemann, Tim O'Reilly, and other important figures in the open source movement share their thoughts on the forward momentum of [open source software][30]. (Recommendation by [Jim Hall][4] | Review by Jen Wike Huger)
|
||||
|
||||
[Producing Open Source Software: How to Run a Successful Free Software Project][31] by Karl Fogel
|
||||
|
||||
This book is for anyone who wants to build an open source community, is already building one, or wants to better understand trends in successful open source project community development. Karl Fogel analyzes and studies traits and characteristics of successful open source projects and how they have developed a community around the project. The book offers helpful advice to community managers (or want-to-be community managers) on how to navigate community development around a project. This is a rare book that takes a deeper look into open source community development and offers plenty of ingredients for success, but you have to take it and create the recipe for your project or community. (Recommendation and review by [Justin Flory][32])
|
||||
|
||||
[Programming with Robots][33] by Albert W. Schueller
|
||||
|
||||
This book introduces the basics of programming using the Lego Mindstorms NXT. Instead of writing abstract programs, learn how to program devices that can sense and interface with the physical world. Learn how software and hardware interact with each other while experimenting with sensors, motors or making music using code. (Recommendation and review by [Rahul Thakoor][7])
|
||||
|
||||
[The AWK programming language][34] by Alfred V. Aho, Brian W. Kernighan, and Peter J. Weinberger
|
||||
|
||||
This book, written by the creators of awk, follows a pattern similar to other books about *nix tools written by the original Bell Labs Unix team and published in the 1970s-1990s, explaining the rationale and intended use of awk in clear and compact prose, liberally sprinkled with examples that start simply and are further elaborated by the need to deal with more fully-detailed problems and edge cases. When published, the typical reader of this book would have been someone who had files of textual or numeric data that needed to be processed and transformed, and who wanted to be able to easily create lookup tables, apply regular expressions, react to structure changes within the input, apply mathematical transformations to numbers and easily format the output.
|
||||
|
||||
While that characterization still applies, today the book can also provide a window back into the time when the only user interface available was a terminal, when "modularity" created the ability to string together numerous single-purpose utility programs in shell scripts to create data transformation pipelines that crunched the data and produced the reports that everyone expected of computers. Today, awk should be a part of the operations toolbox, providing a fine ability to further process configuration and log files, and this book still provides a great introduction to that process. (Recommendation by [Jim Hall][4] | Review by [Chris Hermansen][35])
|
||||
|
||||
[Think Python: Think Like a Computer Scientist][36] by Allen Downey
|
||||
|
||||
This book about [Python][37] is part of [a series][38] that covers other languages as well, like Java, [Perl][39], etc. It moves past simple language syntax downloads and approaches the topic through the lens of how a problem solver would build a solution. It's both a great introductory guide to programming through a layering of concepts, but it can serve the dabbler who is looking to develop skills in an area such as classes or inheritance with chapters that have examples and exercises to then apply the skills taught. (Recommendation and review by [Steve Morris][40])
|
||||
|
||||
[Understanding Open Source and Free Software Licensing][41] (O'Reilly, 2004)
|
||||
|
||||
"This book bridges the gap between the open source vision and the practical implications of its legal underpinnings. If open source and free software licenses interest you, this book will help you understand them. If you're an open source/free software developer, this book is an absolute necessity." (Recommendation by [Jim Hall][4] | review from [Amazon][42])
|
||||
|
||||
[Unix Text Processing][43] by Dale Dougherty and Tim O'Reilly
|
||||
|
||||
This book was written in 1987 as an introduction to Unix systems and how writers could use Unix tools to do work. It's still a useful resource for beginners to learn the basics of the Unix shell, the vi editor, awk and shell scripts, and the nroff and troff typesetting system. The original edition is out of print, but O'Reilly has made the book available for free via their website. (Recommendation and review by [Jim Hall][4])
|
||||
|
||||
### Bonus: Fiction book
|
||||
|
||||
[Station Eleven][44] by Emily St. John Mandel
|
||||
|
||||
This story is set in a near future, twenty years after the earth's population has been decimated by a mysterious and deadly flu. We follow Kirsten Raymonde, a young woman who is traveling near the Great Lakes with a nomadic theatre group because "Survival is insufficient," as she makes her way through the post-apocalyptic world. It's a wonderful story, well worth reading.
|
||||
|
||||
What struck me about the book is how tenuous our relationship with technology actually is. In the Douglas Adams book "Mostly Harmless", there is a great line: "Left to his own devices he couldn't build a toaster. He could just about make a sandwich and that was it." This is the world of Kristin Raymonde. Everyone has been left to their own devices: There is no electricity because no one can work the power grid. No cars, no oil refineries.
|
||||
|
||||
There is a fascinating passage where one inventor has rigged up a generator with a bicycle and is trying to turn on a laptop, trying to see if there is still an internet. We discover the Museum of Civilization, stocked with objects which have no use, which has been left over from the old world: passports, mobile phones, credit cards, stilettoes.
|
||||
|
||||
All of the world's technology becomes useless. (Recommendation and review by [Dave Neary][14])
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/5/list-books-Linux-open-source
|
||||
|
||||
作者:[Jen Wike Huger][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://opensource.com/users/remyd
|
||||
[1]:https://twitter.com/opensourceway
|
||||
[2]:http://www.freedos.org/ebook/
|
||||
[3]:https://opensource.com/article/18/5/node/44116
|
||||
[4]:https://opensource.com/users/jim-hall
|
||||
[5]:https://eloquentjavascript.net/
|
||||
[6]:https://opensource.com/article/18/5/node/32826
|
||||
[7]:https://opensource.com/users/rahul27
|
||||
[8]:https://pragprog.com/book/vbopens/forge-your-future-with-open-source
|
||||
[9]:https://opensource.com/users/bcotton
|
||||
[10]:http://gitforteams.com/
|
||||
[11]:https://opensource.com/article/18/5/node/43741
|
||||
[12]:https://opensource.com/business/15/11/git-for-teams-review
|
||||
[13]:http://www.williamury.com/books/getting-to-yes/
|
||||
[14]:https://opensource.com/users/dneary
|
||||
[15]:http://a.co/749s27n
|
||||
[16]:https://opensource.com/article/18/5/node/19796
|
||||
[17]:https://opensource.com/users/don-watkins
|
||||
[18]:https://manning.com/ovadia
|
||||
[19]:https://opensource.com/article/18/5/node/42626
|
||||
[20]:https://opensource.com/users/stevenov
|
||||
[21]:https://www.manning.com/books/linux-in-action?a_aid=bootstrap-it&a_bid=4ca15fc9
|
||||
[22]:https://opensource.com/article/18/5/node/44696
|
||||
[23]:https://bootstrap-it.com/index.php/books/
|
||||
[24]:https://opensource.com/users/dbclinton
|
||||
[25]:https://www.makershed.com/products/make-linux-for-makers
|
||||
[26]:https://opensource.com/article/18/5/node/35731
|
||||
[27]:https://www.amazon.com/Managing-Humans-Humorous-Software-Engineering/dp/1484221575/ref=dp_ob_title_bk
|
||||
[28]:http://randsinrepose.com/
|
||||
[29]:https://www.oreilly.com/openbook/opensources/book/index.html
|
||||
[30]:https://opensource.com/article/18/5/node/42001
|
||||
[31]:https://producingoss.com/
|
||||
[32]:https://opensource.com/users/justinflory
|
||||
[33]:http://engineering.nyu.edu/gk12/amps-cbri/pdf/RobotC%20FTC%20Books/notesRobotC.pdf
|
||||
[34]:https://archive.org/details/pdfy-MgN0H1joIoDVoIC7
|
||||
[35]:https://opensource.com/users/clhermansen
|
||||
[36]:http://greenteapress.com/thinkpython2/thinkpython2.pdf
|
||||
[37]:https://opensource.com/article/18/5/node/40481
|
||||
[38]:http://greenteapress.com/wp/
|
||||
[39]:https://opensource.com/article/18/5/node/35141
|
||||
[40]:https://opensource.com/users/smorris12
|
||||
[41]:http://shop.oreilly.com/product/9780596005818.do
|
||||
[42]:https://www.amazon.com/Understanding-Open-Source-Software-Licensing/dp/0596005814
|
||||
[43]:http://www.oreilly.com/openbook/utp/
|
||||
[44]:http://www.emilymandel.com/stationeleven.html
|
@ -0,0 +1,90 @@
|
||||
How To Improve Application Startup Time In Linux
|
||||
======
|
||||
|
||||

|
||||
Most Linux distributions are fast enough by default. However, we can still make them a little bit faster using some additional applications and methods. One such application we are about to see is **Preload**. It monitors the most frequently-used applications by the user and adds them to the memory, so that the applications will load little bit faster than before. Because, as you might already know, reading from the RAM is always faster than from the hard drive. Preload runs as a daemon on the background all the time and records the statistics about usage of files by more frequently-used programs. It then fetches those binaries and their dependencies into memory to improve the application loading time. In a nutshell, once preload is installed, you should be able to load the often-used applications much faster.
|
||||
|
||||
In this brief tutorial, we are going to see how to install and use Preload to improve an application startup time in Linux.
|
||||
|
||||
### Improve Application Startup Time In Linux Using Preload
|
||||
|
||||
Preload is available in [**AUR**][1]. So you can install it using AUR helper programs in any Arch-based systems such as Antergos, Manjaro Linux.
|
||||
|
||||
Using [**Pacaur**][2]:
|
||||
```
|
||||
$ pacaur -S preload
|
||||
|
||||
```
|
||||
|
||||
Using [**Packer**][3]:
|
||||
```
|
||||
$ packer -S preload
|
||||
|
||||
```
|
||||
|
||||
Using [**Trizen**][4]:
|
||||
```
|
||||
$ trizen -S preload
|
||||
|
||||
```
|
||||
|
||||
Using [**Yay**][5]:
|
||||
```
|
||||
$ yay -S preload
|
||||
|
||||
```
|
||||
|
||||
Using [**Yaourt**][6]:
|
||||
```
|
||||
$ yaourt -S preload
|
||||
|
||||
```
|
||||
|
||||
On Debian, Ubuntu, Linux Mint, Preload is available in the default repositories. So you can install it using APT package manager like below.
|
||||
```
|
||||
$ sudo apt-get install preload
|
||||
|
||||
```
|
||||
|
||||
Once Preload installed, reboot your system. From now on, Preload monitors the frequently-used applications and adds their binaries and libraries into the Memory for faster startup time. For example, if you often use Firefox, Chrome or LibreOffice, Preload will then add those binaries and libraries into RAM, so those applications will start faster. Good thing is it doesn’t need any configuration. It will just work out of the box. If you, however, wants to tweak the configuration, you can do it by editing the default configuration file **/etc/preload.conf**.
|
||||
|
||||
### Preload isn’t for everyone!
|
||||
|
||||
Here are some drawbacks of Preload and why it is not that effective for everyone, discussed in this [**thread**][7].
|
||||
|
||||
1. I do have a decent specification system with 8GB RAM. So my system is generally fast. Also, I will open heavy memory-consuming applications, such as Firefox, Chrome, VirtualBox, Gimp etc., one or two times per day. They remain open all the time, hence their binaries and libraries are preloaded into memory and occupying the RAM all day. I rarely close and open those applications, so the RAM usage is simply waste.
|
||||
2. If you’re using modern systems with SSD, Preload is obviously useless. Because SSDs access time is much faster than normal hard drives, so using Preload is pointless.
|
||||
3. Preload significantly affects the boot time. Because the more applications are preloaded into RAM, the longer it takes to get your system up and running.
|
||||
|
||||
|
||||
|
||||
You will only the see the real difference only if you’re reloading applications a LOT of time per day. So Preload will be ideal for the developers and testers who open and close the applications several times everyday.
|
||||
|
||||
For more details about what exactly preload is and how it works, read the complete [**Preload thesis**][8] paper submitted by the author.
|
||||
|
||||
And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned!
|
||||
|
||||
Cheers!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/how-to-improve-application-startup-time-in-linux/
|
||||
|
||||
作者:[SK][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.ostechnix.com/author/sk/
|
||||
[1]:https://aur.archlinux.org/packages/preload/
|
||||
[2]:https://www.ostechnix.com/install-pacaur-arch-linux/
|
||||
[3]:https://www.ostechnix.com/install-packer-arch-linux-2/
|
||||
[4]:https://www.ostechnix.com/trizen-lightweight-aur-package-manager-arch-based-systems/
|
||||
[5]:https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/
|
||||
[6]:https://www.ostechnix.com/install-yaourt-arch-linux/
|
||||
[7]:https://askubuntu.com/questions/110335/drawbacks-of-using-preload-why-isnt-it-included-by-default
|
||||
[8]:https://cs.uwaterloo.ca/~brecht/courses/702/Possible-Readings/prefetching-to-memory/preload-thesis.pdf
|
@ -0,0 +1,181 @@
|
||||
Systemd Services: Beyond Starting and Stopping
|
||||
======
|
||||
|
||||

|
||||
[In the previous article][1], we showed how to create a systemd service that you can run as a regular user to start and stop your game server. As it stands, however, your service is still not much better than running the server directly. Let's jazz it up a bit by having it send out emails to the players, alerting them when the server becomes available and warning them when it is about to be turned off:
|
||||
```
|
||||
# minetest.service
|
||||
|
||||
[Unit]
|
||||
Description= Minetest server
|
||||
Documentation= https://wiki.minetest.net/Main_Page
|
||||
|
||||
[Service]
|
||||
Type= simple
|
||||
|
||||
ExecStart= /usr/games/minetest --server
|
||||
ExecStartPost= /home/<username>/bin/mtsendmail.sh "Ready to rumble?" "Minetest Starting up"
|
||||
|
||||
TimeoutStopSec= 180
|
||||
ExecStop= /home/<username>/bin/mtsendmail.sh "Off to bed. Nightie night!" "
|
||||
Minetest Stopping in 2 minutes"
|
||||
ExecStop= /bin/sleep 120
|
||||
ExecStop= /bin/kill -2 $MAINPID
|
||||
|
||||
```
|
||||
|
||||
There are a few new things in here. First, there's the `ExecStartPost` directive. You can use this directive for anything you want to run right after the main application starts. In this case, you run a custom script, `mtsendmail` (see below), that sends an email to your friends telling them that the server is up.
|
||||
```
|
||||
#!/bin/bash
|
||||
# mtsendmail
|
||||
echo $1 | mutt -F /home/<username>/.muttrc -s "$2" my_minetest@mailing_list.com
|
||||
|
||||
```
|
||||
|
||||
You can use [Mutt][2], a command-line email client, to shoot off your messages. Although the script shown above is to all practical effects only one line long, remember you can't have a line with pipes and redirections as a systemd unit argument, so you have to wrap it in a script.
|
||||
|
||||
For the record, there is also an `ExecStartPre` directive for things you want to execute before starting the service proper.
|
||||
|
||||
Next up, you have a block of commands that close down the server. The `TimeoutStopSec` directive pushes up the time before systemd bails on shutting down the service. The default time out value is round about 90 seconds. Anything longer, and systemd will force the service to close down and report a failure. But, as you want to give your users a couple of minutes before closing the server completely, you are going to push the default up to three minutes. This will stop systemd from thinking the closedown has failed.
|
||||
|
||||
Then the close down proper starts. Although there is no `ExecStopPre` as such, you can simulate running stuff before closing down your server by using more than one `ExecStop` directive. They will be executed in order, from topmost to bottommost, and will allow you to send out a message before the server is actually stopped.
|
||||
|
||||
With that in mind, the first thing you do is shoot off an email to your friends, warning them the server is going down. Then you wait two minutes. Finally you close down the server. Minetest likes to be closed down with [Ctrl] + [c], which translates into an interrupt signal ( _SIGINT_ ). That is what you do when you issue the `kill -2 $MAINPID` command. `$MAINPID` is a systemd variable for your service that points to the PID of the main application.
|
||||
|
||||
This is much better! Now, when you run
|
||||
```
|
||||
systemctl --user start minetest
|
||||
|
||||
```
|
||||
|
||||
The service will start up the Minetest server and send out an email to your users. Likewise when you are about to close down, but giving two minutes to users to log off.
|
||||
|
||||
### Starting at Boot
|
||||
|
||||
The next step is to make your service available as soon as the machine boots up, and close down when you switch it off at night.
|
||||
|
||||
Start be moving your service out to where the system services live, The directory youa re looking for is _/etc/systemd/system/_ :
|
||||
```
|
||||
sudo mv /home/<username>/.config/systemd/user/minetest.service /etc/systemd/system/
|
||||
|
||||
```
|
||||
|
||||
If you were to try and run the service now, it would have to be with superuser privileges:
|
||||
```
|
||||
sudo systemctl start minetest
|
||||
|
||||
```
|
||||
|
||||
But, what's more, if you check your service's status with
|
||||
```
|
||||
sudo systemctl status minetest
|
||||
|
||||
```
|
||||
|
||||
You would see it had failed miserably. This is because systemd does not have any context, no links to worlds, textures, configuration files, or details of the specific user running the service. You can solve this problem by adding the `User` directive to your unit:
|
||||
```
|
||||
# minetest.service
|
||||
|
||||
[Unit]
|
||||
Description= Minetest server
|
||||
Documentation= https://wiki.minetest.net/Main_Page
|
||||
|
||||
[Service]
|
||||
Type= simple
|
||||
User= <username>
|
||||
|
||||
ExecStart= /usr/games/minetest --server
|
||||
ExecStartPost= /home/<username>/bin/mtsendmail.sh "Ready to rumble?"
|
||||
"Minetest Starting up"
|
||||
|
||||
TimeoutStopSec= 180
|
||||
ExecStop= /home/<username>/bin/mtsendmail.sh "Off to bed. Nightie night!"
|
||||
"Minetest Stopping in 2 minutes"
|
||||
ExecStop= /bin/sleep 120
|
||||
ExecStop= /bin/kill -2 $MAINPID
|
||||
|
||||
```
|
||||
|
||||
The `User` directive tells systemd which user's environment it should use to correctly run the service. You could use root, but that would probably be a security hazard. You could also use your personal user and that would be a bit better, but what many administrators do is create a specific user for each service, effectively isolating the service from the rest of the system and users.
|
||||
|
||||
The next step is to make your service start when you boot up and stop when you power down your computer. To do that you need to _enable_ your service, but, before you can do that, you have to tell systemd where to _install_ it.
|
||||
|
||||
In systemd parlance, _installing_ means telling systemd when in the boot sequence should your service become activated. For example the _cups.service_ , the service for the _Common UNIX Printing System_ , will have to be brought up after the network framework is activated, but before any other printing services are enabled. Likewise, the _minetest.service_ uses a user's email (among other things) and will have to be slotted in when the network is up and services for regular users become available.
|
||||
|
||||
You do all that by adding a new section and directive to your unit:
|
||||
```
|
||||
...
|
||||
[Install]
|
||||
WantedBy= multi-user.target
|
||||
|
||||
```
|
||||
|
||||
You can read this as "wait until we have everything ready for a multiples user system." Targets in systemd are like the old run levels and can be used to put your machine into one state or another, or, like here, to tell your service to wait until a certain state has been reached.
|
||||
|
||||
Your final _minetest.service_ file will look like this:
|
||||
```
|
||||
# minetest.service
|
||||
[Unit]
|
||||
Description= Minetest server
|
||||
Documentation= https://wiki.minetest.net/Main_Page
|
||||
|
||||
[Service]
|
||||
Type= simple
|
||||
User= <username>
|
||||
|
||||
ExecStart= /usr/games/minetest --server
|
||||
ExecStartPost= /home/<username>/bin/mtsendmail.sh "Ready to rumble?"
|
||||
"Minetest Starting up"
|
||||
|
||||
TimeoutStopSec= 180
|
||||
ExecStop= /home/<username>/bin/mtsendmail.sh "Off to bed. Nightie night!"
|
||||
"Minetest Stopping in 2 minutes"
|
||||
ExecStop= /bin/sleep 120
|
||||
ExecStop= /bin/kill -2 $MAINPID
|
||||
|
||||
[Install]
|
||||
WantedBy= multi-user.target
|
||||
|
||||
```
|
||||
|
||||
Before trying it out, you may have to do some adjustments to your email script:
|
||||
```
|
||||
#!/bin/bash
|
||||
# mtsendmail
|
||||
|
||||
sleep 20
|
||||
echo $1 | mutt -F /home/<username>/.muttrc -s "$2" my_minetest@mailing_list.com
|
||||
sleep 10
|
||||
|
||||
```
|
||||
|
||||
This is because the system will need some time to set up the emailing system (so you wait 20 seconds) and also some time to actually send the email (so you wait 10 seconds). Notice that these are the wait times that worked for me. You may have to adjust these for your own system.
|
||||
|
||||
And you're done! Run:
|
||||
```
|
||||
sudo systemctl enable minetest
|
||||
|
||||
```
|
||||
|
||||
and the Minetest service will come online when you power up and gracefully shut down when you power off, warning your users in the process.
|
||||
|
||||
### Conclusion
|
||||
|
||||
The fact that Debian, Ubuntu, and distros of the same family have a special package called _minetest-server_ that does some of the above for you (but no messaging!) should not deter you from setting up your own customised services. In fact, the version you set up here is much more versatile and does more than Debian's default server.
|
||||
|
||||
Furthermore, the process described here will allow you to set up most simple servers as services, whether they are for games, web applications, or whatever. And those are the first steps towards veritable systemd guruhood.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/blog/learn/2018/5/systemd-services-beyond-starting-and-stopping
|
||||
|
||||
作者:[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.linux.com/blog/learn/intro-to-linux/2018/5/writing-systemd-services-fun-and-profit
|
||||
[2]:http://www.mutt.org/
|
@ -0,0 +1,114 @@
|
||||
4MLinux Revives Your Older Computer [Review]
|
||||
======
|
||||
**Brief:** 4MLinux is a lightweight Linux distribution that can turn your old computer into a functional one with multimedia support, maintenance tools and classic games.
|
||||
|
||||
As more and more [Linux distributions drop the support for 32-bit systems][1], you may wonder what would you do with that old computer of yours. Thankfully, there are plenty of [lightweight Linux distributions][2] that could put those old computers for some regular computing tasks such as playing small games, watching movies, listening to music and surfing web.
|
||||
|
||||
[4MLinux][3] is one such Linux distribution that requires fewer system resources and can even run on 128 MB of RAM. The desktop edition comes only for 32-bit architecture while the server edition is of 64-bit.
|
||||
|
||||
4MLinux can also be used as a rescue CD along with serving as a full-fledged working system or as a mini-server.
|
||||
|
||||
![4MLinux Review][4]
|
||||
|
||||
It is named 4MLinux because it focuses mainly on four points, called the “4 M”:
|
||||
|
||||
* Maintenance – You can use 4MLinux as a rescue Live CD.
|
||||
* Multimedia – There is inbuilt support for almost every multimedia format, be it for Image, Audio and Video.
|
||||
* Miniserver – A 64-bit server is included running LAMP suite, which can be enabled from the Application Menu.
|
||||
* Mystery – Includes a collection of classic Linux games.
|
||||
|
||||
|
||||
|
||||
Most of the Linux distributions are either based on Debian with DEB packages or Fedora with RPM. 4MLinux, on the other hand, does not rely on these package management systems, is pretty damn fast and works quite well on older systems.
|
||||
|
||||
### 4MLinux
|
||||
|
||||
The 4MLinux Desktop comes with a variety of [lightweight applications][5] so that it could work on older hardware. [JWM][6] – Joe’s Windows Manager, which is a lightweight stacking windows manager for [X Window System][7]. For managing the desktop wallpapers, a lightweight and powerful [feh][8] is used. It uses [PCMan File Manager][9] which is a standard file manager for [LXDE][10] too.
|
||||
|
||||
#### Installing 4MLinux is quick
|
||||
|
||||
I grabbed the ISO from 4MLinux website and used [MultiBootUSB][11] to create a bootable drive and live booted with it.
|
||||
|
||||
4MLinux do not use the grub or grub2 bootloader but uses **LI** nux **LO** ader ([LILO][12]) bootloader. The main advantage of LILO is that it allows fast boot-ups for a Linux system.
|
||||
|
||||
Now to install the 4MLinux, you will have to manually create a partition. Go to **Maintenance - > Partitions -> GParted**. Click on **Device - > Create Partition Table**. Once done, click on **New** , leave the settings to default and click on **Add**. Click on **Apply** to save the settings and close it.
|
||||
|
||||
Next step is to go to 4MLinux -> Installer and it will launch a text-based installer.
|
||||
|
||||
![][13]
|
||||
|
||||
Identify the partition you have created for the default partition to install 4MLinux and follow the instructions to complete the installation.
|
||||
|
||||
Surprisingly, the installation took less than a minute. Restart your system and remove the live USB and you will be greeted with this desktop.
|
||||
|
||||
![][14]
|
||||
|
||||
#### Experiencing 4MLinux
|
||||
|
||||
The default desktop screen has a dock at the top with most common applications pinned. There is a taskbar, a [Conky theme][15] with option to turn it on/off in the dock and a clock at the bottom right corner. Left click on the desktop opens the application menu.
|
||||
|
||||
The CPU usage was too minimal with less than 2% and RAM was less than 100 MB.
|
||||
|
||||
4MLinux comes with a number of applications tabbed under different sections. There is Transmission for torrent downloads, Tor is included by default and Bluetooth support is there.
|
||||
|
||||
Under Maintenance, there are options to backup the system and recover using TestDisk and GNUddrescue, CD burning tools are available along with partitioning tools. There are a number of Monitoring tools and Clam Antivirus.
|
||||
|
||||
Multimedia section includes various video and music players and mixers, image viewers and editors and tools for digital cameras.
|
||||
|
||||
Mystery section is interesting. It includes a number of [console games][16] like Snake, Tetris, Mines, Casino etc.
|
||||
|
||||
Under Settings, you can select your preferences for display and others, networking, Desktop and choose default applications. The default desktop resolution was 1024×768 at the highest, so that might disappoint you.
|
||||
|
||||
Some of the applications are not installed by default. Launching it gives you an option to install it. But that’s about it. Since there is no package manager here, you are limited to the available applications. If you want more software that are not available in the system, you’ll have to [install it from source code][17].
|
||||
|
||||
This is by design because 4MLinux is focused on providing only essential desktop experience. A small handful selection of lightweight applications fit in its ecosystem.
|
||||
|
||||
#### Download 4M Linux
|
||||
|
||||
The Download section features the 32-bit stable 4MLinux and its beta version, 64bit 4MServer and a 4MRescueKit. Although the ISO size is over 1GB, 4mlinux is very light in its design.
|
||||
|
||||
[Download 4MLinux][18]
|
||||
|
||||
There is a [separate page to downloaded additional drivers][19]. For any other missing drivers, while you launch an application, 4MLinux asks you to download and install it.
|
||||
|
||||
#### Final thoughts on 4MLinux
|
||||
|
||||
4MLinux has look and feel of an old-school Linux system but the desktop is super fast. I was able to run it on an Intel Dual Core processor desktop with ease and most of the things worked. WiFi was connecting fine; the application section included most of the software I use on daily basis and the retro games section was pretty cool.
|
||||
|
||||
The one negative point was the limitation of available application. If you can manage with the handful of applications, 4MLinux can be seen as one of the best Linux distribution for older systems and for the people who don’t prefer going in the technicality even for once.
|
||||
|
||||
Fast boot makes it an ideal rescue disc!
|
||||
|
||||
Let us know in the comment section. What do you think of 4MLinux? Are you willing to give it a try? Let us know in the comments.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/4mlinux-review/
|
||||
|
||||
作者:[Ambarish Kumar][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://itsfoss.com/author/ambarish/
|
||||
[1]:https://itsfoss.com/32-bit-os-list/
|
||||
[2]:https://itsfoss.com/lightweight-linux-beginners/
|
||||
[3]:http://4mlinux.com/
|
||||
[4]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/05/4minux-review-feature-800x450.jpeg
|
||||
[5]:https://itsfoss.com/lightweight-alternative-applications-ubuntu/
|
||||
[6]:https://joewing.net/projects/jwm/
|
||||
[7]:https://en.wikipedia.org/wiki/X_Window_System
|
||||
[8]:https://feh.finalrewind.org/
|
||||
[9]:https://wiki.lxde.org/en/PCManFM
|
||||
[10]:https://lxde.org/
|
||||
[11]:https://itsfoss.com/multiple-linux-one-usb/
|
||||
[12]:https://en.wikipedia.org/wiki/LILO_(boot_loader)
|
||||
[13]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/05/4MLinux-installer.png
|
||||
[14]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/05/2-800x600.jpg
|
||||
[15]:https://itsfoss.com/conky-gui-ubuntu-1304/
|
||||
[16]:https://itsfoss.com/best-command-line-games-linux/
|
||||
[17]:https://itsfoss.com/install-software-from-source-code/
|
||||
[18]:http://4mlinux.com/index.php?page=download
|
||||
[19]:http://sourceforge.net/projects/linux4m/files/24.0/drivers/
|
@ -0,0 +1,104 @@
|
||||
|
||||
为什么 Linux 比 Windows 和 macOS 的安全性好
|
||||
======
|
||||
|
||||
> 多年前做出的操作系统选型终将影响到如今的企业安全。在三大主流操作系统当中,有一个能被称作最安全的。
|
||||
|
||||

|
||||
|
||||
企业投入了大量时间、精力和金钱来保障系统的安全性。最强的安全意识可能就是有一个安全运营中心,肯定用上了防火墙以及反病毒软件,可能花费大量时间监控他们的网络,寻找可能表明违规的异常信号,就像 IDS、SIEM 和 NGFW 一样,他们部署了一个名副其实的防御阵列。
|
||||
|
||||
然而又有多少人想过数字化操作的基础之一:部署在员工的个人电脑上的操作系统?当选择桌面操作系统时,安全性是一个考虑的因素吗?
|
||||
|
||||
这就产生了一个 IT 人士都应该能回答的问题:一般部署哪种操作系统最安全呢?
|
||||
|
||||
我们问了一些专家他们对于以下三种选项的看法:Windows,最复杂的平台也是最受欢迎的桌面操作系统;macOS X,基于 FreeBSD 的 Unix 操作系统,驱动着苹果的 Macintosh 系统运行;还有 Linux,这里我们指的是所有的 Linux 发行版以及与基于 Unix 的操作系统相关的系统。
|
||||
|
||||
### 怎么会这样
|
||||
|
||||
企业可能没有评估他们部署到工作人员的操作系统的安全性的一个原因是,他们多年前就已经做出了选择。退一步讲,所有操作系统都还算安全,因为侵入它们,窃取数据或安装恶意软件的业务还处于起步阶段。而且一旦选择了操作系统,就很难再想改变。很少有 IT 组织希望将全球分散的员工队伍转移到全新的操作系统上。唉,他们已经受够了把用户搬到一个选好的新版本操作系统时的负面反响。
|
||||
|
||||
还有,重新考虑它是高明的吗?这三款领先的桌面操作系统在安全方面的差异是否足以值得我们去做出改变呢?
|
||||
|
||||
当然商业系统面临的威胁近几年已经改变了。攻击变得成熟多了。曾经支配了公众想象力的单枪匹马的青少年黑客已经被组织良好的犯罪分子网络以及具有庞大计算资源的政府资助组织的网络所取代。
|
||||
|
||||
像你们许多人一样,我有过很多那时的亲身经历:我曾经在许多 Windows 电脑上被恶意软件和病毒感染,我甚至被 宏病毒感染了 Mac 上的文件。最近,一个广泛传播的自动黑客绕开了网站的保护程序并用恶意软件感染了它。这种恶意软件的影响一开始是隐形的,甚至有些东西你没注意,直到恶意软件最终深深地植入系统以至于它的性能开始变差。一件有关病毒蔓延的震惊之事是不法之徒从来没有特定针对过我;当今世界,用僵尸网络攻击 100,000 台电脑容易得就像一次攻击几台电脑一样。
|
||||
|
||||
### 操作系统真的很重要吗?
|
||||
|
||||
给你的用户部署的那个操作系统确实对你的安全态度产生了影响,但那并不是一个可靠的安全措施。首先,现在的攻击很可能会发生,因为攻击者探测了你的用户,而不是你的系统。一项对参与过 DEFCON 会议黑客的[调查][1]表明“84%的人使用社交工程作为攻击策略的一部分。”部署安全操作系统只是一个重要的起点,但如果没有用户培训,强大的防火墙和持续的警惕性,即使是最安全的网络也会受到入侵。当然,用户下载的软件,扩展程序,实用程序,插件和其他看起来还好的软件总是有风险的,成为了恶意软件出现在系统上的一种途径.
|
||||
|
||||
无论你选择哪种平台,保持你系统安全最好的方法之一就是确保立即应用了软件更新。一旦补丁正式发布,黑客就可以对其进行反向工程并找到一种新的漏洞,以便在下一波攻击中使用。
|
||||
|
||||
而且别忘了最基本的操作。别用 root 权限,别授权用户连接到网络中的老服务器上。教您的用户如何挑选一个真正的好密码并且使用例如 [1Password][2] 这样的工具,以便在每个他们使用的帐户和网站上拥有不同的密码
|
||||
|
||||
因为底线是您对系统做出的每一个决定都会影响您的安全性,即使您的用户工作使用的操作系统也是如此。
|
||||
|
||||
### Windows,流行之选
|
||||
|
||||
若你是一个安全管理人员,很可能文章中提出的问题就会变成这样:是否我们远离微软的 Windows 会更安全呢?说 Windows 主导商业市场都是低估事实了。[NetMarketShare][4] 估计互联网上 88% 的电脑令人震惊地运行着 Windows 的某个版本。
|
||||
|
||||
如果你的系统在这 88% 之中,你可能知道微软会继续加强 Windows 系统的安全性。不断重写其改进或者重新改写了其代码库,增加了它的反病毒软件系统,改进了防火墙以及实现了沙箱架构,这样在沙箱里的程序就不能访问系统的内存空间或者其他应用程序。
|
||||
|
||||
但可能 Windows 的流行本身就是个问题,操作系统的安全性可能很大程度上依赖于装机用户量的规模。对于恶意软件作者来说,Windows 提供了大的施展平台。专注其中可以让他们的努力发挥最大作用。
|
||||
|
||||
像 Troy Wilkinson,Axiom Cyber Solutions 的 CEO 解释的那样,“Windows 总是因为很多原因而导致安全性保障来的最晚,主要是因为消费者的采用率。由于市场上大量基于 Windows 的个人电脑,黑客历来最有针对性地将这些系统作为目标。”
|
||||
|
||||
可以肯定地说,从梅丽莎病毒到 WannaCry 或者更强的,许多世界上已知的恶意软件早已对准了 Windows 系统.
|
||||
|
||||
### macOS X 以及通过隐匿实现的安全
|
||||
|
||||
如果最流行的操作系统总是成为大目标,那么用一个不流行的操作系统能确保安全吗?这个主意是老法新用——而且是完全不可信的概念——“通过隐匿实现的安全”,这秉承了让软件内部运作保持专有,从而不为人知是抵御攻击的最好方法的理念。
|
||||
|
||||
Wilkinson 坦言,macOS X “比 Windows 更安全”,但他急于补充说,“macOS 曾被认为是一个安全漏洞很小的完全安全的操作系统,但近年来,我们看到黑客制造了攻击苹果系统的额外漏洞。”
|
||||
|
||||
换句话说,攻击者会扩大活动范围而不会无视 Mac 领域。
|
||||
|
||||
Comparitech 的安全研究员 Lee Muson 说,在选择更安全的操作系统时,“macOS 很可能是被选中的目标”,但他提醒说,这一想法并不令人费解。它的优势在于“它仍然受益于通过隐匿实现的安全感和微软提供的更大的目标。”
|
||||
|
||||
Wolf Solutions 公司的 Joe Moore 给予了苹果更多的信任,称“现成的 macOS X 在安全方面有着良好的记录,部分原因是它不像 Windows 那么广泛,而且部分原因是苹果公司在安全问题上干的不错。”
|
||||
|
||||
### 最终胜者是 ……
|
||||
|
||||
你可能一开始就知道它:专家们的明确共识是 Linux 是最安全的操作系统。然而,尽管它是服务器的首选操作系统,而将其部署在桌面上的企业很少。
|
||||
|
||||
如果你确定 Linux 是要选择的系统,你仍然需要决定选择哪种 Linux 系统,并且事情会变得更加复杂。 用户需要一个看起来很熟悉的用户界面,而你需要最安全的操作系统。
|
||||
|
||||
像 Moore 解释的那样,“Linux 有可能是最安全的,但要求用户是资深用户。”所以,它不是针对所有人的。
|
||||
|
||||
将安全性作为主要功能的 Linux 发行版包括 Parrot Linux,这是一个基于 Debian 的发行版,Moore 说,它提供了许多与安全相关开箱即用的工具。
|
||||
|
||||
当然,一个重要的区别是 Linux 是开源的。Simplex Solutions 的 CISO Igor Bidenko 说,编码人员可以阅读和评论彼此工作的现实看起来像是一场安全噩梦,但这确实是让 Linux 如此安全的重要原因。 “Linux 是最安全的操作系统,因为它的源代码是开放的。任何人都可以查看它,并确保没有错误或后门。”
|
||||
|
||||
Wilkinson 阐述说:“Linux 和基于 Unix 的操作系统具有较少的信息安全领域已知的、可利用的安全缺陷。技术社区对 Linux 代码进行了审查,该代码有助于提高安全性:通过进行这么多的监督,易受攻击之处、漏洞和威胁就会减少。”
|
||||
|
||||
这是一个微妙的而违反直觉的解释,但是通过让数十人(有时甚至数百人)通读操作系统中的每一行代码,代码实际上更加健壮,并且发布漏洞错误的机会减少了。这与 PC World 为何出来说 Linux 更安全有很大关系。正如 Katherine Noyes 解释的那样,“微软可能吹捧它的大型付费开发者团队,但团队不太可能与基于全球的 Linux 用户开发者进行比较。 安全只能通过所有额外的关注获益。”
|
||||
|
||||
另一个被 《PC World》举例的原因是 Linux 更好的用户特权模式:Windows 用户“一般被默认授予管理员权限,那意味着他们几乎可以访问系统中的一切,”Noye 的文章讲到。Linux,反而很好地限制了“root”权限。
|
||||
|
||||
Noyes 还指出,Linux 环境下的多样性可能比典型的 Windows 单一文化更好地对抗攻击:Linux 有很多不同的发行版。其中一些以其特别的安全关注点进行差异化。Comparitech 的安全研究员 Lee Muson 为 Linux 发行版提供了这样的建议:“Qubes OS 对于 Linux 来说是一个很好的出发点,现在你可以发现,爱德华·斯诺登的认可大大地掩盖了它自己极其不起眼的主张。”其他安全性专家指出了专门的安全 Linux 发行版,如 Tails Linux,它旨在直接从 USB 闪存驱动器或类似的外部设备安全地匿名运行。
|
||||
|
||||
### 构建安全趋势
|
||||
|
||||
惯性是一股强大的力量。虽然人们有明确的共识,认为 Linux 是桌面系统的最安全选择,但并没有出现对 Windows 和 Mac 机器压倒性的倾向。尽管如此,Linux 采用率的小幅增长却可能会产生对所有人都更加安全的计算,因为市场份额的丧失是确定能获得微软和苹果公司关注的一个方式。换句话说,如果有足够的用户在桌面上切换到 Linux,Windows 和 Mac PC 很可能成为更安全的平台。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.computerworld.com/article/3252823/linux/why-linux-is-better-than-windows-or-macos-for-security.html
|
||||
|
||||
作者:[Dave Taylor][a]
|
||||
译者:[fuzheng1998](https://github.com/fuzheng1998)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.computerworld.com/author/Dave-Taylor/
|
||||
[1]:https://www.esecurityplanet.com/hackers/fully-84-percent-of-hackers-leverage-social-engineering-in-attacks.html
|
||||
[2]:http://www.1password.com
|
||||
[3]:https://www.facebook.com/Computerworld/posts/10156160917029680
|
||||
[4]:https://www.netmarketshare.com/operating-system-market-share.aspx?options=%7B%22filter%22%3A%7B%22%24and%22%3A%5B%7B%22deviceType%22%3A%7B%22%24in%22%3A%5B%22Desktop%2Flaptop%22%5D%7D%7D%5D%7D%2C%22dateLabel%22%3A%22Trend%22%2C%22attributes%22%3A%22share%22%2C%22group%22%3A%22platform%22%2C%22sort%22%3A%7B%22share%22%3A-1%7D%2C%22id%22%3A%22platformsDesktop%22%2C%22dateInterval%22%3A%22Monthly%22%2C%22dateStart%22%3A%222017-02%22%2C%22dateEnd%22%3A%222018-01%22%2C%22segments%22%3A%22-1000%22%7D
|
||||
[5]:https://www.parrotsec.org/
|
||||
[6]:https://www.pcworld.com/article/202452/why_linux_is_more_secure_than_windows.html
|
||||
[7]:https://www.qubes-os.org/
|
||||
[8]:https://twitter.com/snowden/status/781493632293605376?lang=en
|
||||
[9]:https://tails.boum.org/about/index.en.html
|
@ -1,164 +0,0 @@
|
||||
# 系统调用,让世界转起来!
|
||||
|
||||
我其实不想将它分解开给你看,一个用户应用程序在整个系统中就像一个可怜的孤儿一样无依无靠:
|
||||
|
||||

|
||||
|
||||
它与外部世界的每个交流都要在内核的帮助下通过系统调用才能完成。一个应用程序要想保存一个文件、写到终端、或者打开一个 TCP 连接,内核都要参与。应用程序是被内核高度怀疑的:认为它到处充斥着 bugs,而最糟糕的是那些充满邪恶想法的天才大脑(写的恶意程序)。
|
||||
|
||||
这些系统调用是从一个应用程序到内核的函数调用。它们因为安全考虑使用一个特定的机制,实际上你只是调用了内核的 API。“系统调用”这个术语指的是调用由内核提供的特定功能(比如,系统调用 open())或者是调用途径。你也可以简称为:syscall。
|
||||
|
||||
这篇文章讲解系统调用,系统调用与调用一个库有何区别,以及在操作系统/应用程序接口上的刺探工具。如果想彻底了解应用程序借助操作系统都发生的哪些事情?那么就可以将一个不可能解决的问题转变成一个快速而有趣的难题。
|
||||
|
||||
因此,下图是一个运行着的应用程序,一个用户进程:
|
||||
|
||||

|
||||
|
||||
它有一个私有的 [虚拟地址空间][2]—— 它自己的内存沙箱。整个系统都在地址空间中,程序的二进制文件加上它所需要的库全部都 [被映射到内存中][3]。内核自身也映射为地址空间的一部分。
|
||||
|
||||
下面是我们程序的代码和 PID,进程的 PID 可以通过 [getpid(2)][4]:
|
||||
|
||||
pid.c [download][1]
|
||||
|
||||
|
|
||||
```
|
||||
123456789
|
||||
```
|
||||
|
|
||||
```
|
||||
#include #include #include int main(){ pid_t p = getpid(); printf("%d\n", p);}
|
||||
```
|
||||
|
|
||||
|
||||
**(致校对:本文的所有代码部分都出现了排版错误,请与原文核对确认!!)**
|
||||
|
||||
在 Linux 中,一个进程并不是一出生就知道它的 PID。要想知道它的 PID,它必须去询问内核,因此,这个询问请求也是一个系统调用:
|
||||
|
||||

|
||||
|
||||
它的第一步是开始于调用一个 C 库的 [getpid()][5],它是系统调用的一个封装。当你调用一些功能时,比如,open(2)、read(2)、以及相关的一些支持时,你就调用了这些封装。其实,对于大多数编程语言在这一块的原生方法,最终都是在 libc 中完成的。
|
||||
|
||||
极简设计的操作系统都提供了方便的 API 封装,这样可以保持内核的简洁。所有的内核代码运行在特权模式下,有 bugs 的内核代码行将会产生致命的后果。在用户模式下做的任何事情都是在用户模式中完成的。由库来提供友好的方法和想要的参数处理,像 printf(3) 这样。
|
||||
|
||||
我们拿一个 web APIs 进行比较,内核的封装方式与构建一个简单易行的 HTTP 接口去提供服务是类似的,然后使用特定语言的守护方法去提供特定语言的库。或者也可能有一些缓存,它是库的 getpid() 完成的内容:首次调用时,它真实地去执行了一个系统调用,然后,它缓存了 PID,这样就可以避免后续调用时的系统调用开销。
|
||||
|
||||
一旦封装完成,它做的第一件事就是进入了超空间(hyperspace)的内核(译者注:一个快速而安全的计算环境,独立于操作系统而存在)。这种转换机制因处理器架构设计不同而不同。(译者注:就是前一段时间爆出的存在于处理器硬件中的运行于 Ring -3 的操作系统,比如,Intel 的 ME)在 Intel 处理器中,参数和 [系统调用号][6] 是 [加载到寄存器中的][7],然后,运行一个 [指令][8] 将 CPU 置于 [特权模式][9] 中,并立即将控制权转移到内核中的全局系统调用 [入口][10]。如果你对这些细节感兴趣,David Drysdale 在 LWN 上有两篇非常好的文章([第一篇][11],[第二篇][12])。
|
||||
|
||||
内核然后使用这个系统调用号作为进入 [sys_call_table][14] 的一个 [索引][13],它是一个函数指针到每个系统调用实现的数组。在这里,调用 了 [sys_getpid][15]:
|
||||
|
||||

|
||||
|
||||
在 Linux 中,系统调用大多数都实现为独立的 C 函数,有时候这样做 [很琐碎][16],但是通过内核优秀的设计,系统调用被严格隔离。它们是工作在一般数据结构中的普通代码。关于这些争论的验证除了完全偏执的以外,其它的还是非常好的。
|
||||
|
||||
一旦它们的工作完成,它们就会正常返回,然后,根据特定代码转回到用户模式,封装将在那里继续做一些后续处理工作。在我们的例子中,[getpid(2)][17] 现在缓存了由内核返回的 PID。如果内核返回了一个错误,另外的封装可以去设置全局 errno 变量。让你知道 GNU 所关心的一些小事。
|
||||
|
||||
如果你想看未处理的原生内容,glibc 提供了 [syscall(2)][18] 函数,它可以不通过封装来产生一个系统调用。你也可以通过它来做一个你自己的封装。这对一个 C 库来说,并不神奇,也不是保密的。
|
||||
|
||||
这种系统调用的设计影响是很深远的。我们从一个非常有用的 [strace(1)][19] 开始,这个工具可以用来监视 Linux 进程的系统调用(在 Mac 上,看 [dtruss(1m)][20] 和神奇的 [dtrace][21];在 Windows 中,看 [sysinternals][22])。这里在 pid 上的跟踪:
|
||||
|
||||
|
|
||||
```
|
||||
1234567891011121314151617181920
|
||||
```
|
||||
|
|
||||
```
|
||||
~/code/x86-os$ strace ./pidexecve("./pid", ["./pid"], [/* 20 vars */]) = 0brk(0) = 0x9aa0000access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7767000access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3fstat64(3, {st_mode=S_IFREG|0644, st_size=18056, ...}) = 0mmap2(NULL, 18056, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7762000close(3) = 0[...snip...]getpid() = 14678fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 1), ...}) = 0mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7766000write(1, "14678\n", 614678) = 6exit_group(6) = ?
|
||||
```
|
||||
|
|
||||
|
||||
输出的每一行都显示了一个系统调用 、它的参数、以及返回值。如果你在一个循环中将 getpid(2) 运行 1000 次,你就会发现始终只有一个 getpid() 系统调用,因为,它的 PID 已经被缓存了。我们也可以看到在格式化输出字符串之后,printf(3) 调用了 write(2)。
|
||||
|
||||
strace 可以开始一个新进程,也可以附加到一个已经运行的进程上。你可以通过不同程序的系统调用学到很多的东西。例如,sshd 守护进程一天都干了什么?
|
||||
|
||||
|
|
||||
```
|
||||
1234567891011121314151617181920212223242526272829
|
||||
```
|
||||
|
|
||||
```
|
||||
~/code/x86-os$ ps ax | grep sshd12218 ? Ss 0:00 /usr/sbin/sshd -D~/code/x86-os$ sudo strace -p 12218Process 12218 attached - interrupt to quitselect(7, [3 4], NULL, NULL, NULL[ ... nothing happens ... No fun, it's just waiting for a connection using select(2) If we wait long enough, we might see new keys being generated and so on, but let's attach again, tell strace to follow forks (-f), and connect via SSH]~/code/x86-os$ sudo strace -p 12218 -f[lots of calls happen during an SSH login, only a few shown][pid 14692] read(3, "-----BEGIN RSA PRIVATE KEY-----\n"..., 1024) = 1024[pid 14692] open("/usr/share/ssh/blacklist.RSA-2048", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)[pid 14692] open("/etc/ssh/blacklist.RSA-2048", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)[pid 14692] open("/etc/ssh/ssh_host_dsa_key", O_RDONLY|O_LARGEFILE) = 3[pid 14692] open("/etc/protocols", O_RDONLY|O_CLOEXEC) = 4[pid 14692] read(4, "# Internet (IP) protocols\n#\n# Up"..., 4096) = 2933[pid 14692] open("/etc/hosts.allow", O_RDONLY) = 4[pid 14692] open("/lib/i386-linux-gnu/libnss_dns.so.2", O_RDONLY|O_CLOEXEC) = 4[pid 14692] stat64("/etc/pam.d", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0[pid 14692] open("/etc/pam.d/common-password", O_RDONLY|O_LARGEFILE) = 8[pid 14692] open("/etc/pam.d/other", O_RDONLY|O_LARGEFILE) = 4
|
||||
```
|
||||
|
|
||||
|
||||
看懂 SSH 的调用是块难啃的骨头,但是,如果搞懂它你就学会了跟踪。也可以用它去看一个应用程序打开的哪个文件是有用的(“这个配置是从哪里来的?”)。如果你有一个出现错误的进程,你可以跟踪它,然后去看它通过系统调用做了什么?当一些应用程序没有提供适当的错误信息而意外退出时,你可以去检查它是否是一个系统调用失败。你也可以使用过滤器,查看每个调用的次数,等等:
|
||||
|
||||
|
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
123456789
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
|
|
||||
```
|
||||
~/code/x86-os$ strace -T -e trace=recv curl -silent www.google.com. > /dev/nullrecv(3, "HTTP/1.1 200 OK\r\nDate: Wed, 05 N"..., 16384, 0) = 4164 <0.000007>recv(3, "fl a{color:#36c}a:visited{color:"..., 16384, 0) = 2776 <0.000005>recv(3, "adient(top,#4d90fe,#4787ed);filt"..., 16384, 0) = 4164 <0.000007>recv(3, "gbar.up.spd(b,d,1,!0);break;case"..., 16384, 0) = 2776 <0.000006>recv(3, "$),a.i.G(!0)),window.gbar.up.sl("..., 16384, 0) = 1388 <0.000004>recv(3, "margin:0;padding:5px 8px 0 6px;v"..., 16384, 0) = 1388 <0.000007>recv(3, "){window.setTimeout(function(){v"..., 16384, 0) = 1484 <0.000006>
|
||||
```
|
||||
|
|
||||
|
||||
我鼓励你去浏览在你的操作系统中的这些工具。使用它们会让你觉得自己像个超人一样强大。
|
||||
|
||||
但是,足够有用的东西,往往要让我们深入到它的设计中。我们可以看到那些用户空间中的应用程序是被严格限制在它自己的虚拟地址空间中,它的虚拟地址空间运行在 Ring 3(非特权模式)中。一般来说,只涉及到计算和内存访问的任务是不需要请求系统调用的。例如,像 [strlen(3)][23] 和 [memcpy(3)][24] 这样的 C 库函数并不需要内核去做什么。这些都是在应用程序内部发生的事。
|
||||
|
||||
一个 C 库函数的 man 页面节上(在圆括号 2 和 3 中)也提供了线索。节 2 是用于系统调用封装,而节 3 包含了其它 C 库函数。但是,正如我们在 printf(3) 中所看到的,一个库函数可以最终产生一个或者多个系统调用。
|
||||
|
||||
如果你对此感到好奇,这里是 [Linux][25] ( [Filippo's list][26])和 [Windows][27] 的全部系统调用列表。它们各自有 ~310 和 ~460 个系统调用。看这些系统调用是非常有趣的,因为,它们代表了软件在现代的计算机上能够做什么。另外,你还可能在这里找到与进程间通讯和性能相关的“宝藏”。这是一个“不懂 Unix 的人注定最终还要重新发明一个蹩脚的 Unix ” 的地方。(译者注:“Those who do not understand Unix are condemned to reinvent it,poorly。”这句话是 [Henry Spencer][35] 的名言,反映了 Unix 的设计哲学,它的一些理念和文化是一种技术发展的必须结果,看似糟糕却无法超越。)
|
||||
|
||||
与 CPU 周期相比,许多系统调用花很长的时间去执行任务,例如,从一个硬盘驱动器中读取内容。在这种情况下,调用进程在底层的工作完成之前一直处于休眠状态。因为,CPUs 运行的非常快,一般的程序都因为 I/O 的限制在它的生命周期的大部分时间处于休眠状态,等待系统的调用。相反,如果你跟踪一个计算密集型任务,你经常会看到没有任何的系统调用参与其中。在这种情况下,[top(1)][29] 将显示大量的 CPU 使用。
|
||||
|
||||
在一个系统调用中的开销可能会是一个问题。例如,固态硬盘比普通硬盘要快很多,但是,操作系统的开销可能比 I/O 操作本身的开销 [更加昂贵][30]。执行大量读写操作的程序可能就是操作系统开销的瓶颈所在。[向量化 I/O][31] 对此有一些帮助。因此要做 [文件的内存映射][32],它允许一个程序仅访问内存就可以读或写磁盘文件。类似的映射也存在于像视频卡这样的地方。最终,经济性俱佳的云计算可能导致内核在用户模式/内核模式的切换消失或者最小化。
|
||||
|
||||
最终,系统调用还有益于系统安全。一是,无论看起来多么模糊的一个二进制程序,你都可以通过观察它的系统调用来检查它的行为。这种方式可能用于去检测恶意程序。例如,我们可以记录一个未知程序的系统调用的策略,并对它的偏差进行报警,或者对程序调用指定一个白名单,这样就可以让漏洞利用变得更加困难。在这个领域,我们有大量的研究,和许多工具,但是没有“杀手级”的解决方案。
|
||||
|
||||
这就是系统调用。很抱歉这篇文章有点长,我希望它对你有用。接下来的时间,我将写更多(短的)文章,也可以在 [RSS][33] 和 [Twitter][34] 关注我。这篇文章献给 glorious Clube Atlético Mineiro。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via:https://manybutfinite.com/post/system-calls/
|
||||
|
||||
作者:[Gustavo Duarte][a]
|
||||
译者:[qhwdw](https://github.com/qhwdw)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://duartes.org/gustavo/blog/about/
|
||||
[1]:https://manybutfinite.com/code/x86-os/pid.c
|
||||
[2]:https://manybutfinite.com/post/anatomy-of-a-program-in-memory
|
||||
[3]:https://manybutfinite.com/post/page-cache-the-affair-between-memory-and-files/
|
||||
[4]:http://linux.die.net/man/2/getpid
|
||||
[5]:https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/getpid.c;h=937b1d4e113b1cff4a5c698f83d662e130d596af;hb=4c6da7da9fb1f0f94e668e6d2966a4f50a7f0d85#l49
|
||||
[6]:https://github.com/torvalds/linux/blob/v3.17/arch/x86/syscalls/syscall_64.tbl#L48
|
||||
[7]:https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/x86_64/sysdep.h;h=4a619dafebd180426bf32ab6b6cb0e5e560b718a;hb=4c6da7da9fb1f0f94e668e6d2966a4f50a7f0d85#l139
|
||||
[8]:https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/x86_64/sysdep.h;h=4a619dafebd180426bf32ab6b6cb0e5e560b718a;hb=4c6da7da9fb1f0f94e668e6d2966a4f50a7f0d85#l179
|
||||
[9]:https://manybutfinite.com/post/cpu-rings-privilege-and-protection
|
||||
[10]:https://github.com/torvalds/linux/blob/v3.17/arch/x86/kernel/entry_64.S#L354-L386
|
||||
[11]:http://lwn.net/Articles/604287/
|
||||
[12]:http://lwn.net/Articles/604515/
|
||||
[13]:https://github.com/torvalds/linux/blob/v3.17/arch/x86/kernel/entry_64.S#L422
|
||||
[14]:https://github.com/torvalds/linux/blob/v3.17/arch/x86/kernel/syscall_64.c#L25
|
||||
[15]:https://github.com/torvalds/linux/blob/v3.17/kernel/sys.c#L800-L809
|
||||
[16]:https://github.com/torvalds/linux/blob/v3.17/kernel/sys.c#L800-L859
|
||||
[17]:http://linux.die.net/man/2/getpid
|
||||
[18]:http://linux.die.net/man/2/syscall
|
||||
[19]:http://linux.die.net/man/1/strace
|
||||
[20]:https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/dtruss.1m.html
|
||||
[21]:http://dtrace.org/blogs/brendan/2011/10/10/top-10-dtrace-scripts-for-mac-os-x/
|
||||
[22]:http://technet.microsoft.com/en-us/sysinternals/bb842062.aspx
|
||||
[23]:http://linux.die.net/man/3/strlen
|
||||
[24]:http://linux.die.net/man/3/memcpy
|
||||
[25]:https://github.com/torvalds/linux/blob/v3.17/arch/x86/syscalls/syscall_64.tbl
|
||||
[26]:https://filippo.io/linux-syscall-table/
|
||||
[27]:http://j00ru.vexillium.org/ntapi/
|
||||
[28]:https://manybutfinite.com/post/what-your-computer-does-while-you-wait/
|
||||
[29]:http://linux.die.net/man/1/top
|
||||
[30]:http://danluu.com/clwb-pcommit/
|
||||
[31]:http://en.wikipedia.org/wiki/Vectored_I/O
|
||||
[32]:https://manybutfinite.com/post/page-cache-the-affair-between-memory-and-files/
|
||||
[33]:http://feeds.feedburner.com/GustavoDuarte
|
||||
[34]:http://twitter.com/food4hackers
|
||||
[35]:https://en.wikipedia.org/wiki/Henry_Spencer
|
@ -1,20 +1,21 @@
|
||||
Getting Started with Taskwarrior
|
||||
======
|
||||
Taskwarrior is a flexible [command-line task management program][1]. In their [own words][2]:
|
||||
Taskwarrior 入门
|
||||
=====
|
||||
|
||||
Taskwarrior manages your TODO list from your command line. It is flexible, fast, efficient, unobtrusive, does its job then gets out of your way.
|
||||
Taskwarrior 是一个灵活的[命令行任务管理程序][1],用他们[自己的话说][2]:
|
||||
|
||||
Taskwarrior is highly customizable, but can also be used "right out of the box." In this article, we'll show you the basic commands to add and complete tasks. Then we'll cover a couple more advanced commands. And finally, we'll show you some basic configuration settings to begin customizing your setup.
|
||||
Taskwarrior 是从你的命令行管理你的 TODO 列表。它灵活,快速,高效,不显眼,它默默做自己的事情让你避免自己管理。
|
||||
|
||||
### Installing Taskwarrior
|
||||
Taskwarrior 是高度可定制的,但也可以“立即使用”。在本文中,我们将向你展示添加和完成任务的基本命令,然后我们将介绍几个更高级的命令。最后,我们将向你展示一些基本的配置设置,以开始自定义你的设置。
|
||||
|
||||
Taskwarrior is available in the Fedora repositories, so installing it is simple:
|
||||
### 安装 Taskwarrior
|
||||
|
||||
Taskwarrior 在 Fedora 仓库中是可用的,所有安装它很容易:
|
||||
```
|
||||
sudo dnf install task
|
||||
|
||||
```
|
||||
|
||||
Once installed, run `task`. This first run will create a `~/.taskrc` file for you.
|
||||
一旦完成安装,运行 `task`。第一次运行将会创建一个 `~/.taskrc` 文件。
|
||||
```
|
||||
$ **task**
|
||||
A configuration file could not be found in ~
|
||||
@ -25,16 +26,16 @@ No matches.
|
||||
|
||||
```
|
||||
|
||||
### Adding Tasks
|
||||
### 添加任务
|
||||
|
||||
Adding tasks is fast and unobtrusive.
|
||||
添加任务快速而不显眼。
|
||||
```
|
||||
$ **task add Plant the wheat**
|
||||
Created task 1.
|
||||
|
||||
```
|
||||
|
||||
Run `task` or `task list` to show upcoming tasks.
|
||||
运行 `task` 或者 `task list` 来显示即将来临的任务。
|
||||
```
|
||||
$ **task list**
|
||||
|
||||
@ -45,7 +46,7 @@ ID Age Description Urg
|
||||
|
||||
```
|
||||
|
||||
Let's add a few more tasks to round out the example.
|
||||
让我们添加一些任务来完成这个示例。
|
||||
```
|
||||
$ **task add Tend the wheat**
|
||||
Created task 2.
|
||||
@ -58,7 +59,7 @@ Created task 5.
|
||||
|
||||
```
|
||||
|
||||
Run `task` again to view the list.
|
||||
再次运行 `task` 来查看列表。
|
||||
```
|
||||
[task next]
|
||||
|
||||
@ -73,9 +74,9 @@ ID Age Description Urg
|
||||
|
||||
```
|
||||
|
||||
### Completing Tasks
|
||||
### 完成任务
|
||||
|
||||
To mark a task as complete, look up its ID and run:
|
||||
将一个任务标记为完成, 查找其 ID 并运行:
|
||||
```
|
||||
$ **task 1 done**
|
||||
Completed task 1 'Plant the wheat'.
|
||||
@ -83,7 +84,7 @@ Completed 1 task.
|
||||
|
||||
```
|
||||
|
||||
You can also mark a task done with its description.
|
||||
你也可以用它的描述来标记一个任务已完成。
|
||||
```
|
||||
$ **task 'Tend the wheat' done**
|
||||
Completed task 1 'Tend the wheat'.
|
||||
@ -91,31 +92,32 @@ Completed 1 task.
|
||||
|
||||
```
|
||||
|
||||
With `add`, `list` and `done`, you're all ready to get started with Taskwarrior.
|
||||
通过使用 `add`, `list` 和 `done`,你可以说已经入门了。
|
||||
|
||||
### Setting Due Dates
|
||||
### 设定截止日期
|
||||
|
||||
Many tasks do not require a due date:
|
||||
很多任务不需要一个截止日期:
|
||||
```
|
||||
task add Finish the article on Taskwarrior
|
||||
|
||||
```
|
||||
|
||||
But sometimes, setting a due date is just the kind of motivation you need to get productive. Use the `due` modifier when adding a task to set a specific due date.
|
||||
但是有时候,设定一个截止日期正是你需要提高效率的动力。在添加任务时使用 `due` 修饰符来设置特定的截止日期。
|
||||
|
||||
```
|
||||
task add Finish the article on Taskwarrior due:tomorrow
|
||||
|
||||
```
|
||||
|
||||
`due` is highly flexible. It accepts specific dates ("2017-02-02"), or ISO-8601 ("2017-02-02T20:53:00Z"), or even relative time ("8hrs"). See the [Date & Time][3] documentation for all the examples.
|
||||
`due` 非常灵活。它接受特定日期 ("2017-02-02") 或 ISO-8601 ("2017-02-02T20:53:00Z"),甚至相对时间 ("8hrs")。可以查看所有示例的 [Date & Time][3] 文档。
|
||||
|
||||
Dates go beyond due dates too. Taskwarrior has `scheduled`, `wait`, and `until`.
|
||||
日期也会超出截止日期,Taskwarrior 有 `scheduled`, `wait` 和 `until` 选项。
|
||||
```
|
||||
task add Proof the article on Taskwarrior scheduled:thurs
|
||||
|
||||
```
|
||||
|
||||
Once the date (Thursday in this example) passes, the task is tagged with the `READY` virtual tag. It will then show up in the `ready` report.
|
||||
一旦日期(本例中的星期四)通过,该任务就会被标记为 `READY` 虚拟标记。它会显示在 `ready` 报告中。
|
||||
```
|
||||
$ **task ready**
|
||||
|
||||
@ -124,15 +126,15 @@ ID Age S Description Urg
|
||||
|
||||
```
|
||||
|
||||
To remove a date, `modify` the task with a blank value:
|
||||
要移除一个日期,使用空白值来 `modify` 任务:
|
||||
```
|
||||
$ task 1 modify scheduled:
|
||||
|
||||
```
|
||||
|
||||
### Searching Tasks
|
||||
### 查找任务
|
||||
|
||||
No task list is complete without the ability to search with regular expressions, right?
|
||||
如果没有使用正则表达式搜索的能力,任务列表是不完整的,对吧?
|
||||
```
|
||||
$ **task '/.* the wheat/' list**
|
||||
|
||||
@ -144,9 +146,9 @@ ID Age Project Description Urg
|
||||
|
||||
```
|
||||
|
||||
### Customizing Taskwarrior
|
||||
### 自定义 Taskwarrior
|
||||
|
||||
Remember that file we created back in the beginning (`~/.taskrc`). Let's take at the defaults:
|
||||
记得我们在开头创建的文件 (`~/.taskrc`)吗?让我们来看看默认设置:
|
||||
```
|
||||
# [Created by task 2.5.1 2/9/2017 16:39:14]
|
||||
# Taskwarrior program configuration file.
|
||||
@ -182,13 +184,13 @@ data.location=~/.task
|
||||
|
||||
```
|
||||
|
||||
The only active option right now is `data.location=~/.task`. To view active configuration settings (including the built-in defaults), run `show`.
|
||||
现在唯一有效的选项是 `data.location=~/.task`。要查看活动配置设置(包括内置的默认设置),运行 `show`。
|
||||
```
|
||||
task show
|
||||
|
||||
```
|
||||
|
||||
To change a setting, use `config`.
|
||||
改变设置,使用 `config`。
|
||||
```
|
||||
$ **task config displayweeknumber no**
|
||||
Are you sure you want to add 'displayweeknumber' with a value of 'no'? (yes/no) yes
|
||||
@ -196,29 +198,29 @@ Config file /home/link/.taskrc modified.
|
||||
|
||||
```
|
||||
|
||||
### Examples
|
||||
### 示例
|
||||
|
||||
These are just some of the things you can do with Taskwarrior.
|
||||
这些只是你可以用 Taskwarrior 做的一部分事情。
|
||||
|
||||
Assign a project to your tasks:
|
||||
为你的任务分配一个项目:
|
||||
```
|
||||
task 'Fix leak in the roof' modify project:Home
|
||||
|
||||
```
|
||||
|
||||
Use `start` to mark what you were working on. This can help you remember what you were working on after the weekend:
|
||||
使用 `start` 来标记你正在做的事情,这可以帮助你回忆起你周末后在做什么:
|
||||
```
|
||||
task 'Fix bug #141291' start
|
||||
|
||||
```
|
||||
|
||||
Use relevant tags:
|
||||
使用相关的标签:
|
||||
```
|
||||
task add 'Clean gutters' +weekend +house
|
||||
|
||||
```
|
||||
|
||||
Be sure to read the [complete documentation][4] to learn all the ways you can catalog and organize your tasks.
|
||||
务必阅读[完整文档][4]以了解你可以编目和组织任务的所有方式。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -226,7 +228,7 @@ Be sure to read the [complete documentation][4] to learn all the ways you can ca
|
||||
via: https://fedoramagazine.org/getting-started-taskwarrior/
|
||||
|
||||
作者:[Link Dupont][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
@ -1,187 +0,0 @@
|
||||
Python全局,局部和非局部变量(带示例)
|
||||
======
|
||||
|
||||
### 全局变量
|
||||
|
||||
在Python中,在函数之外或在全局范围内声明的变量被称为全局变量。 这意味着,全局变量可以在函数内部或外部访问。
|
||||
|
||||
我们来看一个关于如何在Python中创建一个全局变量的示例。
|
||||
|
||||
#### 示例1:创建全局变量
|
||||
```python
|
||||
x = "global"
|
||||
|
||||
def foo():
|
||||
print("x inside :", x)
|
||||
|
||||
foo()
|
||||
print("x outside:", x)
|
||||
```
|
||||
|
||||
当我们运行代码时,将会输出:
|
||||
```
|
||||
x inside : global
|
||||
x outside: global
|
||||
```
|
||||
|
||||
在上面的代码中,我们创建了x作为全局变量,并定义了一个`foo()`来打印全局变量x。 最后,我们调用`foo()`来打印x的值。
|
||||
|
||||
倘若你想改变一个函数内的x的值该怎么办?
|
||||
|
||||
```python
|
||||
x = "global"
|
||||
|
||||
def foo():
|
||||
x = x * 2
|
||||
print(x)
|
||||
foo()
|
||||
```
|
||||
|
||||
当我们运行代码时,将会输出:
|
||||
```
|
||||
UnboundLocalError: local variable 'x' referenced before assignment
|
||||
```
|
||||
|
||||
输出显示一个错误,因为Python将x视为局部变量,x也没有`foo()`内部定义。
|
||||
|
||||
为了运行正常,我们使用`global`关键字,访问[PythonGlobal关键字][1]以便了解更多。
|
||||
|
||||
### 局部变量
|
||||
|
||||
在函数体内或局部作用域内声明的变量称为局部变量。
|
||||
|
||||
#### 示例2:访问作用域外的局部变量
|
||||
|
||||
```python
|
||||
def foo():
|
||||
y = "local"
|
||||
|
||||
foo()
|
||||
print(y)
|
||||
```
|
||||
|
||||
当我们运行代码时,将会输出:
|
||||
```
|
||||
NameError: name 'y' is not defined
|
||||
```
|
||||
|
||||
输出显示了一个错误,因为我们试图在全局范围内访问局部变量y,而局部变量只能在`foo() `函数内部或局部作用域内有效。
|
||||
|
||||
我们来看一个关于如何在Python中创建一个局部变量的例子。
|
||||
|
||||
#### 示例3:创建一个局部变量
|
||||
|
||||
通常,我们在函数内声明一个变量来创建一个局部变量。
|
||||
```python
|
||||
def foo():
|
||||
y = "local"
|
||||
print(y)
|
||||
|
||||
foo()
|
||||
```
|
||||
|
||||
当我们运行代码时,将会输出:
|
||||
```
|
||||
local
|
||||
```
|
||||
|
||||
让我们来看看前面的问题,其中x是一个全局变量,我们想修改`foo()`内部的x。
|
||||
|
||||
### 全局变量和局部变量
|
||||
|
||||
在这里,我们将展示如何在同一份代码中使用全局变量和局部变量。
|
||||
|
||||
#### 示例4:在同一份代码中使用全局变量和局部变量
|
||||
```python
|
||||
x = "global"
|
||||
|
||||
def foo():
|
||||
global x
|
||||
y = "local"
|
||||
x = x * 2
|
||||
print(x)
|
||||
print(y)
|
||||
|
||||
foo()
|
||||
```
|
||||
|
||||
当我们运行代码时,将会输出(译者注:原文中输出结果的两个global有空格,正确的是没有空格):
|
||||
```
|
||||
globalglobal
|
||||
local
|
||||
```
|
||||
|
||||
在上面的代码中,我们将x声明为全局变量,将y声明为`foo()`中的局部变量。 然后,我们使用乘法运算符`*`来修改全局变量x,并打印x和y。
|
||||
|
||||
在调用`foo()`之后,x的值变成`globalglobal`了(译者注:原文同样有空格,正确的是没有空格),因为我们使用`x * 2`打印两次`global`。 之后,我们打印局部变量y的值,即`local`。
|
||||
|
||||
#### 示例5:具有相同名称的全局变量和局部变量
|
||||
```python
|
||||
x = 5
|
||||
|
||||
def foo():
|
||||
x = 10
|
||||
print("local x:", x)
|
||||
|
||||
foo()
|
||||
print("global x:", x)
|
||||
```
|
||||
|
||||
当我们运行代码时,将会输出:
|
||||
```
|
||||
local x: 10
|
||||
global x: 5
|
||||
```
|
||||
|
||||
在上面的代码中,我们对全局变量和局部变量使用了相同的名称x。 当我们打印相同的变量时却得到了不同的结果,因为这两个作用域内都声明了变量,即`foo()`内部的局部作用域和`foo()`外面的全局作用域。
|
||||
|
||||
当我们在`foo()`内部打印变量时,它输出`local x: 10`,这被称为变量的局部作用域。
|
||||
|
||||
同样,当我们在`foo()`外部打印变量时,它输出`global x: 5`,这被称为变量的全局作用域。
|
||||
|
||||
### 非局部变量
|
||||
|
||||
非局部变量用于局部作用域未定义的嵌套函数。 这意味着,变量既不能在局部也不能在全局范围内。
|
||||
|
||||
我们来看一个关于如何在Python中创建一个非局部变量的例子。(译者注:原文为创建全局变量,疑为笔误)
|
||||
|
||||
我们使用`nonlocal`关键字来创建非局部变量。
|
||||
|
||||
#### 例6:创建一个非局部变量
|
||||
```python
|
||||
def outer():
|
||||
x = "local"
|
||||
|
||||
def inner():
|
||||
nonlocal x
|
||||
x = "nonlocal"
|
||||
print("inner:", x)
|
||||
|
||||
inner()
|
||||
print("outer:", x)
|
||||
|
||||
outer()
|
||||
```
|
||||
|
||||
当我们运行代码时,将会输出:
|
||||
```
|
||||
inner: nonlocal
|
||||
outer: nonlocal
|
||||
```
|
||||
|
||||
在上面的代码中有一个嵌套函数`inner()`。 我们使用`nonlocal`关键字来创建非局部变量。`inner()`函数是在另一个函数`outer()`的作用域中定义的。
|
||||
|
||||
注意:如果我们改变非局部变量的值,那么变化就会出现在局部变量中。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.programiz.com/python-programming/global-local-nonlocal-variables
|
||||
|
||||
作者:[programiz][a]
|
||||
译者:[Flowsnow](https://github.com/Flowsnow)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.programiz.com/
|
||||
[1]:https://www.programiz.com/python-programming/global-keyword
|
@ -0,0 +1,151 @@
|
||||
|
||||
|
||||
如何使用树莓派制作一个数字针孔摄像头
|
||||
======
|
||||
|
||||

|
||||
在 2015 年底的时候,树莓派基金会发布了一个非常小的 [Raspberry Pi Zero][1],这让大家感到很意外。更夸张的是,他们随 MagPi 杂志一起 [免费赠送][2]。我看到这个消息后立即冲出去到处找报刊亭,直到我在这一区域的某处找到最后两份。实际上我还没有想好如何去使用它们,但是我知道,因为它们非常小,所以,它们可以做很多全尺寸树莓派没法做的一些项目。
|
||||
|
||||
|
||||
![Raspberry Pi Zero][4]
|
||||
|
||||
从 MagPi 杂志上获得的树莓派 Zero。CC BY-SA.4.0。
|
||||
|
||||
因为我对天文摄影非常感兴趣,我以前还改过一台微软出的 LifeCam Cinema 高清网络摄像头,拆掉了它的外壳、镜头、以及红外滤镜,露出了它的 [CCD 芯片][5]。我把它定制为我的 Celestron 天文望远镜的目镜。用它我捕获到了令人难以置信的木星照片、月球上的陨石坑、以及太阳黑子的特写镜头(使用了适当的 Baader 安全保护膜)。
|
||||
|
||||
在那之前,我甚至还在我的使用胶片的 SLR 摄像机上,通过在镜头盖(这个盖子就是在摄像机上没有安装镜头时,用来保护摄像机的内部元件的那个盖子)上钻一个小孔来变成一个 [针孔摄像头][6],将这个钻了小孔的盖子,盖到一个汽水罐上切下来的小圆盘上,以提供一个针孔。碰巧有一天,在我的桌子上发现了一个可以用来做针孔体的盖子,随后我将它改成了用于天文摄像的网络摄像头。我很好奇这个网络摄像头是否有从针孔盖子后面捕获低照度图像的能力。我花了一些时间使用 [GNOME Cheese][7] 应用程序,去验证这个针孔摄像头确实是个可行的创意。
|
||||
|
||||
自从有了这个想法,我就有了树莓派 Zero 的一个用法!针孔摄像机一般都非常小,除了曝光时间和胶片的 ISO 速率外,一般都不提供其它的控制选项。数字摄像机就不一样了,它至少有 20 多个按钮和成百上千的设置菜单。我的数字针孔摄像头的目标是真实反映天文摄像的传统风格,设计一个没有控制选项的极简设备,甚至连曝光时间控制也没有。
|
||||
|
||||
用树莓派 Zero、高清网络镜头和空粉盒设计的数字针孔摄像头,是我设计的 [一系列][9] 针孔摄像头的 [第一个项目][8]。现在,我们开始来制作它。
|
||||
|
||||
### 硬件
|
||||
|
||||
因为我手头已经有了一个树莓派 Zero,为完成这个项目我还需要一个网络摄像头。这个树莓派 Zero 在英国的零售价是 4 英磅,这个项目其它部件的价格,我希望也差不多是这样的价格水平。花费 30 英磅买来的摄像头安装在一个 4 英磅的计算机主板上,让我感觉有些不平衡。显而易见的答案是前往一个知名的拍卖网站上,去找到一些二手的网络摄像头。不久之后,我仅花费了 1 英磅再加一些运费,获得了一个普通的高清摄像头。之后,在 Fedora 上做了一些测试操作,以确保它是可用正常使用的,我拆掉了它的外壳,以检查它的电子元件的大小是否适合我的项目。
|
||||
|
||||
|
||||
![Hercules DualPix HD webcam][11]
|
||||
|
||||
Hercules DualPix 高清网络摄像头,它将被解剖以提取它的电路板和 CCD 图像传感器。CC BY-SA 4.0.
|
||||
|
||||
接下来,我需要一个安放摄像头的外壳。树莓派 Zero 电路板大小仅仅为 65mm x 30mm x 5mm。虽然网络摄像头的 CCD 芯片周围有一个用来安装镜头的塑料支架,但是,实际上它的电路板尺寸更小。我在家里找了一圈,希望能够找到一个适合盛放这两个极小的电路板的容器。最后,我发现我妻子的粉盒足够去安放树莓派的电路板。稍微做一些小调整,似乎也可以将网络摄像头的电路板放进去。
|
||||
|
||||
![Powder compact][13]
|
||||
|
||||
变成我的针孔摄像头外壳的粉盒。CC BY-SA 4.0.
|
||||
|
||||
我拆掉了网络摄像头外壳上的一些螺丝,取出了它的内部元件。网络摄像头外壳的大小反映了它的电路板的大小或 CCD 的位置。我很幸运,这个网络摄像头很小而且它的电路板的布局也很方便。因为我要做一个针孔摄像头,我需要取掉镜像,露出 CCD 芯片。
|
||||
|
||||
它的塑料外壳大约有 1 厘米高,它太高了没有办法放进粉盒里。我拆掉了电路板后面的螺丝,将它完全拆开,我认为将它放在盒子里有助于阻挡从缝隙中来的光线,因此,我用一把工艺刀将它修改成 4 毫米高,然后将它重新安装。我折弯了 LED 的支脚以降低它的高度。最后,我切掉了安装麦克风的塑料管,因为我不想采集声音。
|
||||
|
||||
![Bare CCD chip][15]
|
||||
|
||||
取下镜头以后,就可以看到裸露的 CCD 芯片了。圆柱形的塑料柱将镜头固定在合适的位置上,并阻挡 LED 光进入镜头破坏图像。CC BY-SA 4.0
|
||||
|
||||
网络摄像头有一个很长的带全尺寸插头的 USB 线缆,而树莓派 Zero 使用的是一个 Micro-USB 插座,因此,我需要一个 USB-to-Micro-USB 适配器。但是,使用适配器插入,这个树莓派将放不进这个粉盒中,更不用说还有将近一米长的 USB 线缆。因此,我用刀将 Micro-USB 适配器削开,切掉了它的 USB 插座并去掉这些塑料,露出连接到 Micro-USB 插头上的金属材料。同时也切掉了网络摄像头上大约 6 厘米长的 USB 电缆,并剥掉裹在它外面的锡纸,露出它的四根电线。我把它们直接焊接到 Micro-USB 插头上。现在网络摄像头可以插入到树莓派 Zero 上了,并且电线也可以放到粉盒中了。
|
||||
|
||||
![Modified USB plugs][17]
|
||||
|
||||
网络摄像头使用的 Micro-USB 插头已经剥掉了线,并直接焊接到触点上。这个插头现在插入到树莓派 Zero 后大约仅高出树莓派 1 厘米。CC BY-SA 4.0
|
||||
|
||||
最初,我认为到此为止,已经全部完成了电子设计部分,但是在测试之后,我意识到,如果摄像头没有捕获图像或者甚至没有加电我都不知道。我决定使用树莓派的 GPIO 针脚去驱动 LED 指示灯。一个黄色的 LED 表示网络摄像头控制软件已经运行,而一个绿色的 LED 表示网络摄像头正在捕获图像。我在 BCM 的 17 号和 18 号针脚上各自串接一个 300 欧姆的电阻,并将它们各自连接到 LED 的正极上,然后将 LED 的负极连接到一起并接入到公共地针脚上。
|
||||
|
||||
![LEDs][19]
|
||||
|
||||
LED 使用一个 300 欧姆的电阻连接到 GPIO 的 BCM 17 号和 BCM 18 号针脚上,负极连接到公共地针脚。CC BY-SA 4.0.
|
||||
|
||||
接下来,该去修改粉盒了。首先,我去掉了卡在粉盒上的托盘以腾出更多的空间,并且用刀将连接处切开。我打算在一个便携式充电宝上运行树莓派 Zero,充电宝肯定是放不到这个盒子里面,因此,我挖了一个孔,这样就可以引出 USB 连接头。LED 的光需要能够从盒子外面看得见,因此,我在盖子上钻了两个 3 毫米的小孔。
|
||||
|
||||
然后,我使用一个 6 毫米的钻头在盖子的底部中间处钻了一个孔,并找了一个薄片盖在它上面,然后用针在它的中央扎了一个小孔。一定要确保针尖很细,因为如果插入整个针会使孔太大。我使用干/湿砂纸去打磨这个针孔,以让它更光滑,然后从另一面再次打孔,再强调一次仅使用针尖。使用针孔摄像头的目的是为了得到一个规则的、没有畸形或凸起的圆孔,并且勉强让光通过。孔越小,图像越锐利。
|
||||
|
||||
![Bottom of the case with the pinhole aperture][21]
|
||||
|
||||
带针孔的盒子底部。CC BY-SA 4.0
|
||||
|
||||
剩下的工作就是将这些已经改造完成的设备封装起来。首先我使用蓝色腻子将摄像头的电路板固定在盒子中合适的位置,这样针孔就直接处于 CCD 之上了。使用蓝色腻子的好处是,如果我需要清理污渍(或者如果放错了位置)时,就可以很容易地重新安装 CCD 了。将树莓派 Zero 直接放在摄像头电路板上面。为防止这两个电路板之间可能出现的短路情况,我在这两个电路板之间放了几层防静电袋。
|
||||
|
||||
[树莓派 Zero][22] 非常适合放到这个粉盒中,并且不需要任何固定,而从小孔中穿出去连接充电宝的 USB 电缆需要将它粘住固定。最后,我将 LED 塞进了前面在盒子上钻的孔中,并用胶水将它们固定住。我在 LED 的针脚之中放了一些防静电袋,以防止盒子盖上时,它与树莓派电路板接触而发生短路。
|
||||
|
||||
![Raspberry Pi Zero slotted into the case][24]
|
||||
|
||||
树莓派 Zero 塞入到这个盒子中后,周围的空隙不到 1mm。从盒子中引出的连接到网络摄像头上的 Micro-USB 插头,接下来需要将它连接到充电宝上。CC BY-SA 4.0
|
||||
|
||||
### 软件
|
||||
|
||||
当然,计算机硬件离开控制它的软件是不能使用的。树莓派 Zero 同样可以运行全尺寸树莓派能够运行的软件,但是,因为树莓派 Zero 的 CPU 速度比较慢,让它去引导传统的 [Raspbian OS][25] 镜像非常耗时。打开摄像头都要花费差不多一分钟的时间,这样的速度在现实中是没有什么用处的。而且,一个完整的树莓派操作系统对我的这个摄像头项目来说也没有必要。甚至是,我禁用了引导时启动的所有可禁用的服务,启动仍然需要很长的时间。因此,我决定仅使用需要的软件,我将用一个 [U-Boot][26] 引导加载器和 Linux 内核。自定义 `init` 二进制文件从 microSD 卡上加载 root 文件系统,读入驱动网络摄像头所需要的内核模块,并将它放在 `/dev` 目录下,然后运行二进制的应用程序。
|
||||
|
||||
这个二进制的应用程序是另一个定制的 C 程序,它做的核心工作就是管理摄像头。首先,它等待内核驱动程序去初始化网络摄像头、打开它、以及通过低级的 `v4l ioctl` 调用去初始化它。GPIO 针是通过 `/dev/mem` 寄存器被配置为驱动 LED。
|
||||
|
||||
初始化完成之后,摄像头进入一个 loop 循环。每个图像捕获循环是摄像头使用缺省配置,以 JPEG 格式捕获一个单一的图像帧、保存这个图像帧到 SD 卡、然后休眠三秒。这个循环持续运行直到断电为止。这已经很完美地实现了我的最初目标,那就是用一个传统的模拟的针孔摄像头设计一个简单的数字摄像头。
|
||||
|
||||
定制的用户空间 [代码][27] 在遵守 [GPLv3][28] 或者更新版许可下自由使用。树莓派 Zero 需要 ARMv6 的二进制文件,因此,我使用了 [QEMU ARM][29] 模拟器在一台 x86_64 主机上进行编译,它使用了 [Pignus][30] 发行版(一个针对 ARMv6 移植/重构建的 Fedora 23 版本)下的工具链,在 `chroot` 下进行编译。所有的二进制文件都静态链接了 [glibc][31],因此,它们都是自包含的。我构建了一个定制的 RAMDisk 去包含这些二进制文件和所需的内核模块,并将它拷贝到 SD 卡,这样引导加载器就可以找到它们了。
|
||||
|
||||
![Completed camera][33]
|
||||
|
||||
最终完成的摄像机完全隐藏在这个粉盒中了。唯一露在外面的东西就是 USB 电缆。CC BY-SA 4.0
|
||||
|
||||
### 照像
|
||||
|
||||
软件和硬件已经完成了,是该去验证一下它能做什么了。每个人都熟悉用现代的数字摄像头拍摄的高质量图像,不论它是用专业的 DSLRs 还是移动电话拍的。但是,这个高清的 1280x1024 分辨率的网络摄像头(差不多是一百万像素),在这里可能会让你失望。这个 CCD 从一个光通量极小的针孔中努力捕获图像。网络摄像头自动提升增益和曝光时间来进行补偿,最后的结果是一幅噪点很高的图像。图像的动态范围也非常窄,从一个非常拥挤的柱状图就可以看出来,这可以通过后期处理来拉长它,以得到更真实的亮部和暗部。
|
||||
|
||||
在户外阳光充足时捕获的图像达到了最佳效果,因此在室内获得的图像大多数都是不可用的图像。它的 CCD 直径仅有大约 1cm,并且是从一个几毫米的针孔中来捕获图像的,它的视界相当窄。比如,在自拍时,手臂拿着相机尽可能伸长,所获得的图像也就是充满整个画面的人头。最后,图像都是失焦的,所有的针孔摄像机都是这样的。
|
||||
|
||||
![Picture of houses taken with pinhole webcam][35]
|
||||
|
||||
在伦敦,大街上的屋顶。CC BY-SA 4.0
|
||||
|
||||
![Airport photo][37]
|
||||
|
||||
范堡罗机场的老航站楼。CC BY-SA 4.0
|
||||
|
||||
最初,我只是想使用摄像头去捕获一些静态图像。后面,我降低了 loop 循环的延迟时间,从三秒改为一秒,然后用它捕获一段时间内的一系列图像。我使用 [GStreamer][38] 将这些图像做成了延时视频。
|
||||
|
||||
以下是我创建视频的过程:
|
||||
|
||||
[][38]
|
||||
|
||||
视频是我在某天下班之后,从银行沿着泰晤式河到滑铁卢的画面。以每分钟 40 帧捕获的 1200 帧图像被我制作成了每秒 20 帧的动画。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/3/how-build-digital-pinhole-camera-raspberry-pi
|
||||
|
||||
作者:[Daniel Berrange][a]
|
||||
译者:[qhwdw](https://github.com/qhwdw)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/berrange
|
||||
[1]:https://www.raspberrypi.org/products/raspberry-pi-zero/
|
||||
[2]:https://opensource.com/users/node/24776
|
||||
[3]:https://opensource.com/file/390776
|
||||
[4]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-raspberrypizero.jpg?itok=1ry7Kx9m "Raspberry Pi Zero"
|
||||
[5]:https://en.wikipedia.org/wiki/Charge-coupled_device
|
||||
[6]:https://en.wikipedia.org/wiki/Pinhole_camera
|
||||
[7]:https://help.gnome.org/users/cheese/stable/
|
||||
[8]:https://pinholemiscellany.berrange.com/motivation/m-arcturus/
|
||||
[9]:https://pinholemiscellany.berrange.com/
|
||||
[10]:https://opensource.com/file/390756
|
||||
[11]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-hercules_dualpix_hd.jpg?itok=r858OM9_ "Hercules DualPix HD webcam"
|
||||
[12]:https://opensource.com/file/390771
|
||||
[13]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-powdercompact.jpg?itok=RZSwqCY7 "Powder compact"
|
||||
[14]:https://opensource.com/file/390736
|
||||
[15]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-bareccdchip.jpg?itok=IQzjZmED "Bare CCD chip"
|
||||
[17]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-usbs.jpg?itok=QJBkbI1F "Modified USB plugs"
|
||||
[19]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-_pi-zero-led.png?itok=oH4c2oCn "LEDs"
|
||||
[21]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-casebottom.jpg?itok=QjDMaWLi "Bottom of the case with the pinhole aperture"
|
||||
[22]:https://opensource.com/users/node/34916
|
||||
[24]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-pizeroincase.jpg?itok=cyUIvjjt "Raspberry Pi Zero slotted into the case"
|
||||
[25]:https://www.raspberrypi.org/downloads/raspbian/
|
||||
[26]:https://www.denx.de/wiki/U-Boot
|
||||
[27]:https://gitlab.com/berrange/pinholemiscellany/
|
||||
[28]:https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
[29]:https://wiki.qemu.org/Documentation/Platforms/ARM
|
||||
[30]:https://pignus.computer/
|
||||
[31]:https://www.gnu.org/software/libc/
|
||||
[33]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-completedcamera.jpg?itok=VYFaT-kA "Completed camera"
|
||||
[35]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-housesimage.jpg?itok=-_gtwn9N "Picture of houses taken with pinhole webcam"
|
||||
[37]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/pinhole-farnboroughairportimage.jpg?itok=E829gg4F "Airport photo"
|
||||
[38]:https://gstreamer.freedesktop.org/modules/gst-ffmpeg.html
|
@ -1,137 +0,0 @@
|
||||
在 Linux 上寻找你正在寻找的东西
|
||||
=====
|
||||
|
||||

|
||||
在 Linux 系统上找到你要找的东西并不难 - 一个文件或一个命令 - 但是有很多种方法可以寻找。
|
||||
|
||||
### 7 个命令来寻找 Linux 文件
|
||||
|
||||
#### find
|
||||
|
||||
最明显的无疑是 **find** 命令,并且 find 变得比以前更容易使用。它过去需要一个搜索的起始位置,但是现在,如果你想将搜索限制在本地目录中,你还可以使用仅包含文件名或正则表达式的 find 命令。
|
||||
```
|
||||
$ find e*
|
||||
empty
|
||||
examples.desktop
|
||||
|
||||
```
|
||||
|
||||
这样,它就像 **ls** 命令一样工作,并没有做太多的搜索。
|
||||
|
||||
对于更专业的搜索,find 命令需要一个起点和一些搜索条件(除非你只是希望它提供该起点目录的递归列表)。命令 **find -type f** 从当前目录开始将递归列出所有常规文件,而 **find ~nemo -type f -empty** 将在 nemo 的主目录中找到空文件。
|
||||
```
|
||||
$ find ~nemo -type f -empty
|
||||
/home/nemo/empty
|
||||
|
||||
```
|
||||
|
||||
**同样在网络世界:[11 个毫无意义但是很棒的 Linux 终端技巧][1]。**
|
||||
|
||||
#### locate
|
||||
|
||||
**locate** 命令的名称表明它与 find 命令基本相同,但它的工作原理完全不同。**find** 命令可以根据各种条件 - 名称,大小,所有者,权限,状态(如空)等等选择文件并作为搜索选择深度,**locate** 命令通过名为 /var/lib/mlocate/mlocate.db 的文件查找你要查找的内容。该数据文件会定期更新,因此你刚创建的文件的位置它可能无法找到。如果这让你感到困扰,你可以运行 updatedb 文件并立即获得更新。
|
||||
```
|
||||
$ sudo updatedb
|
||||
|
||||
```
|
||||
|
||||
#### mlocate
|
||||
|
||||
**mlocate** 命令的工作类似于 **locate** 命令,它使用与 locate 相同的 mlocate.db 文件。
|
||||
|
||||
#### which
|
||||
|
||||
**which** 命令的工作方式与 **find** 命令和 **locate** 命令有很大的区别。它使用你的搜索路径并检查其上的每个目录,以查找具有你要查找的文件名的可执行文件。一旦找到一个,它会停止搜索并显示该可执行文件的完整路径。
|
||||
|
||||
**which** 命令的主要优点是它回答了“如果我输入此命令,将运行什么可执行文件?”的问题。它会忽略不可执行文件,并且不会列出系统上带有该名称的所有可执行文件 - 列出的就是它找到的第一个。如果你想查找具有某个名称的所有可执行文件,则可以像这样运行 find 命令,但运行非常高效 **which** 命令可能需要相当长的时间。
|
||||
```
|
||||
$ find / -name locate -perm -a=x 2>/dev/null
|
||||
/usr/bin/locate
|
||||
/etc/alternatives/locate
|
||||
|
||||
```
|
||||
|
||||
在这个 find 命令中,我们在寻找名为 “locate” 的所有可执行文件(任何人都可以运行的文件)。我们也选择了不要查看所有“拒绝访问”的消息,否则这些消息会混乱我们的屏幕。
|
||||
|
||||
#### whereis
|
||||
|
||||
**whereis** 命令与 **which** 命令非常类似,但它提供了更多信息。它不仅仅是寻找可执行文件,它还寻找手册页(man page)和源文件。像 **which** 命令一样,它使用搜索路径($PATH) 来驱动搜索。
|
||||
```
|
||||
$ whereis locate
|
||||
locate: /usr/bin/locate /usr/share/man/man1/locate.1.gz
|
||||
|
||||
```
|
||||
|
||||
#### whatis
|
||||
|
||||
**whatis** 命令有其独特的使命。它不是实际查找文件,而是在手册页中查找有关所询问命令的信息,并从手册页的顶部提供该命令的简要说明。
|
||||
```
|
||||
$ whatis locate
|
||||
locate (1) - find files by name
|
||||
|
||||
```
|
||||
|
||||
如果你询问你刚刚设置的脚本,它不会知道你指的是什么,并会告诉你。
|
||||
```
|
||||
$ whatis cleanup
|
||||
cleanup: nothing appropriate.
|
||||
|
||||
```
|
||||
|
||||
#### apropos
|
||||
|
||||
当你知道你想要做什么,但不知道应该使用什么命令来执行此操作时,**apropos** 命令很有用。例如,如果你想知道如何查找文件,那么 “apropos find” 和 “apropos locate” 会提供很多建议。
|
||||
```
|
||||
$ apropos find
|
||||
File::IconTheme (3pm) - find icon directories
|
||||
File::MimeInfo::Applications (3pm) - Find programs to open a file by mimetype
|
||||
File::UserDirs (3pm) - find extra media and documents directories
|
||||
find (1) - search for files in a directory hierarchy
|
||||
findfs (8) - find a filesystem by label or UUID
|
||||
findmnt (8) - find a filesystem
|
||||
gst-typefind-1.0 (1) - print Media type of file
|
||||
ippfind (1) - find internet printing protocol printers
|
||||
locate (1) - find files by name
|
||||
mlocate (1) - find files by name
|
||||
pidof (8) - find the process ID of a running program.
|
||||
sane-find-scanner (1) - find SCSI and USB scanners and their device files
|
||||
systemd-delta (1) - Find overridden configuration files
|
||||
xdg-user-dir (1) - Find an XDG user dir
|
||||
$
|
||||
$ apropos locate
|
||||
blkid (8) - locate/print block device attributes
|
||||
deallocvt (1) - deallocate unused virtual consoles
|
||||
fallocate (1) - preallocate or deallocate space to a file
|
||||
IO::Tty (3pm) - Low-level allocate a pseudo-Tty, import constants.
|
||||
locate (1) - find files by name
|
||||
mlocate (1) - find files by name
|
||||
mlocate.db (5) - a mlocate database
|
||||
mshowfat (1) - shows FAT clusters allocated to file
|
||||
ntfsfallocate (8) - preallocate space to a file on an NTFS volume
|
||||
systemd-sysusers (8) - Allocate system users and groups
|
||||
systemd-sysusers.service (8) - Allocate system users and groups
|
||||
updatedb (8) - update a database for mlocate
|
||||
updatedb.mlocate (8) - update a database for mlocate
|
||||
whereis (1) - locate the binary, source, and manual page files for a...
|
||||
which (1) - locate a command
|
||||
|
||||
```
|
||||
|
||||
### 总结
|
||||
|
||||
Linux 上可用于查找和识别文件的命令有很多种,但它们都非常有用。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3268768/linux/finding-what-you-re-looking-for-on-linux.html
|
||||
|
||||
作者:[Sandra Henry-Stocker][a]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.networkworld.com/author/Sandra-Henry_Stocker/
|
||||
[1]:http://www.networkworld.com/article/2926630/linux/11-pointless-but-awesome-linux-terminal-tricks.html#tk.nww-fsb
|
@ -0,0 +1,93 @@
|
||||
使用交互式 shell 来增强你的 Python
|
||||
======
|
||||

|
||||
Python 编程语言已经成为 IT 中使用的最流行的语言之一。成功的一个原因是它可以用来解决各种问题。从网站开发到数据科学、机器学习到任务自动化,Python 生态系统有丰富的框架和库。本文将介绍 Fedora 软件包集合中提供的一些有用的 Python shell 来简化开发。
|
||||
|
||||
### Python Shell
|
||||
|
||||
Python Shell 让你以交互模式使用解释器。在测试代码或尝试新库时非常有用。在 Fedora 中,你可以通过在终端会话中输入 python3 来调用默认的 shell。虽然 Fedora 提供了一些更高级和增强的 shell。
|
||||
|
||||
### IPython
|
||||
|
||||
IPython 为 Python shell 提供了许多有用的增强功能。例子包括 tab 补全,对象内省,系统 shell 访问和命令历史检索。许多功能也被 [Jupyter Notebook][1] 使用,因为它底层使用 IPython。
|
||||
|
||||
#### 安装和运行 IPython
|
||||
```
|
||||
dnf install ipython3
|
||||
ipython3
|
||||
|
||||
```
|
||||
|
||||
使用 tab 补全会提示你可能的选择。当你使用不熟悉的库时,此功能会派上用场。
|
||||
|
||||
![][2]
|
||||
|
||||
如果你需要更多信息,输入 ? 命令使用文档。有关更多详细信息,你可以使用 ?? 命令。
|
||||
|
||||
![][3]
|
||||
|
||||
另一个很酷的功能是使用 ! 字符执行系统 shell 命令的能力。然后可以在 IPython shell 中引用该命令的结果。
|
||||
|
||||
![][4]
|
||||
|
||||
IPython 完整的功能列表可在[官方文档][5]中找到。
|
||||
|
||||
### bpython
|
||||
|
||||
bpython 并不能像 IPython 做那么多,但它却在一个简单轻量级包中提供了一系列有用功能。除其他功能之外,bpython 提供:
|
||||
|
||||
* 内嵌语法高亮显示
|
||||
* 在你输入时提供自动补全建议
|
||||
* 可预期的参数列表
|
||||
* 能够将代码发送或保存到 pastebin 服务或文件中
|
||||
|
||||
|
||||
|
||||
#### 安装和运行 bpython
|
||||
```
|
||||
dnf install bpython3
|
||||
bpython3
|
||||
|
||||
```
|
||||
|
||||
在你输入的时候,bpython 为你提供了选择来自动补全你的代码。
|
||||
|
||||
![][6]
|
||||
|
||||
当你调用函数或方法时,会自动显示需要的参数和文档字符串。
|
||||
|
||||
![][7]
|
||||
|
||||
另一个很好的功能是可以使用功能键 F7 在外部编辑器(默认为 Vim)中打开当前的 bpython 会话。这在测试更复杂的程序时非常有用。
|
||||
|
||||
有关配置和功能的更多细节,请参考 bpython [文档][8]。
|
||||
|
||||
### 总结
|
||||
|
||||
使用增强的 Python shell 是提高生产力的好方法。它为你提供增强的功能来编写快速原型或尝试新库。你在使用增强的 Python shell 吗?请随意在评论区留言。
|
||||
|
||||
图片由 [David Clode][9] 在 [Unsplash][10] 上发布
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/enhance-python-interactive-shell/
|
||||
|
||||
作者:[Clément Verna][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://fedoramagazine.org/author/cverna/
|
||||
[1]:https://ipython.org/notebook.html
|
||||
[2]:https://fedoramagazine.org/wp-content/uploads/2018/03/ipython-tabcompletion.png
|
||||
[3]:https://fedoramagazine.org/wp-content/uploads/2018/03/ipyhton_doc1.png
|
||||
[4]:https://fedoramagazine.org/wp-content/uploads/2018/03/ipython_shell.png
|
||||
[5]:https://ipython.readthedocs.io/en/stable/overview.html#main-features-of-the-interactive-shell
|
||||
[6]:https://fedoramagazine.org/wp-content/uploads/2018/03/bpython1.png
|
||||
[7]:https://fedoramagazine.org/wp-content/uploads/2018/03/bpython2.png
|
||||
[8]:https://docs.bpython-interpreter.org/
|
||||
[9]:https://unsplash.com/photos/d0CasEMHDQs?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
||||
[10]:https://unsplash.com/search/photos/python?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
@ -0,0 +1,87 @@
|
||||
在 Linux 中轻松搜索和安装 Google Web 字体
|
||||
======
|
||||
|
||||

|
||||
**Font Finder** 是旧的 [**Typecatcher**][1] 的 Rust 实现,用于从[**Google 的字体存档**][2]中轻松搜索和安装 Google Web 字体。它可以帮助你在 Linux 桌面上安装数百种免费和开源字体。如果你正在为你的 Web 项目和应用以及其他任何地方寻找好看的字体,Font Finder 可以轻松地为你提供。它是用 Rust 编程语言编写的免费开源 GTK3 应用程序。与使用 Python 编写的 Typecatcher 不同,Font Finder 可以按类别过滤字体,没有 Python 运行时依赖关系,并且有更好的性能和资源消耗。
|
||||
|
||||
在这个简短的教程中,我们将看到如何在 Linux 中安装和使用 Font Finder。
|
||||
|
||||
### 安装 Font Finder
|
||||
|
||||
由于 Fond Finder 是使用 Rust 语言编写的,因此你需要向下面描述的那样在系统中安装 Rust。
|
||||
|
||||
安装 Rust 后,运行以下命令安装 Font Finder:
|
||||
```
|
||||
$ cargo install fontfinder
|
||||
|
||||
```
|
||||
|
||||
Font Finder 也可以从 [**flatpak app**][3] 安装。首先在你的系统中安装 Flatpak,如下面的链接所述。
|
||||
|
||||
然后,使用命令安装 Font Finder:
|
||||
```
|
||||
$ flatpak install flathub io.github.mmstick.FontFinder
|
||||
|
||||
```
|
||||
|
||||
### 在 Linux 中使用 Font Finder 搜索和安装 Google Web 字体
|
||||
|
||||
你可以从程序启动器启动 Font Finder,也可以运行以下命令启动它。
|
||||
```
|
||||
$ flatpak run io.github.mmstick.FontFinder
|
||||
|
||||
```
|
||||
|
||||
这是 Font Finder 默认界面的样子。
|
||||
|
||||
![][5]
|
||||
|
||||
正如你所看到的,Font Finder 的用户界面非常简单。所有 Google Web 字体都列在左侧窗格中,相应字体的预览显示在右侧窗格中。你可以在预览框中输入任何单词以查看单词在所选字体中的外观。在左上方还有一个搜索框,可以让你快速搜索你选择的字体。
|
||||
|
||||
默认情况下,Font Finder 显示所有类型的字体。但是,你可以通过搜索框上方的类别下拉框中的分类显示字体。
|
||||
|
||||
![][6]
|
||||
|
||||
要安装字体,只需选择它并点击顶部的 **Install** 按钮即可。
|
||||
|
||||
![][7]
|
||||
|
||||
你可以在任何文本处理程序中测试新安装的字体。
|
||||
|
||||
![][8]
|
||||
|
||||
同样,要删除字体,只需从 Font Finder 面板中选择它并单击 **Uninstall** 按钮。就这么简单!
|
||||
|
||||
左上角的设置按钮(齿轮按钮)提供了切换到暗色预览的选项。
|
||||
|
||||
![][9]
|
||||
|
||||
如你所见,Font Finder 非常简单,完全可以像在主页上宣传的那样完成工作。如果你正在寻找安装 Google Web 字体的程序,Font Finder 就是这样的一个程序。
|
||||
|
||||
今天就是这些。希望这有帮助。还有更好的东西。敬请关注!
|
||||
|
||||
干杯!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/font-finder-easily-search-and-install-google-web-fonts-in-linux/
|
||||
|
||||
作者:[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/install-google-web-fonts-ubuntu/
|
||||
[2]:https://fonts.google.com/
|
||||
[3]:https://flathub.org/apps/details/io.github.mmstick.FontFinder
|
||||
[4]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[5]:http://www.ostechnix.com/wp-content/uploads/2018/04/font-finder-1.png
|
||||
[6]:http://www.ostechnix.com/wp-content/uploads/2018/04/font-finder-2.png
|
||||
[7]:http://www.ostechnix.com/wp-content/uploads/2018/04/font-finder-3.png
|
||||
[8]:http://www.ostechnix.com/wp-content/uploads/2018/04/font-finder-5.png
|
||||
[9]:http://www.ostechnix.com/wp-content/uploads/2018/04/font-finder-4.png
|
@ -0,0 +1,81 @@
|
||||
在 5 分钟内重置丢失的 root 密码
|
||||
======
|
||||
|
||||

|
||||
|
||||
系统管理员可以轻松地为忘记密码的用户重置密码。但是如果系统管理员忘记 root 密码或离开公司,会发生什么情况?本指南将向你介绍如何在不到 5 分钟的时间内在 Red Hat 兼容系统(包括 Fedora 和 CentOS)上重置丢失或忘记的 root 密码。
|
||||
|
||||
请注意,如果整个系统硬盘已用 LUKS 加密,则需要在出现提示时提供 LUKS 密码。此外,此过程适用于运行 systemd 的系统,该系统自 Fedora 15、CentOS 7.14.04 和 Red Hat Enterprise Linux 7.0 以来一直是缺省的初始系统。。
|
||||
|
||||
首先你需要终端启动的过程,因此你需要启动或者如果已经启动就重启它。第一步可能有点棘手因为 GRUB 菜单会在屏幕上快速地闪烁过去。你可能需要尝试几次,直到你能够做到这一点。
|
||||
|
||||
当你看到这个屏幕时,按下键盘上的 **e** 键:
|
||||
|
||||

|
||||
|
||||
如果你正确地做了这点,你应该看到一个类似于这个的屏幕:
|
||||
|
||||

|
||||
|
||||
使用箭头键移动到 Linux16 这行:
|
||||
|
||||

|
||||
|
||||
使用你的 **del** 键或你的 **backspace** 键,删除 `rhgb quiet` 并替换为以下内容:
|
||||
|
||||
`rd.break enforcing=0`
|
||||
|
||||

|
||||
|
||||
设置 `enforcing=0` 可以避免执行完整的系统 SELinux 重标记。一旦系统重新启动,你只需要为 `/etc/shadow` 恢复正确的 SELinux 上下文。我会告诉你如何做到这一点。
|
||||
|
||||
按下 **Ctrl-x** 启动。
|
||||
|
||||
**系统现在将处于紧急模式。**
|
||||
|
||||
以读写权限重新挂载硬盘驱动器:
|
||||
```
|
||||
# mount –o remount,rw /sysroot
|
||||
|
||||
```
|
||||
|
||||
运行 `chroot` 来访问系统:
|
||||
```
|
||||
# chroot /sysroot
|
||||
|
||||
```
|
||||
|
||||
你现在可以更改 root 密码:
|
||||
```
|
||||
# passwd
|
||||
|
||||
```
|
||||
|
||||
出现提示时,输入新的 root 密码两次。如果成功,你应该看到一条消息显示 “**all authentication tokens updated successfully**”。
|
||||
|
||||
输入 **exit** 两次以重新启动系统。
|
||||
|
||||
Log in as root and restore the SELinux label to the `/etc/shadow` file.
|
||||
以 root 身份登录并将 SELinux 标签恢复到 `/etc/shadow` 。
|
||||
```
|
||||
# restorecon -v /etc/shadow
|
||||
|
||||
```
|
||||
|
||||
将 SELinux 回到 enforce 模式:
|
||||
```
|
||||
# setenforce 1
|
||||
|
||||
```
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/4/reset-lost-root-password
|
||||
|
||||
作者:[Curt Warfield][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://opensource.com/users/rcurtiswarfield
|
@ -0,0 +1,91 @@
|
||||
如何在任何地方使用 Vim 编辑器输入文本
|
||||
======
|
||||

|
||||
|
||||
各位Vim使用者大家好!今天,我这里有个好消息告诉大家。我会向大家介绍 **Vim-anywhere**,这是一个简单的脚本,它允许你使用 Vim 编辑器在 Linux 中的任何地方输入文本。这意味着你能简单地调用自己最爱的 Vim 编辑器,输入任何你所想的,并将这些文本粘贴到任意的应用和网站中。这些文本将在剪贴板可用,直到你重启了系统。这个工具对那些喜欢在非 Vim 环境中使用 Vim 键位绑定的人来说十分有用。
|
||||
|
||||
### 在 Linux 中安装 Vim-anywhere
|
||||
Vim-anywhere 工具可以运行在任何基本 GNOME(或其他衍生品)的 Linux 发行版上。另外,确保你已经安装了下面的依赖。
|
||||
|
||||
* Curl
|
||||
* Git
|
||||
* gVim
|
||||
* xclip
|
||||
|
||||
|
||||
比如,你可以用下面的命令在 Ubuntu 中安装这些工具:
|
||||
```
|
||||
$ sudo apt install curl git vim-gnome xclip
|
||||
|
||||
```
|
||||
然后运行如下的命令来安装 Vim-anywhere:
|
||||
```
|
||||
$ curl -fsSL https://raw.github.com/cknadler/vim-anywhere/master/install | bash
|
||||
|
||||
```
|
||||
Vim-anywhere 到此已经安装完成。现在我们来看看如何使用它。
|
||||
### 在任何地方使用 Vim 编辑器输入文本
|
||||
假如你需要创建一个 word 文档。但是你更愿意使用 Vim 编辑器,而不是 LibreOffice。没问题,这里 Vim-anywhere 就派上用场了。Vim-anywhere 自动化了整个流程。它仅仅简单地调用 Vim 编辑器,所以你能写任何你所想的,然后将之粘贴到 .doc 文件中。
|
||||
|
||||
让我给你展示一个用例。打开 LibreOffice 或者你选的任何图形文本编辑器。然后打开 Vim-anywhere。你只需要按下 **CTRL+ALT+V** 即可。它将会打开 gVim 编辑器。按下"i"切换到交互模式然后输入文本。完成之后,键入 **:wq** 关闭并保存文件。
|
||||
|
||||
![][2]
|
||||
|
||||
这些文本会在剪贴板中可用,直到你重启了系统。在你关闭编辑器之后,你之前的应用会重新占据主界面。你只需按下 **CTRL+P** 将文本粘贴进去。
|
||||
|
||||
![][3]
|
||||
|
||||
这仅仅只是一个例子。你甚至可以使用 Vim-anywhere 在烦人的 web 表单或者其他应用上进行输入。一旦 Vim-anywhere被调用,它将会打开一个缓冲区。关闭 Vim-anywhere之后,缓冲器内的内容会自动复制到你的剪贴板中,之前的应用会重新占据主界面。
|
||||
|
||||
Vim-anywhere 在被调用的时候会在 **/tmp/vim-anywhere** 中创建一个临时文件。这些临时文件会一致保存着,直到你重启了系统,并为你提供临时的历史记录。
|
||||
```
|
||||
$ ls /tmp/vim-anywhere
|
||||
|
||||
```
|
||||
你可以用下面的命令重新打开最近的文件:
|
||||
```
|
||||
$ vim $( ls /tmp/vim-anywhere | sort -r | head -n 1 )
|
||||
|
||||
```
|
||||
**更新 Vim-anywhere **
|
||||
|
||||
运行下面的命令来更新 Vim-anywhere:
|
||||
```
|
||||
$ ~/.vim-anywhere/update
|
||||
|
||||
```
|
||||
|
||||
**更改快捷键**
|
||||
|
||||
默认调用 Vim-anywhere 的键位是 CTRL+ALT+V。你可以用 gconf 工具将其更改为任何自定义的键位绑定。
|
||||
```
|
||||
$ gconftool -t str --set /desktop/gnome/keybindings/vim-anywhere/binding <custom binding>
|
||||
|
||||
```
|
||||
|
||||
**卸载 Vim-anywhere**
|
||||
|
||||
可能有些人觉得每次打开Vim编辑器,输入一些文本,然后将文本复制到其他应用中是没有意义也毫无必要的。
|
||||
|
||||
如果你不觉得这个工具有用,只需使用下面的命令来卸载它:
|
||||
```
|
||||
$ ~/.vim-anywhere/uninstall
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/how-to-use-vim-editor-to-input-text-anywhere/
|
||||
|
||||
作者:[SK][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[paperzhang](https://github.com/paperzhang)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.ostechnix.com/author/sk/
|
||||
[2]:http://www.ostechnix.com/wp-content/uploads/2018/05/vim-anywhere-1-1.png
|
||||
[3]:http://www.ostechnix.com/wp-content/uploads/2018/05/vim-anywhere-2.png
|
@ -1,36 +1,35 @@
|
||||
zzupdate - Single Command To Upgrade Ubuntu
|
||||
zzupdate —— 升级 Ubuntu 的简单命令
|
||||
======
|
||||
Ubuntu 18.04 was already out and got good feedback from multiple community because Ubuntu 18.04 is the most exciting release of Ubuntu in years.
|
||||
Ubuntu 18.04 版本已经发布,并得到各个社区的一致好评,因为 Ubuntu 18.04 可能是 Ubuntu 多年来最令人兴奋的版本。
|
||||
|
||||
By default Ubuntu and it’s derivatives can be upgraded from one version to another version using standard commands, which is official and recommended way to upgrade the system to latest version.
|
||||
通常情况下,Ubuntu 及其衍生版可以使用命令从一个版本升级到最新版本或者其它版本,这也是官方推荐的升级方式。
|
||||
|
||||
### Ubuntu 18.04 Features/Highlights
|
||||
### Ubuntu 18.04 特性/亮点
|
||||
|
||||
This release is contains vast of improvement and features and i picked only major things. Navigate to [Ubuntu 18.04 official][1] release page, if you want to know more detailed release information.
|
||||
这次更新包含大量改进和新功能,这里只列举的几个主要的。如果您想要更详细的更新信息,请访问 [Ubuntu 18.04 官方][1] 页面。
|
||||
|
||||
* It ships with Linux kernel 4.15, which delivers new features inherited from upstream.
|
||||
* It feature the latest GNOME 3.28
|
||||
* It offers minimal install option similar to RHEL, this allow users to install basic desktop environment with a web browser and core system utilities.
|
||||
* For new installs, a swap file will be used by default instead of a swap partition.
|
||||
* You can enable Livepatch to install Kernel updates without rebooting.
|
||||
* laptops will automatically suspend after 20 minutes of inactivity while on battery power
|
||||
* 32-bit installer images are no longer provided for Ubuntu Desktop
|
||||
- 使用 Linux 4.15 内核,提供了从上游继承的新功能
|
||||
- 它具有最新版本的 GNOME 3.28
|
||||
- 它提供了与 RHEL 相似的最简安装选项,该选项可安装只包含一个 web 浏览器和核心系统程序的基本桌面环境
|
||||
- 对于新安装,交换文件将取代默认的交换分区
|
||||
- 您可以启用 Livepatch 安装内核更新而无需重新启动
|
||||
- 笔记本电脑在使用电池供电时会在无操作 20 分钟后自动待机
|
||||
- 不再提供 32 位的 Ubuntu 桌面安装程序映像
|
||||
|
||||
|
||||
**注意:**
|
||||
1. 不要忘记备份重要数据。如果升级出现问题,我们将重新安装并恢复数据。
|
||||
2. 安装所需时间取决于您的网络状况和安装的程序。
|
||||
|
||||
**Note :**
|
||||
1) Don’t forget to take backup of your important/valuable data. If something goes wrong we will install freshly and restore the data.
|
||||
2) Upgrade will take time based on your Internet connection and application which you have installed.
|
||||
### zzupdate 是什么?
|
||||
|
||||
### What Is zzupdate?
|
||||
我们可以通过使用 [zzupdate][2] 工具中的单个命令将 Ubuntu PC/Server 从一个版本升级到另一个版本。它是一个免费的开源工具,使用它不需要任何脚本知识,因为它只需要配置文件即可运行。
|
||||
|
||||
We can upgrade Ubuntu PC/Server from one version to another version with just a single command using [zzupdate][2] utility. It’s a free and open source utility and it doesn’t required any scripting knowledge to work on this because it’s purely configfile-driven script.
|
||||
工具中提供两个默认 shell 文件。`setup.sh` 自动安装、更新代码,将脚本转换为一个简单的 zzupdate shell 命令。`zzupdate.sh` 将执行版本间的升级。
|
||||
|
||||
There were two shell files are available in the utility, which make the utility to do the work as expected. The provided setup.sh auto-installs/updates the code and makes the script available as a new, simple shell command (zzupdate). The zzupdate.sh will do the actual upgrade from one version to next available version.
|
||||
### 如何安装 zzipdate?
|
||||
|
||||
### How To Install zzupdate?
|
||||
|
||||
To install zzupdate, just execute the following command.
|
||||
要安装 zzupdate,只需执行以下命令。
|
||||
```
|
||||
$ curl -s https://raw.githubusercontent.com/TurboLabIt/zzupdate/master/setup.sh | sudo sh
|
||||
.
|
||||
@ -50,21 +49,21 @@ See https://github.com/TurboLabIt/zzupdate for the quickstart guide.
|
||||
|
||||
```
|
||||
|
||||
To upgrade the Ubuntu system from one version to another version, you don’t want to run multiple commands and also no need to initiate the reboot. Just fire the below zzupdate command and sit back rest it will take care.
|
||||
将 Ubuntu 系统从一个版本升级到另一个版本,您不需要输入很多命令,也不需要重新启动,只需要运行下面的 zzupdate 命令并坐下喝杯咖啡就可以了。
|
||||
|
||||
Make a note, When you are upgrading the remote system, i would advise you to use any of the one below utility because it will help you to reconnect the session in case of any disconnection.
|
||||
请注意,当您远程升级系统时,建议您使用以下的工具来帮助您在任何断开连接时重新连接会话。
|
||||
|
||||
**Suggested Read :** [How To Keep A Process/Command Running After Disconnecting SSH Session][3]
|
||||
**建议阅读:** [如何让一个进程/命令在 SSH 连接断开后继续运行][3]
|
||||
|
||||
### How To Configure zzupdate [optional]
|
||||
### 如何配置 zzupdate(可选)
|
||||
|
||||
By default zzupdate works out of the box and no need to configure anything. It’s optional and if you want to configure something yes, you can. To do so, copy the provided sample configuration file `zzupdate.default.conf` to your own `zzupdate.conf` and set your preference.
|
||||
默认情况下,zzupdate 可以直接使用,不需要配置任何东西。当然,如果您想要自己配置一些内容,可以的。复制提供的实例配置文件 `zzupdate.default.conf` 到 `zzupdate.conf` 并在 `zzupdate.conf` 中配置您的首选项。
|
||||
```
|
||||
$ sudo cp /usr/local/turbolab.it/zzupdate/zzupdate.default.conf /etc/turbolab.it/zzupdate.conf
|
||||
|
||||
```
|
||||
|
||||
Open the file and the default values are below.
|
||||
打开文件,默认配置如下。
|
||||
```
|
||||
$ sudo nano /etc/turbolab.it/zzupdate.conf
|
||||
|
||||
@ -77,16 +76,16 @@ SWITCH_PROMPT_TO_NORMAL=0
|
||||
|
||||
```
|
||||
|
||||
* **`REBOOT=1 :`**System will automatically reboot once upgrade is done.
|
||||
* **`REBOOT_TIMEOUT=15 :`**Default time out value for reboot.
|
||||
* **`VERSION_UPGRADE=1 :`**It perform version upgrade from one version to another.
|
||||
* **`VERSION_UPGRADE_SILENT=0 :`**It disable automatic upgrade perform version upgrade from one version to another.
|
||||
* **`COMPOSER_UPGRADE=1 :`**This will automatically upgrade the composer.
|
||||
* **`SWITCH_PROMPT_TO_NORMAL=0 :`**If it’s “0” then it looks for same kind of version upgrade. If you are running on LTS version then it will looking for LTS version upgrade and not for the normal release upgrade. If it’s “1” then it looks for the latest release whether you are running an LTS or a normal release.
|
||||
* **`REBOOT=1 :`**系统在更新完成后自动重启
|
||||
* **`REBOOT_TIMEOUT=15 :`**重启的默认超时值
|
||||
* **`VERSION_UPGRADE=1 :`**执行从一个版本到另一个版本的版本升级
|
||||
* **`VERSION_UPGRADE_SILENT=0 :`**禁用自动升级
|
||||
* **`COMPOSER_UPGRADE=1 :`**自动升级
|
||||
* **`SWITCH_PROMPT_TO_NORMAL=0 :`**如果值为 `0`,将寻找相同种类的版本升级。例如您正在运行 LTS 的版本,那么将寻找 LTS 的版本升级,而不是用于正常版本升级。如果值为 `1`,那么无论您是运行 LTS 还是正常版本,都会查找最新版本
|
||||
|
||||
|
||||
|
||||
I’m currently running Ubuntu 17.10 and see the details.
|
||||
我现在使用 Ubuntu 17.10 并查看详细信息。
|
||||
```
|
||||
$ cat /etc/*-release
|
||||
DISTRIB_ID=Ubuntu
|
||||
@ -108,7 +107,7 @@ UBUNTU_CODENAME=artful
|
||||
|
||||
```
|
||||
|
||||
To upgrade the Ubuntu to latest release, just execute the below command.
|
||||
要升级 Ubuntu 到最新版本,只需要执行以下命令。
|
||||
```
|
||||
$ sudo zzupdate
|
||||
|
||||
@ -185,7 +184,7 @@ Reading state information... Done
|
||||
|
||||
```
|
||||
|
||||
We need to disable `Third Party` repository by hitting the `Enter` button to move forward the upgrade.
|
||||
我们需要按下 `Enter` 按钮禁用 `Third Party` 仓库以继续升级。
|
||||
```
|
||||
Updating repository information
|
||||
|
||||
@ -213,7 +212,7 @@ Calculating the changes
|
||||
|
||||
```
|
||||
|
||||
Start Downloading the `Ubuntu 18.04 LTS` packages, It will take a while based on your Internet connection. Its time to have a cup of coffee.
|
||||
开始下载 `Ubuntu 18.04 LTS` 软件包,所需时间取决于您的网络状况,一般情况下这将需要几分钟。
|
||||
```
|
||||
Do you want to start the upgrade?
|
||||
|
||||
@ -248,7 +247,7 @@ Fetched 999 MB in 6s (721 kB/s)
|
||||
|
||||
```
|
||||
|
||||
Few services need to be restart, While installing new packages. Hit `Yes` button, it will automatically restart the required services.
|
||||
安装新软件包时,很少有服务需要重新启动。 点击 `Yes` 按钮,它会自动重启所需的服务。
|
||||
```
|
||||
Upgrading
|
||||
Inhibiting until Ctrl+C is pressed...
|
||||
@ -280,7 +279,7 @@ Progress: [ 95%]
|
||||
|
||||
```
|
||||
|
||||
It’s time to remove obsolete (Which is anymore needed for system) packages. Hit `y` to remove it.
|
||||
现在删除旧版的、系统不再需要的包。点击 `y` 以删除。
|
||||
```
|
||||
Searching for obsolete software
|
||||
ing package lists... 97%
|
||||
@ -313,7 +312,7 @@ Fetched 0 B in 0s (0 B/s)
|
||||
|
||||
```
|
||||
|
||||
Upgrade is successfully completed and need to restart the system. Hit `Y` to restart the system.
|
||||
升级成功,需要重启系统。点击 `Y` 以重启系统。
|
||||
```
|
||||
System upgrade is complete.
|
||||
|
||||
@ -326,9 +325,9 @@ Continue [yN]y
|
||||
|
||||
```
|
||||
|
||||
**`Note :`** Few times, it will ask you to confirm the configuration file replacement to move forward the installation.
|
||||
**注意:** 少数情况下,会要求您确认配置文件替换以继续安装。
|
||||
|
||||
See the upgraded system details.
|
||||
查看升级后的系统详情。
|
||||
```
|
||||
$ cat /etc/*-release
|
||||
DISTRIB_ID=Ubuntu
|
||||
@ -356,7 +355,7 @@ via: https://www.2daygeek.com/zzupdate-single-command-to-upgrade-ubuntu-18-04/
|
||||
|
||||
作者:[PRAKASH SUBRAMANIAN][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[XiatianSummer](https://github.com/XiatianSummer)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
@ -0,0 +1,135 @@
|
||||
如何使用 Buildah 构建容器镜像
|
||||
======
|
||||
|
||||

|
||||
|
||||
Project Atomic 通过他们在 Open Container Initiative(OCI)上的努力创造了一个名为 [Buildah][1] 的伟大工具。Buildah 能帮助创建、构建和更新,它支持 Docker 容器镜像以及 OCI 兼容镜像。
|
||||
|
||||
Buildah 处理构建容器镜像时无需安装完整的容器运行时或守护进程。这对建立容器的持续集成和持续交付管道尤其有用。
|
||||
|
||||
Buildah 使容器的文件系统可以直接供构建主机使用。这意味着构建工具在主机上可用,并且在容器镜像中不需要,从而使构建更快速,镜像更小,更安全。Buildah 有 CentOS、Fedora 和 Debian 的软件包。
|
||||
|
||||
### 安装 Buildah
|
||||
|
||||
从 Fedora 26 开始 Buildah 可以使用 dnf 进行安装。
|
||||
```
|
||||
$ sudo dnf install buildah -y
|
||||
|
||||
```
|
||||
|
||||
buildah 的当前版本为 0.16,可以通过以下命令显示。
|
||||
```
|
||||
$ buildah --version
|
||||
|
||||
```
|
||||
|
||||
### 基本命令
|
||||
|
||||
构建容器镜像的第一步是获取基础镜像,这是通过 Dockerfile 中的 FROM 语句完成的。Buildah 以类似的方式处理这个。
|
||||
```
|
||||
$ sudo buildah from fedora
|
||||
|
||||
```
|
||||
|
||||
该命令将拉取 Fedora 的基础镜像并存储在主机上。通过执行以下操作可以检查主机上可用的镜像。
|
||||
```
|
||||
$ sudo buildah images
|
||||
IMAGE ID IMAGE NAME CREATED AT SIZE
|
||||
9110ae7f579f docker.io/library/fedora:latest Mar 7, 2018 20:51 234.7 MB
|
||||
|
||||
```
|
||||
|
||||
在拉取基础镜像后,有一个该镜像的运行容器实例,这是一个“工作容器”。
|
||||
|
||||
以下命令显示正在运行的容器。
|
||||
```
|
||||
$ sudo buildah containers
|
||||
CONTAINER ID BUILDER IMAGE ID IMAGE NAME
|
||||
CONTAINER NAME
|
||||
6112db586ab9 * 9110ae7f579f docker.io/library/fedora:latest fedora-working-container
|
||||
|
||||
```
|
||||
|
||||
Buildah 还提供了一个非常有用的命令来停止和删除当前正在运行的所有容器。
|
||||
```
|
||||
$ sudo buildah rm --all
|
||||
|
||||
```
|
||||
|
||||
完整的命令列表可以使用 -help 选项。
|
||||
```
|
||||
$ buildah --help
|
||||
|
||||
```
|
||||
|
||||
### 构建一个 Apache Web 服务器容器镜像
|
||||
|
||||
让我们看看如何使用 Buildah 在 Fedora 基础镜像上安装 Apache Web 服务器,然后复制一个可供服务的自定义 index.html。
|
||||
|
||||
首先让我们创建自定义的 index.html。
|
||||
```
|
||||
$ echo "Hello Fedora Magazine !!!" > index.html
|
||||
|
||||
```
|
||||
|
||||
然后在正在运行的容器中安装 httpd 包。
|
||||
```
|
||||
$ sudo buildah from fedora
|
||||
$ sudo buildah run fedora-working-container dnf install httpd -y
|
||||
|
||||
```
|
||||
|
||||
让我们将 index.html 复制到 /var/www/html/。
|
||||
```
|
||||
$ sudo buildah copy fedora-working-container index.html /var/www/html/index.html
|
||||
|
||||
```
|
||||
|
||||
然后配置容器入口点以启动 httpd。
|
||||
```
|
||||
$ sudo buildah config --entrypoint "/usr/sbin/httpd -DFOREGROUND" fedora-working-container
|
||||
|
||||
```
|
||||
|
||||
现在为了使“工作容器”可用,commit 命令将容器保存到镜像。
|
||||
```
|
||||
$ sudo buildah commit fedora-working-container hello-fedora-magazine
|
||||
|
||||
```
|
||||
|
||||
hello-fedora-magazine 镜像现在可用,并且可以推送到仓库以供使用。
|
||||
```
|
||||
$ sudo buildah images
|
||||
IMAGE ID IMAGE NAME CREATED
|
||||
AT SIZE
|
||||
9110ae7f579f docker.io/library/fedora:latest
|
||||
Mar 7, 2018 22:51 234.7 MB
|
||||
49bd5ec5be71 docker.io/library/hello-fedora-magazine:latest
|
||||
Apr 27, 2018 11:01 427.7 MB
|
||||
|
||||
```
|
||||
|
||||
通过运行以下步骤,还可以使用 Buildah 来测试此镜像。
|
||||
```
|
||||
$ sudo buildah from --name=hello-magazine docker.io/library/hello-fedora-magazine
|
||||
|
||||
$ sudo buildah run hello-magazine
|
||||
|
||||
```
|
||||
|
||||
访问 <http://localhost> 将显示 “Hello Fedora Magazine !!!”
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/daemon-less-container-management-buildah/
|
||||
|
||||
作者:[Ashutosh Sudhakar Bhakare][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://fedoramagazine.org/author/ashutoshbhakare/
|
||||
[1]:https://github.com/projectatomic/buildah
|
Loading…
Reference in New Issue
Block a user