Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu.Wang 2018-11-25 10:10:54 +08:00
commit 67bef69f4d
15 changed files with 1173 additions and 768 deletions

View File

@ -1,18 +1,27 @@
language: c
language: minimal
install:
- sudo apt-get install jq
- git clone --depth=1 -b gh-pages https://github.com/LCTT/TranslateProject/ build && rm -rf build/.git
script:
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then sh ./scripts/check.sh; fi'
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sh ./scripts/badge.sh; fi'
- 'if [ "$TRAVIS_EVENT_TYPE" = "cron" ]; then sh ./scripts/status.sh; fi'
branches:
only:
- master
# - status
except:
- gh-pages
git:
submodules: false
depth: false
deploy:
provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN
local_dir: build
on:
branch: master
branch:
- master
# - status

View File

@ -1,256 +1,189 @@
如何使用 Emacs 创建 LaTeX 文档
======
> 这篇教程将带你遍历在 Emacs 使用强大的开源排版系统 LaTex 来创建文档的全过程。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/email_paper_envelope_document.png?itok=uPj_kouJ)
一篇由 Aaron Cocker 写的很棒的文章 [An introduction to creating documents in LaTeX][1] 中,介绍了 LaTeX 排版系统 [LaTeX typesetting system][3] 并描述了如何使用 [TeXstudio][4] 来创建 LaTeX 文档。同时,他也列举了一些很多用户觉得创建 LaTeX 文档很方便的编辑器。
一篇由 Aaron Cocker 写的很棒的文章 “[在 LaTeX 中创建文件的介绍][1]” 中,介绍了 [LaTeX 排版系统][3] 并描述了如何使用 [TeXstudio][4] 来创建 LaTeX 文档。同时,他也列举了一些很多用户觉得创建 LaTeX 文档很方便的编辑器。
[Greg Pittman][5] 对这篇文章的评论吸引了我:“当你第一次开始使用 LaTeX 时,他似乎是个和差劲的排版。。。” 事实也确实如此。LaTeX 包含了多种排版字体和调试,如果你漏了一个特殊的字符比如说感叹号,这会阻碍很多用户,尤其是新手。在本文中,我将介绍如何使用 [GNU Emacs][6] 来创建 LaTeX 文档。
[Greg Pittman][5] 对这篇文章的评论吸引了我:“当你第一次开始使用 LaTeX 时,他似乎是个很差劲的排版……” 事实也确实如此。LaTeX 包含了多种排版字体和调试,如果你漏了一个特殊的字符比如说感叹号,这会让很多用户感到沮丧,尤其是新手。在本文中,我将介绍如何使用 [GNU Emacs][6] 来创建 LaTeX 文档。
### 创建你的第一个文档
启动 Emacs:
启动 Emacs
```
emacs -q --no-splash helloworld.org
```
参数 `-q` 确保 Emacs 不会加载其他的初始化配置。参数 `--no-splash-screen` 防止 emacs 打开多个窗口,确保只打开一个窗口,最后的参数 `helloworld.org` 表示你要创建的文件名为 `helloworld.org`
参数 `-q` 确保 Emacs 不会加载其他的初始化配置。参数 `--no-splash-screen` 防止 Emacs 打开多个窗口,确保只打开一个窗口,最后的参数 `helloworld.org` 表示你要创建的文件名为 `helloworld.org`
![Emacs startup screen][8]
GNU Emacs 打开文件名为 helloworld.org 的窗口时的样子。
*GNU Emacs 打开文件名为 helloworld.org 的窗口时的样子。*
现在让我们用 Emacs 添加一些 LaTeX 的标题吧: 在菜单栏找到 **Org** 选项并选择 **Export/Publish**.
现在让我们用 Emacs 添加一些 LaTeX 的标题吧:在菜单栏找到 “Org” 选项并选择 “Export/Publish”。
![template_flow.png][10]
导入一个默认的模板:
*导入一个默认的模板*
在下一个窗口中Emacs 同时提供了导入和导出一个模板。使用 #[#] Insert template来导入一个模板。这将会是光标跳转到一个带有 **Options category** 提示的 mini-buffer 中。第一次你可能不知道这个类型的名字,但是你可以使用 Tab 键来查看所有的补全。输入 “default” 然后按回车,之后你就能看到如下的内容被插入了:
在下一个窗口中Emacs 同时提供了导入和导出一个模板。输入 `#`(“[#] Insert template”来导入一个模板。这将会使光标跳转到一个带有 “Options category:” 提示的 mini-buffer 中。第一次你可能不知道这个类型的名字,但是你可以使用 `Tab` 键来查看所有的补全。输入 “default” 然后按回车,之后你就能看到如下的内容被插入了:
```
#+TITLE: helloworld
#+DATE: <2018-03-12 Mon>
#+AUTHOR:
#+EMAIL: makerpm@nubia
#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
#+OPTIONS: author:t c:nil creator:comment d:(not "LOGBOOK") date:t
#+OPTIONS: e:t email:nil f:t inline:t num:t p:nil pri:nil stat:t
#+OPTIONS: tags:t tasks:t tex:t timestamp:t toc:t todo:t |:t
#+CREATOR: Emacs 25.3.1 (Org mode 8.2.10)
#+DESCRIPTION:
#+EXCLUDE_TAGS: noexport
#+KEYWORDS:
#+LANGUAGE: en
#+SELECT_TAGS: export
```
根据自己的需求修改标题,日期,作者和 email。我自己的话是下面这样的
根据自己的需求修改标题、日期、作者和 email。我自己的话是下面这样的
```
#+TITLE: Hello World! My first LaTeX document
#+DATE: \today
#+AUTHOR: Sachin Patil
#+EMAIL: psachin@redhat.com
```
我们目前还不想创建一个目录,所以要将 `toc` 的值由 `t` 改为 `nil`,具体如下:
```
#+OPTIONS: tags:t tasks:t tex:t timestamp:t toc:nil todo:t |:t
```
现在让我们添加一个章节和段落吧。章节是由一个星号(*)开头。我们从 Aaron 的贴子([Lipsum Lorem Ipsum generator][11])复制一些文本过来:
现在让我们添加一个章节和段落吧。章节是由一个星号(`*`)开头。我们从 Aaron 的贴子(来自 [Lipsum Lorem Ipsum 生成器][11])复制一些文本过来:
```
* Introduction
\paragraph{}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras lorem
nisi, tincidunt tempus sem nec, elementum feugiat ipsum. Nulla in
diam libero. Nunc tristique ex a nibh egestas sollicitudin.
  \paragraph{}
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras lorem
  nisi, tincidunt tempus sem nec, elementum feugiat ipsum. Nulla in
  diam libero. Nunc tristique ex a nibh egestas sollicitudin.
  \paragraph{}
  Mauris efficitur vitae ex id egestas. Vestibulum ligula felis,
  pulvinar a posuere id, luctus vitae leo. Sed ac imperdiet orci, non
  elementum leo. Nullam molestie congue placerat. Phasellus tempor et
  libero maximus commodo.
\paragraph{}
Mauris efficitur vitae ex id egestas. Vestibulum ligula felis,
pulvinar a posuere id, luctus vitae leo. Sed ac imperdiet orci, non
elementum leo. Nullam molestie congue placerat. Phasellus tempor et
libero maximus commodo.
```
![helloworld_file.png][13]
helloworld.org 文件
*helloworld.org 文件*
将内容修改好后,我们要把它导出为 PDF 格式。再次在 **Org** 的菜单选项中选择 **Export/Publish**,但是这次,要输入 **l**export to LaTeX紧跟着输入 **o**as PDF file and open)。这次操作不止会打开 PDF 文件让你浏览,同时也会将文件保存为 `helloworld.pdf`,并保存在与 `helloworld.org` 的同一个目录下。
将内容修改好后,我们要把它导出为 PDF 格式。再次在 “Org” 的菜单选项中选择 “Export/Publish”但是这次要输入 `l`“export to LaTeX”紧跟着输入 `o`“as PDF file and open”。这次操作不止会打开 PDF 文件让你浏览,同时也会将文件保存为 `helloworld.pdf`,并保存在与 `helloworld.org` 的同一个目录下。
![org_to_pdf.png][15]
将 helloworld.org 导出为 helloworld.pdf
*将 helloworld.org 导出为 helloworld.pdf*
![org_and_pdf_file.png][17]
打开 helloworld.pdf 文件
*打开 helloworld.pdf 文件*
你也可以按下 `Alt + x` 键,然后输入 “org-latex-export-to-pdf” 来将 org 文件导出为 PDF 文件。可以使用 Tab 键来自动补全命令。
你也可以按下 `Alt + x` 键,然后输入 `org-latex-export-to-pdf` 来将 org 文件导出为 PDF 文件。可以使用 `Tab` 键来自动补全命令。
Emacs 也会创建 `helloworld.tex` 文件来让你控制具体的内容。
![org_tex_pdf.png][19]
Emacs 在三个不同的窗口中分别打开 LaTeXorg 和 PDF 文档。
*Emacs 在三个不同的窗口中分别打开 LaTeXorg 和 PDF 文档。*
你可以使用命令来将 `.tex` 文件转换为 `.pdf` 文件:
```
pdflatex helloworld.tex
```
你也可以将 `.org` 文件输出问HTML或是一个简单的文本格式的文件。我最喜欢 .org 文件的原因是他们可以被 push 到 [GitHub][20] 上,然后被渲染的同 markdown 的一样的格式
你也可以将 `.org` 文件输出为 HTML 或是一个简单的文本格式的文件。我最喜欢 `.org` 文件的原因是他们可以被推送到 [GitHub][20] 上,然后同 markdown 一样被渲染
### 创建一个 LaTeX 的 Beamer presentation
### 创建一个 LaTeX 的 Beamer 简报
现在让我们更进一步,通过少量的修改上面的文档来创建一个 LaTeX [Beamer][21] 简报,如下所示:
现在让我们更进一步,通过少量的修改上面的文档来创建一个 LaTeX [Beamer][21]的 presentation如下所示
```
#+TITLE: LaTeX Beamer presentation
#+DATE: \today
#+AUTHOR: Sachin Patil
#+EMAIL: psachin@redhat.com
#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
#+OPTIONS: author:t c:nil creator:comment d:(not "LOGBOOK") date:t
#+OPTIONS: e:t email:nil f:t inline:t num:t p:nil pri:nil stat:t
#+OPTIONS: tags:t tasks:t tex:t timestamp:t toc:nil todo:t |:t
#+CREATOR: Emacs 25.3.1 (Org mode 8.2.10)
#+DESCRIPTION:
#+EXCLUDE_TAGS: noexport
#+KEYWORDS:
#+LANGUAGE: en
#+SELECT_TAGS: export
#+LATEX_CLASS: beamer
#+BEAMER_THEME: Frankfurt
#+BEAMER_INNER_THEME: rounded
* Introduction
*** Programming
    - Python
    - Ruby
- Python
- Ruby
*** Paragraph one
    Lorem ipsum dolor sit amet, consectetur adipiscing
    elit. Cras lorem nisi, tincidunt tempus sem nec, elementum feugiat
    ipsum. Nulla in diam libero. Nunc tristique ex a nibh egestas
    sollicitudin.
Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Cras lorem nisi, tincidunt tempus sem nec, elementum feugiat
ipsum. Nulla in diam libero. Nunc tristique ex a nibh egestas
sollicitudin.
*** Paragraph two
    Mauris efficitur vitae ex id egestas. Vestibulum
    ligula felis, pulvinar a posuere id, luctus vitae leo. Sed ac
    imperdiet orci, non elementum leo. Nullam molestie congue
    placerat. Phasellus tempor et libero maximus commodo.
Mauris efficitur vitae ex id egestas. Vestibulum
ligula felis, pulvinar a posuere id, luctus vitae leo. Sed ac
imperdiet orci, non elementum leo. Nullam molestie congue
placerat. Phasellus tempor et libero maximus commodo.
* Thanks
*** Links
    - Link one
    - Link two
- Link one
- Link two
```
We have added three more lines to the header:
我们给标题增加了三行:
```
#+LATEX_CLASS: beamer
#+BEAMER_THEME: Frankfurt
#+BEAMER_INNER_THEME: rounded
```
导出为 PDF按下 `Alt + x` 键后输入 “org-beamer-export-to-pdf”
导出为 PDF按下 `Alt + x` 键后输入 `org-beamer-export-to-pdf`
![latex_beamer_presentation.png][23]
用 Emacs 和 Org mode 创建的 Latex Beamer persentation
*用 Emacs 和 Org 模式创建的 Latex Beamer 简报*
希望你会爱上使用 Emacs 来创建 LaTex 和 Beamer 文档(注意:使用快捷键比用鼠标更快些。Emacs 的 Org-mode 提供了比我在这篇文章中说的更多的功能,你可以在 [orgmode.org][24] 获取更多的信息.
希望你会爱上使用 Emacs 来创建 LaTex 和 Beamer 文档(注意使用快捷键比用鼠标更快些。Emacs 的 Org 模式提供了比我在这篇文章中说的更多的功能,你可以在 [orgmode.org][24] 获取更多的信息.
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/4/how-create-latex-documents-emacs
作者:[Sachin Patil][a]
译者:[oneforalone](https://github.com/oneforalone)
校对:[校对者ID](https://github.com/校对者ID)
选题:[lujun9972](https://github.com/lujun9972)
译者:[oneforalone](https://github.com/oneforalone)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -0,0 +1,80 @@
学习 Golang 的 4 个技巧
======
> 到达 Golang 大陆:一位资深开发者之旅。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_laptop_code_programming_mountain_view.jpg?itok=yx5buqkr)
2014 年夏天……
> IBM“我们需要你弄清楚这个 Docker。”
> 我:“没问题。”
> IBM“那就开始吧。”
> 我“好的。”内心声音”Docker 是用 Go 编写的。是吗Google 一下)“哦,一门编程语言。我在我的岗位上已经学习了很多了。这不会太难。”
我的大学新生编程课是使用 VAX 汇编程序教授的。在数据结构课上,我们使用 Pascal —— 在图书馆计算机中心的旧电脑上使用软盘加载。在一门更高一级的课程中,我的教授教授喜欢用 ADA 去展示所有的例子。在我们的 Sun 工作站上,我通过各种 UNIX 的实用源代码学到了一点 C。在 IBMOS/2 源代码中我们使用了 C 和一些 x86 汇编程序;在一个与 Apple 合作的项目中我们大量使用 C++ 的面向对象功能。不久后我学到了 shell 脚本,开始是 csh但是在 90 年代中期发现 Linux 后就转到了 Bash。在 90 年代后期,我在将 IBM 的定制的 JVM 代码中的即时JIT编译器移植到 Linux 时,我不得不开始学习 m4与其说是编程语言不如说是一种宏处理器
一晃 20 年……我从未因为学习一门新的编程语言而焦灼。但是 [Go][1] 让我感觉有些不同。我打算公开贡献,上传到 GitHub让任何有兴趣的人都可以看到作为一个 40 多岁的资深开发者的 Go 新手,我不想成为一个笑话。我们都知道程序员的骄傲,不想丢人,不论你的经验水平如何。
我早期的调研显示Go 似乎比某些语言更 “地道”。它不仅仅是让代码可以编译;也需要让代码可以 “Go Go Go”。
现在,我的个人的 Go 之旅四年间有了几百个拉取请求PR我不是致力于成为一个专家但是现在我觉得贡献和编写代码比我在 2014 年的时候更舒服了。所以,你该怎么教一个老人新的技能或者一门编程语言呢?以下是我自己在前往 Golang 大陆之旅的四个步骤。
### 1、不要跳过基础
虽然你可以通过复制代码来进行你早期的学习谁还有时间阅读手册Go 有一个非常易读的 [语言规范][2],它写的很易于理解,即便你在语言或者编译理论方面没有取得硕士学位。鉴于 Go 的 **参数:类型** 顺序的特有习惯,以及一些有趣的语言功能,例如通道和 go 协程,搞定这些新概念是非常重要的是事情。阅读这个附属的文档 [高效 Go 编程][3],这是 Golang 创造者提供的另一个重要资源,它将为你提供有效和正确使用语言的准备。
### 2、从最好的中学习
有许多宝贵的资源可供挖掘,可以将你的 Go 知识提升到下一个等级。最近在 [GopherCon][4] 上的所有讲演都可以在网上找到,如这个 [GopherCon US 2018][5] 的详尽列表。这些讲演的专业知识和技术水平各不相同,但是你可以通过它们轻松地找到一些你所不了解的事情。[Francesc Campoy][6] 创建了一个名叫 [JustForFunc][7] 的 Go 编程视频系列,其不断增多的剧集可以用来拓宽你的 Go 知识和理解。直接搜索 “Golang" 可以为那些想要了解更多信息的人们展示许多其它视频和在线资源。
想要看代码?在 GitHub 上许多受欢迎的云原生项目都是用 Go 写的:[Docker/Moby][8]、[Kubernetes][9]、[Istio][10]、[containerd][11]、[CoreDNS][12],以及许多其它的。语言纯粹主义者可能会认为一些项目比另外一些更地道,但这些都是很好的起点,可以看到在高度活跃的项目的大型代码库中使用 Go 的程度。
### 3、使用优秀的语言工具
你会很快了解到 [gofmt][13] 的宝贵之处。Go 最漂亮的一个地方就在于没有关于每个项目代码格式的争论 —— **gofmt** 内置在语言的运行环境中,并且根据一系列可靠的、易于理解的语言规则对 Go 代码进行格式化。我不知道有哪个基于 Golang 的项目会在持续集成中不坚持使用 **gofmt** 检查拉取请求。
除了直接构建于运行环境和 SDK 中的一系列有价值的工具之外,我强烈建议使用一个对 Golang 的特性有良好支持的编辑器或者 IDE。由于我经常在命令行中进行工作我依赖于 Vim 加上强大的 [vim-go][14] 插件。我也喜欢微软提供的 [VS Code][15],特别是它的 [Go 语言][16] 插件。
想要一个调试器?[Delve][17] 项目在不断的改进和成熟,它是在 Go 二进制文件上进行 [gdb][18] 式调试的强有力的竞争者。
### 4、写一些代码
你要是不开始尝试使用 Go 写代码,你永远不知道它有什么好的地方。找一个有 “需要帮助” 问题标签的项目,然后开始贡献代码。如果你已经使用了一个用 Go 编写的开源项目,找出它是否有一些可以用初学者方式解决的 Bug然后开始你的第一个拉取请求。与生活中的大多数事情一样实践出真知所以开始吧。
事实证明,你可以教会一个资深的老开发者一门新的技能甚至编程语言。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/11/learning-golang
作者:[Phill Estes][a]
选题:[lujun9972][b]
译者:[dianbanjiu](https://github.com/dianbanjiu)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/estesp
[b]: https://github.com/lujun9972
[1]: https://golang.org/
[2]: https://golang.org/ref/spec
[3]: https://golang.org/doc/effective_go.html
[4]: https://www.gophercon.com/
[5]: https://tqdev.com/2018-gophercon-2018-videos-online
[6]: https://twitter.com/francesc
[7]: https://www.youtube.com/channel/UC_BzFbxG2za3bp5NRRRXJSw
[8]: https://github.com/moby/moby
[9]: https://github.com/kubernetes/kubernetes
[10]: https://github.com/istio/istio
[11]: https://github.com/containerd/containerd
[12]: https://github.com/coredns/coredns
[13]: https://blog.golang.org/go-fmt-your-code
[14]: https://github.com/fatih/vim-go
[15]: https://code.visualstudio.com/
[16]: https://code.visualstudio.com/docs/languages/go
[17]: https://github.com/derekparker/delve
[18]: https://www.gnu.org/software/gdb/

8
scripts/status.sh Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
# 重新生成badge
set -o errexit
SCRIPTS_DIR=$(cd $(dirname "$0") && pwd)
BUILD_DIR=$(cd $SCRIPTS_DIR/.. && pwd)/build
mkdir -p ${BUILD_DIR}/status
${SCRIPTS_DIR}/status/status.sh > ${BUILD_DIR}/status/status.json

View File

@ -13,12 +13,15 @@ function get_status_of()
git log --date=short --pretty=format:"{\"file\":\"${file}\",\"time\":\"%ad\",\"user\":\"%an\"}" -n 1 "${file}"
}
(
git grep -niE "translat|fanyi|翻译" sources/*.md |awk -F ":" '{if ($2<=3) print $1}' |xargs -I{} git log --date=short --pretty=format:"{\"filename\":\"{}\",\"time\":\"%ad\",\"user\":\"%an\"}" -n 1 "{}"|jq --slurp
translating=$( git grep -niE "translat|fanyi|翻译" sources/*.md |awk -F ":" '{if ($2<=3) print $1}' |xargs -I{} git log --date=short --pretty=format:"{\"filename\":\"{}\",\"time\":\"%ad\",\"user\":\"%an\"}" -n 1 "{}")
unselected=$(
find sources -name "2*.md"|sort|while read file;do
if ! file-translating-p "${file}";then
get_status_of "${file}"
fi
done |jq --slurp
)|jq --slurp '{"translating":.[0],"unselected":.[1]}'
done
)
(
echo ${translating}|jq -s "."
echo ${unselected} |jq -s "."
)|jq -s '{"translating":.[0],"unselected":.[1]}'

View File

@ -1,3 +1,5 @@
Translating by Jamskr
Continuous infrastructure: The other CI
======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/BIZ_darwincloud_520x292_0311LL.png?itok=74DLgd8Q)

View File

@ -1,113 +0,0 @@
translating by lixinyuxx
5 reasons the i3 window manager makes Linux better
======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cloud-windows.png?itok=jd5sBNQH)
One of the nicest things about Linux (and open source software in general) is the freedom to choose among different alternatives to address our needs.
I've been using Linux for a long time, but I was never entirely happy with the desktop environment options available. Until last year, [Xfce][1] was the closest to what I consider a good compromise between features and performance. Then I found [i3][2], an amazing piece of software that changed my life.
I3 is a tiling window manager. The goal of a window manager is to control the appearance and placement of windows in a windowing system. Window managers are often used as part a full-featured desktop environment (such as GNOME or Xfce), but some can also be used as standalone applications.
A tiling window manager automatically arranges the windows to occupy the whole screen in a non-overlapping way. Other popular tiling window managers include [wmii][3] and [xmonad][4].
![i3 tiled window manager screenshot][6]
Screenshot of i3 with three tiled windows
Following are the top five reasons I use the i3 window manager and recommend it for a better Linux desktop experience.
### 1\. Minimalism
I3 is fast. It is neither bloated nor fancy. It is designed to be simple and efficient. As a developer, I value these features, as I can use the extra capacity to power my favorite development tools or test stuff locally using containers or virtual machines.
In addition, i3 is a window manager and, unlike full-featured desktop environments, it does not dictate the applications you should use. Do you want to use Thunar from Xfce as your file manager? GNOME's gedit to edit text? I3 does not care. Pick the tools that make the most sense for your workflow, and i3 will manage them all in the same way.
### 2\. Screen real estate
As a tiling window manager, i3 will automatically "tile" or position the windows in a non-overlapping way, similar to laying tiles on a wall. Since you don't need to worry about window positioning, i3 generally makes better use of your screen real estate. It also allows you to get to what you need faster.
There are many useful cases for this. For example, system administrators can open several terminals to monitor or work on different remote systems simultaneously; and developers can use their favorite IDE or editor and a few terminals to test their programs.
In addition, i3 is flexible. If you need more space for a particular window, enable full-screen mode or switch to a different layout, such as stacked or tabbed.
### 3\. Keyboard-driven workflow
I3 makes extensive use of keyboard shortcuts to control different aspects of your environment. These include opening the terminal and other programs, resizing and positioning windows, changing layouts, and even exiting i3. When you start using i3, you need to memorize a few of those shortcuts to get around and, with time, you'll use more of them.
The main benefit is that you don't often need to switch contexts from the keyboard to the mouse. With practice, it means you'll improve the speed and efficiency of your workflow.
For example, to open a new terminal, press `<SUPER>+<ENTER>`. Since the windows are automatically positioned, you can start typing your commands right away. Combine that with a nice terminal-driven text editor (e.g., Vim) and a keyboard-focused browser for a fully keyboard-driven workflow.
In i3, you can define shortcuts for everything. Here are some examples:
* Open terminal
* Open browser
* Change layouts
* Resize windows
* Control music player
* Switch workspaces
Now that I am used to this workflow, I can't see myself going back to a regular desktop environment.
### 4\. Flexibility
I3 strives to be minimal and use few system resources, but that does not mean it can't be pretty. I3 is flexible and can be customized in several ways to improve the visual experience. Because i3 is a window manager, it doesn't provide tools to enable customizations; you need external tools for that. Some examples:
* Use `feh` to define a background picture for your desktop.
* Use a compositor manager such as `compton` to enable effects like window fading and transparency.
* Use `dmenu` or `rofi` to enable customizable menus that can be launched from a keyboard shortcut.
* Use `dunst` for desktop notifications.
I3 is fully configurable, and you can control every aspect of it by updating the default configuration file. From changing all keyboard shortcuts, to redefining the name of the workspaces, to modifying the status bar, you can make i3 behave in any way that makes the most sense for your needs.
![i3 with rofi menu and dunst desktop notifications][8]
i3 with `rofi` menu and `dunst` desktop notifications
Finally, for more advanced users, i3 provides a full interprocess communication ([IPC][9]) interface that allows you to use your favorite language to develop scripts or programs for even more customization options.
### 5\. Workspaces
In i3, a workspace is an easy way to group windows. You can group them in different ways according to your workflow. For example, you can put the browser on one workspace, the terminal on another, an email client on a third, etc. You can even change i3's configuration to always assign specific applications to their own workspaces.
Switching workspaces is quick and easy. As usual in i3, do it with a keyboard shortcut. Press `<SUPER>+num` to switch to workspace `num`. If you get into the habit of always assigning applications/groups of windows to the same workspace, you can quickly switch between them, which makes workspaces a very useful feature.
In addition, you can use workspaces to control multi-monitor setups, where each monitor gets an initial workspace. If you switch to that workspace, you switch to that monitor—without moving your hand off the keyboard.
Finally, there is another, special type of workspace in i3: the scratchpad. It is an invisible workspace that shows up in the middle of the other workspaces by pressing a shortcut. This is a convenient way to access windows or programs that you frequently use, such as an email client or your music player.
### Give it a try
If you value simplicity and efficiency and are not afraid of working with the keyboard, i3 is the window manager for you. Some say it is for advanced users, but that is not necessarily the case. You need to learn a few basic shortcuts to get around at the beginning, but they'll soon feel natural and you'll start using them without thinking.
This article just scratches the surface of what i3 can do. For more details, consult [i3's documentation][10].
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/8/i3-tiling-window-manager
作者:[Ricardo Gerardi][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/rgerardi
[1]:https://xfce.org/
[2]:https://i3wm.org/
[3]:https://code.google.com/archive/p/wmii/
[4]:https://xmonad.org/
[5]:/file/406476
[6]:https://opensource.com/sites/default/files/uploads/i3_screenshot.png (i3 tiled window manager screenshot)
[7]:/file/405161
[8]:https://opensource.com/sites/default/files/uploads/rofi_dunst.png (i3 with rofi menu and dunst desktop notifications)
[9]:https://i3wm.org/docs/ipc.html
[10]:https://i3wm.org/docs/userguide.html

View File

@ -1,5 +1,3 @@
translating by Flowsnow
Quiet log noise with Python and machine learning
======

View File

@ -1,147 +0,0 @@
Translating by Jamskr
How to install a device driver on Linux
======
Learn how Linux drivers work and how to use them.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/car-penguin-drive-linux-yellow.png?itok=twWGlYAc)
One of the most daunting challenges for people switching from a familiar Windows or MacOS system to Linux is installing and configuring a driver. This is understandable, as Windows and MacOS have mechanisms that make this process user-friendly. For example, when you plug in a new piece of hardware, Windows automatically detects it and shows a pop-up window asking if you want to continue with the driver's installation. You can also download a driver from the internet, then just double-click it to run a wizard or import the driver through Device Manager.
This process isn't as easy on a Linux operating system. For one reason, Linux is an open source operating system, so there are [hundreds of Linux distribution variations][1] . This means it's impossible to create one how-to guide that works for all Linux distros. Each Linux operating system handles the driver installation process a different way.
Second, most default Linux drivers are open source and integrated into the system, which makes installing any drivers that are not included quite complicated, even though most hardware devices can be automatically detected. Third, license policies vary among the different Linux distributions. For example, [Fedora prohibits][2] including drivers that are proprietary, legally encumbered, or that violate US laws. And Ubuntu asks users to [avoid using proprietary or closed hardware][3].
To learn more about how Linux drivers work, I recommend reading [An Introduction to Device Drivers][4] in the book Linux Device Drivers.
### Two approaches to finding drivers
#### 1\. User interfaces
If you are new to Linux and coming from the Windows or MacOS world, you'll be glad to know that Linux offers ways to see whether a driver is available through wizard-like programs. Ubuntu offers the [Additional Drivers][5] option. Other Linux distributions provide helper programs, like [Package Manager for GNOME][6], that you can check for available drivers.
#### 2\. Command line
What if you can't find a driver through your nice user interface application? Or you only have access through the shell with no graphic interface whatsoever? Maybe you've even decided to expand your skills by using a console. You have two options:
A. **Use a repository**
This is similar to the [**homebrew**][7] command in MacOS.** ** By using **yum** , **dnf** , **apt-get** , etc., you're basically adding a repository and updating the package cache.
B. **Download, compile, and build it yourself**
This usually involves downloading a package directly from a website or using the **wget** command and running the configuration file and Makefile to install it. This is beyond the scope of this article, but you should be able to find online guides if you choose to go this route.
### Check if a driver is already installed
Before jumping further into installing a driver in Linux, let's look at some commands that will determine whether the driver is already available on your system.
The [**lspci**][8] command shows detailed information about all PCI buses and devices on the system:
```
$ lscpci
```
Or with **grep** :
```
$ lscpci | grep SOME_DRIVER_KEYWORD
```
For example, you can type **lspci | grep SAMSUNG** if you want to know if a Samsung driver is installed.
The [**dmesg**][9] command shows all device drivers recognized by the kernel:
```
$ dmesg
```
Or with **grep** :
```
$ dmesg | grep SOME_DRIVER_KEYWORD
```
Any driver that's recognized will show in the results.
If nothing is recognized by the **dmesg** or **lscpi** commands, try these two commands to see if the driver is at least loaded on the disk:
```
$ /sbin/lsmod
```
and
```
$ find /lib/modules
```
Tip: As with **lspci** or **dmesg** , append **| grep** to either command above to filter the results.
If a driver is recognized by those commands but not by **lscpi** or **dmesg** , it means the driver is on the disk but not in the kernel. In this case, load the module with the **modprobe** command:
```
$ sudo modprobe MODULE_NAME
```
Run as this command as **sudo** since this module must be installed as a root user.
### Add the repository and install
There are different ways to add the repository through **yum** , **dnf** , and **apt-get** ; describing them all is beyond the scope of this article. To make it simple, this example will use **apt-get** , but the idea is similar for the other options.
**1\. Delete the existing repository, if it exists.**
```
$ sudo apt-get purge NAME_OF_DRIVER*
```
where **NAME_OF_DRIVER** is the probable name of your driver. You can also add pattern match to your regular expression to filter further.
**2\. Add the repository to the repolist, which should be specified in the driver guide.**
```
$ sudo add-apt-repository REPOLIST_OF_DRIVER
```
where **REPOLIST_OF_DRIVER** should be specified from the driver documentation (e.g., **epel-list** ).
**3\. Update the repository list.**
```
$ sudo apt-get update
```
**4\. Install the package.**
```
$ sudo apt-get install NAME_OF_DRIVER
```
**5\. Check the installation.**
Run the **lscpi** command (as above) to check that the driver was installed successfully.
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/11/how-install-device-driver-linux
作者:[Bryant Son][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/brson
[b]: https://github.com/lujun9972
[1]: https://en.wikipedia.org/wiki/List_of_Linux_distributions
[2]: https://fedoraproject.org/wiki/Forbidden_items?rd=ForbiddenItems
[3]: https://www.ubuntu.com/licensing
[4]: https://www.xml.com/ldd/chapter/book/ch01.html
[5]: https://askubuntu.com/questions/47506/how-do-i-install-additional-drivers
[6]: https://help.gnome.org/users/gnome-packagekit/stable/add-remove.html.en
[7]: https://brew.sh/
[8]: https://en.wikipedia.org/wiki/Lspci
[9]: https://en.wikipedia.org/wiki/Dmesg

View File

@ -1,300 +0,0 @@
HankChow translating
How To Customize Bash Prompt In Linux
======
![](https://www.ostechnix.com/wp-content/uploads/2017/10/BASH-720x340.jpg)
As you know already, **BASH** (the **B** ourne- **A** gain **Sh** ell) is the default shell for most modern Linux distributions. In this guide, we are going to customize BASH prompt and enhance its look by adding some colors and styles. Of course, there are many plugins/tools available to get this job done easily and quickly. However, we still can do some basic customization, such as adding, modifying elements, changing the foreground and background color etc., without having to install any additional tools and plugins. Let us get started!
### Customize Bash Prompt In Linux
In BASH, we can customize and change the BASH prompt as the way you want by changing the value of **PS1** environment variable.
Usually, the BASH prompt will look something like below:
![](https://www.ostechnix.com/wp-content/uploads/2017/10/Linux-Terminal.png)
Here, **sk** is my username and **ubuntuserver** is my hostname.
Now, we are going to change this prompt as per your liking by inserting some backslash-escaped special characters called **Escape Sequences**.
Let me show you some examples.
Before going further, it is highly recommended to backup the **~/.bashrc** file.
```
$ cp ~/.bashrc ~/.bashrc.bak
```
**Modify “[[email protected]][1]” part in the Bash prompt**
As I mentioned above, the BASH prompt has “[[email protected]][1]” part by default in most Linux distributions. You can change this part to something else.
To do so, edit **~/.bashrc **file:
```
$ vi ~/.bashrc
```
Add the following line at the end:
```
PS1="ostechnix> "
```
Replace “ostechnix” with any letters/words of your choice. Once added, hit the **ESC** key and type **:wq** to save and exit the file.
Run the following command to update the changes:
```
$ source ~/.bashrc
```
Now, the BASH prompt will have the letters “ostechnix” in the shell prompt.
![][3]
Here is another example. I am going to replace “[[email protected]][1]” part with “[[email protected]][1]>”.
To do so, add the following entry in your **~./bashrc** file.
Dont forget to update the changes using “source ~./bashrc” command.
Here is the output of my BASH prompt in Ubuntu 18.04 LTS.
![](https://www.ostechnix.com/wp-content/uploads/2017/10/bash-prompt-1.png)
**Display username only:**
To display the username only, just add the following line in **~/.bashrc** file.
```
export PS1="\u "
```
Here, **\u** is the escape sequence.
Here are some more values to add to your PS1 variable to change the BASH prompt. After adding each entry, you must run “source ~/.bashrc” command to take effect the changes.
**Add username with hostname:**
```
export PS1="\u\h "
```
Your prompt will now look like below:
```
skubuntuserver
```
**Add username and FQDN (Fully Qualified Domain Name):**
```
export PS1="\u\H "
```
**Add extra characters between username and hostname:**
If you want to any letter, for example **@** , between the username and hostname, use the following entry:
```
export PS1="\u@\h "
```
The bash prompt will look like below:
```
sk@ubuntuserver
```
**Add username with hostname with $ symbol at the end:**
```
export PS1="\u@\h\\$ "
```
**Add special characters between and after username and hostname:**
```
export PS1="\u@\h> "
```
This entry will change the BASH prompt as shown below.
```
sk@ubuntuserver>
```
Similarly, you can add other special characters, such as colon, semi-colon, *, underscore, space etc.
**Display username, hostname, shell name:**
```
export PS1="\u@\h>\s "
```
**Display username, hostname, shell and and its version:**
```
export PS1="\u@\h>\s\v "
```
Bash prompt output:
![][4]
Display username, hostname and path to current directory:
```
export PS1="\u@\h\w "
```
You will see a tilde (~) symbol if the current directory is $HOME.
**Display date in BASH prompt:**
To display date with your username and hostname in the BASH prompt, add the following entry in ~/.bashrc file.
```
export PS1="\u@\h>\d "
```
![][5]
**Date and time in 12 hour format in BASH prompt:**
```
export PS1="\u@\h>\d\@ "
```
**Date and 12 hour time hh:mm:ss format:**
```
export PS1="\u@\h>\d\T "
```
**Date and 24 hour time:**
```
export PS1="\u@\h>\d\A "
```
**Date and 24 hour hh:mm:ss format:**
```
export PS1="\u@\h>\d\t "
```
These are some common escape sequences to change the Bash prompt format. There are few more escape sequences are available. You can view them all in in the **bash man page** under the **“PROMPTING”** section.
And, you can view the current prompt settings at any time using command:
```
$ echo $PS1
```
**Hide “username@hostname” Part In Bash prompt**
I dont want to change anything. Can I hide it altogether? Yes, you can!
If youre a blogger or tech writer, there are chances that you have to upload the screenshots of your Linux Terminal in your websites and blogs. Your username/hostname might be too cool, so you may not want others to copy and use them as their own. On the other hand, your username/hostname might be too weird or too bad or contain offensive characters, so you dont want others to view them. In such cases, this small tip might help you to hide or modify “[[email protected]][1]” part in Terminal.
If you dont like to let the users to view your username/hostname part, just follow the steps given below.
Edit your **“~/.bashrc”** file:
```
$ vi ~/.bashrc
```
Add the following at the end:
```
PS1="\W> "
```
Type **:wq** to save and close the file.
Then, run the following command to take effect the changes.
```
$ source ~/.bashrc
```
Thats it. Now, check your Terminal. You will not see the [[email protected]][1] part. You will only see the **~ >** symbol.
![][6]
Want to know another simplest way without messing the **~/.bashrc** file? Just create another user account something like **[[email protected]][1]** , or **[[email protected]][1]**. Use these accounts for making guides, videos and upload them on your blog or online. Now, you have nothing to worry about your identity.
**Warning:** This is a bad practice in some cases. For example, if another shells like zsh inherits your current shell, it will cause some problems. Use it only for hiding or modifying your [[email protected]][1] part if you use single shell. Apart from hiding the [[email protected]][1] part in the Terminal, this tip is pretty useless and might be problematic.
### Colorizing BASH prompt
What we have seen so far is we just changed/added some elements to the BASH prompt. In this section, we are going to add colors the elements.
You can enhance the foreground (text) and background color of BASH prompts elements by adding some code to the ~/.bashrc file.
For example, to change the foreground color of all texts to Red, add the following code:
```
export PS1="\u@\[\e[31m\]\h\[\e[m\] "
```
Once added, update the changes using command:
Now, your BASH prompt will look like below:
![][7]
Similarly, to change the background color, add this code:
```
export PS1="\u@\[\e[31;46m\]\h\[\e[m\] "
```
![][8]
### **Adding Emojis**
Who doesnt love emoji? We can add an emoji by placing the following code in the ~/.bashrc file.
```
PS1="\W 🔥 >"
```
Please note that some terminal may not show the emojis properly depending upon the font used. You may see either garbled characters or monochrome emoji if you dont have suitable fonts.
### Customizing BASH is bit difficult to me, Is there any other easy way?
If youre a newbie, writing and adding PS1 values will be confusing and difficult. Also, you will find it bit difficult to arrange the elements to get the result of your choice. No worries! There is an online Bash PS1 generator available which allows you to easily generate different PS1 values as you wish.
Go to the following website:
[![EzPrompt](https://www.ostechnix.com/wp-content/uploads/2017/10/EzPrompt.png)][9]
Just pick the elements you want to use in your BASH prompt. Add the colors to the elements and re-arrange them in any order of your liking. Preview the output instantly and finally copy/paste resulting code in your **~/.bashrc** file. It is that simple! Most of the examples mentioned in this guide are taken from this website.
### I messed up with my .bashrc file? How to restore it to default settings?
As I mentioned earlier, it is strongly recommended to take backup ~./bashrc (Or any important configuration files in general) before making any changes. So, you can restore it to the previous working version if something went wrong. However if you forgot to backup the ~/.bashrc file in the first place, you still can restore it to the default settings as described in the following guide.
[How To Restore .bashrc File To Default Settings][10]
The above guide is based on Ubuntu, but it may applicable to other Linux distributions as well. Please let us be clear that the aforementioned guide will help you to reset ~/.bashrc to its default settings at the time of new installation. Any changes done afterwards will be lost.
And, thats all for now. I will keep updating this guide as I learned more ways to customize the BASH prompt in future.
Hope this helps. More good stuffs to come. Stay tuned!
Cheers!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/hide-modify-usernamelocalhost-part-terminal/
作者:[SK][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.ostechnix.com/author/sk/
[b]: https://github.com/lujun9972
[1]: https://www.ostechnix.com/cdn-cgi/l/email-protection
[2]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
[3]: http://www.ostechnix.com/wp-content/uploads/2017/10/Linux-Terminal-2.png
[4]: http://www.ostechnix.com/wp-content/uploads/2017/10/bash-prompt-2.png
[5]: http://www.ostechnix.com/wp-content/uploads/2017/10/bash-prompt-3.png
[6]: http://www.ostechnix.com/wp-content/uploads/2017/10/Linux-Terminal-1.png
[7]: http://www.ostechnix.com/hide-modify-usernamelocalhost-part-terminal/bash-prompt-4/
[8]: http://www.ostechnix.com/hide-modify-usernamelocalhost-part-terminal/bash-prompt-5/
[9]: http://ezprompt.net/
[10]: https://www.ostechnix.com/restore-bashrc-file-default-settings-ubuntu/

View File

@ -0,0 +1,466 @@
[^#]: collector: lujun9972
[^#]: translator:
[^#]: reviewer:
[^#]: publishor:
[^#]: subject: How to Build a Netboot Server, Part 1
[^#]: via: https://fedoramagazine.org/how-to-build-a-netboot-server-part-1/
[^#]: author: [Gregory Bartholomew](https://fedoramagazine.org/author/glb/)
[^#]: url:
How to Build a Netboot Server, Part 1
======
![](https://fedoramagazine.org/wp-content/uploads/2018/11/build-netboot-816x345.jpg)
Some computer networks need to maintain identical software installations and configurations on several physical machines. One such environment would be a school computer lab. A [netboot][1] server can be set up to serve an entire operating system over a network so that the client computers can be configured from one central location. This tutorial will show one method of building a netboot server.
Part 1 of this tutorial will cover creating a netboot server and image. Part 2 will show how to add Kerberos-authenticated home directories to the netboot configuration.
### Initial Configuration
Start by downloading one of Fedora Servers [netinst][2] images, burning it to a CD, and booting the server that will be reformatted from it. We just need a typical “Minimal Install” of Fedora Server for our starting point and we will use the command line to add any additional packages that are needed after the installation is finished.
![][3]
> NOTE: For this tutorial we will be using Fedora 28. Other versions may include a slightly different set of packages in their “Minimal Install”. If you start with a different version of Fedora, then you may need to do some troubleshooting if an expected file or command is not available.
Once you have your minimal installation of Fedora Server up and running, log in as root and set the hostname:
```
$ MY_HOSTNAME=server-01.example.edu
$ hostnamectl set-hostname $MY_HOSTNAME
```
> NOTE: Red Hat recommends that both static and transient names match the fully-qualified domain name (FQDN) used for the machine in DNS, such as host.example.com ([Understanding Host Names][4]).
>
> NOTE: This guide is meant to be copy-and-paste friendly. Any value that you might need to customize will be stated as a MY_* variable that you can tweak before running the remaining commands. Beware that if you log out, the variable assignments will be cleared.
>
> NOTE: Fedora 28 Server tends to dump a lot of logging output to the console by default. You may want to disable the console logging temporarily by running: sysctl -w kernel.printk=0
Next, we need a static network address on our server. The following sequence of commands should find and reconfigure your default network connection appropriately:
```
$ MY_DNS1=192.0.2.91
$ MY_DNS2=192.0.2.92
$ MY_IP=192.0.2.158
$ MY_PREFIX=24
$ MY_GATEWAY=192.0.2.254
$ DEFAULT_DEV=$(ip route show default | awk '{print $5}')
$ DEFAULT_CON=$(nmcli d show $DEFAULT_DEV | sed -n '/^GENERAL.CONNECTION:/s!.*:\s*!! p')
$ nohup bash << END
nmcli con mod "$DEFAULT_CON" connection.id "$DEFAULT_DEV"
nmcli con mod "$DEFAULT_DEV" connection.interface-name "$DEFAULT_DEV"
nmcli con mod "$DEFAULT_DEV" ipv4.method disabled
nmcli con up "$DEFAULT_DEV"
nmcli con add con-name br0 ifname br0 type bridge
nmcli con mod br0 bridge.stp no
nmcli con mod br0 ipv4.dns $MY_DNS1,$MY_DNS2
nmcli con mod br0 ipv4.addresses $MY_IP/$MY_PREFIX
nmcli con mod br0 ipv4.gateway $MY_GATEWAY
nmcli con mod br0 ipv4.method manual
nmcli con up br0
nmcli con add con-name br0-slave0 ifname "$DEFAULT_DEV" type bridge-slave master br0
nmcli con up br0-slave0
END
```
> NOTE: The last set of commands above is wrapped in a “nohup” script because it will disable networking temporarily. The nohup command should allow the nmcli commands to finish running even while your ssh connection is down. Beware that it may take 10 or so seconds for the connection to come back up and that you will have to start a new ssh connection if you changed the servers IP address.
>
> NOTE: The above network configuration creates a [network bridge][5] on top of the default connection so that we can run a virtual machine instance directly on the server for testing later. If you do not want to test the netboot image directly on the server, you can skip creating the bridge and set the static IP address directly on your default network connection.
### Install and Configure NFS4
Start by installing the nfs-utils package:
```
$ dnf install -y nfs-utils
```
Create a top-level [pseudo filesystem][6] for the NFS exports and share it out to your network:
```
$ MY_SUBNET=192.0.2.0
$ mkdir /export
$ echo "/export -fsid=0,ro,sec=sys,root_squash $MY_SUBNET/$MY_PREFIX" > /etc/exports
```
SELinux will interfere with the netboot servers operation. Configuring exceptions for it is beyond the scope of this tutorial, so we will disable it:
```
$ sed -i '/GRUB_CMDLINE_LINUX/s/"$/ audit=0 selinux=0"/' /etc/default/grub
$ grub2-mkconfig -o /boot/grub2/grub.cfg
$ sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
$ setenforce 0
```
> NOTE: Editing the grub command line should not be necessary, but simply editing /etc/sysconfig/selinux proved ineffective across reboots of Fedora Server 28 during testing, so the “selinux=0” flag has been set here to be doubly sure.
Now, add an exception for the NFS service to the local firewall and start the NFS service:
```
$ firewall-cmd --add-service nfs
$ firewall-cmd --runtime-to-permanent
$ systemctl enable nfs-server.service
$ systemctl start nfs-server.service
```
### Create the Netboot Image
Now that our NFS server is up and running, we need to supply it with an operating system image to serve to the client computers. We will start with a very minimal image and add to it after everything is working.
First, create a new directory where our image will be stored:
```
$ mkdir /fc28
```
Use the “dnf” command to build the image under the new directory with only a few base packages:
```
$ dnf -y --releasever=28 --installroot=/fc28 install fedora-release systemd passwd rootfiles sudo dracut dracut-network nfs-utils vim-minimal dnf
```
It is important that the “kernel” packages were omitted from the above command. Before they are installed, we need to tweak the set of drivers that will be included in the “initramfs” image that is built automatically when the kernel is first installed. In particular, we need to disable “hostonly” mode so that the initramfs image will work on a wider set of hardware platforms and we need to add support for networking and NFS:
```
$ echo 'hostonly=no' > /fc28/etc/dracut.conf.d/hostonly.conf
$ echo 'add_dracutmodules+=" network nfs "' > /fc28/etc/dracut.conf.d/netboot.conf
```
Now, install the kernel:
```
$ dnf -y --installroot=/fc28 install kernel
```
Set a rule to prevent the kernel from being updated:
```
$ echo 'exclude=kernel-*' >> /fc28/etc/dnf/dnf.conf
```
Set the locale:
```
$ echo 'LANG="en_US.UTF-8"' > /fc28/etc/locale.conf
```
> NOTE: Some programs (e.g. GNOME Terminal) will not function if the locale is not properly configured.
Blank roots passwd:
```
$ sed -i 's/^root:\*/root:/' /fc28/etc/shadow
```
Set the clients hostname:
```
$ MY_CLIENT_HOSTNAME=client-01.example.edu
$ echo $MY_CLIENT_HOSTNAME > /fc28/etc/hostname
```
Disable logging to the console:
```
$ echo 'kernel.printk = 0 4 1 7' > /fc28/etc/sysctl.d/00-printk.conf
```
Define a local “liveuser” in the netboot image:
```
$ echo 'liveuser:x:1000:1000::/home/liveuser:/bin/bash' >> /fc28/etc/passwd
$ echo 'liveuser::::::::' >> /fc28/etc/shadow
$ echo 'liveuser:x:1000:' >> /fc28/etc/group
$ echo 'liveuser:!::' >> /fc28/etc/gshadow
```
Allow “liveuser” to sudo:
```
$ echo 'liveuser ALL=(ALL) NOPASSWD: ALL' > /fc28/etc/sudoers.d/liveuser
```
Enable automatic home directory creation:
```
$ dnf install -y --installroot=/fc28 authselect oddjob-mkhomedir
$ echo 'dirs /home' > /fc28/etc/rwtab.d/home
$ chroot /fc28 authselect select sssd with-mkhomedir --force
$ chroot /fc28 systemctl enable oddjobd.service
```
Since multiple clients will be mounting our image concurrently, we need to configure the image so that it will operate in read-only mode:
```
$ sed -i 's/^READONLY=no$/READONLY=yes/' /fc28/etc/sysconfig/readonly-root
```
Configure logging to go to RAM rather than permanent storage:
```
$ sed -i 's/^#Storage=auto$/Storage=volatile/' /fc28/etc/systemd/journald.conf
```
Configure DNS:
```
$ MY_DNS1=192.0.2.91
$ MY_DNS2=192.0.2.92
$ cat << END > /fc28/etc/resolv.conf
nameserver $MY_DNS1
nameserver $MY_DNS2
END
```
Work-around a few bugs that exist for read-only root mounts at the time this tutorial is being written ([BZ1542567][7]):
```
$ echo 'dirs /var/lib/gssproxy' > /fc28/etc/rwtab.d/gssproxy
$ cat << END > /fc28/etc/rwtab.d/systemd
dirs /var/lib/systemd/catalog
dirs /var/lib/systemd/coredump
END
```
Finally, we can create the NFS filesystem for our image and share it out to our subnet:
```
$ mkdir /export/fc28
$ echo '/fc28 /export/fc28 none bind 0 0' >> /etc/fstab
$ mount /export/fc28
$ echo "/export/fc28 -ro,sec=sys,no_root_squash $MY_SUBNET/$MY_PREFIX" > /etc/exports.d/fc28.exports
$ exportfs -vr
```
### Create the Boot Loader
Now that we have an operating system available to netboot, we need a boot loader to kickstart it on the client systems. For this setup, we will be using [iPXE][8].
> NOTE: This section and the following section — Testing with QEMU — can be done on a separate computer; they do not have to be run on the netboot server.
Install git and use it to download iPXE:
```
$ dnf install -y git
$ git clone http://git.ipxe.org/ipxe.git $HOME/ipxe
```
Now we need to create a special startup script for our bootloader:
```
$ cat << 'END' > $HOME/ipxe/init.ipxe
#!ipxe
prompt --key 0x02 --timeout 2000 Press Ctrl-B for the iPXE command line... && shell ||
dhcp || exit
set prefix file:///linux
chain ${prefix}/boot.cfg || exit
END
```
Enable the “file” download protocol:
```
$ echo '#define DOWNLOAD_PROTO_FILE' > $HOME/ipxe/src/config/local/general.h
```
Install the C compiler and related tools and libraries:
```
$ dnf groupinstall -y "C Development Tools and Libraries"
```
Build the boot loader:
```
$ cd $HOME/ipxe/src
$ make clean
$ make bin-x86_64-efi/ipxe.efi EMBED=../init.ipxe
```
Make note of where the where the newly-compiled boot loader is. We will need it for the next section:
```
$ IPXE_FILE="$HOME/ipxe/src/bin-x86_64-efi/ipxe.efi"
```
### Testing with QEMU
This section is optional, but you will need to duplicate the file layout of the [EFI system partition][9] that is shown below on your physical machines to configure them for netbooting.
> NOTE: You could also copy the files to a TFTP server and reference that server from DHCP if you wanted a fully diskless system.
In order to test our boot loader with QEMU, we are going to create a small disk image containing only an EFI system partition and our startup files.
Start by creating the required directory layout for the EFI system partition and copying the boot loader that we created in the previous section to it:
```
$ mkdir -p $HOME/esp/efi/boot
$ mkdir $HOME/esp/linux
$ cp $IPXE_FILE $HOME/esp/efi/boot/bootx64.efi
```
The below command should identify the kernel version that our netboot image is using and store it in a variable for use in the remaining configuration directives:
```
$ DEFAULT_VER=$(ls -c /fc28/lib/modules | head -n 1)
```
Define the boot configuration that our client computers will be using:
```
$ MY_DNS1=192.0.2.91
$ MY_DNS2=192.0.2.92
$ MY_NFS4=server-01.example.edu
$ cat << END > $HOME/esp/linux/boot.cfg
#!ipxe
kernel --name kernel.efi \${prefix}/vmlinuz-$DEFAULT_VER initrd=initrd.img ro ip=dhcp rd.peerdns=0 nameserver=$MY_DNS1 nameserver=$MY_DNS2 root=nfs4:$MY_NFS4:/fc28 console=tty0 console=ttyS0,115200n8 audit=0 selinux=0 quiet
initrd --name initrd.img \${prefix}/initramfs-$DEFAULT_VER.img
boot || exit
END
```
> NOTE: The above boot script shows a minimal example of how to get iPXE to netboot Linux. Much more complex configurations are possible. Most notably, iPXE has support for interactive boot menus which can be configured with a default selection and a timeout. A more advanced iPXE script could, for example, default to booting an operation system from the local disk and only go to the netboot operation if a user pressed a key before a countdown timer reached zero.
Copy the Linux kernel and its associated initramfs to the EFI system partition:
```
$ cp $(find /fc28/lib/modules -maxdepth 2 -name 'vmlinuz' | grep -m 1 $DEFAULT_VER) $HOME/esp/linux/vmlinuz-$DEFAULT_VER
$ cp $(find /fc28/boot -name 'init*' | grep -m 1 $DEFAULT_VER) $HOME/esp/linux/initramfs-$DEFAULT_VER.img
```
Our resulting directory layout should look like this:
```
esp
├── efi
│   └── boot
│   └── bootx64.efi
└── linux
├── boot.cfg
├── initramfs-4.18.18-200.fc28.x86_64.img
└── vmlinuz-4.18.18-200.fc28.x86_64
```
To use our EFI system partition with QEMU, we need to create a small “uefi.img” disk image containing it and then connect that to QEMU as the primary boot drive.
Begin by installing the necessary tools:
```
$ dnf install -y parted dosfstools
```
Now create the “uefi.img” file and copy the files from the “esp” directory into it:
```
$ ESP_SIZE=$(du -ks $HOME/esp | cut -f 1)
$ dd if=/dev/zero of=$HOME/uefi.img count=$((${ESP_SIZE}+5000)) bs=1KiB
$ UEFI_DEV=$(losetup --show -f $HOME/uefi.img)
$ parted ${UEFI_DEV} -s mklabel gpt mkpart EFI FAT16 1MiB 100% toggle 1 boot
$ mkfs -t msdos ${UEFI_DEV}p1
$ mkdir -p $HOME/mnt
$ mount ${UEFI_DEV}p1 $HOME/mnt
$ cp -r $HOME/esp/* $HOME/mnt
$ umount $HOME/mnt
$ losetup -d ${UEFI_DEV}
```
> NOTE: On a physical computer, you need only copy the files from the “esp” directory to the computers existing EFI system partition. You do not need the “uefi.img” file to boot a physical computer.
>
> NOTE: On a physical computer you can rename the “bootx64.efi” file if a file by that name already exists, but if you do so, you will probably have to edit the computers BIOS settings and add the renamed efi file to the boot list.
Next we need to install the qemu package:
```
$ dnf install -y qemu-system-x86
```
Allow QEMU to access the bridge that we created in the “Initial Configuration” section of this tutorial:
```
$ echo 'allow br0' > /etc/qemu/bridge.conf
```
Create a copy of the “OVMF_VARS.fd” image to store our virtual machines persistent BIOS settings:
```
$ cp /usr/share/edk2/ovmf/OVMF_VARS.fd $HOME
```
Now, start the virtual machine:
```
$ qemu-system-x86_64 -machine accel=kvm -nographic -m 1024 -drive if=pflash,format=raw,unit=0,file=/usr/share/edk2/ovmf/OVMF_CODE.fd,readonly=on -drive if=pflash,format=raw,unit=1,file=$HOME/OVMF_VARS.fd -drive if=ide,format=raw,file=$HOME/uefi.img -net bridge,br=br0 -net nic,model=virtio
```
If all goes well, you should see results similar to what is shown in the below image:
![][10]
You can use the “shutdown” command to get out of the virtual machine and back to the server:
```
$ sudo shutdown -h now
```
> NOTE: If something goes wrong and the virtual machine hangs, you may need to start a new ssh session to the server and use the “kill” command to terminate the “qemu-system-x86_64” process.
### Adding to the Image
Adding to the image should be a simple matter of chrooting into the image on the server and running “dnf install <package_name>”.
There is no limit to what can be installed on the netboot image. A full graphical installation should function perfectly.
Here is an example of how to bring our minimal netboot image up to a complete graphical installation:
```
$ for i in dev dev/pts dev/shm proc sys run; do mount -o bind /$i /fc28/$i; done
$ chroot /fc28 /usr/bin/bash --login
$ dnf -y groupinstall "Fedora Workstation"
$ dnf -y remove gnome-initial-setup
$ systemctl disable sshd.service
$ systemctl enable gdm.service
$ systemctl set-default graphical.target
$ sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
$ logout
$ for i in run sys proc dev/shm dev/pts dev; do umount /fc28/$i; done
```
Optionally, you may want to enable automatic login for the “liveuser” account:
```
$ sed -i '/daemon/a AutomaticLoginEnable=true' /fc28/etc/gdm/custom.conf
$ sed -i '/daemon/a AutomaticLogin=liveuser' /fc28/etc/gdm/custom.conf
```
#### Like this:
Like
Loading...
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/how-to-build-a-netboot-server-part-1/
作者:[Gregory Bartholomew][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://fedoramagazine.org/author/glb/
[b]: https://github.com/lujun9972
[1]: https://en.wikipedia.org/wiki/Network_booting
[2]: https://dl.fedoraproject.org/pub/fedora/linux/releases/28/Server/x86_64/iso/
[3]: https://fedoramagazine.org/wp-content/uploads/2018/11/installation-summary-1024x768.png
[4]: https://docs.fedoraproject.org/en-US/Fedora/25/html/Networking_Guide/ch-Configure_Host_Names.html#sec_Understanding_Host_Names
[5]: https://en.wikipedia.org/wiki/Bridging_(networking)
[6]: https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s3-nfs-server-config-exportfs-nfsv4.html
[7]: https://bugzilla.redhat.com/show_bug.cgi?id=1542567
[8]: https://ipxe.org/
[9]: https://en.wikipedia.org/wiki/EFI_system_partition
[10]: https://fedoramagazine.org/wp-content/uploads/2018/11/netboot-liveuser-1024x641.png

View File

@ -0,0 +1,109 @@
i3窗口管理器让Linux更好的五个原因
======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cloud-windows.png?itok=jd5sBNQH)
Linux和一般的开源软件 最美好的一点是在不同的替代方案中进行选择的自由,以满足我们的需求。
我使用 Linux 已经很长时间了,但我从来没有对可用的桌面环境完全满意。直到去年 [Xfce][1] 是我认为在功能和性能之间的一个接近优秀的妥协。然后我发现 [i3][2] 一个惊人的软件改变了我的生活
I3 是一个平铺窗口管理器。窗口管理器的目标是控制窗口系统中窗口的外观和位置。窗口管理器通常用作功能齐全的桌面环境 (如 GONME 或 Xfce ) 的一部分, 但也有一些可以用作独立的应用程序。
平铺式窗口管理器会自动排列窗口, 以不重叠的方式占据整个屏幕。其他流行的平铺式窗口管理器包括 [wmii][3] 和 [xmonad][4] 。
![i3 tiled window manager screenshot][6]
带有三个的 i3 屏幕截图
以下是我使用 i3 窗口管理器的五个首要原因,并推荐它以获得更好的 Linux 桌面体验。
### 1\.简化的艺术
I3 速度很快。它既不冗杂, 也不花哨。它的设计简单而高效。作为开发人员, 我重视这些功能, 因为我可以使用额外的功能为我最喜欢的开发工具助力, 或者使用容器或虚拟机在本地测试内容。
此外, I3 是一个窗口管理器,与功能齐全的桌面环境不同,它并不规定您应该使用的应用程序。您是否想使用 Xfce 的 Thunar 作为文件管理器GNOME 的 gedit 去编辑文本? I3 并不在乎。选择对您的工作流最有意义的工具I3 将以相同的方式管理它们。
### 2\. 屏幕实际使用面积
作为平铺式窗口管理器, I3 将自动 "平铺" 或以不重叠的方式定位窗口, 类似于在墙上放置瓷砖。因为您不需要担心窗口定位, i3 一般会更好地利用您的屏幕空间。它还可以让您更快地找到您需要的东西。
对于这种情况有很多有用的例子。例如, 系统管理员可以打开多个?来同时监视或在不同的远程系统上工作;开发人员可以使用他们最喜欢的 IDE 或编辑器和几个?来测试他们的程序。
此外, i3 具有灵活性。如果您需要为特定窗口提供更多空间, 请启用全屏模式或切换到其他布局, 如堆叠或选项卡式(标签式)。
### 3\. 键盘驱动的工作流程
i3 广泛使用键盘快捷键来控制环境的不同方面。其中包括打开?和其他程序、调整大小和定位窗口、更改布局, 甚至退出 i3。当您开始使用 i3 时, 您需要记住其中的一些快捷方式来绕行,随着时间的推移,您会使用更多的快捷方式。
主要好处是, 您不需要经常用键盘和鼠标切换上下文。通过练习, 意味着您将提高工作流程的速度和效率。
例如, 要打开新的?,请按 `<SUPER>+<ENTER>` .由于窗口是自动定位的, 您可以立即开始键入命令。结合一个很好的?驱动的文本编辑器 (如 Vim) 和一个以键盘为焦点的浏览器,形成一个完全由键盘驱动的工作流程。
在 i3 中, 您可以为所有内容定义快捷方式。下面是一些示例:
* 打开?
* 打开浏览器
* 更改布局
* 调整窗口大小
* 控制音乐播放器
* 切换工作区
现在我已经习惯了这个工作形式,我已无法回到了常规的桌面环境。
### 4\. 灵活
i3 力求最小化,很少使用系统资源, 但这并不意味着它不可能漂亮。i3 具有灵活性, 可通过多种方式进行自定义, 以改善视觉体验。因为 i3 是一个窗口管理器, 所以它不提供启用自定义的工具,而是提供启用自定义的工具。您需要外部工具来实现这一点。一些例子:
* 用 `feh` 定义桌面的背景图片。
* 使用复合器管理器, 如`compton`以启用窗口淡入淡出和透明度等效果。
* 用 `dmenu``rofi`以启用可从键盘快捷方式启动的可自定义菜单。
* 用 `dunst` 用于桌面通知。
i3 是完全可配置的,您可以通过更新默认配置文件来控制它的各个方面。从更改所有键盘快捷键,到重新定义工作区的名称,再到修改状态栏,您都可以使 i3 以任何最适合您需要的方式运行。
![i3 with rofi menu and dunst desktop notifications][8]
i3 与 `rofi` 菜单和 `dunst` 桌面通知。
最后, 对于更高级的用户, i3 提供了完整的进程间通信([IPC][9]) 界面, 允许您使用您最喜爱的语言来开发脚本或程序,以实现更多的自定义选项。
### 5\. 工作空间
在 i3 中, 工作区是对窗口进行分组的一种简单方法。您可以根据您的工作流以不同的方式对它们进行分组。例如, 您可以将浏览器放在一个工作区上, ?命令行放在另一个工作区上, 将电子邮件客户端放在第三个工作区上, 等等。您甚至可以更改 i3 的配置, 以便始终将特定应用程序分配给它们自己的工作区。
切换工作区既快速又简单。像 i3 中的往常一样,使用键盘快捷方式执行此操作。按 `<SUPER>+num` 切换到工作区 `num` 。如果您养成了始终将应用程序组的窗口分配到同一工作区的习惯,则可以在它们之间快速切换,这使得工作区成为非常有用的功能。
此外,还可以使用工作区来控制多监视器的设置,其中每个监视器都可以获得初始工作区。如果切换到该工作区, 则切换到该监视器,而无需让手离开键盘。
最后i3 中还有另一种特殊类型的工作空间: the scratchpad便笺簿。它是一个不可见的工作区通过按快捷方式显示在其他工作区的中间。这是一种方便的方式来访问您经常使用的窗口或程序如电子邮件客户端或音乐播放器。
### 尝试一下吧
如果您重视简单性和效率, 并且不抵触使用键盘, i3 就是您的窗口管理器。有人说是为高级用户准备的,但情况不一定如此。你需要学习一些基本的快捷方式来度过开始的阶段,不久就会越来越自然并且不假思索地使用它们。
这篇文章只是触及了 i3 表面能做的事情。欲了解更多详情, 请咨询 [i3's documentation][10].
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/8/i3-tiling-window-manager
作者:[Ricardo Gerardi][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[lixinyuxx](https://github.com/lixinyuxx)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://opensource.com/users/rgerardi
[1]:https://xfce.org/
[2]:https://i3wm.org/
[3]:https://code.google.com/archive/p/wmii/
[4]:https://xmonad.org/
[5]:/file/406476
[6]:https://opensource.com/sites/default/files/uploads/i3_screenshot.png "i3 tiled window manager screenshot"
[7]:/file/405161
[8]:https://opensource.com/sites/default/files/uploads/rofi_dunst.png "i3 with rofi menu and dunst desktop notifications"
[9]:https://i3wm.org/docs/ipc.html
[10]:https://i3wm.org/docs/userguide.html

View File

@ -1,76 +0,0 @@
学习 Golang 的 4 个技巧
======
到达 Golang 大陆:一个高级开发者的日记。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_laptop_code_programming_mountain_view.jpg?itok=yx5buqkr)
2014 年夏天...
> IBM“我们需要你弄清楚这个 Docker。”
> Me“没问题。”
> IBM“那就开始吧。”
> Me“好的。”内心声音”Docker 是用 Go 编写的。是吗Googles“哦一门编程语言。我在我的岗位上已经学习了很多了。这不会太难。”
我的大学新生编程课是使用 VAX 汇编程序教授的。在数据结构课上,我们在图书馆计算机中心的旧电脑上使用 Pascal 加载的软盘。在一门更上一级的课程中,我有一个教授喜欢用 ADA 去展示所有的例子。我在我们的 Sun 工作站上通过各种的 UNIX 的实用源代码学到了一点 C。在 IBM我们使用 C 和一些 x86 汇编程序来获取 OS/2 源代码,我们大量使用 C++ 的面向对象功能与 Apple 合作。不久后我学到了 shell 脚本,并开始使用 csh但是在 90 年代中期发现 Linux 后就转到了 Bash。在 90 年代后期将其移植到 Linux 时,我正在研究 IBM 的自定义 JVM 代码中的即时JIT编译器因此我开始学习 m4可以说是宏编程器而不是编程语言
快进 20 年... 我从未因为学习一门新的编程语言而焦灼。但是 [Go][1] 感觉有些不同。我打算在 GitHub 上游公开贡献,让任何有兴趣的人都可以看到!作为一个 40 多岁高级开发者的 Go 新手,我不想成为一个笑话。我们都知道程序员的骄傲是不想受伤,不论你的经验水平如何。
我早期的调查显示Go 似乎比某些语言更倾向于 “惯用语”。它不仅仅是编译代码; 我需要能够用 “Go 的方式” 写代码。
现在在我的私人 Go 日志上,四年有上百个 pull requests我不是致力于成为一个专家但是我觉得贡献和编写代码比我在 2014 年的时候更舒服了。所以,你该怎么教一个老人新的技能或者至少一门编程语言?以下是我自己在前往 Golang 大陆的四个步骤。
### 1. 不要跳过基础
虽然你可以通过复制代码来进行你早期的学习还有谁有时间阅读手册Go 有一个非常易读的 [语言规范][2],它写的很清楚,即便你在语言或者编译理论方面没有硕士学位。鉴于 Go 在 **参数:类型** 的顺序做的独特决定,在使用有趣的语言功能,例如 通道和 goroutines 时,搞定这些新概念是非常重要的是事情。阅读文档 [高效 Go 编程][3],这是 Golang 创作者的另一个重要资源,它将为你提供有效和正确使用语言的准备。
### 2. 从最好的中学习
有许多宝贵的资源可供挖掘,并将你的 Go 知识提升到下一个等级。最近在 [GopherCon][4] 上的所有谈话都可以在网上找到,就像 [GopherCon US 在 2018][5] 中的详尽列表一样。谈话的专业知识和技术水平各不相同,但是你可以通过谈话轻松地找到一些你不了解的事情。[Francesc Campoy][6] 创建了一个名叫 [JustForFunc][7] 的 Go 编程视频系列,其中有越来越多的剧集来拓宽你的 Go 知识和理解。快速搜索 “Golang" 可以为那些想要了解更多信息的人们展示许多其他视频和在线资源。
想要看代码?在 GitHub 上许多受欢迎的云原生项目都是用 Go 写的:[Docker/Moby][8][Kubernetes][9][Istio][10][containerd][11][CoreDNS][12],以及许多其他的。语言纯粹者可能会评价一些项目的惯用语优于其他的,但是这些都是在了解大型代码在高度活跃的项目中开始使用 Go 的大好起点。
### 3. 使用优秀的语言工具
你将要快速了解有关 [gofmt][13] 的宝贵之处。Go 最漂亮的一个地方就在于没有关于每个项目代码格式的争论 —— **gofmt** 内置在语言的运行库中,并且根据一系列稳固、易于理解的语言规则对 Go 代码进行格式化。我不理解任何基于 Golang 不坚持使用 **gofmt** 检查 pull requests 作为持续集成一部分的项目。
除了直接构建在 runtime/SDK 有价值的工具之外,我强烈建议使用一个对 Golang 的特性有良好支持的编辑器或者 IDE。由于我经常在命令行中进行工作我依赖于 Vim 加上强大的 [vim-go][14] 插件。我也喜欢微软提供的 [VS Code][15],特别是它的 [Go language][16] 插件。
想要一个调试器?[Delve][17] 项目在不断的改进和成熟,而且是在 Go 二进制文件上进行 [gdb][18] 式调试的强有力的竞争者。
### 4. 写一些代码
你要是不开始尝试使用 Go 写代码,你永远不知道它有什么好的地方。找一个有 “需要帮助” 问题标签的项目,然后开始贡献代码。如果你已经使用了一个用 Go 编写的开源项目,找出它是否有一些用初学者方式解决的 Bugs然后开始你的第一个 pull request。与生活中的大多数事情一样唯一真正的改进方法就是通过实践所以开始吧。
事实证明,你似乎可以教一个老高级开发者至少一门新的技能或者编程语言。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/11/learning-golang
作者:[Phill Estes][a]
选题:[lujun9972][b]
译者:[dianbanjiu](https://github.com/dianbanjiu)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/estesp
[b]: https://github.com/lujun9972
[1]: https://golang.org/
[2]: https://golang.org/ref/spec
[3]: https://golang.org/doc/effective_go.html
[4]: https://www.gophercon.com/
[5]: https://tqdev.com/2018-gophercon-2018-videos-online
[6]: https://twitter.com/francesc
[7]: https://www.youtube.com/channel/UC_BzFbxG2za3bp5NRRRXJSw
[8]: https://github.com/moby/moby
[9]: https://github.com/kubernetes/kubernetes
[10]: https://github.com/istio/istio
[11]: https://github.com/containerd/containerd
[12]: https://github.com/coredns/coredns
[13]: https://blog.golang.org/go-fmt-your-code
[14]: https://github.com/fatih/vim-go
[15]: https://code.visualstudio.com/
[16]: https://code.visualstudio.com/docs/languages/go
[17]: https://github.com/derekparker/delve
[18]: https://www.gnu.org/software/gdb/

View File

@ -0,0 +1,143 @@
如何在 Linux 上安装设备驱动程序
======
学习 Linux 设备驱动如何工作,并知道如何使用它们。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/car-penguin-drive-linux-yellow.png?itok=twWGlYAc)
对于一个熟悉 Windows 或者 MacOS 的人,想要切换到 Linux它们都会面临一个艰巨的问题就是怎么安装和配置设备驱动。这是可以理解的因为 Windows 和 MacOS 都有一套机制把这个过程做得非常的友好。比如说,当你插入一个新的硬件设备, Windows 能够自动检测并会弹出一个窗口询问你是否要继续驱动程序。你也可以从网络上下载驱动程序,仅仅需要双击解压或者是通过设备管理器导入驱动程序即可。
而这在 Linux 操作系统上并非这么简单。第一个原因是, Linux 是一个开源的操作系统,所以有 [数百种 Linux 发行版的变体][1]。也就是说不可能做一个指南来适应所有的 Linux 发行版。因为每种 Linux 安装驱动程序的过程都有差异。
第二,大多数默认的 Linux 驱动程序也都是开源的,并被集成到了系统中,这使得安装一些并未包含的驱动程序变得非常复杂,即使已经可以检测大多数的硬件设备。第三,不同发行版的许可也有差异。例如,[Fedora 禁止事项][2] 禁止包含专有的,受法律保护,或者是违反美国法律的驱动程序。而 Ubuntu 则让用户[避免使用受法律保护或闭源的硬件设备][3]。
为了更好的学习 Linux 驱动程序是如何工作的,我建议阅读 Linux 设备驱动程序一书中的 [设备驱动程序简介][4]。
### 两种方式来寻找驱动程序
#### 1\. 用户界面
如果是一个刚从 Windows 或 MacOS 转过来的 Linux 新手,那你会很高兴知道 Linux 也提供了一个通过向导式的程序来查看驱动程序是否可用的方法。 Ubuntu 提供了一个 [附加驱动程序][5] 选项。其它的 Linux 发行版也提供了帮助程序,像 [GNOME 的包管理器][6],你可以使用它来检查驱动程序是否可用。
#### 2\. 命令行
如果你通过漂亮的用户界面找到驱动程序,那又该怎么办呢?或许你只能通过没有任何图形界面的 shell甚至你可以使用控制台来展现你的技能。你有两个选择
A. **通过一个仓库**
这和 MacOS 中的 [**homebrew**][7] 命令行很像。通过使用 `yum` , `dnf` , `apt-get` , 等等。你基本可以通过添加仓库,并更新包缓存。
B. **下载, 编译, 然后自己构建**
这通常包括直接从网络,或通过 `wget` 命令下载源码包,然后运行配置和编译、安装。这超出了本文的范围,但是你可以在网络上找到很多在线指南,如果你选择的是这条路的话。
### 检查是否已经安装了这个驱动程序
在进一步学习安装 Linux 驱动程序之前,让我们来学习几条命令,用来检测驱动程序是否已经在你的系统上可用。
[`lspci`][8] 命令显示了系统上所有 PCI 总线和设备驱动程序的详细信息。
```
$ lscpci
```
或者使用 `grep`
```
$ lscpci | grep SOME_DRIVER_KEYWORD
```
例如,你可以使用 `lspci | grep SAMSUNG` 命令,如果你想知道是否安装过三星的驱动。
[`dmesg`][9] 命令显示了所有内核识别的驱动程序。
```
$ dmesg
```
或配合 `grep` 使用
```
$ dmesg | grep SOME_DRIVER_KEYWORD
```
任何识别到的驱动程序都会显示在结果中。
如果通过 `dmesg` 或者 `lscpi` 命令没有识别到任何驱动程序,尝试下这两个命令,看看驱动程序至少是否加载到硬盘。
```
$ /sbin/lsmod
```
```
$ find /lib/modules
```
小贴士:和`lspci` 或 `dmesg` 一样,通过在上面的命令后面加上 `| grep` 来过滤结果。
如果一个驱动程序已经被识别到了,但是通过 `lscpi``dmesg` 并没有找到,这意味着驱动程序已经存在于硬盘上,但是并没有加载到内核中,这种情况,你可以通过 `modprobe` 命令来加载这个模块。
```
$ sudo modprobe MODULE_NAME
```
使用 `sudo` 来运行这个命令,因为这个模块要使用 root 权限来安装。
### 添加仓库并安装
可以通过 `yum` , `dnf` , 和 `apt-get` 几种不同的方式来添加一个仓库;一个个介绍完它们并不在本文的范围。简单一点来说,这个示例将会使用 `apt-get` ,但是这个命令和其它的几个都是很类似的。
**1\. 删除存在的仓库,如果它存在.**
```
$ sudo apt-get purge NAME_OF_DRIVER*
```
其中 `NAME_OF_DRIVER` 是你的驱动程序的可能的名称。你还可以将模式匹配加到正则表达式中来进一步过滤。
**2\. 将仓库加入到仓库表中,这应该在驱动程序指南中有指定**
```
$ sudo add-apt-repository REPOLIST_OF_DRIVER
```
其中 `REPOLIST_OF_DRIVER` 应该从驱动文档中有指定(例如:`epel-list`)。
**3\. 更新仓库列表。**
```
$ sudo apt-get update
```
**4\. 安装驱动程序。**
```
$ sudo apt-get install NAME_OF_DRIVER
```
**5\. 检查安装状态.**
像上面说的一样,通过 `lscpi` 命令来检查驱动程序是否已经安装成功。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/11/how-install-device-driver-linux
作者:[Bryant Son][a]
选题:[lujun9972][b]
译者:[Jamskr](https://github.com/Jamskr)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/brson
[b]: https://github.com/lujun9972
[1]: https://en.wikipedia.org/wiki/List_of_Linux_distributions
[2]: https://fedoraproject.org/wiki/Forbidden_items?rd=ForbiddenItems
[3]: https://www.ubuntu.com/licensing
[4]: https://www.xml.com/ldd/chapter/book/ch01.html
[5]: https://askubuntu.com/questions/47506/how-do-i-install-additional-drivers
[6]: https://help.gnome.org/users/gnome-packagekit/stable/add-remove.html.en
[7]: https://brew.sh/
[8]: https://en.wikipedia.org/wiki/Lspci
[9]: https://en.wikipedia.org/wiki/Dmesg

View File

@ -0,0 +1,290 @@
在 Linux 上自定义 bash 命令提示符
======
![](https://www.ostechnix.com/wp-content/uploads/2017/10/BASH-720x340.jpg)
众所周知,**bash**the **B**ourne-**A**gain **Sh**ell是目前绝大多数 Linux 发行版使用的默认 shell。本文将会介绍如何通过添加颜色和样式来自定义 bash 命令提示符的显示。尽管很多插件或工具都可以很轻易地满足这一需求,但我们也可以不使用插件和工具,自己手动自定义一些基本的显示方式,例如添加或者修改某些元素、更改前景色、更改背景色等等。
### 在 Linux 中自定义 bash 命令提示符
在 bash 中,我们可以通过更改 `$PS1` 环境变量的值来自定义 bash 命令提示符。
一般情况下bash 命令提示符会是以下这样的形式:
![](https://www.ostechnix.com/wp-content/uploads/2017/10/Linux-Terminal.png)
在上图这种默认显示形式当中sk 是我的用户名,而 ubuntuserver 是我的主机名。
只要插入一些以反斜杠开头的特殊转义字符串,就可以按照你的喜好修改命令提示符了。下面我来举几个例子。
在开始之前,我强烈建议你预先备份 `~/.bashrc` 文件。
```
$ cp ~/.bashrc ~/.bashrc.bak
```
#### 更改 bash 命令提示符中的 username@hostname 部分
如上所示bash 命令提示符一般都带有 username@hostname 部分,这个部分是可以修改的。
只需要编辑 `~/.bashrc` 文件:
```
$ vi ~/.bashrc
```
在文件的最后添加一行:
```
PS1="ostechnix> "
```
将上面的“ostechnix”替换为任意一个你想使用的单词然后按 `ESC` 并输入 `:wq` 保存、退出文件。
执行以下命令使刚才的修改生效:
```
$ source ~/.bashrc
```
你就可以看见 bash 命令提示符中出现刚才添加的“ostechnix”了。
![][3]
再来看看另一个例子,比如将 username@hostname 替换为 Hello@welcome>。
同样是像刚才那样修改 `~/.bashrc` 文件,然后执行 `source ~/.bashrc` 让修改结果立即生效。
以下是我在 Ubuntu 18.04 LTS 上修改后的效果。
![](https://www.ostechnix.com/wp-content/uploads/2017/10/bash-prompt-1.png)
#### 仅显示用户名
如果需要仅显示用户名,只需要在 `~/.bashrc` 文件中加入以下这一行。
```
export PS1="\u "
```
这里的 `\u` 就是一个转义字符串。
下面提供了一些可以添加到 `$PS1` 环境变量中的用以改变 bash 命令提示符样式的转义字符串。每次修改之后,都需要执行 `source ~/.bashrc` 命令才能立即生效。
**显示用户名和主机名:**
```
export PS1="\u\h "
```
命令提示符会这样显示:
```
skubuntuserver
```
**显示用户名和<ruby>完全限定域名<rt>Fully Qualified Domain Name</rt></ruby>FQDN**
```
export PS1="\u\H "
```
**在用户名和主机名之间显示其它字符**
如果你还需要在用户名和主机名之间显示其它字符(例如 `@`),可以使用以下格式:
```
export PS1="\u@\h "
```
命令提示符会这样显示:
```
sk@ubuntuserver
```
**显示用户名、主机名,并在末尾添加符号**
```
export PS1="\u@\h\\$ "
```
**综合以上两种显示方式**
```
export PS1="\u@\h> "
```
命令提示符最终会这样显示:
```
sk@ubuntuserver>
```
相似地,还可以添加其它特殊字符,例如冒号、分号、星号、下划线、空格等等。
**显示用户名、主机名、shell 名称**
```
export PS1="\u@\h>\s "
```
**显示用户名、主机名、shell 名称以及 shell 版本**
```
export PS1="\u@\h>\s\v "
```
bash 命令提示符显示样式:
![][4]
**显示用户名、主机名、当前目录**
```
export PS1="\u@\h\w "
```
如果当前目录是 `$HOME` ,会以一个波浪线(`~`)显示。
**在 bash 命令提示符中显示日期**
除了用户名和主机名,如果还想在 bash 命令提示符中显示日期,可以在 `~/.bashrc` 文件中添加以下内容:
```
export PS1="\u@\h>\d "
```
![][5]
**在 bash 命令提示符中显示日期及 12 小时制时间**
```
export PS1="\u@\h>\d\@ "
```
**显示日期及 hh:mm:ss 格式时间**
```
export PS1="\u@\h>\d\T "
```
**显示日期及 24 小时制时间**
```
export PS1="\u@\h>\d\A "
```
**显示日期及 24 小时制 hh:mm:ss 格式时间**
```
export PS1="\u@\h>\d\t "
```
以上是一些常见的可以改变 bash 命令提示符的转义字符串。除此以外的其它转义字符串,可以在 bash 的 man 手册 PROMPTING 章节中查阅。
你也可以随时执行以下命令查看当前的命令提示符样式。
```
$ echo $PS1
```
#### 在 bash 命令提示符中去掉 username@hostname 部分
如果我不想做任何调整,直接把 username@hostname 部分整个去掉可以吗?答案是肯定的。
如果你是一个技术方面的博主,你有可能会需要在网站或者博客中上传自己的 Linux 终端截图。或许你的用户名和主机名太拉风、太另类,不想让别人看到,在这种情况下,你就需要隐藏命令提示符中的 username@hostname 部分。
如果你不想暴露自己的用户名和主机名,只需要按照以下步骤操作。
编辑 `~/.bashrc` 文件:
```
$ vi ~/.bashrc
```
在文件末尾添加这一行:
```
PS1="\W> "
```
输入 `:wq` 保存并关闭文件。
执行以下命令让修改立即生效。
```
$ source ~/.bashrc
```
现在看一下你的终端username@hostname 部分已经消失了,只保留了一个 `~>` 标记。
![][6]
如果你想要尽可能简单的操作,又不想弄乱你的 `~/.bashrc` 文件,最好的办法就是在系统中创建另一个用户(例如 user@example、admin@demo。用带有这样的命令提示符的用户去截图或者录屏就不需要顾虑自己的用户名或主机名被别人看见了。
**警告:**在某些情况下,这种做法并不推荐。例如像 zsh 这种 shell 会继承当前 shell 的设置,这个时候可能会出现一些意想不到的问题。这个技巧只用于隐藏命令提示符中的 username@hostname 部分,仅此而已,如果把这个技巧挪作他用,也可能会出现异常。
### 为 bash 命令提示符着色
目前我们也只是变更了 bash 命令提示符中的内容,下面介绍一下如何对命令提示符进行着色。
通过向 `~/.bashrc` 文件写入一些配置,可以修改 bash 命令提示符的前景色(也就是文本的颜色)和背景色。
例如,下面这一行配置可以令某些文本的颜色变成红色:
```
export PS1="\u@\[\e[31m\]\h\[\e[m\] "
```
添加配置后,执行 `source ~/.bashrc` 立即生效。
你的 bash 命令提示符就会变成这样:
![][7]
类似地,可以用这样的配置来改变背景色:
```
export PS1="\u@\[\e[31;46m\]\h\[\e[m\] "
```
![][8]
### 添加 emoji
大家都喜欢 emoji。还可以按照以下配置把 emoji 插入到命令提示符中。
```
PS1="\W 🔥 >"
```
需要注意的是emoji 的显示取决于使用的字体,因此某些终端可能会无法正常显示 emoji取而代之的是一些乱码或者单色表情符号。
### 自定义 bash 命令提示符有点难,有更简单的方法吗?
如果你是一个新手,编辑 `$PS1` 环境变量的过程可能会有些困难,因为命令提示符中的大量转义字符串可能会让你有点晕头转向。但不要担心,有一个在线的 bash `$PS1` 生成器可以帮助你轻松生成各种 `$PS1` 环境变量值。
就是这个网站:
[![EzPrompt](https://www.ostechnix.com/wp-content/uploads/2017/10/EzPrompt.png)][9]
只需要直接选择你想要的 bash 命令提示符样式,添加颜色、设计排序,然后就完成了。你可以预览输出,并将配置代码复制粘贴到 `~/.bashrc` 文件中。就这么简单。顺便一提,本文中大部分的示例都是通过这个网站制作的。
### 我把我的 `~/.bashrc` 文件弄乱了,该如何恢复?
正如我在上面提到的,强烈建议在更改 `~/.bashrc` 文件前做好备份(在更改其它重要的配置文件之前也一定要记得备份)。这样一旦出现任何问题,你都可以很方便地恢复到更改之前的配置状态。当然,如果你忘记了备份,还可以按照下面这篇文章中介绍的方法恢复为默认配置。
[如何将 `~/.bashrc` 文件恢复到默认配置][10]
这篇文章是基于 ubuntu 的,但也适用于其它的 Linux 发行版。不过事先声明,这篇文章的方法会将 `~/.bashrc` 文件恢复到系统最初时的状态,你对这个文件做过的任何修改都将丢失。
感谢阅读!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/hide-modify-usernamelocalhost-part-terminal/
作者:[SK][a]
选题:[lujun9972][b]
译者:[HankChow](https://github.com/HankChow)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.ostechnix.com/author/sk/
[b]: https://github.com/lujun9972
[1]: https://www.ostechnix.com/cdn-cgi/l/email-protection
[2]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
[3]: http://www.ostechnix.com/wp-content/uploads/2017/10/Linux-Terminal-2.png
[4]: http://www.ostechnix.com/wp-content/uploads/2017/10/bash-prompt-2.png
[5]: http://www.ostechnix.com/wp-content/uploads/2017/10/bash-prompt-3.png
[6]: http://www.ostechnix.com/wp-content/uploads/2017/10/Linux-Terminal-1.png
[7]: http://www.ostechnix.com/hide-modify-usernamelocalhost-part-terminal/bash-prompt-4/
[8]: http://www.ostechnix.com/hide-modify-usernamelocalhost-part-terminal/bash-prompt-5/
[9]: http://ezprompt.net/
[10]: https://www.ostechnix.com/restore-bashrc-file-default-settings-ubuntu/