Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2019-12-09 06:02:52 +08:00
commit bfa8e92488
15 changed files with 1672 additions and 589 deletions

View File

@ -1,8 +1,8 @@
[#]: collector: (lujun9972)
[#]: translator: (wxy)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-11654-1.html)
[#]: subject: (How to port an awk script to Python)
[#]: via: (https://opensource.com/article/19/11/awk-to-python)
[#]: author: (Moshe Zadka https://opensource.com/users/moshez)
@ -12,13 +12,13 @@
> 将一个 awk 脚本移植到 Python 主要在于代码风格而不是转译。
![Woman sitting in front of her laptop][1]
![](https://img.linux.net.cn/data/attachment/album/201912/08/095256ko6xdfwooe8zctfz.jpg)
脚本是解决问题的有效方法,而 awk 是编写脚本的出色语言。它特别擅长于简单的文本处理,它可以带你完成配置文件的某些复杂重写或目录中文件名的重新格式化。
### 何时从 awk 转向 Python
但是在某方面awk 的限制开始显现出来。它没有将文件分解为模块的真正概念,它缺乏质量错误报告,并且缺少了现在被认为是编程语言工作原理的其他内容。当编程语言的这些丰富功能有助于维护关键脚本时,移植将是一个不错的选择。
但是在某方面awk 的限制开始显现出来。它没有将文件分解为模块的真正概念,它缺乏质量错误报告,并且缺少了现在被认为是编程语言工作原理的其他内容。当编程语言的这些丰富功能有助于维护关键脚本时,移植将是一个不错的选择。
我最喜欢的完美移植 awk 的现代编程语言是 Python。
@ -75,7 +75,7 @@ def awk_like_lines(list_of_file_names):
### 更复杂的 FNR、NR 和行数的 awk 行为
如果 `FNR`、`NR` 和行数这三个你全部需要,仍然会有问题。如果确实如此,则使用三元组(其中两个项目是数字)会导致混淆。命名参数可使该代码更易于阅读,因此最好使用 `dataclass
如果 `FNR`、`NR` 和行数这三个你全都需要,仍然会有一些问题。如果确实如此,则使用三元组(其中两个项目是数字)会导致混淆。命名参数可使该代码更易于阅读,因此最好使用 `dataclass`
```
import dataclass
@ -95,7 +95,7 @@ def awk_like_lines(list_of_file_names):
        yield AwkLikeLine(nr=nr, fnr=fnr, line=line)
```
你可能想知道,为什么不总用这种方法呢?用其它方式的的原因是这总是太复杂了。如果你的目标是把一个通用库更容易地从 awk 移植到 Python请考虑这样做。但是编写一个可以使你确切地了解特定情况所需的循环的方法通常更容易实现也更容易理解因而易于维护
你可能想知道,为什么不一直用这种方法呢?使用其它方式的的原因是总用这种方法太复杂了。如果你的目标是把一个通用库更容易地从 awk 移植到 Python请考虑这样做。但是编写一个可以使你确切地了解特定情况所需的循环的方法通常更容易实现也更容易理解因而易于维护
### 理解 awk 字段
@ -181,7 +181,7 @@ for line in unique_generator(open("your_file")):
将 awk 脚本移植到 Python 时,通常是在考虑适当的 Python 代码风格时重新实现核心需求,而不是按条件/操作进行笨拙的音译。考虑原始上下文并产生高质量的 Python 解决方案。虽然有时候使用 awk 的 Bash 单行代码可以完成这项工作,但 Python 编码是通往更易于维护的代码的途径。
另外如果你正在编写awk脚本我相信您也可以学习 Python如果你有任何疑问请告诉我。
另外,如果你正在编写 awk 脚本,我相信您也可以学习 Python如果你有任何疑问请告诉我。
--------------------------------------------------------------------------------
@ -190,7 +190,7 @@ via: https://opensource.com/article/19/11/awk-to-python
作者:[Moshe Zadka][a]
选题:[lujun9972][b]
译者:[wxy](https://github.com/wxy)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,34 +1,34 @@
[#]: collector: (lujun9972)
[#]: translator: (hj24)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-11653-1.html)
[#]: subject: (Using Ansible to organize your SSH keys in AWS)
[#]: via: (https://fedoramagazine.org/using-ansible-to-organize-your-ssh-keys-in-aws/)
[#]: author: (Daniel Leite de Abreu https://fedoramagazine.org/author/dabreu/)
在 AWS 中使用 Ansible 来管理你的 SSH keys
在 AWS 中使用 Ansible 来管理你的 SSH 密钥
======
![][1]
如果你长期使用亚马逊Web服务AWS中的实例你可能会遇到下面这个常见的问题它不是因为技术性的原因导致的更多的是因为人类追求方便舒适的天性当你登录一台你最近没有使用的区域的实例你最终会创建一个新的SSH密钥对久而久之这最终就会造成个人拥有太多密钥导致管理起来复杂混乱。
如果你长期使用亚马逊 Web 服务AWS中的实例你可能会遇到下面这个常见的问题它不是因为技术性的原因导致的更多的是因为人类追求方便舒适的天性当你登录一台你最近没有使用的区域的实例,你最终会创建一个新的 SSH 密钥对,久而久之这最终就会造成个人拥有太多密钥,导致管理起来复杂混乱。
本文将会介绍一种在所有区域中使用你的公钥的方法。最近,一篇[Fedora Magazine article][2]介绍了另一种解决方案。但本文中的解决方案可以进一步的以更简洁和可扩展的方式实现自动化。
本文将会介绍一种在所有区域中使用你的公钥的方法。最近,一篇 [Fedora Magazine 的文章][2]介绍了另一种解决方案。但本文中的解决方案可以进一步的以更简洁和可扩展的方式实现自动化。
假设你有一个Fedora 30或31系统其中存储了你的密钥并且还安装了Ansible。当这两件事同时满足时就提供了解决这个问题的办法甚至它还能做到更多。
假设你有一个 Fedora 30 31 系统,其中存储了你的密钥,并且还安装了 Ansible。当这两件事同时满足时就提供了解决这个问题的办法甚至它还能做到更多。
使用Ansible的[ec2_key 模块][3],你可以创建一个简单的playbook来在所有区域中维护你的SSH密钥对。如果你需要增加或者删除密钥在ansible中这就像从文件中添加和删除行一样简单。
使用 Ansible [ec2_key 模块][3],你可以创建一个简单的 Ansible 剧本来在所有区域中维护你的 SSH 密钥对。如果你需要增加或者删除密钥,在 Ansible 中这就像从文件中添加和删除行一样简单。
### 设置和运行 playbook
### 设置和运行 Ansible 剧本
如果要使用playbook首先需要安装 _ec2_key_ 模块的必要依赖项:
如果要使用剧本,首先需要安装 `ec2_key` 模块的必要依赖项:
```
$ sudo dnf install python3-boto python3-boto3
```
playbook很简单:你只需要像下面的例子一样,修改其中的密钥及其对应的名称。然后,运行playbook它会帮你遍历所有列出的公共AWS区域。该示例还包括一些受限区域以防你有访问权限只需根据需要来取消对应行的注释然后保存文件重新运行playbook即可。
该剧本很简单:你只需要像下面的例子一样,修改其中的密钥及其对应的名称。然后,运行该剧本,它会帮你遍历所有列出的公共 AWS 区域。该示例还包括一些你可能要访问的受限区域,只需根据需要来取消对应行的注释,然后,保存文件重新运行剧本即可。
```
---
@ -71,34 +71,35 @@ playbook很简单你只需要像下面的例子一样修改其中的密钥
# - cn-northwest-1 #China (Ningxia)
```
这个playbook需要通过API访问AWS为此请使用环境变量如下所示
这个剧本需要通过 API 访问 AWS为此请使用环境变量如下所示
```
$ AWS_ACCESS_KEY="aws-access-key-id" AWS_SECRET_KEY="aws-secret-key-id" ansible-playbook ec2-playbook.yml
```
另一个选项是安装aws cli工具并添加凭据如以前的一篇[Fedora Magazine article][4]文章所述。如果你在线存储它们这些参数将不建议插入到playbook中你可以在[GitHub][5]中找到本文的playbook代码。
另一个方式是安装 aws 命令行工具并添加凭据,如以前的一篇 [Fedora Magazine 文章][4]所述。如果你在线存储它们,这些参数将**不建议**插入到剧本中!你可以在 [GitHub][5] 中找到本文的剧本代码。
完成playbook之后请确认你的密钥在AWS控制台上可用。为此可以做如下操作
1. 登录你的AWS控制台
2. 转到 **EC2 > Key Pairs**
3. 您应该会看到列出的密钥。唯一的限制是你必须使用此方法逐个区域来检查。
完成该剧本之后,请确认你的密钥在 AWS 控制台上可用。为此,可以做如下操作:
另一种方法是在shell中使用一个快速命令来为你做这些检查。
1. 登录你的 AWS 控制台
2. 转到 “EC2 > Key Pairs”
3. 你应该会看到列出的密钥。唯一的限制是你必须使用此方法逐个区域来检查。
首先在playbook上创建一个包含所有区域的变量
另一种方法是在 shell 中使用一个快速命令来为你做这些检查。
首先在剧本上创建一个包含所有区域的变量:
```
AWS_REGION="us-east-1 us-west-1 us-west-2 ap-east-1 ap-south-1 ap-northeast-2 ap-southeast-1 ap-southeast-2 ap-northeast-1 ca-central-1 eu-central-1 eu-west-1 eu-west-2 eu-west-3 eu-north-1 me-south-1 sa-east-1"
```
然后执行如下循环你就可以从aws的API获得结果
然后,执行如下循环,你就可以从 aws API 获得结果:
```
for each in ${AWS_REGION} ; do aws ec2 describe-key-pairs --key-name <YOUR KEY GOES HERE> ; done
```
请记住,要执行上述操作,您需要安装 aws cli
请记住,要执行上述操作,你需要安装 aws 命令行
--------------------------------------------------------------------------------
@ -107,7 +108,7 @@ via: https://fedoramagazine.org/using-ansible-to-organize-your-ssh-keys-in-aws/
作者:[Daniel Leite de Abreu][a]
选题:[lujun9972][b]
译者:[hj24](https://github.com/hj24)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -0,0 +1,93 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (New machine learning from Alibaba and Netflix, mimicking animal vision, and more open source news)
[#]: via: (https://opensource.com/article/19/12/news-december-7)
[#]: author: (Scott Nesbitt https://opensource.com/users/scottnesbitt)
New machine learning from Alibaba and Netflix, mimicking animal vision, and more open source news
======
Catch up on the biggest open source headlines from the past two weeks.
![Weekly news roundup with TV][1]
In this edition of our open source news roundup, we take a look an open source election auditing tool, new open source from Alibaba and Netflix, mimicking animal vision, and more!
### Alibaba and Netflix share machine learning and data science software
Two companies at the forefront of machine learning and data science have just released some of their tools under open source licenses.
Chinese ecommerce giant Alibaba just [open sourced the algorithm libraries][2] for its Alink platform. The algorithms "are essential to support machine learning tasks such as online product recommendations and smart customer services." According to Jia Yangqing, president of Alibaba Cloud, Alink is a good fit for "developers seeking big data and machine-learning tools." You can find the source code for Alink (which is under an Apache 2.0 license) [on GitHub][3], with documentation in both Chinese and English.
Not to be outdone, streaming service Netflix just released its [Metaflow Python library][4] under an Apache 2.0 license. Metaflow enables data scientists to "see early on whether a prototyped model would fail in production, allowing them to fix whatever the issue was". It also works with a number of Python data science libraries, like SciKit Learn, Pytorch, and Tensorflow. You can grab Metaflow's code from [its GitHub repository][5] or learn more about it at the [Metaflow website][6].
### Open source software to mimic animal vision
Have you ever wondered how your dog or cat sees the world? Thanks to work by researchers at the University of Exeter in the UK and Australia's University of Queensland, you can find out. The team just released [software that allows humans to see the world as animals do][7].
Called micaToolbox, the software can interpret digital photos and process images of various environments by mimicking the limitations of animal vision. Anyone with a camera, a computer, or smartphone can use the software without knowing how to code. But micaToolbox isn't just a novelty. It's a serious scientific tool that can help "help biologists better understand a variety of animal behaviors, including mating systems, distance-dependent signalling and mimicry." And, according to researcher Jolyon Troscianko, the software can help identify "how an animal's camouflage works so that we can manage our land to protect certain species."
You can [download micaBox][8] or [browse its source code][9] on GitHub.
### New tool for post-election auditing
More and more aspects of our lives and institutions are being automated. With that comes an increased danger of systems breaking down or malicious someones tampering with those systems. Open source gives us an opportunity to look at exactly how the automation works.
Elections, in particular, are increasingly vulnerable. To combat election tampering, the US Cybersecurity and Infrastructure Security Agency (CISA) has joined forces with the non-profit organization VotingWorks to create a [web-based application for auditing ballots][10].
Called Arlo, the application is designed to ensure that "elections are secure, resilient, and transparent," said CISA's director Chris Krebs. Arlo works with a range of automated voting systems to help "officials compare audited votes to tabulated votes, and providing monitoring &amp; reporting capabilities." Arlo was used to verify the results of recent state and local elections and is being further field-tested in the states of Georgia, Michigan, Missouri, Ohio, Pennsylvania, and Virginia.
Arlo's source code, released under an AGPL-3.0 license, is [available on GitHub][11].
### Royal Navy debuts open source application development kit
Consistency across user interfaces is key to a successful set of applications and services. The UK's Royal Navy understands the importance of this and has released the [open source NELSON standards toolkit][12] to help its developers and suppliers "save time and give users a consistent experience."
Named after the legendary British admiral, NELSON is intended to "maintain high visual consistency and user-experience quality across the different applications developed or subcontracted by the Royal Navy." The toolkit consists of a set of components including visual styles, typographic elements, forms, elements like buttons and checkboxes, and notifications.
NELSON has its own [GitHub repository][13], from which the Royal Navy encourages developers to make pull requests.
#### In other news
* [Council group plans for open source revenues and benefits platform][14]
* [Introducing Nebula, the open source global overlay network from Slack][15]
* [webOS Open Source Edition 2.0 keeps Palm's spirit alive in cars and IoT][16]
* [Duke University Introduces an Open Source Tool as an Alternative to a Monolithic LMS][17]
* [Open Source Technology Could Be a Boon to Farmers][18]
_Thanks, as always, to Opensource.com staff members and moderators for their help this week._
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/12/news-december-7
作者:[Scott Nesbitt][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/scottnesbitt
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/weekly_news_roundup_tv.png?itok=B6PM4S1i (Weekly news roundup with TV)
[2]: https://www.zdnet.com/article/alibaba-cloud-publishes-machine-learning-algorithm-on-github/
[3]: https://github.com/alibaba/alink
[4]: https://www.zdnet.com/article/netflix-our-metaflow-python-library-for-faster-data-science-is-now-open-source/
[5]: https://github.com/Netflix/metaflow
[6]: https://metaflow.org/
[7]: https://www.upi.com/Science_News/2019/12/03/Novel-software-helps-scientists-see-what-animals-see/5961575389734/
[8]: http://www.empiricalimaging.com/download/micatoolbox/
[9]: https://github.com/troscianko/micaToolbox
[10]: https://www.zdnet.com/article/cisa-and-votingworks-release-open-source-post-election-auditing-tool/
[11]: https://github.com/votingworks/arlo
[12]: https://joinup.ec.europa.eu/collection/open-source-observatory-osor/news/open-source-royal-navy
[13]: https://github.com/Royal-Navy/standards-toolkit
[14]: https://www.ukauthority.com/articles/council-group-plans-for-open-source-revenues-and-benefits/
[15]: https://slack.engineering/introducing-nebula-the-open-source-global-overlay-network-from-slack-884110a5579
[16]: https://www.slashgear.com/webos-open-source-edition-2-0-keeps-palms-spirit-alive-in-cars-and-iot-25601309/
[17]: https://iblnews.org/duke-university-introduces-an-open-source-tool-as-an-alternative-to-a-monolithic-lms/
[18]: https://civileats.com/2019/12/02/open-source-technology-could-be-a-boon-to-farmers/

View File

@ -0,0 +1,85 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (First Ever Release of Ubuntu Cinnamon Distribution is Finally Here!)
[#]: via: (https://itsfoss.com/ubuntu-cinnamon/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
First Ever Release of Ubuntu Cinnamon Distribution is Finally Here!
======
_**Brief: Ubuntu Cinnamon is a new distribution that utilizes Linux Mints Cinnamon desktop environment on top of Ubuntu code base. Its first stable release is based on Ubuntu 19.10 Eoan Ermine.**_
[Cinnamon][1] is Linux Mints flagship desktop environment. Like [MATE desktop][2], Cinnamon is also a product of dissatisfaction with GNOME 3. With the GNOME Classic like user interface and relatively lower hardware requirements, Cinnamon soon gathered a dedicated userbase.
Like any other desktop environment out there, you can [install Cinnamon on Ubuntu][3] and other distributions.
Installing multiple [desktop environments][4] (DE) is not a difficult task but it often leads to conflicts (with other DEs elements) and may not always provide the best experience. This is why major Linux distributions separate spins/flavors with various popular desktop environments.
[Ubuntu also has various official flavors][5] featuring [KDE][6] (Kubuntu), [LXQt][7] (Lubuntu), Xfce (Xubuntu), Budgie ([Ubuntu Budgie][8]) etc. Cinnamon was not in this list but Ubuntu Cinnamon Remix project is trying to change that.
### Ubuntu Cinnamon distribution
![Ubuntu Cinnamon Desktop Screenshot][9]
[Ubuntu Cinnamon][10] (website under construction) is a new Linux distribution that brings Cinnamon desktop to Ubuntu distribution. Joshua Peisach is the lead developer for the project and he is being helped by other volunteer contributors. The ex-developer of the now discontinued Ubuntu GNOME project and some members from Ubuntu team are also advising the team to help with the development.
![Ubuntu Cinnamon Remix Screeenshot 1][11]
Do note that Ubuntu Cinnamon is not an official flavor of Ubuntu. They are trying to get the flavorship but I think that will take a few more releases.
The first stable release of Ubuntu Cinnamon is based on [Ubuntu 19.10 Eoan Ermine][12]. It uses Calamares installer from Lubuntu and features Cinnamon desktop version 4.0.10. Naturally, it uses Nemo file manager and LightDM.
It supports EFI and UEFI and only comes with 64-bit support.
Youll get your regular goodies like LibreOffice, Firefox and some GNOME software and games. You can of course install more applications as per your need.
### Download and install Ubuntu Cinnamon
Do note that this is the first ever release of Ubuntu Cinnamon and the developers are not that experienced at this moment.
If you dont like troubleshooting, dont use it on your main system. I expect this release to have a few bugs and issues which will be fixed eventually as more users test it out.
You can download Ubuntu Cinnamon ISO from Sourceforge website:
[Download Ubuntu Cinnamon][13]
### What next from here?
The dev team has a few improvements planned for the 20.04 release. The changes are mostly on the cosmetics though. There will be new GRUB and Plymouth theme, layout application and welcome screen.
I downloaded it and tried it in a live session. Heres what this distribution looks like:
[Subscribe to our YouTube channel for more Linux videos][14]
Meanwhile, if you manage to try it on your own, why not share your experience in the comments? If you use Linux Mint, will you switch to Ubuntu Cinnamon in near future? What are your overall opinion about this new project? Do share it in the comment section.
--------------------------------------------------------------------------------
via: https://itsfoss.com/ubuntu-cinnamon/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://en.wikipedia.org/wiki/Cinnamon_(desktop_environment)
[2]: https://mate-desktop.org/
[3]: https://itsfoss.com/install-cinnamon-on-ubuntu/
[4]: https://itsfoss.com/best-linux-desktop-environments/
[5]: https://itsfoss.com/which-ubuntu-install/
[6]: https://kde.org/
[7]: https://lxqt.org/
[8]: https://itsfoss.com/ubuntu-budgie-18-review/
[9]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/12/ubuntu_cinnamon_distribution_screenshot.jpg?ssl=1
[10]: https://ubuntucinnamon.org/
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/ubuntu_cinnamon_remix_screeenshot_1.jpg?ssl=1
[12]: https://itsfoss.com/ubuntu-19-10-released/
[13]: https://sourceforge.net/projects/ubuntu-cinnamon-remix/
[14]: https://www.youtube.com/c/itsfoss?sub_confirmation=1

View File

@ -20,7 +20,7 @@ But how do you know you can trust a particular website? To put this a different
This article aims to demystify the mechanisms that make a website secure. I will start by discussing the web protocols HTTP and HTTPS and the concept of Transport Layer Security (TLS), which is one of the cryptographic protocols in the internet protocol's (IP) layers. Then, I will explain certificate authorities (CAs) and self-signed certificates and how they can help secure a website. Finally, I will introduce some open source tools you can use to create and manage certificates.
## Securing routes through HTTPS
### Securing routes through HTTPS
The easiest way to understand a secured website is to see it in action. Fortunately, it is far easier to find a secured website than an unsecured website on the internet today. But, since you are already on Opensource.com, I'll use it as an example. No matter what browser you're using, you should see an icon that looks like a lock next to the address bar. Click on the lock icon, and you should see something similar to this.
@ -40,7 +40,7 @@ This certificate information enables the end user to check that the website is s
If you see a warning sign, which is rare for most publicly facing websites, it usually means that the certificate is expired or uses a self-signed certificate instead of one issued through a trusted CA. Before we get into those topics, I want to explain the TLS and SSL.
## Internet protocols with TLS and SSL
### Internet protocols with TLS and SSL
TLS is the current generation of the old Secure Socket Layer (SSL) protocol. The best way to understand this is by examining the different layers of the IP.
@ -50,8 +50,77 @@ There are six layers that make up the internet as we know it today: physical, da
This process ensures that communication is secure and encrypted when an end user consumes the service.
## Certificate authorities and self-signed certificates
### Certificate authorities and self-signed certificates
A CA is a trusted organization that can issue a digital certificate.
TLS and SSL can make a connection secure, but the encryption mechanism needs a way to validate it; this is the SSL/TLS certificate. TLS uses a mechanism called asymmetric encryption, which i
TLS and SSL can make a connection secure, but the encryption mechanism needs a way to validate it; this is the SSL/TLS certificate. TLS uses a mechanism called asymmetric encryption, which is a pair of security keys called a private key and a public key. (This is a very complex topic that is beyond the scope of this article, but you can read "[An introduction to cryptography and public key infrastructure][5]" if you would like to learn about it.) The essential thing to know is that CAs, like GlobalSign, DigiCert, and GoDaddy, are the external trusted vendors that issue certificates that are used to validate the TLS/SSL certificate used by the website. This certificate is imported to the hosted server to secure the website.
However, a CA might be too expensive or complicated when you're just trying to test a website or service in development. You must have a trusted CA for production purposes, but developers and website administrators need a simpler way to test websites before they're deployed to production; this is where self-signed certificates come in.
A self-signed certificate is a TLS/SSL certificate that is signed by the person who creates it rather than a trusted CA. It's easy to generate a self-signed certificate from a computer, and it can enable you to test a secure website without buying an expensive CA-signed certificate right away. While the self-signed certificate is definitely risky to put into production use, it is an easy and flexible option for developing and testing in pre-production stages.
### Open source tools for generating certificates
Several open source tools are available for managing TLS/SSL certificates. The most well-known one is OpenSSL, which is included in many Linux distributions and on macOS. However, other open source tools are also available.
| Tool Name | Description | License |
| --------- | ------------------------------------------------------------------------------ | --------------------------------- |
| OpenSSL | The most well-known open source tool for implementing TLS and crypto libraries | Apache License 2.0 |
| EasyRSA | Command-line utility for building and managing a PKI CA | GPL v2 |
| CFSSL | PKI/TLS "Swiss Army Knife" from Cloudflare | BSD 2-Clause "Simplified" License |
| Lemur | TLS creation tool from Netflix | Apache License 2.0 |
Netflix's Lemur is a particularly interesting option when you consider its goals of scaling and being user friendly. You can read more about it on [Netflix's tech blog][6].
### How to create an OpenSSL certificate
e have the power to create certificates on our own. This example generates a self-signed certificate using OpenSSL.
1. Create a private key using the openssl command:
```
openssl genrsa -out example.key 2048
```
![](https://opensource.com/sites/default/files/uploads/4_openssl_generatekey.jpg)
2. Create a certificate signing request (CSR) using the private key generated in step 1:
```
openssl req -new -key example.key -out example.csr \
-subj "/C=US/ST=TX/L=Dallas/O=Red Hat/OU=IT/CN=test.example.com"
```
![](https://opensource.com/sites/default/files/uploads/5_openssl_generatecsr.jpg)
3. Create a certificate using your CSR and private key:
```
openssl x509 -req -days 366 -in example.csr \
-signkey example.key -out example.crt
```
![](https://opensource.com/sites/default/files/uploads/6_openssl_generatecert.jpg)
### Learn more on internet security
If you'd like to learn more about the internet and website security, watch the companion YouTube video I made for this article.
<https://youtu.be/r0F1Hlcmjsk>
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/11/internet-security-tls-ssl-certificate-authority
作者:[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://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/security-lock-password.jpg?itok=KJMdkKum
[2]: https://opensource.com/sites/default/files/uploads/1_certificatecheckwebsite.jpg
[3]: https://opensource.com/sites/default/files/uploads/2_certificatedisplaywebsite.jpg
[4]: https://opensource.com/sites/default/files/uploads/3_internetprotocol.jpg
[5]: https://opensource.com/article/18/5/cryptography-pki
[6]: https://medium.com/netflix-techblog/introducing-lemur-ceae8830f621

View File

@ -1,234 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (luuming)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (The many faces of awk)
[#]: via: (https://www.networkworld.com/article/3454979/the-many-faces-of-awk.html)
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
The many faces of awk
======
The awk command provides a lot more than simply selecting fields from input strings, including pulling out columns of data, printing simple text, evaluating content even doing math.
Thinkstock
If you only use **awk** when you need to select a specific field from lines of text, you might be missing out on a lot of other services that the command can provide. In this post, we'll look at this simple use along with some of the other things that **awk** can do for you and provide some examples.
### Plucking out columns of data
The easiest and most commonly used service that **awk** provides is selecting specific fields from files or from data that is piped to it. With the default of using white space as a field separator, this is very simple.
[[Get regularly scheduled insights by signing up for Network World newsletters.]][1]
```
$ echo one two three four five | awk {print $4}
four
$ who | awk {print $1}
jdoe
fhenry
```
White space is any sequence of blanks and tabs. In the commands shown above, **awk** is extracting just the fourth and first fields from the data provided.
[][2]
BrandPost Sponsored by HPE
[Take the Intelligent Route with Consumption-Based Storage][2]
Combine the agility and economics of HPE storage with HPE GreenLake and run your IT department with efficiency.
Awk can also pull text from files by just adding the name of the file after the **awk** command.
```
$ awk '{print $1,$5,$NF}' HelenKellerQuote
The beautiful heart.
```
In this case, **awk** has picked out the first, fifth and last words in the single line of test.
The **$NF** specification in the command picks the last piece of text on each line. That is because **NF** represents the number of fields in a line (23) while **$NF** then represents the _value_ of that field ("heart."). The period is included because it's part of the final text string.
Fields can be printed in any order that you might find useful. In this example, we are rearranging the fields in **date** command output.
```
$ date | awk '{print $4,$3,$2}'
2019 Nov 22
```
If you omit the commas between the field designators in an **awk** command, the output will be pushed into a single string.
```
$ date | awk '{print $4 $3 $2}'
2019Nov21
```
If you replace the usual commas with hyphens, **awk** will attempt to subtract one field from another probably not what you intended. It doesn't take the hyphens as characters to be inserted into the print output. Instead, it puts some of its mathematical prowess into play.
```
$ date | awk '{print $4-$3-$2}'
1997
```
In this case, it's subtracting 22 (the day of the month) from the year (2019) and simply ignoring "Nov".
If you want your output to be separated by something other than white space, you can specify your output separator with **OFS** (output field separator) like this:
```
$ date | awk '{OFS="-"; print $4,$3,$2}'
2019-Nov-22
```
### Printing simple text
You can also use **awk** to simply display some text. Of course, if all you want to do is print a line of text, you'd be better off using an **echo** command. On the other hand, as part of an **awk** script, printing some relevant text can be very useful. Here's a practically useless example:
```
$ awk 'BEGIN {print "Hello, World" }'
Hello, World
```
Here's a more sensible example in which adding a line of text to label your data can help identify what you're looking at:
```
$ who | awk 'BEGIN {print "Current logins:"} {print $1}'
Current logins:
shs
nemo
```
### Specifying a field separator
Not all input is going to be separated by white space. If your text is separated by some other character (e.g., commas, colons or semicolons), you can inform **awk** by using the **-F** (input separator) option as shown here:
```
$ cat testfile
a:b:c,d:e
$ awk -F : '{print $2,$3}' testfile
b c,d
```
Here's a more useful example  pulling a field from the colon-separated **/etc/passwd** file:
```
$ awk -F: '{print $1}' /etc/passwd | head -11
root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
```
### Evaluating content
You can also evaluate fields using **awk**. If you, for example, want to list only _user accounts_ in **/etc/passwd**, you can include a test for the 3rd field. Here we're only going after UIDs that are 1000 and above:
```
$ awk -F":" ' $3 >= 1000 ' /etc/passwd
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
shs:x:1000:1000:Sandra Henry-Stocker,,,:/home/shs:/bin/bash
nemo:x:1001:1001:Nemo,,,:/home/nemo:/usr/bin/zsh
dory:x:1002:1002:Dory,,,:/home/dory:/bin/bash
...
```
If you want to add a title for your listing, you can add a BEGIN clause:
```
$ awk -F":" 'BEGIN {print "user accounts:"} $3 >= 1000 ' /etc/passwd
user accounts:
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
shs:x:1000:1000:Sandra Henry-Stocker,,,:/home/shs:/bin/bash
nemo:x:1001:1001:Nemo,,,:/home/nemo:/usr/bin/zsh
dory:x:1002:1002:Dory,,,:/home/dory:/bin/bash
```
If you want more than one line in your title, you can separate your intended output lines with "\n" (newline characters).
```
$ awk -F":" 'BEGIN {print "user accounts\n============="} $3 >= 1000 ' /etc/passwd
user accounts
=============
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
shs:x:1000:1000:Sandra Henry-Stocker,,,:/home/shs:/bin/bash
nemo:x:1001:1001:Nemo,,,:/home/nemo:/usr/bin/zsh
dory:x:1002:1002:Dory,,,:/home/dory:/bin/bash
```
### Doing math with awk
**awk** provides a surprising mathematical ability and can calculate square roots, logs, tangents, etc.
Here are a couple examples:
```
$ awk 'BEGIN {print sqrt(2019)}'
44.9333
$ awk 'BEGIN {print log(2019)}'
7.61036
```
For more details on **awk**'s mathematical skills, check out [Doing math with awk][3].
### awk scripts
You can also write standalone scripts with **awk**. Here's an example that mimics one of the examples provided earlier, but also counts the number of users with accounts on the system.
```
#!/usr/bin/awk -f
# This line is a comment
BEGIN {
printf "%s\n","User accounts:"
print "=============="
FS=":"
n=0
}
# Now we'll run through the data
{
if ($3 >= 1000) {
print $1
n ++
}
}
END {
print "=============="
print n " accounts"
}
```
Notice how the BEGIN section, which is run only when the script starts, provides a heading, dictates the field separator and sets up a counter to start with 0. The script also includes an END section which only runs after all the lines in the text provided to the script have been processed. It displays the final count of lines that meet the specification in the middle section (third field is 1,000 or larger)
A long-standing Unix command, **awk** still provides very useful services and remains one of the reasons that I fell in love with Unix many decades ago.
To see **awk** in action, click below.
Join the Network World communities on [Facebook][4] and [LinkedIn][5] to comment on topics that are top of mind.
--------------------------------------------------------------------------------
via: https://www.networkworld.com/article/3454979/the-many-faces-of-awk.html
作者:[Sandra Henry-Stocker][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.networkworld.com/author/Sandra-Henry_Stocker/
[b]: https://github.com/lujun9972
[1]: https://www.networkworld.com/newsletters/signup.html
[2]: https://www.networkworld.com/article/3440100/take-the-intelligent-route-with-consumption-based-storage.html?utm_source=IDG&utm_medium=promotions&utm_campaign=HPE20773&utm_content=sidebar ( Take the Intelligent Route with Consumption-Based Storage)
[3]: https://www.networkworld.com/article/2974753/doing-math-with-awk.html
[4]: https://www.facebook.com/NetworkWorld/
[5]: https://www.linkedin.com/company/network-world

View File

@ -0,0 +1,220 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Challenge: find Twitter memes with suffix arrays)
[#]: via: (https://jvns.ca/blog/twitter-memes-challenge/)
[#]: author: (Julia Evans https://jvns.ca/)
Challenge: find Twitter memes with suffix arrays
======
This challenge is a mix of data analysis and using fun algorithms! Its the second challenge in a a short series of programming challenge Im writing with Julian. (the [first one was to write a tiny fun window manager][1])
Twitter has a lot of memes. For example, if you search Twitter for [Flight attendant: is there a doctor on this flight?][2], youll find a bunch of tweets making jokes like this:
```
Flight Attendant: is there a doctor on board?
Parent: *nudging* That should've been you
Me: Not now, this is serious
Parent: Not asking for a hacker to help, are they?
Me: AAAAAAAA\x00\xd0X?\xfc\x7fBBBBj\x0bX\x99Rfh-p\x89\xe1Rjhh/bash/bin\x89\xe3RQS\x89\xe1\xcd\x80
Parent:~#
```
or if you search [as a kpop fan][3] there are thousands of these:
```
me as a kpop fan
- kpop fan age: 10 years
- first group ever stan: super junior
- current ult groups: iKON, X1, Day6
- number of albums: >20
- concerts attended: 6
- lightsticks owned: 2
```
So! Suppose you have a million tweets from the last 2 days. How do you find the jokes / quizzes / memes people are playing with on Twitter?
### Challenge: find the twitter memes in 1 million tweets
This is a pretty open ended challenge and you can do it any way you want. Heres a [SQLite database with 1.2 million tweets][4], collected from the [twitter streaming api][5] over 2 days. Its 250MB (70MB compressed), it only has English tweets. It excludes retweets and many tweets that are generated by bots.
The challenge: find at least 5 Twitter memes using that dataset.
### memes as common substrings
The idea here is that memes are substrings like “me as a kpop fan” that many different people are using. The tricky thing is that you dont really know how long those substrings will be, and maybe youre interested in phrases of different lengths.
You can probably do this challenge without using anything fancy (with a hashmap of phrases or something) but I think its a nice opportunity to play with a fun data structure: suffix arrays! So lets talk about what those are.
### suffix arrays: sort all suffixes
Suffix arrays sort all suffixes of a string. For example, heres the suffix array for “plantain” which has the suffixes plantain, lantain, antain, ntain, tain, ain, in, n.
```
ain
antain
in
lantain
n
ntain
plantain
tain
```
Representing this as a list of strings would be very inefficient (quadratic space), so instead we replace each suffix with the index of its first character in the original string `[5,2,6,1,7,3,0,4]`.
```
5 (ain)
2 (antain)
6 (in)
1 (lantain)
7 (n)
3 (ntain)
0 (plantain)
4 (tain)
```
Heres a real example of what a suffix array of 1 million tweets concatenated looks like. This is an excerpt from the middle of the suffix array, with some of the suffixes that start with `A little`.
```
...
A little distracted for a bit ...what do i do w my life hon.........
A little exercise I did this afternoon. #comics #art #clip.........
A little extra Christmas Cash on me! Good Luck to everyone!.........
A little girl in Savannah, Ga., appears to be the 38th huma.........
A little heavy on the smut t… https://t.co/nvoxE7SNjTI wa.........
A little in state battle tonight. #nova vs #penn. two very .........
A little kiss...” one more time Im going to vomit. #TT.........
A little late catching up on last nights @GoodDoctorABC. On.........
A little less bling never hurt anyone! Next project...🎄 .........
A little more intensity to augment their talent and a coupl.........
A little more time, because I have never lived really - Os.........
A little mor… https://t.co/kcq3zf9jgeWe love MX ❤️<F0><9F><A7>.........
A little over 50k! Can We Guess How Much Is In Your Account.........
A little ray of joy &amp; light in the midst of these very .........
A little refreshment… https://t.co/HgX8PmYwPIThank you @L.........
A little respect goes a long way. .........
A little salt in d country's troubled legal system“Grant................
A little snow &amp; people lose all common senseromantic st...............
A little sun for the soul @realfreewebcams https://t.co/3CB...............
A little sunkissed moment for yall. ...............
....
```
Again, this is actually represented by a bunch of integer indexes into a concatenated string of all the tweets, like `[18238223, 1921812, ...]` so its a LOT more memory efficient than actually repeating all those strings.
### suffix arrays let you find common substrings!
So what does this have to do with Twitter memes? Well, we can basically
1. concatenate all tweets into a big string
2. make a suffix array of that string
3. iterate through the suffix array and notice when you see a lot of repeated substrings, like here:
```
me as a kpop fan ✨kpop fan age: 15 y/o ✨first group ever stan: blackpink ✨current ult groups: btxt ✨number of albu… https://t.co/24diHX9sLm
me as a kpop fan ⭐k-pop fan age: 12 y/o ⭐first group ever stan: bts ⭐current ult gps: bts and txt ⭐number of albu… https://t.co/8R95roQXoE
me as a kpop fan ⭐k-pop fan age: 14 y/o ⭐first group ever stan: girls generation ⭐current ult gp: txt ⭐number of a… https://t.co/010hLuJscF
me as a kpop fan ⭐k-pop fan age: 14-16 y/o ⭐first group ever stan: bts ⭐current ult gps: bts txt ⭐number of albums… https://t.co/0fDcxZGRrh
me as a kpop fan ⭐k-pop fan age: 15 y/o ⭐first group ever stan: blackpink ⭐current ult gps: txt ⭐number of albums… https://t.co/d8zZL83TvV
me as a kpop fan 🌸 k-pop fan age: 12 years old 🌸 first group ever stan: bts 🌸 current ult gps: bts &amp; wanna one 🌸 n… https://t.co/22R1nJpwNX
me as a kpop fan 🌸k-pop fan age: 10 🌸first group ever stan: 2pm 🌸current ult gps: skz,got7,itzy,twice, 🌸number of… https://t.co/mAluaP2yxH
me as a kpop fan 🌸k-pop fan age: 11 yo 🌸first group ever stan: beast 🌸current ult gps: ateez 🌸number of albums: 1… https://t.co/qxtFHG9HDg
me as a kpop fan 🌸k-pop fan age: 11 🌸first group ever stan: bts 🌸current ult gps: bts and ateez 🌸number of albums:… https://t.co/mKXlkrBBtC
me as a kpop fan 🌸k-pop fan age: 13 (now im 19) 🌸first group ever stan: snsd 🌸current ult gps: nct day6 aoa mamam… https://t.co/8XyQ3r5hwz
me as a kpop fan 🌸k-pop fan age: 13 years 🌸first group ever stan: 2pm,suju,bigbang 🌸current ult gps: bts,tbz,ateez… https://t.co/Zs1nQQz6Lt
me as a kpop fan 🌸k-pop fan age: 14 (2005) 🌸first group ever stan: super junior 🌸current ult gps: exo, gfriend, rv… https://t.co/vgmhe2vFMY
me as a kpop fan 🌸k-pop fan age: 14 y/o 🌸first group ever stan: nct dream 🌸current ult gps: svt and,,*insert stan… https://t.co/I38Ui69PvL
me as a kpop fan 🌸k-pop fan age: 15 y/o 🌸first group ever stan: 5sos 🌸current ult gps: bts and 5sos also some ggs… https://t.co/61ZmRkzmdl
me as a kpop fan 🌸k-pop fan age: 15 y/o 🌸first group ever stan: bts 🌸current ult gps: SVT, GOT7, Day6 🌸number of… https://t.co/16SWb3mSPg
me as a kpop fan 🌸k-pop fan age: 18 🌸first group ever stan: suju &amp; soshi 🌸current ult gps: snsd &amp; izone 🌸number of… https://t.co/SmSBFqJnGk
me as a kpop fan 🌸k-pop fan age: 19 y/o marupok 🌸first group ever stan: APINK 🌸current ult gps: SEVENTEEN 🌸number… https://t.co/StYjxr6uq9
me as a kpop fan 🌸k-pop fan age: 19 🌸first group ever stan: SuJu 🌸current ult gps: SuJu, SF9, SKZ, VIXX, ONEUS, NO… https://t.co/2o2DulCY5b
```
### suffix arrays also enable really fast search
As an aside, the reason I got interested in suffix arrays in the first place was actually not for finding Twitter memes at all but for search.
Ive spent a lot of time using Nelson Elhages [livegrep][6] at work to search code. It creates a suffix array using the divsufsort library. He has a blog post [Regular Expression Search with Suffix Arrays][7] where he talks about some of the implementation details.
The reason suffix arrays work for fast search is basically that if youre looking for the string `A little`, you can do a binary search over the suffix array to find every instance of `A little` in your dataset. Binary searches are extremely fast so every search is guaranteed to run very quickly (in less than a microsecond I believe). What livegrep does is more complicated than that because it does a regular expression search, but thats the idea to start.
Theres another blog post [How to use suffix arrays to combat common limitations of full-text search][8] applying suffix arrays to searching through a patent database. In that example, like with code search, the patent officers want to search patents for exact strings.
### How do you make a suffix array?
You can use an existing suffix array library, for example [index/suffixarray in Go][9], which is what I used, or [divsufsort][10]. There are [Python bindings for divsufsort][11].
If youre more excited about the data structures/algorithms aspect of suffix arrays you can also implement a suffix array-building algorithm yourself! I did not do this but you can see an implementation of [qsufsort here in Go][12]. That implementation links to a paper. There are lots of algorithms for constructing suffix arrays `sais` and `divsufsort` are a couple of others.
### 5 or so hours, 100 lines of Go
As always with these challenges, I did this one to make sure that its both doable in a reasonable amount of time and fun for at least one person (me).
I did this one in about 5 hours and 100 lines of Go using the suffixarray implementation in the Go standard library, with a bit of bash shell scripting to postprocess the results. This is a messy data analysis challenge as an example of a messy thing, Spotify released their end-of-2019 results while I was building the dataset and so there are a lot of tweets generated by the Spotify app.
My results ended up looking something like this:
```
5 an Aries and thats why I gotta
5 an Aries and thats why I am so
5 an Aquarius and thats why I
5 AM SO PROUD OF YOU
5 am not a fan of
5 am I the only one who
5 am going to have to
```
Then I sifted through them pretty manually to find the Twitter memes.
### suffix arrays are used in bioinformatics
This “find twitter memes using suffix arrays” approach is a silly thing but it does have some relationship to reality DNA sequences are basically really long strings, and biologists need to find patterns in them, and they sometimes use suffix arrays to do it.
I looked up [packages in Debian that use libdivsufsort][13] and I found [infernal][14]:
> Infernal (“INFERence of RNA ALignment”) is for searching DNA sequence databases for RNA structure and sequence similarities. It is an implementation of a special case of profile stochastic context-free grammars called covariance models (CMs). A CM is like a sequence profile, but it scores a combination of sequence consensus and RNA secondary structure consensus, so in many cases, it is more capable of identifying RNA homologs that conserve their secondary structure more than their primary sequence.
### email me the twitter memes you find if you do this!
If you do this exercise, Id love it if you emailed me ([[email protected]][15]) with the twitter memes you found and/or your code! I found about 8 but Im sure there are more.
Ill publish any solutions I get (unless you dont want me to publish your solution just let me know!).
Thanks to Julian for discussing suffix arrays and suffix trees and trigram indexes with me at length, and to Kamal who had the idea of using suffix arrays to find Twitter memes.
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/twitter-memes-challenge/
作者:[Julia Evans][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://jvns.ca/
[b]: https://github.com/lujun9972
[1]: https://jvns.ca/blog/2019/11/25/challenge--make-a-bouncy-window-manager/
[2]: https://twitter.com/search?q=%22attendant%3A%20is%20there%20a%20doctor%20on%20%22&src=typed_query&f=live
[3]: https://twitter.com/search?q=%22as%20a%20kpop%20fan%22&src=typed_query
[4]: https://www.dropbox.com/s/5xnaf1mbdr1424p/twitter.db.gz?dl=0
[5]: https://developer.twitter.com/en/docs/tutorials/consuming-streaming-data
[6]: https://livegrep.com/search/linux
[7]: https://blog.nelhage.com/2015/02/regular-expression-search-with-suffix-arrays/
[8]: https://blog.griddynamics.com/using-suffix-arrays-to-fix-limitations-of-full-text-search/
[9]: https://golang.org/pkg/index/suffixarray/
[10]: https://github.com/y-256/libdivsufsort
[11]: https://github.com/debatem1/pydivsufsort
[12]: https://github.com/golang/go/blob/release-branch.go1.12/src/index/suffixarray/qsufsort.go
[13]: https://codesearch.debian.net/search?q=divsufsort
[14]: http://eddylab.org/infernal/
[15]: https://jvns.ca/cdn-cgi/l/email-protection

View File

@ -0,0 +1,110 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (5 cool terminal pagers in Fedora)
[#]: via: (https://fedoramagazine.org/5-cool-terminal-pagers-in-fedora/)
[#]: author: (Jacob Burns https://fedoramagazine.org/author/jaek/)
5 cool terminal pagers in Fedora
======
![][1]
Large files like logs or source code can run into the thousands of lines. That makes navigating them difficult, particularly from the terminal. Additionally, most terminal emulators have a scrollback buffer of only a few hundred lines. That can make it impossible to browse large files in the terminal using utilities which print to standard output like _cat_, _head_ and _tail_. In the early days of computing, programmers solved these problems by developing utilities for displaying text in the form of virtual “pages” — utilities imaginatively described as _pagers_.
Pagers offer a number of features which make text file navigation much simpler, including scrolling, search functions, and the ability to feature as part of a [pipeline][2] of commands. In contrast to most text editors, some terminal pagers do not require loading the entire file for viewing, which makes them faster, especially for very large files.
In the modern era of Linux computing, terminal emulators are more sophisticated than ever. They offer support for a kaleidoscope of colors, terminal resizing, as well as a host of other features to make parsing text on screen easier and more efficient. Terminal pagers have undergone a similar evolution, from extremely simple UNIX utilities like _pg_ and _more_, to sophisticated programs with a wide range of features, covering any number of use cases. With this in mind, weve put together a list of some of the most popular terminal paging utilities — more or less.
### More
_more_ is one of the earliest pagers, initially featured in version 3.0 BSD. The first implementation of _more_ was written in 1978 by [Daniel Halbert][3]. Since then, _more_ has become a ubiquitous feature of many operating systems, including Windows, OS/2, MacOS and most linux distributions.
_more_ is a very lightweight utility. The version featured in util-linux runs to just under 2100 lines of C. However, this small footprint comes at a price. Most versions of _more_ feature relatively limited functionality, with no support for backwards scroll or search. Commands are similarly stripped back: press enter to scroll one line, or space to scroll one page. Some other useful commands include:
* Press v while reading to open the current file in your default terminal editor.
* /_pattern_ lets you search for the next occurrence of _pattern_.
* :n and :p will open the next and previous files respectively when more is called with more than one file as arguments
### Less
_less_ was initially conceived as a successor to _more_, addressing some of its limitations. Building on the functionality of _more_, _less_ adds a number of useful features including backwards scroll, backwards search. It is also more amenable to window resizing.
Navigation in _less_ is similar to _more_, though _less_ borrows a few useful commands from the _vi_ editor as well. Users can navigate the document using the familiar home row navigational keys. A glance at the man page for _less_ reveals a fairly rich repertoire of available commands. Some particularly useful examples include:
* ?_pattern_ lets you search backwards in the file for _pattern_
* &amp;_pattern_ shows only lines which feature _pattern_. This is particularly useful for those who find themselves issuing **$ grep pattern | less** regularly.
* Calling less with the -s (sqeueeze-blank-lines) flag allows you to view text files with large gaps. Multiple newline characters are reduced to single breaks.
* s _filename_, called from within the program, saves input to _filename_ (if input is a pipe).
* Alternatively, calling less with the -o _filename_ flag will save the input of less to _filename._
With this enhanced functionality comes a little extra weight. The version of _less_ that ships with Fedora at the time of writing clocks in at around 25000 lines of source code. Granted, for all but the most storage constrained systems, this is a non-issue. Besides, _less_ is more than _more_.
### Most
While _less_ aims to expand on the existing capabilities of _more_, _most_ takes a different approach. Rather than expanding on the traditional single file view, _most_ gives users the ability to split their view into “windows.” Each window contains different files in different viewing modes.
Significantly, _most_ takes into account the width of its input text. The default viewing mode doesnt wrap text (-S in less), a feature particularly useful when dealing with “wide” files. While these design decisions might represent a significant departure from tradition for some users, the end result is very powerful.
In addition to the navigation commands offered by _more_, _most_ uses intuitive mnemonics for file navigation. For example, _**t**_ moves to the **t**op of a file, and _**b**_ moves to the bottom. As a result, users unfamiliar with _vi_ and its descendants will find most to be refreshingly simple.
The distinguishing feature of _most_ is its ability to split windows and contexts quickly and easily. For example, one could open two distinct text files using the following:
```
$ most textFile1.txt textFile2.txt
```
In order to split the screen horizontally, use the key combos **Ctrl+x, 2** or **Ctrl+w, 2**. The command _:n_ will open the next file argument in a given window, offering a split screen view of two files:
![][4]
If you turn wrap off in one window, it does not affect the behavior of other windows. The \ character indicates a wrap or fold, while the $ character indicates that the file extends past the limitations of the current window.
### pspg
Those who work with SQL databases often need to be able to examine the contents of our databases at a glance. The command line interfaces for many popular open source DBMSs, such as MySQL and PostGreSQL, use the system default pager to view outputs that dont fit on a single screen. Utilities like _more_ and _less_ are designed around the idea of presenting text files, but for more structured data, leave something to be desired. Naive text paginating programs have no concept of broad, tabular data, which can be frustrating when dealing with large queries.
[pspg][5] attempts to address this by offering users the ability to freeze columns while viewing, sort data _in situ_, and colourize output. While _pspg_ was intended initially to serve as a pager replacement for _psql_ specifically, the program also supports the viewing of CSV data, and is a suitable drop-in replacement for _mysql_ and _pgcli_.
### Vim
In a modern, technicolor terminal, the idea of endless pages of drab grey on black text can feel like something of an anachronism. The syntax highlighting options offered by powerful text editors like _vim_ can be useful for browsing source code. Furthermore, the search functions offered by _vim_ vastly outclass the competition. With this in mind, _vim_ ships with a shell script _less.sh_ that lets _vim_ serve as a replacement for conventional pagers.
To set _vim_ as [the default pager][6] for man pages, add the following to your shells config (such as _~/.bashrc_ if using the default bash shell):
```
export MANPAGER="/bin/sh -c \"col -b | vim -c 'set ft=man ts=8 nomod nolist nonu noma' -\""
```
Alternatively, to set _vim_ as the default pager system-wide, locate the _less.sh_ script. (You can find it at _/usr/share/vim/vim81/macros/_ on current Fedora systems.) Export this location as the variable _PAGER_ to set it as default, or under an alias to invoke it explicitly.
* * *
_Photo by [Cathy Mü][7] on [Unsplash][8]._
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/5-cool-terminal-pagers-in-fedora/
作者:[Jacob Burns][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/jaek/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2019/11/5-pagers-816x345.jpg
[2]: https://fedoramagazine.org/command-line-quick-tips-using-pipes-to-connect-tools/
[3]: https://danhalbert.org/more.html
[4]: https://fedoramagazine.org/wp-content/uploads/2019/11/image-2.png
[5]: https://github.com/okbob/pspg
[6]: https://zameermanji.com/blog/2012/12/30/using-vim-as-manpager/
[7]: https://unsplash.com/@zyljosa?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
[8]: https://unsplash.com/s/photos/pages?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText

View File

@ -1,320 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (6 Ways to Send Email from the Linux Command Line)
[#]: via: (https://www.2daygeek.com/6-ways-to-send-email-from-the-linux-command-line/)
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
6 Ways to Send Email from the Linux Command Line
======
Sending email from the command line is required when you need to create emails from a shell script.
There are several commands on Linux to send emails from the Linux command line.
Ive included the Top 6 Command Line Mail Clients in this tutorial.
You can use any one of the following to send email from the Linux command line.
This can be done using the following six commands.
* mail
* mailx
* mutt
* mpack
* sendmail
* ssmtp
### How does it work?
Let me give you an overall explanation of how the mail command delivers the mails to recipients on Linux.
The mail command compose emails and sends them to a local mail transfer agent (MTA), such as sendmail, postfix, and so on.
The mail server actually communicates with remote mail servers for sending and receiving emails.
The flow chart below can explain more about that.
[![][1]][2]
### 1) How to Install mail Command on Linux
The mail command is most popular command to send emails from Linux terminal.
The mail command can be installed from the distribution official repository as follows.
For **“Debian/Ubuntu”** systems, use **[APT-GET Command][3]** or **[APT Command][4]** to install mailutils.
```
$ sudo apt-get install mailutils
```
 For **“RHEL/CentOS”** systems, use **[YUM Command][5]** to install mailx.
```
$ sudo yum install mailx
```
For **“Fedora”** system, use the **[DNF Command][6]** to install mailx.
```
$ sudo dnf install mailx
```
### 1a) How to Use mail Command on Linux to Send a Mail
Its straightforward and easy to use.
Use the following format to send mail using the mail command without an attachment.
```
$ echo "This is the mail body" | mail -s "Subject" [email protected]
```
Use the following format to send mail using the mail command with attachment.
```
$ echo "This is the mail body" | mail -a test1.txt -s "Subject" [email protected]
```
```
+---------+----------------------------------------------------+
| Options | Description |
+---------+----------------------------------------------------+
| -a | It's used for attachment on Red Hat based systems. |
| -A | It's used for attachment on Debian based systems. |
| -s | Specify the subject of the message |
+--------------------------------------------------------------+
```
### 2) How to Install mutt Command on Linux
The mutt is another popular command to send emails from Linux terminal.
Mutt is a small but very powerful text based program for reading and sending electronic mail under unix operating systems, including support for color terminals, MIME, OpenPGP, and a threaded sorting mode.
The mail command can be installed from the distribution official repository as follows.
For **“Debian/Ubuntu”** systems, use **[APT-GET Command][3]** or **[APT Command][4]** to install mutt.
```
$ sudo apt-get install mutt
```
 For **“RHEL/CentOS”** systems, use **[YUM Command][5]** to install mutt.
```
$ sudo yum install mutt
```
For **“Fedora”** system, use the **[DNF Command][6]** to install mutt.
```
$ sudo dnf install mutt
```
### 2b) How to Use mutt Command on Linux to Send a Mail
This is also straightforward and easy to use.
Use the following format to send mail using the mutt command without an attachment.
```
$ echo "This is the mail body" | mutt -s "Subject" [email protected]
```
Use the following format to send mail using the mutt command with attachment.
```
$ echo "This is the mail body" | mutt -s "Subject" [email protected] -a test1.txt
```
### 3) How to Install mpack Command on Linux
The mpack is another popular command to send emails from Linux terminal.
The mpack program encodes the the named file in one or more MIME messages. The resulting messages are mailed to one or more recipients.
The mpack command can be installed from the distribution official repository as follows.
For **“Debian/Ubuntu”** systems, use **[APT-GET Command][3]** or **[APT Command][4]** to install mpack.
```
$ sudo apt-get install mpack
```
 For **“RHEL/CentOS”** systems, use **[YUM Command][5]** to install mpack.
```
$ sudo yum install mpack
```
For **“Fedora”** system, use the **[DNF Command][6]** to install mpack.
```
$ sudo dnf install mpack
```
### 3a) How to Use mpack Command on Linux to Send a Mail
This is also straight forward and easy to use.
Use the following format to send mail using the mpack command without an attachment.
```
$ echo "This is the mail body" | mpack -s "Subject" [email protected]
```
Use the following format to send mail using the mpack command with attachment.
```
$ echo "This is the mail body" | mpack -s "Subject" [email protected] -a test1.txt
```
### 4) How to Install mail Command on Linux
Mailx is the newer version of mail command.
It is based on Berkeley Mail 8.1, is intended to provide the functionality of the POSIX mailx command, and offers extensions for MIME, IMAP, POP3, SMTP, and S/MIME.
Mailx provides enhanced features for interactive use, such as caching message threading, scoring, and filtering.
The mailx command can be installed from the distribution official repository as follows.
For **“Debian/Ubuntu”** systems, use **[APT-GET Command][3]** or **[APT Command][4]** to install mailutils.
```
$ sudo apt-get install mailutils
```
 For **“RHEL/CentOS”** systems, use **[YUM Command][5]** to install mailx.
```
$ sudo yum install mailx
```
For **“Fedora”** system, use the **[DNF Command][6]** to install mailx.
```
$ sudo dnf install mailx
```
### 4a) How to Use mailx Command on Linux to Send a Mail
Its straight forward and easy to use.
Use the following format to send mail using the mailx command without an attachment.
```
$ echo "This is the mail body" | mail -s "Subject" [email protected]
```
Use the following format to send mail using the mailx command with attachment.
```
$ echo "This is the mail body" | mail -a test1.txt -s "Subject" [email protected]
```
### 5) How to Install sendmail Command on Linux
Sendmail is a most popular and general purpose SMTP server used in most of Linux distribution.
Also, it allows you to sending email from command line.
The sendmail command can be installed from the distribution official repository as follows.
For **“Debian/Ubuntu”** systems, use **[APT-GET Command][3]** or **[APT Command][4]** to install sendmail.
```
$ sudo apt-get install sendmail
```
 For **“RHEL/CentOS”** systems, use **[YUM Command][5]** to install sendmail.
```
$ sudo yum install sendmail
```
For **“Fedora”** system, use the **[DNF Command][6]** to install sendmail.
```
$ sudo dnf install sendmail
```
### 5a) How to Use sendmail Command on Linux to Send a Mail
Its straight forward and easy to use.
Use the following format to send mail using the sendmail command.
```
$ echo -e "Subject: Test Mail\nThis is the mail body" > /tmp/send-mail.txt
```
```
$ sendmail [email protected] < send-mail.txt
```
### 6) How to Install ssmtp Command on Linux
ssmtp is a send-only sendmail emulator for machines which delivers email from a local computer to a configured mailhost (mailhub).
SSMTP allows users to transfer emails through an SMTP server from the Linux command line.
The sendmail command can be installed from the distribution official repository as follows.
For **“Debian/Ubuntu”** systems, use **[APT-GET Command][3]** or **[APT Command][4]** to install ssmtp.
```
$ sudo apt-get install ssmtp
```
 For **“RHEL/CentOS”** systems, use **[YUM Command][5]** to install ssmtp.
```
$ sudo yum install ssmtp
```
For **“Fedora”** system, use the **[DNF Command][6]** to install ssmtp.
```
$ sudo dnf install ssmtp
```
### 6a) How to Use ssmtp Command on Linux to Send a Mail
Its straight forward and easy to use.
Use the following format to send mail using the ssmtp command.
```
$ echo -e "Subject: Test Mail\nThis is the mail body" > /tmp/ssmtp-mail.txt
```
```
$ ssmtp [email protected] < /tmp/ssmtp-mail.txt
```
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/6-ways-to-send-email-from-the-linux-command-line/
作者:[Magesh Maruthamuthu][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.2daygeek.com/author/magesh/
[b]: https://github.com/lujun9972
[1]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
[2]: https://www.2daygeek.com/wp-content/uploads/2019/12/smtp-simple-mail-transfer-protocol.png
[3]: https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
[4]: https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
[5]: https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/
[6]: https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/

View File

@ -0,0 +1,219 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (A beginner's guide to using Vagrant)
[#]: via: (https://opensource.com/article/19/12/beginner-vagrant)
[#]: author: (Jessica Repka https://opensource.com/users/jrepka)
A beginner's guide to using Vagrant
======
This easy "hello world" tutorial makes it easy to start using Vagrant
for virtual machine management.
![A person programming][1]
Vagrant [describes itself][2] as "a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the 'works on my machine' excuse a relic of the past."
Vagrant works with a standard format for documenting an environment, called a Vagrantfile. [According to Vagrant's website][3]:
> "The primary function of the Vagrantfile is to describe the type of machine required for a project, and how to configure and provision these machines. Vagrantfiles are called Vagrantfiles because the actual literal filename for the file is **Vagrantfile** (casing does not matter unless your file system is running in a strict case sensitive mode)."
Vagrant is essentially a wrapper to allow for repeatable virtual machine management, but it does not run VMs itself. This tutorial will use [VirtualBox][4] as that environment manager, though Hyper-V and Docker also work by default. Check out Vagrant's documentation to [learn how to use a different provider][5] for this tutorial.
### Build a Vagrantfile
This tutorial works through an example application for a simple Hello World page inside a Ruby on Rails (Rails for short) web app. Before you begin, install the following (if you haven't already):
* [Vagrant][6]
* [VirtualBox][7]
* [Ruby on Rails][8]
* An editing environment, like [Atom][9] or [Notepad++][10]
If you're on Fedora and prefer using the command line, there is an [excellent Fedora tutorial][11], and there's a similarly helpful tutorial for [Windows using Chocolatey][12]. After everything is installed, open your terminal and create a new directory to work in. You can put your directory wherever you like; I prefer to use a folder under my user account:
```
$ mkdir -p ~/Development/Rails_app
$ cd ~/Development/Rails_app
$ vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
```
This creates a Vagrantfile with the default configuration information written in Ruby syntax. Look at line 15:
```
`config.vm.box = "base"`
```
This indicates that Vagrant will use a default operating system image it hosts called **base**, which you don't have yet. Confirm that by running **box list**:
```
$ vagrant box list
There are no installed boxes! Use `vagrant box add` to add some.
```
If you try to start your environment using the **up** command, it will fail, because Vagrant expects an OS called **base** to exist locally. Switch to the most commonly used environment, **bento/ubuntu-16.04**, then try to spin up your environment. Change the **config.vm.box** line in your Vagrantfile to:
```
`config.vm.box = "centos/7"`
```
And now you can run the most satisfying command in virtual machine history:
```
$ vagrant up
Bringing machine 'default' up with 'libvirt' provider...
==&gt; default: Box 'centos/7' could not be found. Attempting to find and install...
    default: Box Provider: libvirt
    default: Box Version: &gt;= 0
==&gt; default: Loading metadata for box 'centos/7'
    default: URL: <https://vagrantcloud.com/centos/7>
==&gt; default: Adding box 'centos/7' (v1905.1) for provider: libvirt
    default: Downloading: <https://vagrantcloud.com/centos/boxes/7/versions/1905.1/providers/libvirt.box>
    default: Download redirected to host: cloud.centos.org
...
```
Here is why this is so nice. This tutorial sets up a small website, but if you had a larger website and needed to check whether the frontend looks right, your playbook file and copy-over files would allow you to see your changes. If you have small applications you want to test quickly—without doing an entire Docker image build or logging into a server—this local testing is good for quick checks and repairs. If you're working within hardware, this will make it easy to see if the application will work within your operating system, and it allows you to know which dependencies you need. In the end, it makes for easier deployment and faster testing than doing a from-scratch continuous integration and deployment (CI/CD) to a test server, and it provides quicker access and more control.
The reason this is so cool can be explained in one simple sentence: You now have local automation. It also allows you to gather a larger breadth of knowledge behind [Ansible][13] and headless server deployments.
### Verify Vagrant worked correctly
One way to determine whether this finished properly is seeing a bunch of green text and the words **rails server -h** for startup options. This means the web app has started and is running.
![Verifying with the vagrant status command][14]
But you want to use **vagrant global-status** as well as **vagrant status**.
![Verifying with the vagrant global-status command][15]
The **vagrant status** command checks the machine states that originate in the current directory. So, if you have a VM up and running, it will show as up and running. If it is broken in any way, it will display a message with an error and some logs when you run **vagrant up**. If some machines are down, they will also show as not running or shut down.
However, the **vagrant global-status** command can give the status of multiple environments created in Vagrant. So, if you split the environments for different VM types or storage types, this command gives you an option to see everything in all the environments you've created.
### Customize the Vagrant configuration
The machine settings have multiple [config.vm][16] options. This tutorial will use the networking option to allow port forwarding. Port forwarding allows you to access a network port in our virtual environment as if it was a local port via a special local network. This means traffic is allowed to see the one thing you allow on this server; in this case, it's a tiny frontend webpage.
The main reason this matters is for security. Limiting traffic can prevent bad actors and traffic overflow. The way this is built, you can't log into this server unless you configure it as such. This also means no one else can SSH in or see anything except the one little frontend webpage.
Before moving on, remove the VM so you can start over by running [**vagrant destroy**][17]:
```
$ vagrant destroy
    default: Are you sure you want to destroy the 'default' VM? [y/N] y
==&gt; default: Removing domain...
```
To include port forwarding, add this in the next config line:
```
 Vagrant.configure("2") do |config|
  config.vm.box = "bento/ubuntu-16.04"
  config.vm.network "forwarded_port", guest: 3000, host: 9090
  end
```
Save the file and run:
```
`vagrant up`
```
You now have a VM that forwards port **3000** out to the open world as **9090**. You should now be able to go to **127.0.0.1:9090** on your web browser and see nothing but a plain white page.
Run **vagrant destroy** again to remove the VM so you can start over.
### Provision Vagrant with Ansible and scripts
While base boxes offer a good starting point, it's common to customize a VM during the provisioning process, and you can use multiple provisioning tactics. To follow along, [download the playbook and script][18].
This example uses Ansible to set up a basic install of the Ruby on Rails web framework. Then, it adds an extra shell script to configure the web app's welcome page to say: _Hello World, Sorry for the Delay_. (The purpose of this message is because this build takes a long time and people may become frustrated by the delay.)
The following Vagrantfile reflects Ansible and a playbook running locally on my machine, so it will differ from yours. You can read about [using Ansible with Vagrant][19] in Vagrant's docs.
```
Vagrant.configure("2") do |config|
 config.vm.box = "bento/ubuntu-16.04"
  config.vm.network "forwarded_port", guest: 3000, host: 9090
  ####### Provision #######
  config.vm.provision "ansible_local" do |ansible|
   ansible.playbook = "prov/playbook.yml"
    ansible.verbose = true
  config.vm.provision "shell", path: "script.sh"
  end
end
```
After saving the file, run my favorite command:
```
`vagrant up`
```
You now have a VM up and running with Rails, and when you enter **127.0.0.1:9090** in your web browser, you see a webpage that says: _Hello World, Sorry for the Delay_.
Now that you have all this background, you can try to [build your own script][20].
### Final notes
Vagrant is fairly easy to work with and has abundant [documentation][21] to help you along the way. It's is a great tool if you're looking to work with code in a small staging or development environment; any destruction is a non-issue because the environment itself is disposable.
Want to give it a try? Take a look at my [repo][18].
In this short video, Daniel Farrell tells us about Vagrant, a tool for working with Virtual...
Learn how Vagrant and Ansible can be used to provision virtual machines for web development.
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/12/beginner-vagrant
作者:[Jessica Repka][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/jrepka
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_keyboard_laptop_development_code_woman.png?itok=vbYz6jjb (A person programming)
[2]: https://www.vagrantup.com/intro/index.html
[3]: https://www.vagrantup.com/docs/vagrantfile/
[4]: https://www.virtualbox.org/browser/vbox/trunk
[5]: https://www.vagrantup.com/docs/providers/basic_usage.html
[6]: https://www.vagrantup.com/docs/installation/
[7]: https://www.virtualbox.org/wiki/Downloads
[8]: http://installrails.com/steps/choose_os
[9]: https://atom.io/
[10]: https://notepad-plus-plus.org/downloads/
[11]: https://computingforgeeks.com/how-to-install-vagrant-and-virtualbox-on-fedora/
[12]: https://codingbee.net/vagrant/vagrant-installing-vagrant-on-windows
[13]: https://www.ansible.com/
[14]: https://opensource.com/sites/default/files/uploads/vagrant1_vagrant-status.png (Verifying with the vagrant status command)
[15]: https://opensource.com/sites/default/files/uploads/vagrant2_vagrant-global-status.png (Verifying with the vagrant global-status command)
[16]: https://www.vagrantup.com/docs/vagrantfile/machine_settings.html
[17]: https://www.vagrantup.com/docs/cli/destroy.html
[18]: https://github.com/Alynder/vagrant_adwx
[19]: https://www.vagrantup.com/docs/provisioning/ansible.html
[20]: https://www.bogotobogo.com/RubyOnRails/RubyOnRails_HelloWorld_Rails.php
[21]: https://www.vagrantup.com/docs/index.html

View File

@ -0,0 +1,95 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Pekwm: A lightweight Linux desktop)
[#]: via: (https://opensource.com/article/19/12/pekwm-linux-desktop)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
Pekwm: A lightweight Linux desktop
======
This article is part of a special series of 24 days of Linux desktops.
If you're a minimalist who finds traditional desktops get in your way,
try the Pekwm Linux desktop.
![Penguin with green background][1]
Let's say you want a lightweight desktop environment, with just enough to get graphics on the screen, move some windows around, and not much else. You find traditional desktops get in your way, with their notifications and taskbars and system trays. You want to live your life primarily from a terminal, but you also want the luxury of launching graphical applications. If that sounds like you, then [Pekwm][2] may be what you've been looking for all along.
Pekwm is, presumably, inspired by the likes of Window Maker and Fluxbox. It provides an application menu, window decoration, and not a whole lot more. It's ideal for minimalists—users who want to conserve resources and users who prefer to work from a terminal.
Install Pekwm from your distribution's software repository. After installing, log out of your current desktop session so you can log into your new desktop. By default, your session manager (KDM, GDM, LightDM, or XDM, depending on your setup) will continue to log you into your previous desktop, so you must override that before logging in.
To override the previous desktop on GDM:
![Selecting your desktop in GDM][3]
And on KDM:
![Selecting your desktop in KDM][4]
The first time you log into Pekwm, you may encounter nothing but a black screen. Believe it or not, that's normal. What you're seeing is a blank desktop without background wallpaper. You can set a wallpaper with the **feh** command (you may need to install it from your repository). This command has a few options for setting the background, including **\--bg-fill** to fill the screen with your wallpaper, **\--bg-scale** to scale it to fit, and so on.
```
`$ feh --bg-fill ~/Pictures/wallpapers/mybackground.jpg`
```
### Application menu
By default, Pekwm auto-generates a menu, available with a right-click anywhere on the desktop, that gives you access to applications. This menu also provides a few preference settings, such as the ability to pick a theme and to log out of your Pekwm session.
![Pekwm running on Fedora][5]
### Configuration
Pekwm is primarily configured in text config files stored in **$HOME/.pekwm**. The **menu** file defines your application menu, the **keys** file defines keyboard shortcuts, and so on.
The **start** file is a shell script that is executed after Pekwm launches. It is analogous to the **rc.local** file on a traditional Unix system; it's intentionally last in line, so whatever you put into it overrides everything that came before it. This is an important file—it's probably where you want to set your background so that _your_ choice overrides the default on the theme you're using. 
The **start** file is also where you can launch dockapps. Dockapps are tiny applets that rose to prominence with Window Maker and Fluxbox. They usually provide network monitors, a clock, audio settings, and other things you might be used to seeing in a system tray or as a KDE plasmoid or widget in a full desktop environment. You might find some dockapps in your distribution's repository, or you can look for them online at [dockapps.net][6].
You can launch dockapps at startup by listing them in the **start** file followed by an **&amp;** symbol:
```
feh --bg-fill ~/Pictures/wallpapers/mybackground.jpg
wmnd &amp;
bubblemon -d &amp;
```
The **start** file must be [marked executable][7] for it to run when Pekwm starts.
```
`$ chmod +x $HOME/.pekwm/start`
```
### Features
There's not much to Pekwm, and that's the beauty of it. If you want extra services to run on your desktop, it's up to you to launch them. If you're still learning Linux, this is a great way to learn about the minute GUI components you usually don't think about when they come bundled with a complete desktop environment (like [a taskbar][8]). It's also a good way to get used to some of the Linux commands, like [nmcli][9], that you've been meaning to learn.
Pekwm is a fun window manager. It's sparse, terse, and very lightweight. Give it a try!
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/12/pekwm-linux-desktop
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/linux_penguin_green.png?itok=ENdVzW22 (Penguin with green background)
[2]: http://www.pekwm.org/
[3]: https://opensource.com/sites/default/files/uploads/advent-gdm_1.jpg (Selecting your desktop in GDM)
[4]: https://opensource.com/sites/default/files/uploads/advent-enlightenment-kdm_0.jpg (Selecting your desktop in KDM)
[5]: https://opensource.com/sites/default/files/uploads/advent-pekwm.jpg (Pekwm running on Fedora)
[6]: http://dockapps.net
[7]: https://opensource.com/article/19/6/understanding-linux-permissions
[8]: https://opensource.com/article/19/1/productivity-tool-tint2
[9]: https://opensource.com/article/19/5/set-static-network-connection-linux

View File

@ -0,0 +1,69 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Getting started with the GNOME Linux desktop)
[#]: via: (https://opensource.com/article/19/12/gnome-linux-desktop)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
Getting started with the GNOME Linux desktop
======
This article is part of a special series of 24 days of Linux desktops.
GNOME, the default desktop on most modern Linux distributions, is clean,
simple, and well-organized.
![Gnomes in a window.][1]
The [GNOME][2] project is the Linux desktop's darling, and deservedly so. It began as the free and open desktop alternative to proprietary options (including KDE at the time), and it's been going strong ever since. GNOME took GTK+, [developed by the GIMP project][3], and ran with it, developing it into a robust, all-purpose GTK framework. The project has pioneered the user interface, challenging preconceptions of what a desktop "should" look like and offering users new paradigms and options.
GNOME is widely available as the default desktop on most of the major modern Linux distributions, including RHEL, Fedora, Debian, and Ubuntu. If your distribution doesn't offer a version of it, you can probably install GNOME from your software repository. Before you do, though, be aware that it is meant to provide a full desktop experience, so many GNOME apps are installed along with the desktop. If you're already running a different desktop, you may find yourself with redundant applications (two PDF readers, two media players, two file managers, and so on). If you just want to try the GNOME desktop, consider installing a GNOME distribution in a virtual machine, such as [GNOME Boxes][4].
### GNOME features
The GNOME desktop is clean, with a simple taskbar along the top and the bare minimum of items in a system tray in the right corner. There are no desktop icons on GNOME, and that's by design. If you're one of those users who stores _everything_ on your desktop, you probably recognize that your desktop gets badly disorganized on a regular basis, and—worse still—it's permanently hidden from view because your applications are covering it up.
GNOME solves both problems: there _is_ no desktop (functionally), and new virtual workspaces are generated dynamically, so you can run your applications in full-screen mode. It can take some getting used to if you usually clutter up your screen, but in practice, it's an improved workflow in every sense. You learn to keep your assets organized (or you leave them scattered in your home directory), and you can switch between screens just as quickly as you do on your mobile phone.
Of course, not all applications are designed to run in full-screen mode, so if you prefer to click through windows, you can do that, too.
![GNOME running on Debian][5]
The GNOME philosophy extols canonical solutions to common tasks. You don't often find eight different ways to accomplish the same thing in GNOME. You find one or two official ways to accomplish a task, and once you've learned those ways, that's all you have to remember. It's refreshingly simple, but because it's running on Linux, it's also technically flexible (after all, you don't have to use GNOME applications just because you're running a GNOME desktop).
### Application menu
To access the application menu, called **Activities**, click in the upper-left corner of the desktop. This menu takes over your entire screen to reveal a dock along the left edge of the screen with common applications and an icon to browse your apps in a grid. You can launch applications by browsing through what you have installed or by typing the first few letters of the software name to bring up a filtered list of what's available.
![GNOME activities][6]
### GNOME applications
GNOME isn't just a desktop. It's a desktop plus a rich set of integrated applications, like the Gedit text editor, Evince PDF viewer, a web browser, an image viewer, the Nautilus file manager, and more. GNOME applications, like the desktop itself, follow the [GNOME Human Interface Guidelines][7], so the user experience is both pleasant and consistent. Whether or not you use the GNOME desktop, you probably use a GTK application, and you may well use a GNOME application.
### GNOME 3 and beyond
The GNOME project is going strong, and it's left several exciting projects (like MATE and [Cinnamon][8]) in its wake. It's popular, it's comfortable, and it's the face of the Linux desktop.
Exploring different desktops is a good thing. Ive recently converted to GNOME 3 ("hallowed be its...
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/12/gnome-linux-desktop
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/custom_gnomes.png?itok=iG98iL8d (Gnomes in a window.)
[2]: https://www.gnome.org/
[3]: https://www.gtk.org/overview.php
[4]: https://opensource.com/article/19/5/getting-started-gnome-boxes-virtualization
[5]: https://opensource.com/sites/default/files/uploads/advent-gnome.jpg (GNOME running on Debian)
[6]: https://opensource.com/sites/default/files/uploads/advent-gnome-activities.jpg (GNOME activities)
[7]: https://developer.gnome.org/hig/stable/
[8]: https://opensource.com/article/19/11/advent-2019-cinnamon

View File

@ -0,0 +1,199 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (8 Best Open Source Accounting Software)
[#]: via: (https://itsfoss.com/open-source-accounting-software/)
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
8 Best Open Source Accounting Software
======
Accounting software is a necessity when it comes to managing billings, debts, stocks, invoices and any other kind of financial transactions. You might require something for your personal finances or perhaps for enterprise-focused accounting software. No matter what, it is important to consider open source solutions available (especially being Linux enthusiasts).
So, in this article, I list out some of the best open source accounting software that I think would come in handy for you. At the end of the list, feel free to suggest your favorite ones in the comments.
### Best Open Source Accounting Software
**Note:** _The list is in no particular order of ranking._
#### 1\. Skrooge
![][1]
Key Highlights:
* Personal finances manager
* Tailored for Plasma Desktop but compatible with others too
* Cross-platform (Windows, Linux, and macOS)
Skrooge is one of the most useful personal finances manager by KDE. It is originally tailored for the Plasma Desktop but other desktop environments are compatible.
Supports most of the basic features (reporting, budgeting, etc.) and allows you to work on some pretty big data sets.
[Skrooge][2]
#### 2\. Akaunting
![][3]
Key Highlights:
* Online accounting software
* Completely free and open source
* Client portal
* Invoicing
* Expense tracking
* Reporting
* Cashflow
Akaunting is an interesting online accounting software thats available for free. Yes, surprisingly, theres no hidden subscription charges or additional upgrade options. It is totally free. If you are looking for a FreshBooks alternative, you should give it a try.
Ranging from invoicing to managing deposits and transfers. A whole lot of features. You can either utilize their hosting (again, it is free!) or host it yourself. Its fit for both personal and enterprise needs. Try it out!
[Akaunting][4]
#### 3\. Apache OFBiz
![][5]
Key Highlights:
* ERP &amp; CRM
* Developer-friendly
* Powerful Java Web Framework
* Cross-platform (Linux and macOS)
Weve already mentioned this in our list of [best open source CRM software][6]. Apache OFBiz is an impressive open source solution that incorporates an ERP system and a CRM suite for various types of requirements.
Its completely free however, you will have to host it yourself (or just hire someone to do it). In addition to all the basic features needed for accounting software, it lets a developer extend/enhance features easily while being a Java-based web framework.
[Apache OFBiz][7]
#### 4\. iDempiere
![][8]
Key Highlights:
* Community-focused
* Simple and useful
* Cross-platform (Linux and Windows)
Originally based on ADEmpiere ERP. It is a community focused accounting software maintained by an active group of people. iDempiere aims to utilize technologies like [Apache Maven][9] to provide a business suite ERP/CRM/SCM.
Theres a ready-to-use Virtual machine available to download. In addition, you can utilize it on Windows or Linux.
[iDempiere][10]
#### 5\. Openmiracle
![Openmiracle][11]
Key Highlights:
* Plug-ins available
* Completely free
Openmiracle is a quite popular open source and free accounting software. Theres no premium plans to it. So, you can utilize all the power and flexibility for free.
It features all the necessary options needed in an accounting software. From setting the budget to managing the payroll, theres a lot of things to explore.
[Openmiracle][12]
#### 6\. GnuCash
![][13]
Key Highlights:
* Cross-platform (Linux, Windows, and macOS)
* Fit for personal and small businesses
GNUCash is a great open-source financial accounting software to manage stocks/income/expenses for small business or individuals.
From reports to quick calculation features, it has a lot to offer. And, the best thing is it is available across multiple platforms (including Linux), so thats a plus.
[GNUCash][14]
#### 7\. LedgerSMB
![Ledgersmb Screenshot][15]
Key Highlights:
* Dead simple open source ERP
* Optional commercial support available
* Cross-platform (Windows, Linux, and macOS)
A powerful yet simple open source accounting solution. It has been tailored to small and medium sized businesses. Starting from managing invoices to inventory you also get the ability to translate (up to 45 languages supported). You can try pre-release version or just get the latest stable build to test it out yourself!
[LedgerSMB][16]
#### 8\. GNUKhata
Key Highlights:
* GST, VAT compliant Invoices if you are based in India (tailored for Indian users)
* Easy to use
* Simple user interface
* Cross-platform (Windows and Linux)
We already covered an article on [GNUKhata][17], if you want to dive into the details.
However, it is a simple and robust accounting software that is available for free. From the looks of it, the setup is easy and anyone can get used to it. Feel free to try it out and explore.
[GNUKhata][18]
**Wrapping Up**
These are our recommended picks for an open source accounting software. If we missed listing your favorite open-source accounting software, let us in the comments below.
--------------------------------------------------------------------------------
via: https://itsfoss.com/open-source-accounting-software/
作者:[Ankush Das][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/ankush/
[b]: https://github.com/lujun9972
[1]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/09/skrooge.jpg?ssl=1
[2]: https://skrooge.org/
[3]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/09/akaunting.jpg?ssl=1
[4]: https://akaunting.com/
[5]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/07/apache-ofbiz.jpg?ssl=1
[6]: https://itsfoss.com/best-open-source-crm/
[7]: https://ofbiz.apache.org/
[8]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/09/idempiere.jpg?ssl=1
[9]: https://en.wikipedia.org/wiki/Apache_Maven
[10]: https://www.idempiere.org/home
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/09/openmiracle.jpg?ssl=1
[12]: http://www.openmiracle.com/
[13]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/09/gnucash-screenshot.png?ssl=1
[14]: https://www.gnucash.org/
[15]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/09/ledgerSMB-screenshot.jpg?ssl=1
[16]: https://ledgersmb.org/
[17]: https://itsfoss.com/using-gnu-khata/
[18]: https://gnukhata.in/

View File

@ -0,0 +1,219 @@
[#]: collector: (lujun9972)
[#]: translator: (luuming)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (The many faces of awk)
[#]: via: (https://www.networkworld.com/article/3454979/the-many-faces-of-awk.html)
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
千面 awk
======
`awk` 命令不仅提供了简单的输入字符串筛选功能,还包含提取数据列,打印简单文本,筛选内容——甚至做一些数学计算。
![Thinkstock][6]
如果你仅使用 `awk` 选取一行中的特定文本,那么你可能错过了它的很多功能。在这篇文章中,我们会来看看使用 `awk` 可以帮你做一些其他的什么事情,并提供一些例子。
### 提取数据列
`awk` 所提供的最简单与最常用的功能便是从文件或管道传输的数据中选取特定的内容。默认使用空格当做分隔符,这非常简单。
```
$ echo one two three four five | awk {print $4}
four
$ who | awk {print $1}
jdoe
fhenry
```
空格指的是一系列的 `space``tab`。在下面所展示的命令里,`awk` 从提供的数据中筛选第一和第四项。
`awk` 命令也可以通过在其后增加文件名的方式从文本文件中获取数据。
```
$ awk '{print $1,$5,$NF}' HelenKellerQuote
The beautiful heart.
LCTT 译注“The best and most beautiful things in the world can not be seen or even touched , they must be felt with heart.” ——海伦凯勒)
```
在这个例子中,`awk` 挑选了一行中的第一个、第五个和最后一个字段。
命令中的`$NF` 指定选取每行的最后一个字段。这是因为`NF`代表一行中的<ruby>字段数量<rt>Number of Field</rt></ruby>,也就是 23`$NF` 就代表着那个字段的值,也就是`heart`。最后的句号也包含进去了,因为它是最后一个字符串的一部分。
字段能以任何有用的形式打印。在这个例子中,我们将字段以日期的格式进行打印输出。
```
$ date | awk '{print $4,$3,$2}'
2019 Nov 22
```
如果你省略了 `awk` 命令中字段指示符之间的逗号,输出将会挤成一个字符串。
```
$ date | awk '{print $4 $3 $2}'
2019Nov21
```
如果你将通常使用的逗号替换为连字符,`awk` 就会尝试将两个字段的值相减——或许这并不是你想要的。它不会将连字符插入到输出结果中。相反地,它对输出做了一些数学计算。
```
$ date | awk '{print $4-$3-$2}'
1997
```
在这个例子中它将年“2019”和日期“22”相减并忽略了中间的“Nov”。
如果你想要空格之外的字符作为输出分隔符,你可以通过 `OFS`<ruby>输出分隔符<rt>output field separator</rt></ruby>)指定分隔符,就像这样:
```
$ date | awk '{OFS="-"; print $4,$3,$2}'
2019-Nov-22
```
### 打印简单文本
你也可以使用 `awk` 简单地显示一些文本。当然了,比起 `awk` 你可能更想使用 `echo` 命令。但换句话说,作为 `awk` 脚本的一部分,打印某些相关性文本将会非常实用。这里有一个没什么用的例子:
```
$ awk 'BEGIN {print "Hello, World" }'
Hello, World
```
下面的例子更加合理,添加一行文本标签来更好的辨识数据。
```
$ who | awk 'BEGIN {print "Current logins:"} {print $1}'
Current logins:
shs
nemo
```
### 指定字段分隔符
不是所有的输入都以空格作为分隔符的。如果你的文本通过其它的字符作为分隔符(例如:逗号、冒号、分号),你可以通过 `-F` 选项(输入分隔符)告诉 `awk`
```
$ cat testfile
a:b:c,d:e
$ awk -F : '{print $2,$3}' testfile
b c,d
```
下面是一个更加有用的例子——从冒号分隔的 `/etc/passwd` 文件中获取数据:
```
$ awk -F: '{print $1}' /etc/passwd | head -11
root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
```
### 筛选内容
你也可以使用 `awk` 命令评估字段。例如你仅仅想列出 `/etc/passwd` 中的用户账号,就可以对第三个字段做一些筛选。下面的例子中我们只关注大于等于 1000 的 UID
```
$ awk -F":" ' $3 >= 1000 ' /etc/passwd
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
shs:x:1000:1000:Sandra Henry-Stocker,,,:/home/shs:/bin/bash
nemo:x:1001:1001:Nemo,,,:/home/nemo:/usr/bin/zsh
dory:x:1002:1002:Dory,,,:/home/dory:/bin/bash
...
```
如果你想为输出增加标题,可以添加 `BEGIN` 从句:
```
$ awk -F":" 'BEGIN {print "user accounts:"} $3 >= 1000 ' /etc/passwd
user accounts:
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
shs:x:1000:1000:Sandra Henry-Stocker,,,:/home/shs:/bin/bash
nemo:x:1001:1001:Nemo,,,:/home/nemo:/usr/bin/zsh
dory:x:1002:1002:Dory,,,:/home/dory:/bin/bash
```
如果你想要不止一行的标题,你可以通过 `"\n"` 分隔输出:
```
$ awk -F":" 'BEGIN {print "user accounts\n============="} $3 >= 1000 ' /etc/passwd
user accounts
=============
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
shs:x:1000:1000:Sandra Henry-Stocker,,,:/home/shs:/bin/bash
nemo:x:1001:1001:Nemo,,,:/home/nemo:/usr/bin/zsh
dory:x:1002:1002:Dory,,,:/home/dory:/bin/bash
```
### 在 awk 中进行数学计算
`awk` 提供了惊人的数学计算能力,并且可以开平方,算 `log`,算 `tan` 等等。
这里有一对例子:
```
$ awk 'BEGIN {print sqrt(2019)}'
44.9333
$ awk 'BEGIN {print log(2019)}'
7.61036
```
想要详细了解 `awk` 的数学计算能力,可以看《[使用 awk 进行数学计算][3]》这篇文章。
### awk 脚本
你也可以使用 `awk` 写一套单独的脚本。下面的例子模仿了之前写过的一个,不过还计算了系统里账户的数量。
```
#!/usr/bin/awk -f
# 这一行是注释
BEGIN {
printf "%s\n","User accounts:"
print "=============="
FS=":"
n=0
}
# 现在开始遍历数据
{
if ($3 >= 1000) {
print $1
n ++
}
}
END {
print "=============="
print n " accounts"
}
```
注意 `BEGIN` 那一节是如何提供标题、指定字段分隔符和初始化计数器的,它仅在脚本初始化时期执行。这个脚本也包含 `END` 节,它仅在中间所有命令处理完成之后运行,显示了所有中间小节所筛选数据的最终行数(第三个字段大于等于 1000
作为一个长存于 Unix 之上的命令,`awk` 依旧提供着非常有用的服务,这也是我几十年前爱上 Unix 的原因之一。
--------------------------------------------------------------------------------
via: https://www.networkworld.com/article/3454979/the-many-faces-of-awk.html
作者:[Sandra Henry-Stocker][a]
选题:[lujun9972][b]
译者:[LuuMing](https://github.com/LuuMing)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/
[b]: https://github.com/lujun9972
[1]: https://www.networkworld.com/newsletters/signup.html
[2]: https://www.networkworld.com/article/3440100/take-the-intelligent-route-with-consumption-based-storage.html?utm_source=IDG&utm_medium=promotions&utm_campaign=HPE20773&utm_content=sidebar ( Take the Intelligent Route with Consumption-Based Storage)
[3]: https://www.networkworld.com/article/2974753/doing-math-with-awk.html
[4]: https://www.facebook.com/NetworkWorld/
[5]: https://www.linkedin.com/company/network-world
[6]:https://images.techhive.com/images/article/2015/09/thinkstockphotos-512100549-100611755-large.jpg

View File

@ -0,0 +1,258 @@
[#]: collector: (lujun9972)
[#]: translator: (lxbwolf)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (6 Ways to Send Email from the Linux Command Line)
[#]: via: (https://www.2daygeek.com/6-ways-to-send-email-from-the-linux-command-line/)
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
Linux 命令行发送邮件的 6 种方法
======
当你需要在 shell 脚本中创建邮件时就需要用到命令行发送邮件的知识。Linux 中有很多命令可以实现发送邮件。本教程中包含了命令行邮件客户端的 Top 6你可以选择其中一个。6 个命令分别是:
* mail
* mailx
* mutt
* mpack
* sendmail
* ssmtp
### 工作原理
我先从整体上来解释下Linux中邮件命令怎么把邮件传递给收件人的。邮件命令如 sendmailpostfix生成邮件并发送给一个本地的邮件传输代理MTA。本质上发送和接收邮件时邮件服务器和远程邮件服务器之间的通信。下面的流程可以看得更详细。
![](https://www.2daygeek.com/wp-content/uploads/2019/12/smtp-simple-mail-transfer-protocol.png)
### 1) Linux 安装 mail 命令
mail 命令是 Linux 终端发送邮件使用次数最多的命令。可以运行下面的命令从官方发行库安装 mail 命令。对于 **”Debian/Ubuntu“** 系统,使用 **[APT-GET 命令][3]** 或 **[APT 命令][4]** 安装 mailutils。
```
$ sudo apt-get install mailutils
```
 对于 **“RHEL/CentOS”** 系统,使用 **[YUM 命令][5]** 安装 mailx。
```
$ sudo yum install mailx
```
对于 **“Fedora”** 系统,使用 **[DNF 命令][6]** 安装 mailx。
```
$ sudo dnf install mailx
```
### 1a) Linux 安装 mail 命令后发送邮件
mail 命令简单易用。如果你不需要发送附件,使用下面的 mail 命令格式就可以发送邮件了。
```
$ echo "This is the mail body" | mail -s "Subject" [email protected]
```
如果你要发送附件,使用下面的 mail 命令格式。
```
$ echo "This is the mail body" | mail -a test1.txt -s "Subject" [email protected]
```
```
+---------+----------------------------------------------------+
| Options | Description |
+---------+----------------------------------------------------+
| -a | It's used for attachment on Red Hat based systems. |
| -A | It's used for attachment on Debian based systems. |
| -s | Specify the subject of the message |
+--------------------------------------------------------------+
```
### 2) Linux 安装 mutt 命令
mutt 是另一个 Linux 终端发送邮件很受欢迎的命令。mutt 是一个小而强大的基于文本的程序,用来阅读和发送 unix 操作系统的电子邮件功能支持多彩终端、MIME、OpenPGP和按邮件线索排序的模式。可以运行下面的命令从官方发行库安装 mutt 命令。对于 **”Debian/Ubuntu“** 系统,使用 **[APT-GET 命令][3]** 或 **[APT 命令][4]** 安装 mutt。
```
$ sudo apt-get install mutt
```
对于 **“RHEL/CentOS”** 系统,使用 **[YUM 命令][5]** 安装 mutt。
```
$ sudo yum install mutt
```
对于 **“Fedora”** 系统,使用 **[DNF 命令][6]** 安装 mutt。
```
$ sudo dnf install mutt
```
### 2b) Linux 使用 mutt 命令发送邮件
mutt 也是简单易用的。如果你不需要发送附件,使用下面的 mutt 命令格式就可以发送邮件了。
```
$ echo "This is the mail body" | mutt -s "Subject" [email protected]
```
如果你要发送附件,使用下面的 mutt 命令格式。
```
$ echo "This is the mail body" | mutt -s "Subject" [email protected] -a test1.txt
```
### 3) Linux 安装 mpack 命令
mpack 是另一个 Linux 终端发送邮件很受欢迎的命令。mpack 程序会对 MIME 消息中文件进行编码。编码后的消息被发送到一个或多个收件人。可以运行下面的命令从官方发行库安装 mpack 命令。对于 **”Debian/Ubuntu“** 系统,使用 **[APT-GET 命令][3]** 或 **[APT 命令][4]** 安装 mpack。
```
$ sudo apt-get install mpack
```
对于 **“RHEL/CentOS”** 系统,使用 **[YUM 命令][5]** 安装 mpack。
```
$ sudo yum install mpack
```
对于 **“Fedora”** 系统,使用 **[DNF 命令][6]** 安装 mpack。
```
$ sudo dnf install mpack
```
### 3a) Linux 使用 mpack 命令发送邮件
mpack 也是简单易用的。如果你不需要发送附件,使用下面的 mpack 命令格式就可以发送邮件了。
```
$ echo "This is the mail body" | mpack -s "Subject" [email protected]
```
如果你要发送附件,使用下面的 mpack 命令格式。
```
$ echo "This is the mail body" | mpack -s "Subject" [email protected] -a test1.txt
```
### 4) Linux 安装 mailx 命令
mailx 是 mail 命令的更新版本,基于 Berkeley Mail 8.1,意在提供 POSIX mailx 命令的功能和支持MIME、IMAP、POP3、SMTP和S/MIME 的扩展。mailx 在某些交互特性上更加强大,如缓冲邮件消息、排序和过滤等。可以运行下面的命令从官方发行库安装 mailx 命令。对于 **”Debian/Ubuntu“** 系统,使用 **[APT-GET 命令][3]** 或 **[APT 命令][4]** 安装 mailutils。
```
$ sudo apt-get install mailutils
```
 对于 **“RHEL/CentOS”** 系统,使用 **[YUM 命令][5]** 安装 mailx。
```
$ sudo yum install mailx
```
对于 **“Fedora”** 系统,使用 **[DNF 命令][6]** 安装 mailx。
```
$ sudo dnf install mailx
```
### 4a) Linux 使用 mailx 命令发送邮件
mailx 也是简单易用的。如果你不需要发送附件,使用下面的 mail 命令格式就可以发送邮件了。
```
$ echo "This is the mail body" | mail -s "Subject" [email protected]
```
如果你要发送附件,使用下面的 mail 命令格式。
```
$ echo "This is the mail body" | mail -a test1.txt -s "Subject" [email protected]
```
### 5) Linux 安装 sendmail 命令
sendmail 是一个 Linux 上广泛使用的 SMTP 服务器,你也可以从命令行用 sendmail 发邮件。可以运行下面的命令从官方发行库安装 sendmail 命令。对于 **”Debian/Ubuntu“** 系统,使用 **[APT-GET 命令][3]** 或 **[APT 命令][4]** 安装 sendmail。
```
$ sudo apt-get install sendmail
```
对于 **“RHEL/CentOS”** 系统,使用 **[YUM 命令][5]** 安装 sendmail。
```
$ sudo yum install sendmail
```
对于 **“Fedora”** 系统,使用 **[DNF 命令][6]** 安装 sendmail。
```
$ sudo dnf install sendmail
```
### 5a) Linux 使用 sendmail 命令发送邮件
sendmail 也是简单易用的。使用下面的 sendmail 命令格式发送邮件。
```
$ echo -e "Subject: Test Mail\nThis is the mail body" > /tmp/send-mail.txt
```
```
$ sendmail [email protected] < send-mail.txt
```
### 6) Linux 安装 ssmtp 命令
ssmtp 是类似 sendmail 的一个只发送不接收的工具,可以把邮件从本地计算机传递到配置好的 mailhostmailhub。用户可以在 Linux 命令行用 SSMTP 把邮件发送到 SMTP 服务器。可以运行下面的命令从官方发行库安装 ssmtp 命令。对于 **”Debian/Ubuntu“** 系统,使用 **[APT-GET 命令][3]** 或 **[APT 命令][4]** 安装 ssmtp。
```
$ sudo apt-get install ssmtp
```
对于 **“RHEL/CentOS”** 系统,使用 **[YUM 命令][5]** 安装 ssmtp。
```
$ sudo yum install ssmtp
```
对于 **“Fedora”** 系统,使用 **[DNF 命令][6]** 安装 ssmtp。
```
$ sudo dnf install ssmtp
```
### 6a) Linux 使用 ssmtp 命令发送邮件
ssmtp 也是简单易用的。使用下面的 sendmail 命令格式发送邮件。
```
$ echo -e "Subject: Test Mail\nThis is the mail body" > /tmp/ssmtp-mail.txt
```
```
$ ssmtp [email protected] < /tmp/ssmtp-mail.txt
```
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/6-ways-to-send-email-from-the-linux-command-line/
作者:[Magesh Maruthamuthu][a]
选题:[lujun9972][b]
译者:[lxbwolf](https://github.com/lxbwolf)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.2daygeek.com/author/magesh/
[b]: https://github.com/lujun9972
[1]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
[2]: https://www.2daygeek.com/wp-content/uploads/2019/12/smtp-simple-mail-transfer-protocol.png
[3]: https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
[4]: https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
[5]: https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/
[6]: https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/