Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2020-09-04 20:13:01 +08:00
commit e07c496c5f
10 changed files with 520 additions and 304 deletions

View File

@ -1,8 +1,8 @@
[#]: collector: (lujun9972)
[#]: translator: (wxy)
[#]: reviewer: (wxy)
[#]: publisher: ( )
[#]: url: ( )
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-12579-1.html)
[#]: subject: (Linux Jargon Buster: What is Desktop Environment in Linux?)
[#]: via: (https://itsfoss.com/what-is-desktop-environment/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
@ -10,6 +10,8 @@
Linux 黑话解释:什么是桌面环境?
======
![][6]
在桌面 Linux 世界中,最常用的术语之一就是<ruby>桌面环境<rt>Desktop Environment</rt></ruby>DE。如果你是 Linux 的新手,你应该了解一下这个经常使用的术语。
### 什么是 Linux 中的桌面环境?
@ -48,8 +50,6 @@ Linux 黑话解释:什么是桌面环境?
### Linux 发行版及其桌面环境变体
![][6]
同样的桌面环境可以在多个 Linux 发行版上使用,一个 Linux 发行版也可能提供多个桌面环境。
例如Fedora 和 Ubuntu 都默认使用 GNOME 桌面,但 Fedora 和 Ubuntu 都提供了其他桌面环境。

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (Starryi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -0,0 +1,68 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Why your open source project needs more than just coders)
[#]: via: (https://opensource.com/article/20/9/open-source-role-diversity)
[#]: author: (Silona https://opensource.com/users/silona)
Why your open source project needs more than just coders
======
Developers alone don't create open source projects that meet a variety
of needs for a long shelf life; it's time to welcome more roles and
talent.
![Teamwork starts with communication across silos][1]
Why do open source projects fail?
Lack of funding is a major factor, of course, but it's far from the only reason that open source projects fail to achieve sustainability. Sometimes there's a lack of understanding of how to create a product for a broad market, or some fundamental misstep with intellectual property rights (IPR)—such as failing to properly license your code.
It's hard for any open source project to sustain if it doesn't get these types of basics right. Collaboration across boundaries and the ability to iterate and expand are hindered, and innovation is stifled. I see these fatal flaws especially in a lot of humanitarian projects—_passion projects_—and it is heartbreaking.
### Building role diversity
Open source has tended to thrive in instances where it has been developers writing code for developers. Thats why so many underlying technologies developed via open source (Apache and Linux, for example) have succeeded.
However, when it comes to creating quality user experiences and products for people other than developers, open source's record is spottier. Why is that?
One of the big reasons is because the majority of open source communities dont encourage or even welcome people of diverse expertise. Sometimes, theres no acknowledgement of them. The coders get all of the love, and roles and contributions beyond coding are not even thought of.
Sustainable open source demands that communities embrace and reward a lot of different talents. There are the developers, most definitely, and they must be core for any open source project to be successful. But without contributions from marketing expertise, for example, you might not thoroughly understand what the users want. Without the input of product management, you run the risk of failing to develop a product for users other than other developers. Businesses normally invest in these and other roles because their varied contributions are critical to delivering successful results and creating products that are production ready with community support for long term sustainability.
One of the conflicts that I often find amongst open source development communities is an animosity towards product or project management. Its true that product management especially in corporate places has control issues—they may try to do things like dominate a market, or come in from a perspective of scarcity rather than abundance. It shows in behavior, and its antithetical to the spirit of open source.
But, to be fair, I think it is also true that we developers have never been taught how to work well with product management. We are told, "More people would use your product if you just did X," and we respond, "No, you can't tell me anything about my baby." We don't want to hear, "Yeah, but if you change the diaper, more people would like your baby," even if it's true.
Open source hasn't always embraced talent other than developers, and this is what must change in order to foster long term stability.
### Birthing IEEE SA Open
Putting in place the tools and processes needed to encourage project sustainability is our current focus in architecting and designing [IEEE SA Open][2]. To that end, bringing in role diversity and building a platform and a tool that invites and rewards those diverse contributions is crucial in creating IEEE SA Open.
We are creating our community, marketing, and technology onboarding guides to ensure that incoming projects automatically get a level of support that they wouldn't normally get from a technology platform. We're looking at raising the maturity model into advanced processes and practices. For example, progressing to levels 4 (quantitatively managed) and 5 (optimizing) of [Capability Maturity Model Integration][3] (CMMI) requires measurement. Getting our processes right from the outset and assigning the right metrics to inform better, more consistent evaluations will support our sustainability.
This is one of the places where our linkage with IEEE is so important. One of the things that the standards world does especially well is process, and IEEE in particular has a history of making sure that its processes are fair and predicated on advancing technology for the benefit of humanity. With more than 419,000 members in over 160 countries, IEEE is the worlds largest technical professional organization dedicated to advancing technology for humanity. Its roots go back to 1884 when electricity and telecommunications began to become a major influence in society, and today IEEE has over 1,200 active standards and more than 650 standards under development.
IEEE SA Open can borrow on those best practices and lessons learned in sustainability that IEEE has acquired by experience. We aim to bridge the gap between global standards development and open source developer communities. It is definitely a balancing act, and we respect that!
Were reaching out to people all over the global open source and standards communities in a diverse set of roles to be engaged in creating IEEE SA Open. You can participate in that birthing project, and now is the time. If there are things that are super important to you and that youve seen neglected in open source, this is the time to engage, share your experiences and influence the creation of IEEE SA Open. You can help make sure we dont make those mistakes. [We need your unique insights and input.][2]
You don't need to be a master coder to contribute to open source. Jade Wang shares 8 ways you can...
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/9/open-source-role-diversity
作者:[Silona][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/silona
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/happy-team-sticker-laptop.png?itok=91K77IgE (Teamwork starts with communication across silos)
[2]: https://standards.ieee.org/initiatives/opensource?utm_source=External&utm_medium=PR&utm_campaign=IEEE-SA-Open
[3]: https://en.wikipedia.org/wiki/Capability_Maturity_Model_Integration

View File

@ -1,179 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Create and run Python apps on your Android phone)
[#]: via: (https://opensource.com/article/20/8/python-android-mobile)
[#]: author: (Phani Adabala https://opensource.com/users/adabala)
Create and run Python apps on your Android phone
======
Use Termux and Flask to create, develop, and run a web app on your
mobile device.
![Tux and Android stuffed animals on shelf][1]
Learning and using Python is fun. Thanks to its growing popularity, there are a plethora of ways it can be used to make the world of computing better than what it is today.
Imagine building and running python applications, whether it's a command-line tool developed to fetch your favorite curated articles from the Internet, or starting a web server that runs right in the palm of your hand, all with just an Android mobile device and open source tools. This would change how you view your mobile device entirely, changing it from a device that merely lets you consume content to a device that helps you be creative.
In this article, I'll demonstrate all of the tools, software packages, steps, and all the bells and whistles required to build, run, and test a simple Python application on any Android mobile device. I use the [Flask framework][2] to create a simple “Hello, World!” app running on a simple but powerful web server. And best of all, it all happens on the phone. No laptop or desktop required.
### Install Termux on Android
First, [install the Termux application][3]. Termux is a powerful terminal emulator that offers all the most popular Linux commands, plus hundreds of additional packages for easy installation. It doesn't require any special permissions You can use either the default [Google Play][4] store or the open source app repository [F-Droid][5] to install.
![Welcome to Termux][6]
Once you have installed Termux, launch it and perform a few requisite software installations using Termux's **pkg** command:
Subscribe to the additional repository “root-repo”:
```
`$ pkg install root-repo`
```
 Perform an update to bring all the installed software up to date:
```
`$ pkg update`
```
Finally, install Python:
```
`$ pkg install python`
```
![Install Python][7]
Once the installation and auto set-up of configuration is complete, its time to build your application.
### Build an app for Android on Android
Now that you have a terminal installed, you can work on your Android phone largely as if it were just another Linux computer. This is a great demonstration of just how powerful a terminal really is.
Start by creating a project directory:
```
$ mkdir Source
$ cd Source
```
Next, create a Python virtual environment. This is a common practice among Python developers, and it helps keep your Python project independent of your development system (in this case, your phone). Within your virtual environment, you'll be able to install Python modules specific to your app.
```
`$ python -m venv venv`
```
Activate your new virtual environment (note that the two dots at the start are separated by a space):
```
$ . ./venv/bin/activate
(env)$
```
Notice that your shell prompt is now preceded by **(env)** to indicate that you're in a virtual environment.
Now install the Flask Python module using **pip**:
```
`(env) $ pip install flask`
```
### Write Python code on Android
You're all set up. All you need now is to write the code for your app.
To do this, you should have experience with a classic text editor. I use **vi**. If youre unfamiliar with **vi**, install and try the **vimtutor** application, which (as its name suggests) can teach you how to use this editor. If you have a different editor you prefer, such as **jove**, **jed**, **joe**, or **emacs**, you can install and use one of those instead.
For now, because this demonstration app is so simple, you can also just use the shell's **heredoc** function, which allows you to enter text directly at your prompt:
```
(env)$ cat &lt;&lt; EOF &gt;&gt; hello_world.py
&gt; from flask import Flask
&gt; app = Flask(__name__)
&gt;
&gt; @app.route('/')
&gt; def hello_world():
&gt;     return 'Hello, World!'
&gt; EOF
(env)$
```
That's just six lines of code, but with that you import Flask, create an app, and route incoming traffic to the function called **hello_world**.
![Vim on Android][8]
Now you have the web-server code ready. It's time to set up some [environment variables][9] and start a web server on your phone.
```
(env) $ export FLASK_APP=hello_world.py
(env) $ export FLASK_ENV=development
(evn) $ python hello_world.py
```
![Running a Flask app on your phone][10]
After starting your app, you see this message:
```
`serving Flask app… running on http://127.0.0.1:5000/`
```
This indicates that you now have a tiny web server running on **localhost** (that is, your device). This server is listening for requests looking for port 5000.
Open your mobile browser and navigate to **<http://localhost:5000>** to see your web app.
![Your web app][11]
You haven't compromised your phone's security. You're only running a local server, meaning that your phone isn't accepting requests from the outside world. Only you can access your Flask server.
To make your server visible to others, you can disable Flask's debugging mode by adding **\--host=0.0.0.0** to the **run** command. This does open ports on your phone, so use this wisely.
```
(env) $ export FLASK_ENV=””
(env) $ flask run host=0.0.0.0
```
Stop the server by pressing **Ctrl+C** (use the special Termux key for Control).
### Decide what comes next
Your phone is probably not the ideal server platform for a serious web app, but this demonstrates that the possibilities are endless. You might program on your Android phone just because its a convenient way to stay in practice, or because you have an exciting new idea for localized web apps, or maybe you just happen to use a Flask app for your own daily tasks. As Einstein once said “Imagination is more important than knowledge”, and this is a fun little project for any new coder, or a seasoned Linux or Android enthusiast. It can be expanded to endless levels, so let your curiosity take over, and make something exciting!
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/8/python-android-mobile
作者:[Phani Adabala][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/adabala
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/tux_penguin_linux_android.jpg?itok=ctgANLI7 (Tux and Android stuffed animals on shelf)
[2]: https://opensource.com/article/18/4/flask
[3]: https://opensource.com/article/20/8/termux
[4]: https://play.google.com/store/apps/details?id=com.termux
[5]: https://f-droid.org/repository/browse/?fdid=com.termux
[6]: https://opensource.com/sites/default/files/termux-flask-1_0.webp (Welcome to Termux)
[7]: https://opensource.com/sites/default/files/termux-install-python.webp (Install Python)
[8]: https://opensource.com/sites/default/files/termux-python-vim.webp (Vim on Android)
[9]: https://opensource.com/article/19/8/what-are-environment-variables
[10]: https://opensource.com/sites/default/files/termux-flask-run.webp (Running a Flask app on your phone)
[11]: https://opensource.com/sites/default/files/flask-app-android.webp (Your web app)

View File

@ -1,119 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Linux Jargon Buster: What is a Display Server in Linux? What is it Used for?)
[#]: via: (https://itsfoss.com/display-server/)
[#]: author: (Dimitrios Savvopoulos https://itsfoss.com/author/dimitrios/)
Linux Jargon Buster: What is a Display Server in Linux? What is it Used for?
======
In Linux related articles, news and discussions, youll often come across the term display server, Xorg, Wayland etc.
In this explainer article, Ill discuss display servers in Linux.
### What is display server in Linux?
A display server is a program which is responsible for the input and output coordination of its clients, to and from the rest of the operating system, and among the hardware and the operating system. Basically, thanks to a display server, you can use your computer graphically (GUI). Without the display server, you would only be restricted to a command line interface (TTY).
The display server provides the framework for a graphical environment so that you can use mouse and keyboard to interact with applications.
The display server communicates with its clients over the [display server protocol][1], like X11. The display server is a key component in any graphical user interface, specifically the windowing system.
Dont confuse display server with [desktop environment][2]. The desktop environment uses display server underneath it.
Sounds familiar but it is not fully clear? Let me explain.
### Display server communications protocols in Linux
![][3]
There are three display protocols available in Linux, the X11, Wayland and Mir. Ill give you a brief introduction for these display servers.
#### X11
The X11 (also refer as X) is the legacy display server that has been existed for years. It is the most common display server used in Linux distributions.
![X Architecture][4]
The X11 communication protocol, uses the [X.org Server][5] display server. It receives input events from [device drivers][6] and makes them available to one of its clients.
The display server also receives data from its clients, it processes the data and does the compositing and on Linux it passes the data to one of three kernel components the [DRM][7], [gem][8] or [KMS driver][9].
The X.Org Server is a display server that relies on a second program, the [compositing window manager][10], to do the compositing. Examples are [Mutter][11] or [KWin][12]. GNOME uses Mutter.
#### Wayland
As per its website, Wayland is “intended as a simpler replacement for X, easier to develop and maintain”.
And indeed [Wayland][13] is the modern display server that is supposed to replace the legacy X display server.
Its adoption is still a work in progress. Ubuntu tried to switch to Wayland as the default display server with version 17.10 but the experiment met with negative feedback.
A lot of GUI applications and their frameworks depend on the X server. These applications didnt work as intended on Wayland.
This forced Ubuntu to stay on X as default display server. It still provides the option to use Wayland but it is not default anymore.
An overwhelming majority of distributions use X display server by default even today.
![Wayland Architecture][14]
Display servers that put into effect the Wayland display server protocol, are called [Wayland compositors][15]. Like any X11, a Wayland compositor is responsible for handling input and output for its clients but also does the [compositing][16] in contrast to X11.
A few Wayland compositors are [Weston][17], [Mutter][18], [KWin][12] or [Enlightenment][19].
#### Mir
The [Mir display server][20] comes with its own Mir display server protocol which differs to those used by X11 and Wayland. It was developed by [Canonical][21], as part of the development of Unity, and was intended to be the display server of choice for [Ubuntu][22].
As of 2017, it has been replaced with the Wayland display server for desktop editions of Ubuntu, although Mirs development continued for Internet of Things (IoT) applications.
#### Why are we still using Xorg?
Wayland as it is relatively new, is not very stable yet, compared to Xorg. The programs, which act as clients, in order to communicate with a display server, must know how to do it.
For this reason, many programs might not run when using Wayland. Ubuntus experiment to switch to Wayland by default confirmed this.
#### Conclusion
I hope you have a bit better understanding of display server concept in Linux. I have tried to not go into too much technical details but I could not avoid them altogether.
Your feedback and suggestion is welcome.
--------------------------------------------------------------------------------
via: https://itsfoss.com/display-server/
作者:[Dimitrios Savvopoulos][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/dimitrios/
[b]: https://github.com/lujun9972
[1]: https://en.wikipedia.org/wiki/X_Window_System_core_protocol
[2]: https://itsfoss.com/what-is-desktop-environment/
[3]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/08/display-server-linux.png?resize=800%2C450&ssl=1
[4]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/08/x-architecture-1.png?resize=800%2C507&ssl=1
[5]: https://en.wikipedia.org/wiki/X.Org_Server
[6]: https://en.wikipedia.org/wiki/Device_driver
[7]: https://en.wikipedia.org/wiki/Direct_Rendering_Manager
[8]: https://en.wikipedia.org/wiki/Graphics_Execution_Manager
[9]: https://en.wikipedia.org/wiki/KMS_driver
[10]: https://en.wikipedia.org/wiki/Compositing_window_manager
[11]: https://en.wikipedia.org/wiki/Mutter_(window_manager)
[12]: https://en.wikipedia.org/wiki/KWin
[13]: https://wayland.freedesktop.org/
[14]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/08/wayland-architecture-1.png?resize=800%2C500&ssl=1
[15]: https://en.wikipedia.org/wiki/Wayland_compositor
[16]: https://en.wikipedia.org/wiki/Compositing
[17]: https://en.wikipedia.org/wiki/Weston_(software)
[18]: https://en.wikipedia.org/wiki/Mutter_(software)
[19]: https://en.wikipedia.org/wiki/Enlightenment_(software)
[20]: https://mir-server.io/
[21]: https://canonical.com/
[22]: https://itsfoss.com/install-ubuntu/

View File

@ -0,0 +1,149 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (A practical guide to learning awk)
[#]: via: (https://opensource.com/article/20/9/awk-ebook)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
A practical guide to learning awk
======
Get a better handle on the awk command by downloading our free eBook.
![Person programming on a laptop on a building][1]
Of all the [Linux][2] commands out there (and there are many), the three most quintessential seem to be `sed`, `awk`, and `grep`. Maybe it's the arcane sound of their names, or the breadth of their potential use, or just their age, but when someone's giving an example of a "Linuxy" command, it's usually one of those three. And while `sed` and `grep` have several simple one-line standards, the less prestigious `awk` remains persistently prominent for being particularly puzzling.
You're likely to use `sed` for a quick string replacement or `grep` to filter for a pattern on a daily basis. You're far less likely to compose an `awk` command. I often wonder why this is, and I attribute it to a few things. First of all, many of us barely use `sed` and `grep` for anything but some variation upon these two commands:
```
$ sed -e 's/foo/bar/g' file.txt
$ grep foo file.txt
```
So, even though you might feel more comfortable with `sed` and `grep`, you may not use their full potential. Of course, there's no obligation to learn more about `sed` or `grep`, but I sometimes wonder about the way I "learn" commands. Instead of learning _how_ a command works, I often learn a specific incantation that includes a command. As a result, I often feel a false familiarity with the command. I think I know a command because I can name three or four options off the top of my head, even though I don't know what the options do and can't quite put my finger on the syntax.
And that's the problem, I believe, that many people face when confronted with the power and flexibility of `awk`.
### Learning awk to use awk
The basics of `awk` are surprisingly simple. It's often noted that `awk` is a programming language, and although it's a relatively basic one, it's true. This means you can learn `awk` the same way you learn a new coding language: learn its syntax using some basic commands, learn its vocabulary so you can build up to complex actions, and then practice, practice, practice.
### How awk parses input
`Awk` sees input, essentially, as an array. When `awk` scans over a text file, it treats each line, individually and in succession, as a _record_. Each record is broken into _fields_. Of course, `awk` must keep track of this information, and you can see that data using the `NR` (number of records) and `NF` (number of fields) built-in variables. For example, this gives you the line count of a file:
```
$ awk 'END { print NR;}' example.txt
36
```
This also reveals something about `awk` syntax. Whether you're writing `awk` as a one-liner or as a self-contained script, the structure of an `awk` instruction is:
```
`pattern or keyword { actions }`
```
In this example, the word `END` is a special, reserved keyword rather than a pattern. A similar keyword is `BEGIN`. With both of these keywords, `awk` just executes the action in braces at the start or end of parsing data.
You can use a _pattern_ as a filter or qualifier so that `awk` only executes a given action when it is able to match your pattern to the current record. For instance, suppose you want to use `awk`, much as you would `grep`, to find the word _Linux_ in a file of text:
```
$ awk '/Linux/ { print $0; }' os.txt
OS: CentOS Linux (10.1.1.8)
OS: CentOS Linux (10.1.1.9)
OS: Red Hat Enterprise Linux (RHEL) (10.1.1.11)
OS: Elementary Linux (10.1.2.4)
OS: Elementary Linux (10.1.2.5)
OS: Elementary Linux (10.1.2.6)
```
For `awk`, each line in the file is a record, and each word in a record is a field. By default, fields are separated by a space. You can change that with the `--field-separator` option, which sets the `FS` (field separator) variable to whatever you want it to be:
```
$ awk --field-separator ':' '/Linux/ { print $2; }' os.txt
 CentOS Linux (10.1.1.8)
 CentOS Linux (10.1.1.9)
 Red Hat Enterprise Linux (RHEL) (10.1.1.11)
 Elementary Linux (10.1.2.4)
 Elementary Linux (10.1.2.5)
 Elementary Linux (10.1.2.6)
```
In this sample, there's an empty space before each listing because there's a blank space after each colon (`:`) in the source text. This isn't `cut`, though, so the field separator needn't be limited to one character:
```
$ awk --field-separator ': ' '/Linux/ { print $2; }' os.txt
CentOS Linux (10.1.1.8)
CentOS Linux (10.1.1.9)
Red Hat Enterprise Linux (RHEL) (10.1.1.11)
Elementary Linux (10.1.2.4)
Elementary Linux (10.1.2.5)
Elementary Linux (10.1.2.6)
```
### Functions in awk
You can build your own functions in `awk` using this syntax:
```
`name(parameters) { actions }`
```
Functions are important because they allow you to write code once and reuse it throughout your work. When constructing one-liners, custom functions are a little less useful than they are in scripts, but `awk` defines many functions for you already. They work basically the same as any function in any other language or spreadsheet: You learn the order that the function needs information from you, and you can feed it whatever you want to get the results.
There are functions to perform mathematical operations and string processing. The math ones are often fairly straightforward. You provide a number, and it crunches it:
```
$ awk 'BEGIN { print sqrt(1764); }'
42
```
String functions can be more complex but are well documented in the [GNU awk manual][3]. For example, the `split` function takes an entity that `awk` views as a single field and splits it into different parts. It requires a field, a variable to use as an array containing each part of the split, and the character you want to use as the delimiter.
Using the output of the previous examples, I know that there's an IP address at the very end of each record. In this case, I can send just the last field of a record to the `split` function by referencing the variable `NF` because it contains the number of fields (and the final field must be the highest number):
```
$ awk --field-separator ': ' '/Linux/ { split($NF, IP, "."); print "subnet: " IP[3]; }' os.txt
subnet: 1
subnet: 1
subnet: 1
subnet: 2
subnet: 2
subnet: 2
```
There are many more functions, and there's no reason to limit yourself to one per block of `awk` code. You can construct complex pipelines with `awk` in your terminal, or you can write `awk` scripts to define and utilize your own functions.
### Download the eBook
Learning `awk` is mostly a matter of using `awk`. Use it even if it means duplicating functionality you already have with `sed` or `grep` or `cut` or `tr` or any other perfectly valid commands. Once you get comfortable with it, you can write Bash functions that invoke your custom `awk` commands for easier use. And eventually, you'll be able to write scripts to parse complex datasets.
**[Download our][4]** **[eBook][4] **to learn everything you need to know about `awk`, and start using it today.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/9/awk-ebook
作者:[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/computer_code_programming_laptop.jpg?itok=ormv35tV (Person programming on a laptop on a building)
[2]: https://opensource.com/resources/linux
[3]: https://www.gnu.org/software/gawk/manual/gawk.html
[4]: https://opensource.com/downloads/awk-ebook

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -0,0 +1,178 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Create and run Python apps on your Android phone)
[#]: via: (https://opensource.com/article/20/8/python-android-mobile)
[#]: author: (Phani Adabala https://opensource.com/users/adabala)
在你的 Android 手机上创建和运行 Python 应用
======
使用 Termux 和 Flask 在你的移动设备上创建、开发和运行一个网络应用。
![Tux and Android stuffed animals on shelf][1]
学习和使用 Python 是很有趣的。由于它越来越受欢迎,有大量的方式可以让计算世界比现在更好。
想象一下,构建和运行 python 应用,无论是开发一个命令行工具,从互联网上获取你最喜欢的文章,还是启动一个直接在掌上运行的网络服务器,所有这些都只需要一个 Android 移动设备和开源工具。这将完全改变你对移动设备的看法,将它从一个仅仅让你消费内容的设备变成一个帮助你发挥创造力的设备。
在本文中,我将演示运行和测试一个简单的 Python 应用所需的所有的工具、软件包、步骤等等。我使用 [Flask 框架][2]来创建一个简单的 “Hello, World!” 应用,并在一个简单而强大的 Web 服务器上运行。最棒的是,这一切都发生在手机上。不需要笔记本或台式机。
### 在 Android 上安装 Termux
首先,[安装 Termux 应用程序][3]。Termux 是一个强大的终端仿真器,它提供了所有最流行的 Linux 命令,加上数百个额外的包,以便于安装。它不需要任何特殊的权限,你可以使用默认的 [Google Play][4] 商店或开源应用仓库 [F-Droid][5] 来安装。
![Welcome to Termux][6]
安装 Termux 后,启动它并使用 Termux 的 **pkg** 命令执行一些必要的软件安装。
订阅额外的仓库 “root-repo”
```
`$ pkg install root-repo`
```
执行更新,使所有安装的软件达到最新状态。
```
`$ pkg update`
```
最后,安装 Python
```
`$ pkg install python`
```
![Install Python][7]
安装和自动配置完成后,就可以构建你的应用了。
### 在 Android 上构建一个 Android 应用
现在你已经安装了一个终端,你可以在很大程度上像使用另一台 Linux 电脑一样使用你的 Android 手机。这很好地展示了终端到底有多强大。
首先创建一个项目目录:
```
$ mkdir Source
$ cd Source
```
接下来,创建一个 Python 虚拟环境。这是 Python 开发者的常见做法,它有助于让你的 Python 项目独立于你的开发系统(在本例中是你的手机)。在你的虚拟环境中,你将能够安装特定于你应用的 Python 模块。
```
`$ python -m venv venv`
```
激活你的新虚拟环境(注意,开头的两个点用空格隔开)
```
$ . ./venv/bin/activate
(env)$
```
请注意你的 shell 提示符现在以 **(env)** 开头,表示你在虚拟环境中。
现在使用 **pip** 安装 Flask Python 模块。
```
`(env) $ pip install flask`
```
### 在 Android 上写 Python 代码
你已经准备好了。现在你需要为你的应用编写代码。
要做到这一点,你需要有经典文本编辑器的经验。我使用的是 **vi**。如果你不熟悉 **vi**,请安装并试用 **vimtutor**,它(如其名称所暗示的)可以教你如何使用这个编辑器。如果你有其他你喜欢的编辑器,如 **jove**、**jed**、**joe** 或 **emacs**,你可以安装并使用其中一个。
现在,由于这个演示程序非常简单,你也可以直接使用 shell 的 **heredoc** 功能,它允许你直接在提示符中输入文本。
```
(env)$ cat &lt;&lt; EOF &gt;&gt; hello_world.py
&gt; from flask import Flask
&gt; app = Flask(__name__)
&gt;
&gt; @app.route('/')
&gt; def hello_world():
&gt;     return 'Hello, World!'
&gt; EOF
(env)$
```
这是仅六行的代码,但有了它,你可以导入 Flask创建一个应用并将传入流量路由到名为 **hello_world** 的函数。
![Vim on Android][8]
现在你已经准备好了 Web 服务器的代码。现在是时候设置一些[环境变量][9],并在你的手机上启动一个 Web 服务器了。
```
(env) $ export FLASK_APP=hello_world.py
(env) $ export FLASK_ENV=development
(evn) $ python hello_world.py
```
![Running a Flask app on your phone][10]
启动应用后,你会看到这条消息:
```
`serving Flask app… running on http://127.0.0.1:5000/`
```
这表明你现在在 **localhost**(也就是你的设备)上运行着一个微型 Web 服务器。该服务器正在监听来自 5000 端口的请求。
打开你的手机浏览器并进入到 **<http://localhost:5000>**,查看你的网络应用。
![Your web app][11]
你并没有损害手机的安全性。你只运行了一个本地服务器,这意味着你的手机不接受来自外部世界的请求。只有你可以访问你的 Flask 服务器。
为了让别人看到你的服务器,你可以在**运行**命令中加入 **/\--host=0.0.0.0** 来禁用 Flask 的调试模式。这确实会打开手机上的端口,所以要谨慎使用。
```
(env) $ export FLASK_ENV=””
(env) $ flask run host=0.0.0.0
```
**Ctrl+C** 停止服务器(使用特殊的 Termux 控制键)。
### 决定下一步怎么做
你的手机可能不是一个严肃的网络应用的理想服务器平台,但这个例子证明了可能性是无限的。你可能会在 Android 手机上编程,只是因为这是一种方便的实践方式,或者因为你有一个令人兴奋的本地化网络应用的新想法,或者你只是碰巧使用 Flask 应用来完成自己的日常任务。正如爱因斯坦曾经说过的”想象力比知识更重要“,对于任何一个新手编码者,或者一个经验丰富的 Linux 或 Android 爱好者来说,这是一个有趣的小项目。它可以扩展到无穷的层次,所以让你的好奇心接手,并做出一些令人兴奋的东西!
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/8/python-android-mobile
作者:[Phani Adabala][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/adabala
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/tux_penguin_linux_android.jpg?itok=ctgANLI7 (Tux and Android stuffed animals on shelf)
[2]: https://opensource.com/article/18/4/flask
[3]: https://opensource.com/article/20/8/termux
[4]: https://play.google.com/store/apps/details?id=com.termux
[5]: https://f-droid.org/repository/browse/?fdid=com.termux
[6]: https://opensource.com/sites/default/files/termux-flask-1_0.webp (Welcome to Termux)
[7]: https://opensource.com/sites/default/files/termux-install-python.webp (Install Python)
[8]: https://opensource.com/sites/default/files/termux-python-vim.webp (Vim on Android)
[9]: https://opensource.com/article/19/8/what-are-environment-variables
[10]: https://opensource.com/sites/default/files/termux-flask-run.webp (Running a Flask app on your phone)
[11]: https://opensource.com/sites/default/files/flask-app-android.webp (Your web app)

View File

@ -0,0 +1,119 @@
[#]: collector: (lujun9972)
[#]: translator: (wxy)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Linux Jargon Buster: What is a Display Server in Linux? What is it Used for?)
[#]: via: (https://itsfoss.com/display-server/)
[#]: author: (Dimitrios Savvopoulos https://itsfoss.com/author/dimitrios/)
Linux 黑话解释:什么是显示服务器,用来做什么?
======
![][3]
在 Linux 相关的文章、新闻和讨论中,你会经常遇到<ruby>显示服务器<rt>display server</rt></ruby>、Xorg、Wayland 等名词。
在这篇解释文章中,我将讨论 Linux 中的显示服务器。
### 什么是显示服务器?
显示服务器是一个程序它负责协调其客户端与操作系统的其他部分之间以及硬件和操作系统之间的输入和输出。基本上多亏了显示服务器你才能以图形化的方式使用你的计算机GUI。如果没有显示服务器你只能局限于命令行界面TTY
显示服务器提供了一个图形环境的框架,使你可以使用鼠标和键盘与应用程序进行交互。
显示服务器通过[显示服务器协议][1](如 X11与客户端进行通信。显示服务器是图形用户界面 —— 特别是窗口系统 —— 中的一个关键组件。
不要把显示服务器和[桌面环境][2]混淆。桌面环境下面使用的是显示服务器。
听起来很熟悉,但又不完全清楚?让我来解释一下。
### Linux 上的显示服务器协议
Linux 中有三种显示服务器协议,分别是 X11、Wayland 和 Mir。下面我就给大家简单介绍一下这些显示服务器。
#### X11
X11也称 X是已经存在多年的传统显示服务器。它是 Linux 发行版中最常用的显示服务器。
![X 架构][4]
X11 通信协议,使用 [X.org 服务器][5]显示服务器。它接收来自[设备驱动程序][6]的输入事件,并将它们提供给它的一个客户端。
显示服务器也从客户端接收数据,它处理数据并进行合成,在 Linux 上,它将数据传递给三个内核组件之一:[DRM][7]、[gem][8] 或 [KMS 驱动][9]。
X.Org 服务器是一个显示服务器,它依靠第二个程序:[合成窗口管理器][10],来进行合成。例如 [Mutter][11] 或 [KWin][12]。GNOME 使用的是 Mutter。
#### Wayland
按照其网站的说法Wayland “旨在作为 X 的更简单的替代品,更容易开发和维护”。
而事实上 [Wayland][13] 就是现代显示服务器,它应该取代传统的 X 显示服务器。
它的采用还在进行中。Ubuntu 曾试图在 17.10 版本中改用 Wayland 作为默认的显示服务器,但这个实验遭到了负面反馈。
很多 GUI 应用程序及其框架都依赖于 X 服务器。这些应用程序在 Wayland 上无法正常工作。
这迫使 Ubuntu 继续使用 X 作为默认显示服务器。它仍然提供了使用 Wayland 的选项,但它不再是默认的了。
即使在今天,绝大多数的发行版都默认使用 X 显示服务器。
![Wayland 架构][14]
实施 Wayland 显示服务器协议的显示服务器,被称为 [Wayland 合成器][15]。和 X11 上的一样Wayland 合成器负责处理其客户端的输入和输出,但同时也进行[合成][16],这与 X11 相反。
几个 Wayland 合成器是 [Weston][17]、[Mutter][18]、[KWin][12] 或 [Enlightenment][19]。
#### Mir
[Mir 显示服务器][20]自带的 Mir 显示服务器协议,与 X11 和 Wayland 使用的协议不同。它是由 [Canonical][21] 开发的,作为 Unity 开发的一部分,打算成为 [Ubuntu][22] 的首选显示服务器。
但在 2017 年,它已经被 [Ubuntu] 桌面版的 Wayland 显示服务器所取代,不过 Mir 的开发还在继续用于物联网IoT应用。
#### 为什么我们还在使用 Xorg
Wayland 作为比较新的产品,相比 Xorg 来说,还不是很稳定。作为客户端的程序,必须知道如何与显示服务器进行通信。
因此,很多程序在使用 Wayland 时可能无法运行。Ubuntu 默认切换到 Wayland 的实验证实了这一点。
#### 结束语
我希望你对 Linux 中的显示服务器概念有了更好的理解。我已经尽量不谈太多的技术细节,但我无法完全避免。
欢迎你的反馈和建议。
--------------------------------------------------------------------------------
via: https://itsfoss.com/display-server/
作者:[Dimitrios Savvopoulos][a]
选题:[lujun9972][b]
译者:[wxy](https://github.com/wxy)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/dimitrios/
[b]: https://github.com/lujun9972
[1]: https://en.wikipedia.org/wiki/X_Window_System_core_protocol
[2]: https://linux.cn/article-12579-1.html
[3]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/08/display-server-linux.png?resize=800%2C450&ssl=1
[4]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/08/x-architecture-1.png?resize=800%2C507&ssl=1
[5]: https://en.wikipedia.org/wiki/X.Org_Server
[6]: https://en.wikipedia.org/wiki/Device_driver
[7]: https://en.wikipedia.org/wiki/Direct_Rendering_Manager
[8]: https://en.wikipedia.org/wiki/Graphics_Execution_Manager
[9]: https://en.wikipedia.org/wiki/KMS_driver
[10]: https://en.wikipedia.org/wiki/Compositing_window_manager
[11]: https://en.wikipedia.org/wiki/Mutter_(window_manager)
[12]: https://en.wikipedia.org/wiki/KWin
[13]: https://wayland.freedesktop.org/
[14]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/08/wayland-architecture-1.png?resize=800%2C500&ssl=1
[15]: https://en.wikipedia.org/wiki/Wayland_compositor
[16]: https://en.wikipedia.org/wiki/Compositing
[17]: https://en.wikipedia.org/wiki/Weston_(software)
[18]: https://en.wikipedia.org/wiki/Mutter_(software)
[19]: https://en.wikipedia.org/wiki/Enlightenment_(software)
[20]: https://mir-server.io/
[21]: https://canonical.com/
[22]: https://itsfoss.com/install-ubuntu/