From f0f90aef36108e5c724d0e2f88ac8bcf9daa1008 Mon Sep 17 00:00:00 2001 From: darksun Date: Sat, 24 Feb 2018 10:24:35 +0800 Subject: [PATCH 001/296] =?UTF-8?q?=E9=80=89=E9=A2=98:=20How=20to=20config?= =?UTF-8?q?ure=20an=20Apache=20web=20server?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2 How to configure an Apache web server.md | 233 ++++++++++++++++++ 1 file changed, 233 insertions(+) create mode 100644 sources/tech/20180222 How to configure an Apache web server.md diff --git a/sources/tech/20180222 How to configure an Apache web server.md b/sources/tech/20180222 How to configure an Apache web server.md new file mode 100644 index 0000000000..9846afc98c --- /dev/null +++ b/sources/tech/20180222 How to configure an Apache web server.md @@ -0,0 +1,233 @@ +How to configure an Apache web server +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/openweb-osdc-lead.png?itok=yjU4KliG) + +I have hosted my own websites for many years now. Since switching from OS/2 to Linux more than 20 years ago, I have used [Apache][1] as my server software. Apache is solid, well-known, and quite easy to configure for a basic installation. It is not really that much more difficult to configure for a more complex setup, such as multiple websites. + +Installation and configuration of the Apache web server must be performed as root. Configuring the firewall also needs to be performed as root. Using a browser to view the results of this work should be done as a non-root user. (I use the useron `student` on my virtual host.) + +### Installation + +Note: I use a virtual machine (VM) using Fedora 27 with Apache 2.4.29. If you have a different distribution or a different release of Fedora, your commands and the locations and content of the configuration files may be different. However, the configuration lines you need to modify are the same. + +The Apache web server is easy to install. On my CentOS 6.x server, it just takes a simple `yum` command. It installs all the necessary dependencies if any are missing. I used the `dnf` command below on one of my Fedora virtual machines. The syntax for `dnf` and `yum` are the same except for the name of the command itself. +``` +dnf -y install httpd + +``` + +The VM is a very basic desktop installation I am using as a testbed for writing a book. Even on this system, only six dependencies were installed in under a minute. + +All the configuration files for Apache are located in `/etc/httpd/conf` and `/etc/httpd/conf.d`. The data for the websites is located in `/var/www` by default, but you can change that if you want. + +### Configuration + +The primary Apache configuration file is `/etc/httpd/conf/httpd.conf`. It contains a lot of configuration statements that don't need to be changed for a basic installation. In fact, only a few changes must be made to this file to get a basic website up and running. The file is very large so, rather than clutter this article with a lot of unnecessary stuff, I will show only those directives that you need to change. + +First, take a bit of time and browse through the `httpd.conf` file to familiarize yourself with it. One of the things I like about Red Hat versions of most configuration files is the number of comments that describe the various sections and configuration directives in the files. The `httpd.conf` file is no exception, as it is quite well commented. Use these comments to understand what the file is configuring. + +The first item to change is the `Listen` statement, which defines the IP address and port on which Apache is to listen for page requests. Right now, you just need to make this website available to the local machine, so use the `localhost` address. The line should look like this when you finish: +``` +Listen 127.0.0.1:80 + +``` + +With this directive set to the IP address of the `localhost`, Apache will listen only for connections from the local host. If you want the web server to listen for connections from remote hosts, you would use the host's external IP address. + +The `DocumentRoot` directive specifies the location of the HTML files that make up the pages of the website. That line does not need to be changed because it already points to the standard location. The line should look like this: +``` +DocumentRoot "/var/www/html" + +``` + +The Apache installation RPM creates the `/var/www` directory tree. If you wanted to change the location where the website files are stored, this configuration item is used to do that. For example, you might want to use a different name for the `www` subdirectory to make the identification of the website more explicit. That might look like this: +``` +DocumentRoot "/var/mywebsite/html" + +``` + +These are the only Apache configuration changes needed to create a simple website. For this little exercise, only one change was made to the `httpd.conf` file—the `Listen` directive. Everything else is already configured to produce a working web server. + +One other change is needed, however: opening port 80 in our firewall. I use [iptables][2] as my firewall, so I change `/etc/sysconfig/iptables` to add a statement that allows HTTP protocol. The entire file looks like this: +``` +# sample configuration for iptables service + +# you can edit this manually or use system-config-firewall + +# please do not ask us to add additional ports/services to this default configuration + +*filter + +:INPUT ACCEPT [0:0] + +:FORWARD ACCEPT [0:0] + +:OUTPUT ACCEPT [0:0] + +-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT + +-A INPUT -p icmp -j ACCEPT + +-A INPUT -i lo -j ACCEPT + +-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT + +-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT + +-A INPUT -j REJECT --reject-with icmp-host-prohibited + +-A FORWARD -j REJECT --reject-with icmp-host-prohibited + +COMMIT + +``` + +The line I added is the third from the bottom, which allows incoming traffic on port 80. Now I reload the altered iptables configuration. +``` +[root@testvm1 ~]# cd /etc/sysconfig/ ; iptables-restore iptables + +``` + +### Create the index.html file + +The `index.html` file is the default file a web server will serve up when you access the website using just the domain name and not a specific HTML file name. In the `/var/www/html` directory, create a file with the name `index.html`. Add the content `Hello World`. You do not need to add any HTML markup to make this work. The sole job of the web server is to serve up a stream of text data, and the server has no idea what the date is or how to render it. It simply transmits the data stream to the requesting host. + +After saving the file, set the ownership to `apache.apache`. +``` +[root@testvm1 html]# chown apache.apache index.html + +``` + +### Start Apache + +Apache is very easy to start. Current versions of Fedora use `systemd`. Run the following commands to start it and then to check the status of the server: +``` +[root@testvm1 ~]# systemctl start httpd + +[root@testvm1 ~]# systemctl status httpd + +● httpd.service - The Apache HTTP Server + +   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) + +   Active: active (running) since Thu 2018-02-08 13:18:54 EST; 5s ago + +     Docs: man:httpd.service(8) + + Main PID: 27107 (httpd) + +   Status: "Processing requests..." + +    Tasks: 213 (limit: 4915) + +   CGroup: /system.slice/httpd.service + +           ├─27107 /usr/sbin/httpd -DFOREGROUND + +           ├─27108 /usr/sbin/httpd -DFOREGROUND + +           ├─27109 /usr/sbin/httpd -DFOREGROUND + +           ├─27110 /usr/sbin/httpd -DFOREGROUND + +           └─27111 /usr/sbin/httpd -DFOREGROUND + + + +Feb 08 13:18:54 testvm1 systemd[1]: Starting The Apache HTTP Server... + +Feb 08 13:18:54 testvm1 systemd[1]: Started The Apache HTTP Server. + +``` + +The commands may be different on your server. On Linux systems that use SystemV start scripts, the commands would be: +``` +[root@testvm1 ~]# service httpd start + +Starting httpd: [Fri Feb 09 08:18:07 2018]          [  OK  ] + +[root@testvm1 ~]# service httpd status + +httpd (pid  14649) is running... + +``` + +If you have a web browser like Firefox or Chrome on your host, you can use the URL `localhost` on the URL line of the browser to display your web page, simple as it is. You could also use a text mode web browser like [Lynx][3] to view the web page. First, install Lynx (if it is not already installed). +``` +[root@testvm1 ~]# dnf -y install lynx + +``` + +Then use the following command to display the web page. +``` +[root@testvm1 ~]# lynx localhost + +``` + +The result looks like this in my terminal session. I have deleted a lot of the empty space on the page. +``` +  Hello World + + + + + + + + + +Commands: Use arrow keys to move, '?' for help, 'q' to quit, '<-' to go back. + +  Arrow keys: Up and Down to move.  Right to follow a link; Left to go back. + + H)elp O)ptions P)rint G)o M)ain screen Q)uit /=search [delete]=history list + +``` + +Next, edit your `index.html` file and add a bit of HTML markup so it looks like this: +``` +

Hello World

+ +``` + +Now refresh the browser. For Lynx, use the key combination Ctrl+R. The results look just a bit different. The text is in color, which is how Lynx displays headings if your terminal supports color, and it is now centered. In a GUI browser the text would be in a large font. +``` +                                   Hello World + + + + + + + + + +Commands: Use arrow keys to move, '?' for help, 'q' to quit, '<-' to go back. + +  Arrow keys: Up and Down to move.  Right to follow a link; Left to go back. + + H)elp O)ptions P)rint G)o M)ain screen Q)uit /=search [delete]=history list + +``` + +### Parting thoughts + +As you can see from this little exercise, it is easy to set up an Apache web server. The specifics will vary depending upon your distribution and the version of Apache supplied by that distribution. In my environment, this was a pretty trivial exercise. + +But there is more because Apache is very flexible and powerful. Next month I will discuss hosting multiple websites using a single instance of Apache. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/2/how-configure-apache-web-server + +作者:[David Both][a] +译者:[译者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/dboth +[1]:https://httpd.apache.org/ +[2]:https://en.wikipedia.org/wiki/Iptables +[3]:http://lynx.browser.org/ From 63a8cb8c82a3acffa22a35dd151d3f375a8a9cbe Mon Sep 17 00:00:00 2001 From: darksun Date: Sat, 24 Feb 2018 10:30:56 +0800 Subject: [PATCH 002/296] =?UTF-8?q?=E9=80=89=E9=A2=98:=20Create=20a=20wiki?= =?UTF-8?q?=20on=20your=20Linux=20desktop=20with=20Zim?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...e a wiki on your Linux desktop with Zim.md | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 sources/tech/20180221 Create a wiki on your Linux desktop with Zim.md diff --git a/sources/tech/20180221 Create a wiki on your Linux desktop with Zim.md b/sources/tech/20180221 Create a wiki on your Linux desktop with Zim.md new file mode 100644 index 0000000000..9929e45536 --- /dev/null +++ b/sources/tech/20180221 Create a wiki on your Linux desktop with Zim.md @@ -0,0 +1,115 @@ +Create a wiki on your Linux desktop with Zim +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/OSDC_bees_network.png?itok=NFNRQpJi) + +There's no denying the usefulness of a wiki, even to a non-geek. You can do so much with one—write notes and drafts, collaborate on projects, build complete websites. And so much more. + +I've used more than a few wikis over the years, either for my own work or at various contract and full-time gigs I've held. While traditional wikis are fine, I really like the idea of [desktop wikis][1] . They're small, easy to install and maintain, and even easier to use. And, as you've probably guessed, there are a number a desktop wikis available for Linux. + +Let's take a look at one of the better desktop wikis: [Zim][2]. + +### Getting going + +You can either [download][3] and install Zim from the software's website, or do it the easy way and install it through your distro's package manager. + +Once Zim's installed, start it up. + +A key concept in Zim is notebooks. They're like a collection of wiki pages on a single subject. When you first start Zim, it asks you to specify a folder for your notebooks and the name of a notebook. Zim suggests "Notes" for the name, and `~/Notebooks/` for the folder. Change that if you want. I did. + +![](https://opensource.com/sites/default/files/u128651/zim1.png) + +After you set the name and the folder for your notebook, click **OK**. You get what's essentially a container for your wiki pages. + +![](https://opensource.com/sites/default/files/u128651/zim2.png) + +### Adding pages to a notebook + +So you have a container. Now what? You start adding pages to it, of course. To do that, select **File > New Page**. + +![](https://opensource.com/sites/default/files/u128651/zim3.png) + +Enter a name for the page, then click **OK**. From there, you can start typing to add information to that page. + +![](https://opensource.com/sites/default/files/u128651/zim4.png) + +That page can be whatever you want it to be: notes for a course you're taking, the outline for a book or article or essay, or an inventory of your books. It's up to you. + +Zim has a number of formatting options, including: + + * Headings + * Character formatting + * Bullet and numbered lists + * Checklists + + + +You can also add images and attach files to your wiki pages, and even pull in text from a text file. + +### Zim's wiki syntax + +You can add formatting to a page using the toolbar, but that's not the only way to do the deed. If, like me, you're kind of old school, you can use wiki markup for formatting. + +[Zim's markup][4] is based on the markup that's used with [DokuWiki][5]. It's essentially [WikiText][6] with a few minor variations. To create a bullet list, for example, type an asterisk. Surround a word or a phrase with two asterisks to make it bold. + +### Adding links + +If you have a number of pages in a notebook, it's easy to link them. There are two ways to do that. + +The first way is to use [CamelCase][7] to name the pages. Let's say I have a notebook called "Course Notes." I can rename the notebook for the data analysis course I'm taking by typing "AnalysisCourse." When I want to link to it from another page in the notebook, I just type "AnalysisCourse" and press the space bar. Instant hyperlink. + +The second way is to click the **Insert link** button on the toolbar. Type the name of the page you want to link to in the **Link to** field, select it from the displayed list of options, then click **Link**. + +![](https://opensource.com/sites/default/files/u128651/zim5.png) + +I've only been able to link between pages in the same notebook. Whenever I've tried to link to a page in another notebook, the file (which has the extension .txt) always opens in a text editor. + +### Exporting your wiki pages + +There might come a time when you want to use the information in a notebook elsewhere—say, in a document or on a web page. Instead of copying and pasting (and losing formatting), you can export your notebook pages to any of the following formats: + + * HTML + * LaTeX + * Markdown + * ReStructuredText + + + +To do that, click on the wiki page you want to export. Then, select **File > Export**. Decide whether to export the whole notebook or just a single page, then click **Forward**. + +![](https://opensource.com/sites/default/files/u128651/zim6.png) + +Select the file format you want to use to save the page or notebook. With HTML and LaTeX, you can choose a template. Play around to see what works best for you. For example, if you want to turn your wiki pages into HTML presentation slides, you can choose "SlideShow_s5" from the **Template** list. If you're wondering, that produces slides driven by the [S5 slide framework][8]. + +![](https://opensource.com/sites/default/files/u128651/zim7.png) + +Click **Forward**. If you're exporting a notebook, you can choose to export the pages as individual files or as one file. You can also point to the folder where you want to save the exported file. + +![](https://opensource.com/sites/default/files/u128651/zim8.png) + +### Is that all Zim can do? + +Not even close. Zim also has a number of [plugins][9] that expand its capabilities. It even packs a built-in web server that lets you view your notebooks as static HTML files. This is useful for sharing your pages and notebooks on an internal network. + +All in all, Zim is a powerful, yet compact tool for managing your information. It's easily the best desktop wiki I've used, and it's one that I keep going back to. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/2/create-wiki-your-linux-desktop-zim + +作者:[Scott Nesbitt][a] +译者:[译者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 +[1]:https://opensource.com/article/17/2/3-desktop-wikis +[2]:http://zim-wiki.org/ +[3]:http://zim-wiki.org/downloads.html +[4]:http://zim-wiki.org/manual/Help/Wiki_Syntax.html +[5]:https://www.dokuwiki.org/wiki:syntax +[6]:http://en.wikipedia.org/wiki/Wikilink +[7]:https://en.wikipedia.org/wiki/Camel_case +[8]:https://meyerweb.com/eric/tools/s5/ +[9]:http://zim-wiki.org/manual/Plugins.html From 1e889ae4d33c3b1d9e30c984577ec849daf116f5 Mon Sep 17 00:00:00 2001 From: darksun Date: Sat, 24 Feb 2018 10:33:32 +0800 Subject: [PATCH 003/296] =?UTF-8?q?=E9=80=89=E9=A2=98:=20Getting=20started?= =?UTF-8?q?=20with=20SQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tech/20180221 Getting started with SQL.md | 250 ++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 sources/tech/20180221 Getting started with SQL.md diff --git a/sources/tech/20180221 Getting started with SQL.md b/sources/tech/20180221 Getting started with SQL.md new file mode 100644 index 0000000000..469716e478 --- /dev/null +++ b/sources/tech/20180221 Getting started with SQL.md @@ -0,0 +1,250 @@ +Getting started with SQL +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/brain_data.png?itok=RH6NA32X) + +Building a database using SQL is simpler than most people think. In fact, you don't even need to be an experienced programmer to use SQL to create a database. In this article, I'll explain how to create a simple relational database management system (RDMS) using MySQL 5.6. Before I get started, I want to quickly thank [SQL Fiddle][1], which I used to run my script. It provides a useful sandbox for testing simple scripts. + + +In this tutorial, I'll build a database that uses the simple schema shown in the entity relationship diagram (ERD) below. The database lists students and the course each is studying. I used two entities (i.e., tables) to keep things simple, with only a single relationship and dependency. The entities are called `dbo_students` and `dbo_courses`. + +![](https://opensource.com/sites/default/files/u128651/erd.png) + +The multiplicity of the database is 1-to-many, as each course can contain many students, but each student can study only one course. + +A quick note on terminology: + + 1. A table is called an entity. + 2. A field is called an attribute. + 3. A record is called a tuple. + 4. The script used to construct the database is called a schema. + + + +### Constructing the schema + +To construct the database, use the `CREATE TABLE ` command, then define each field name and data type. This database uses `VARCHAR(n)` (string) and `INT(n)` (integer), where n refers to the number of values that can be stored. For example `INT(2)` could be 01. + +This is the code used to create the two tables: +``` +CREATE TABLE dbo_students + +( + +  student_id INT(2) AUTO_INCREMENT NOT NULL, + +  student_name VARCHAR(50), + +  course_studied INT(2), + +  PRIMARY KEY (student_id) + +); + + + +CREATE TABLE dbo_courses + +( + +  course_id INT(2) AUTO_INCREMENT NOT NULL, + +  course_name VARCHAR(30), + +  PRIMARY KEY (course_id) + +); + +``` + +`NOT NULL` means that the field cannot be empty, and `AUTO_INCREMENT` means that when a new tuple is added, the ID number will be auto-generated with 1 added to the previously stored ID number in order to enforce referential integrity across entities. `PRIMARY KEY` is the unique identifier attribute for each table. This means each tuple has its own distinct identity. + +### Relationships as a constraint + +As it stands, the two tables exist on their own with no connections or relationships. To connect them, a foreign key must be identified. In `dbo_students`, the foreign key is `course_studied`, the source of which is within `dbo_courses`, meaning that the field is referenced. The specific command within SQL is called a `CONSTRAINT`, and this relationship will be added using another command called `ALTER TABLE`, which allows tables to be edited even after the schema has been constructed. + +The following code adds the relationship to the database construction script: +``` +ALTER TABLE dbo_students + +ADD CONSTRAINT FK_course_studied + +FOREIGN KEY (course_studied) REFERENCES dbo_courses(course_id); + +``` + +Using the `CONSTRAINT` command is not actually necessary, but it's good practice because it means the constraint can be named and it makes maintenance easier. Now that the database is complete, it's time to add some data. + +### Adding data to the database + +`INSERT INTO
` is the command used to directly choose which attributes (i.e., fields) data is added to. The entity name is defined first, then the attributes. Underneath this command is the data that will be added to that entity, creating a tuple. If `NOT NULL` has been specified, it means that the attribute cannot be left blank. The following code shows how to add records to the table: +``` +INSERT INTO dbo_courses(course_id,course_name) + +VALUES(001,'Software Engineering'); + +INSERT INTO dbo_courses(course_id,course_name) + +VALUES(002,'Computer Science'); + +INSERT INTO dbo_courses(course_id,course_name) + +VALUES(003,'Computing'); + + + +INSERT INTO dbo_students(student_id,student_name,course_studied) + +VALUES(001,'student1',001); + +INSERT INTO dbo_students(student_id,student_name,course_studied) + +VALUES(002,'student2',002); + +INSERT INTO dbo_students(student_id,student_name,course_studied) + +VALUES(003,'student3',002); + +INSERT INTO dbo_students(student_id,student_name,course_studied) + +VALUES(004,'student4',003); + +``` + +Now that the database schema is complete and data is added, it's time to run queries on the database. + +### Queries + +Queries follow a set structure using these commands: +``` +SELECT + +FROM + +WHERE + +``` + +To display all records within the `dbo_courses` entity and display the course code and course name, use an asterisk. This is a wildcard that eliminates the need to type all attribute names. (Its use is not recommended in production databases.) The code for this query is: +``` +SELECT * + +FROM dbo_courses + +``` + +The output of this query shows all tuples in the table, so all available courses can be displayed: +``` +| course_id |          course_name | + +|-----------|----------------------| + +|         1 | Software Engineering | + +|         2 |     Computer Science | + +|         3 |            Computing | + +``` + +In a future article, I'll explain more complicated queries using one of the three types of joins: Inner, Outer, or Cross. + +Here is the completed script: +``` +CREATE TABLE dbo_students + +( + +  student_id INT(2) AUTO_INCREMENT NOT NULL, + +  student_name VARCHAR(50), + +  course_studied INT(2), + +  PRIMARY KEY (student_id) + +); + + + +CREATE TABLE dbo_courses + +( + +  course_id INT(2) AUTO_INCREMENT NOT NULL, + +  course_name VARCHAR(30), + +  PRIMARY KEY (course_id) + +); + + + +ALTER TABLE dbo_students + +ADD CONSTRAINT FK_course_studied + +FOREIGN KEY (course_studied) REFERENCES dbo_courses(course_id); + + + +INSERT INTO dbo_courses(course_id,course_name) + +VALUES(001,'Software Engineering'); + +INSERT INTO dbo_courses(course_id,course_name) + +VALUES(002,'Computer Science'); + +INSERT INTO dbo_courses(course_id,course_name) + +VALUES(003,'Computing'); + + + +INSERT INTO dbo_students(student_id,student_name,course_studied) + +VALUES(001,'student1',001); + +INSERT INTO dbo_students(student_id,student_name,course_studied) + +VALUES(002,'student2',002); + +INSERT INTO dbo_students(student_id,student_name,course_studied) + +VALUES(003,'student3',002); + +INSERT INTO dbo_students(student_id,student_name,course_studied) + +VALUES(004,'student4',003); + + + +SELECT * + +FROM dbo_courses + +``` + +### Learning more + +SQL isn't difficult; I think it is simpler than programming, and the language is universal to different database systems. Note that `dbo.` is not a required entity-naming convention; I used it simply because it is the standard in Microsoft SQL Server. + +If you'd like to learn more, the best guide this side of the internet is [W3Schools.com][2]'s comprehensive guide to SQL for all database platforms. + +Please feel free to play around with my database. Also, if you have suggestions or questions, please respond in the comments. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/2/getting-started-sql + +作者:[Aaron Cocker][a] +译者:[译者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/aaroncocker +[1]:http://sqlfiddle.com +[2]:https://www.w3schools.com/sql/default.asp From 7d32a437b674a0275018f18c76faf58cacc32b99 Mon Sep 17 00:00:00 2001 From: darksun Date: Sat, 24 Feb 2018 10:45:00 +0800 Subject: [PATCH 004/296] =?UTF-8?q?=E9=80=89=E9=A2=98:=2012=20useful=20zyp?= =?UTF-8?q?per=20command=20examples?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...80221 12 useful zypper command examples.md | 434 ++++++++++++++++++ 1 file changed, 434 insertions(+) create mode 100644 sources/tech/20180221 12 useful zypper command examples.md diff --git a/sources/tech/20180221 12 useful zypper command examples.md b/sources/tech/20180221 12 useful zypper command examples.md new file mode 100644 index 0000000000..2e5e2c59a9 --- /dev/null +++ b/sources/tech/20180221 12 useful zypper command examples.md @@ -0,0 +1,434 @@ +12 useful zypper command examples +====== +Learn zypper command with 12 useful examples along with sample outputs. zypper is used for package and patch management in Suse Linux systems. + +![zypper command examples][1] + +zypper is package management system powered by [ZYpp package manager engine][2]. Suse Linux uses zypper for package management. In this article we will be sharing 12 useful zypper commands along with examples whcih are helpful for your day today sysadmin tasks. + +Without any argument `zypper` command will list you all available switches which can be used. Its quite handy than referring to man page which is pretty much in detail. + +``` +root@kerneltalks # zypper + Usage: + zypper [--global-options] [--command-options] [arguments] + zypper [--command-options] [arguments] + + Global Options: + --help, -h Help. + --version, -V Output the version number. + --promptids Output a list of zypper's user prompts. + --config, -c Use specified config file instead of the default . + --userdata User defined transaction id used in history and plugins. + --quiet, -q Suppress normal output, print only error + messages. + --verbose, -v Increase verbosity. + --color + --no-color Whether to use colors in output if tty supports it. + --no-abbrev, -A Do not abbreviate text in tables. + --table-style, -s Table style (integer). + --non-interactive, -n Do not ask anything, use default answers + automatically. + --non-interactive-include-reboot-patches + Do not treat patches as interactive, which have + the rebootSuggested-flag set. + --xmlout, -x Switch to XML output. + --ignore-unknown, -i Ignore unknown packages. + + --reposd-dir, -D Use alternative repository definition file + directory. + --cache-dir, -C Use alternative directory for all caches. + --raw-cache-dir Use alternative raw meta-data cache directory. + --solv-cache-dir Use alternative solv file cache directory. + --pkg-cache-dir Use alternative package cache directory. + + Repository Options: + --no-gpg-checks Ignore GPG check failures and continue. + --gpg-auto-import-keys Automatically trust and import new repository + signing keys. + --plus-repo, -p Use an additional repository. + --plus-content Additionally use disabled repositories providing a specific keyword. + Try '--plus-content debug' to enable repos indic ating to provide debug packages. + --disable-repositories Do not read meta-data from repositories. + --no-refresh Do not refresh the repositories. + --no-cd Ignore CD/DVD repositories. + --no-remote Ignore remote repositories. + --releasever Set the value of $releasever in all .repo files (default: distribution version) + + Target Options: + --root, -R Operate on a different root directory. + --disable-system-resolvables + Do not read installed packages. + + Commands: + help, ? Print help. + shell, sh Accept multiple commands at once. + + Repository Management: + repos, lr List all defined repositories. + addrepo, ar Add a new repository. + removerepo, rr Remove specified repository. + renamerepo, nr Rename specified repository. + modifyrepo, mr Modify specified repository. + refresh, ref Refresh all repositories. + clean Clean local caches. + + Service Management: + services, ls List all defined services. + addservice, as Add a new service. + modifyservice, ms Modify specified service. + removeservice, rs Remove specified service. + refresh-services, refs Refresh all services. + + Software Management: + install, in Install packages. + remove, rm Remove packages. + verify, ve Verify integrity of package dependencies. + source-install, si Install source packages and their build + dependencies. + install-new-recommends, inr + Install newly added packages recommended + by installed packages. + + Update Management: + update, up Update installed packages with newer versions. + list-updates, lu List available updates. + patch Install needed patches. + list-patches, lp List needed patches. + dist-upgrade, dup Perform a distribution upgrade. + patch-check, pchk Check for patches. + + Querying: + search, se Search for packages matching a pattern. + info, if Show full information for specified packages. + patch-info Show full information for specified patches. + pattern-info Show full information for specified patterns. + product-info Show full information for specified products. + patches, pch List all available patches. + packages, pa List all available packages. + patterns, pt List all available patterns. + products, pd List all available products. + what-provides, wp List packages providing specified capability. + + Package Locks: + addlock, al Add a package lock. + removelock, rl Remove a package lock. + locks, ll List current package locks. + cleanlocks, cl Remove unused locks. + + Other Commands: + versioncmp, vcmp Compare two version strings. + targetos, tos Print the target operating system ID string. + licenses Print report about licenses and EULAs of + installed packages. + download Download rpms specified on the commandline to a local directory. + source-download Download source rpms for all installed packages + to a local directory. + + Subcommands: + subcommand Lists available subcommands. + +Type 'zypper help ' to get command-specific help. +``` +##### How to install package using zypper + +`zypper` takes `in` or `install` switch to install package on your system. Its same as [yum package installation][3], supplying package name as argument and package manager (zypper here) will resolve all dependencies and install them along with your required package. + +``` +# zypper install telnet +Refreshing service 'SMT-http_smt-ec2_susecloud_net'. +Refreshing service 'cloud_update'. +Loading repository data... +Reading installed packages... +Resolving package dependencies... + +The following NEW package is going to be installed: + telnet + +1 new package to install. +Overall download size: 51.8 KiB. Already cached: 0 B. After the operation, additional 113.3 KiB will be used. +Continue? [y/n/...? shows all options] (y): y +Retrieving package telnet-1.2-165.63.x86_64 (1/1), 51.8 KiB (113.3 KiB unpacked) +Retrieving: telnet-1.2-165.63.x86_64.rpm .........................................................................................................................[done] +Checking for file conflicts: .....................................................................................................................................[done] +(1/1) Installing: telnet-1.2-165.63.x86_64 .......................................................................................................................[done] +``` + +Above output for your reference in which we installed `telnet` package. + +Suggested read : [Install packages in YUM and APT systems][3] + +##### How to remove package using zypper + +For erasing or removing packages in Suse Linux, use `zypper` with `remove` or `rm` switch. + +``` +root@kerneltalks # zypper rm telnet +Loading repository data... +Reading installed packages... +Resolving package dependencies... + +The following package is going to be REMOVED: + telnet + +1 package to remove. +After the operation, 113.3 KiB will be freed. +Continue? [y/n/...? shows all options] (y): y +(1/1) Removing telnet-1.2-165.63.x86_64 ..........................................................................................................................[done] +``` +We removed previously installed telnet package here. + +##### Check dependencies and verify integrity of installed packages using zypper + +There are times when one can install package by force ignoring dependencies. `zypper` gives you power to scan all installed packages and checks for their dependencies too. If any dependency is missing, it offers you to install/rempve it and hence maintain integrity of your installed packages. + +Use `verify` or `ve` switch with `zypper` to check integrity of installed packages. + +``` +root@kerneltalks # zypper ve +Refreshing service 'SMT-http_smt-ec2_susecloud_net'. +Refreshing service 'cloud_update'. +Loading repository data... +Reading installed packages... + +Dependencies of all installed packages are satisfied. +``` +In above output, you can see last line confirms that all dependencies of installed packages are completed and no action required. + +##### How to download package using zypper in Suse Linux + +`zypper` offers way to download package in local directory without installation. You can use this downloaded package on another system with same configuration. Packages will be downloaded to `/var/cache/zypp/packages///` directory. + +``` +root@kerneltalks # zypper download telnet +Refreshing service 'SMT-http_smt-ec2_susecloud_net'. +Refreshing service 'cloud_update'. +Loading repository data... +Reading installed packages... +Retrieving package telnet-1.2-165.63.x86_64 (1/1), 51.8 KiB (113.3 KiB unpacked) +(1/1) /var/cache/zypp/packages/SMT-http_smt-ec2_susecloud_net:SLES12-SP3-Pool/x86_64/telnet-1.2-165.63.x86_64.rpm ................................................[done] + +download: Done. + +# ls -lrt /var/cache/zypp/packages/SMT-http_smt-ec2_susecloud_net:SLES12-SP3-Pool/x86_64/ +total 52 +-rw-r--r-- 1 root root 53025 Feb 21 03:17 telnet-1.2-165.63.x86_64.rpm + +``` +You can see we have downloaded telnet package locally using `zypper` + +Suggested read : [Download packages in YUM and APT systems without installing][4] + +##### How to list available package update in zypper + +`zypper` allows you to view all available updates for your installed packages so that you can plan update activity in advance. Use `list-updates` or `lu` switch to show you list of all available updates for installed packages. + +``` +root@kerneltalks # zypper lu +Refreshing service 'SMT-http_smt-ec2_susecloud_net'. +Refreshing service 'cloud_update'. +Loading repository data... +Reading installed packages... +S | Repository | Name | Current Version | Available Version | Arch +--|-----------------------------------|----------------------------|-------------------------------|------------------------------------|------- +v | SLES12-SP3-Updates | at-spi2-core | 2.20.2-12.3 | 2.20.2-14.3.1 | x86_64 +v | SLES12-SP3-Updates | bash | 4.3-82.1 | 4.3-83.5.2 | x86_64 +v | SLES12-SP3-Updates | ca-certificates-mozilla | 2.7-11.1 | 2.22-12.3.1 | noarch +v | SLE-Module-Containers12-Updates | containerd | 0.2.5+gitr639_422e31c-20.2 | 0.2.9+gitr706_06b9cb351610-16.8.1 | x86_64 +v | SLES12-SP3-Updates | crash | 7.1.8-4.3.1 | 7.1.8-4.6.2 | x86_64 +v | SLES12-SP3-Updates | rsync | 3.1.0-12.1 | 3.1.0-13.10.1 | x86_64 +``` +Output is properly formatted for easy reading. Column wise it shows name of repo where package belongs, package name, installed version, new updated available version & architecture. + +##### List and install patches in Suse linux + +Use `list-patches` or `lp` switch to display all available patches for your Suse Linux system which needs to be applied. + +``` +root@kerneltalks # zypper lp +Refreshing service 'SMT-http_smt-ec2_susecloud_net'. +Refreshing service 'cloud_update'. +Loading repository data... +Reading installed packages... + +Repository | Name | Category | Severity | Interactive | Status | Summary +----------------------------------|------------------------------------------|-------------|-----------|-------------|--------|------------------------------------------------------------------------------------ +SLE-Module-Containers12-Updates | SUSE-SLE-Module-Containers-12-2018-273 | security | important | --- | needed | Version update for docker, docker-runc, containerd, golang-github-docker-libnetwork +SLE-Module-Containers12-Updates | SUSE-SLE-Module-Containers-12-2018-62 | recommended | low | --- | needed | Recommended update for sle2docker +SLE-Module-Public-Cloud12-Updates | SUSE-SLE-Module-Public-Cloud-12-2018-268 | recommended | low | --- | needed | Recommended update for python-ecdsa +SLES12-SP3-Updates | SUSE-SLE-SERVER-12-SP3-2018-116 | security | moderate | --- | needed | Security update for rsync +---- output clipped ---- +SLES12-SP3-Updates | SUSE-SLE-SERVER-12-SP3-2018-89 | security | moderate | --- | needed | Security update for perl-XML-LibXML +SLES12-SP3-Updates | SUSE-SLE-SERVER-12-SP3-2018-90 | recommended | low | --- | needed | Recommended update for lvm2 + +Found 37 applicable patches: +37 patches needed (18 security patches) +``` + +Output is pretty much nicely organised with respective headers. You can easily figure out and plan your patch update accordingly. We can see out of 37 patches available on our system 18 are security ones and needs to be applied on high priority! + +You can install all needed patches by issuing `zypper patch` command. + +##### How to update package using zypper + +To update package using zypper, use `update` or `up` switch followed by package name. In above list updates command we learned that `rsync` package update is available on our server. Let update it now – + +``` +root@kerneltalks # zypper update rsync +Refreshing service 'SMT-http_smt-ec2_susecloud_net'. +Refreshing service 'cloud_update'. +Loading repository data... +Reading installed packages... +Resolving package dependencies... + +The following package is going to be upgraded: + rsync + +1 package to upgrade. +Overall download size: 325.2 KiB. Already cached: 0 B. After the operation, additional 64.0 B will be used. +Continue? [y/n/...? shows all options] (y): y +Retrieving package rsync-3.1.0-13.10.1.x86_64 (1/1), 325.2 KiB (625.5 KiB unpacked) +Retrieving: rsync-3.1.0-13.10.1.x86_64.rpm .......................................................................................................................[done] +Checking for file conflicts: .....................................................................................................................................[done] +(1/1) Installing: rsync-3.1.0-13.10.1.x86_64 .....................................................................................................................[done] +``` + +##### Search package using zypper in Suse Linux + +If you are not sure about full package name, no worries. You can search packages in zypper by supplying search string with `se` or `search` switch + +``` +root@kerneltalks # zypper se lvm +Refreshing service 'SMT-http_smt-ec2_susecloud_net'. +Refreshing service 'cloud_update'. +Loading repository data... +Reading installed packages... + +S | Name | Summary | Type +---|---------------|------------------------------|----------- + | libLLVM | Libraries for LLVM | package + | libLLVM-32bit | Libraries for LLVM | package + | llvm | Low Level Virtual Machine | package + | llvm-devel | Header Files for LLVM | package + | lvm2 | Logical Volume Manager Tools | srcpackage +i+ | lvm2 | Logical Volume Manager Tools | package + | lvm2-devel | Development files for LVM2 | package + +``` +In above example we searched `lvm` string and came up with the list shown above. You can use `Name` in zypper install/remove/update commands. + +##### Check installed package information using zypper + +You can check installed packages details using zypper. `info` or `if` switch will list out information of installed package. It can also displays package details which is not installed. In that case, `Installed` parameter will reflect `No` value. +``` +root@kerneltalks # zypper info rsync +Refreshing service 'SMT-http_smt-ec2_susecloud_net'. +Refreshing service 'cloud_update'. +Loading repository data... +Reading installed packages... + + +Information for package rsync: +------------------------------ +Repository : SLES12-SP3-Updates +Name : rsync +Version : 3.1.0-13.10.1 +Arch : x86_64 +Vendor : SUSE LLC +Support Level : Level 3 +Installed Size : 625.5 KiB +Installed : Yes +Status : up-to-date +Source package : rsync-3.1.0-13.10.1.src +Summary : Versatile tool for fast incremental file transfer +Description : + Rsync is a fast and extraordinarily versatile file copying tool. It can copy + locally, to/from another host over any remote shell, or to/from a remote rsync + daemon. It offers a large number of options that control every aspect of its + behavior and permit very flexible specification of the set of files to be + copied. It is famous for its delta-transfer algorithm, which reduces the amount + of data sent over the network by sending only the differences between the + source files and the existing files in the destination. Rsync is widely used + for backups and mirroring and as an improved copy command for everyday use. +``` + +##### List repositories using zypper + +To list repo use `lr` or `repos` switch with zypper command. It will list all available repos which includes enabled and not-enabled both repos. + +``` +root@kerneltalks # zypper lr +Refreshing service 'cloud_update'. +Repository priorities are without effect. All enabled repositories share the same priority. + +# | Alias | Name | Enabled | GPG Check | Refresh +---|--------------------------------------------------------------------------------------|-------------------------------------------------------|---------|-----------|-------- + 1 | SMT-http_smt-ec2_susecloud_net:SLE-Module-Adv-Systems-Management12-Debuginfo-Pool | SLE-Module-Adv-Systems-Management12-Debuginfo-Pool | No | ---- | ---- + 2 | SMT-http_smt-ec2_susecloud_net:SLE-Module-Adv-Systems-Management12-Debuginfo-Updates | SLE-Module-Adv-Systems-Management12-Debuginfo-Updates | No | ---- | ---- + 3 | SMT-http_smt-ec2_susecloud_net:SLE-Module-Adv-Systems-Management12-Pool | SLE-Module-Adv-Systems-Management12-Pool | Yes | (r ) Yes | No + 4 | SMT-http_smt-ec2_susecloud_net:SLE-Module-Adv-Systems-Management12-Updates | SLE-Module-Adv-Systems-Management12-Updates | Yes | (r ) Yes | Yes + 5 | SMT-http_smt-ec2_susecloud_net:SLE-Module-Containers12-Debuginfo-Pool | SLE-Module-Containers12-Debuginfo-Pool | No | ---- | ---- + 6 | SMT-http_smt-ec2_susecloud_net:SLE-Module-Containers12-Debuginfo-Updates | SLE-Module-Containers12-Debuginfo-Updates | No | ---- | ---- +``` + +here you need to check enabled column to check which repos are enabled and which are not. + +##### Add and remove repo in Suse Linux using zypper + +To add repo you will need URI of repo/.repo file or else you end up in below error. + +``` +root@kerneltalks # zypper addrepo -c SLES12-SP3-Updates +If only one argument is used, it must be a URI pointing to a .repo file. +``` + + +With URI, you can add repo like below : + +``` +root@kerneltalks # zypper addrepo -c http://smt-ec2.susecloud.net/repo/SUSE/Products/SLE-SDK/12-SP3/x86_64/product?credentials=SMT-http_smt-ec2_susecloud_net SLE-SDK12-SP3-Pool +Adding repository 'SLE-SDK12-SP3-Pool' ...........................................................................................................................[done] +Repository 'SLE-SDK12-SP3-Pool' successfully added + +URI : http://smt-ec2.susecloud.net/repo/SUSE/Products/SLE-SDK/12-SP3/x86_64/product?credentials=SMT-http_smt-ec2_susecloud_net +Enabled : Yes +GPG Check : Yes +Autorefresh : No +Priority : 99 (default priority) + +Repository priorities are without effect. All enabled repositories share the same priority. +``` + +Use `addrepo` or `ar` switch with `zypper` to add repo in Suse. Followed by URI and lastly you need to provide alias as well. + +To remove repo in Suse, use `removerepo` or `rr` switch with `zypper`. +``` +root@kerneltalks # zypper removerepo nVidia-Driver-SLE12-SP3 +Removing repository 'nVidia-Driver-SLE12-SP3' ....................................................................................................................[done] +Repository 'nVidia-Driver-SLE12-SP3' has been removed. +``` + +##### Clean local zypper cache + +Cleaning up local zypper caches with `zypper clean` command – + +``` +root@kerneltalks # zypper clean +All repositories have been cleaned up. +``` + +-------------------------------------------------------------------------------- + +via: https://kerneltalks.com/commands/12-useful-zypper-command-examples/ + +作者:[KernelTalks][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://kerneltalks.com +[1]:https://a2.kerneltalks.com/wp-content/uploads/2018/02/zypper-command-examples.png +[2]:https://en.wikipedia.org/wiki/ZYpp +[3]:https://kerneltalks.com/tools/package-installation-linux-yum-apt/ +[4]:https://kerneltalks.com/howto/download-package-using-yum-apt/ From a9ce7b8fda977ce98403fc2592103735568d8ac6 Mon Sep 17 00:00:00 2001 From: darksun Date: Sat, 24 Feb 2018 10:48:29 +0800 Subject: [PATCH 005/296] =?UTF-8?q?=E9=80=89=E9=A2=98:=20cTop=20-=20A=20CL?= =?UTF-8?q?I=20Tool=20For=20Container=20Monitoring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...p - A CLI Tool For Container Monitoring.md | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 sources/tech/20180221 cTop - A CLI Tool For Container Monitoring.md diff --git a/sources/tech/20180221 cTop - A CLI Tool For Container Monitoring.md b/sources/tech/20180221 cTop - A CLI Tool For Container Monitoring.md new file mode 100644 index 0000000000..9a25f29436 --- /dev/null +++ b/sources/tech/20180221 cTop - A CLI Tool For Container Monitoring.md @@ -0,0 +1,120 @@ +cTop - A CLI Tool For Container Monitoring +====== +Recent days Linux containers are famous, even most of us already working on it and few of us start learning about it. + +We have already covered article about the famous GUI (Graphical User Interface) tools such as Portainer & Rancher. This will help us to manage containers through GUI. + +This tutorial will help us to understand and monitor Linux containers through cTop command. It’s a command-line tool like top command. + +### What’s cTop + +[ctop][1] provides a concise and condensed overview of real-time metrics for multiple containers. It’s Top-like interface for container metrics. + +It displays containers metrics such as CPU utilization, Memory utilization, Disk I/O Read & Write, Process ID (PID), and Network Transmit(TX – Transmit FROM this server) and receive(RX – Receive TO this server). + +ctop comes with built-in support for Docker and runC; connectors for other container and cluster systems are planned for future releases. +It doesn’t requires any arguments and uses Docker host variables by default. + +**Suggested Read :** +**(#)** [Portainer – A Simple Docker Management GUI][2] +**(#)** [Rancher – A Complete Container Management Platform For Production Environment][3] + +### How To Install cTop + +Developer offers a simple shell script, which help us to use ctop instantly. What we have to do, just download the ctop shell file at `/bin` directory for global access. Finally assign the execute permission to ctop shell file. + +Download the ctop shell file @ `/usr/local/bin` directory. +``` +$ sudo wget https://github.com/bcicen/ctop/releases/download/v0.7/ctop-0.7-linux-amd64 -O /usr/local/bin/ctop + +``` + +Set execute permission to ctop shell file. +``` +$ sudo chmod +x /usr/local/bin/ctop + +``` + +Alternatively you can install and run ctop through docker. Make sure you should have installed docker as a pre-prerequisites for this. To install docker, refer the following link. + +**Suggested Read :** +**(#)** [How to install Docker in Linux][4] +**(#)** [How to play with Docker images on Linux][5] +**(#)** [How to play with Docker containers on Linux][6] +**(#)** [How to Install, Run Applications inside Docker Containers][7] +``` +$ docker run --rm -ti \ + --name=ctop \ + -v /var/run/docker.sock:/var/run/docker.sock \ + quay.io/vektorlab/ctop:latest + +``` + +### How To Use cTop + +Just launch the ctop utility without any arguments. By default it’s bind with `a` key which display of all containers (running and non-running). +ctop header shows your system time and total number of containers. +``` +$ ctop + +``` + +You might get the output similar to below. +![][9] + +### How To Manage Containers + +You can able to administrate the containers using ctop. Select a container that you want to manage then hit `Enter` button and choose required options like start, stop, remove, etc,. +![][10] + +### How To Sort Containers + +By default ctop sort the containers using state field. Hit `s` key to sort the containers in the different aspect. +![][11] + +### How To View the Containers Metrics + +If you want to view more details & metrics about the container, just select the corresponding which you want to view then hit `o` key. +![][12] + +### How To View Container Logs + +Select the corresponding container which you want to view the logs then hit `l` key. +![][13] + +### Display Only Active Containers + +Run ctop command with `-a` option to show active containers only. +![][14] + +### Open Help Dialog Box + +Run ctop, just hit `h`key to open help section. +![][15] + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/ctop-a-command-line-tool-for-container-monitoring-and-management-in-linux/ + +作者:[2DAYGEEK][a] +译者:[译者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/2daygeek/ +[1]:https://github.com/bcicen/ctop +[2]:https://www.2daygeek.com/portainer-a-simple-docker-management-gui/ +[3]:https://www.2daygeek.com/rancher-a-complete-container-management-platform-for-production-environment/ +[4]:https://www.2daygeek.com/install-docker-on-centos-rhel-fedora-ubuntu-debian-oracle-archi-scentific-linux-mint-opensuse/ +[5]:https://www.2daygeek.com/list-search-pull-download-remove-docker-images-on-linux/ +[6]:https://www.2daygeek.com/create-run-list-start-stop-attach-delete-interactive-daemonized-docker-containers-on-linux/ +[7]:https://www.2daygeek.com/install-run-applications-inside-docker-containers/ +[8]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[9]:https://www.2daygeek.com/wp-content/uploads/2018/02/ctop-a-command-line-tool-for-container-monitoring-and-management-in-linux-1.png +[10]:https://www.2daygeek.com/wp-content/uploads/2018/02/ctop-a-command-line-tool-for-container-monitoring-and-management-in-linux-2.png +[11]:https://www.2daygeek.com/wp-content/uploads/2018/02/ctop-a-command-line-tool-for-container-monitoring-and-management-in-linux-3.png +[12]:https://www.2daygeek.com/wp-content/uploads/2018/02/ctop-a-command-line-tool-for-container-monitoring-and-management-in-linux-4a.png +[13]:https://www.2daygeek.com/wp-content/uploads/2018/02/ctop-a-command-line-tool-for-container-monitoring-and-management-in-linux-7.png +[14]:https://www.2daygeek.com/wp-content/uploads/2018/02/ctop-a-command-line-tool-for-container-monitoring-and-management-in-linux-5.png +[15]:https://www.2daygeek.com/wp-content/uploads/2018/02/ctop-a-command-line-tool-for-container-monitoring-and-management-in-linux-6.png From e6bff4dcd73b0c58606d20acdc497e21559b9043 Mon Sep 17 00:00:00 2001 From: wxy Date: Sat, 24 Feb 2018 11:09:33 +0800 Subject: [PATCH 006/296] PRF:20171214 How to install and use encryptpad on ubuntu 16.04.md @singledo --- ...tall and Use Encryptpad on Ubuntu 16.04.md | 0 ...tall and use encryptpad on ubuntu 16.04.md | 151 ++++++++++-------- 2 files changed, 84 insertions(+), 67 deletions(-) delete mode 100644 sources/tech/20171214 How to Install and Use Encryptpad on Ubuntu 16.04.md diff --git a/sources/tech/20171214 How to Install and Use Encryptpad on Ubuntu 16.04.md b/sources/tech/20171214 How to Install and Use Encryptpad on Ubuntu 16.04.md deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/translated/tech/20171214 How to install and use encryptpad on ubuntu 16.04.md b/translated/tech/20171214 How to install and use encryptpad on ubuntu 16.04.md index 83e8f78645..baf29e563b 100644 --- a/translated/tech/20171214 How to install and use encryptpad on ubuntu 16.04.md +++ b/translated/tech/20171214 How to install and use encryptpad on ubuntu 16.04.md @@ -1,89 +1,106 @@ -# How To Install and Use Encryptpad on Ubuntu 16.04 -``` -EncryptPad 是一个免费的开源软件 ,它通过简单的图片转换和命令行接口来查看和修改加密的文件文件 ,它使用 OpenPGP RFC 4880 文件格式 。通过 EncryptPad ,你可以很容易的加密或者解密文件 。你能够像保存密码 ,信用卡信息 ,密码或者密钥文件这类的私人信息 。 -``` -## 特性 -- 支持 windows ,Linux ,和 Max OS 。 -- 可定制的密码生成器 ,足够健壮的密码 。 -- 随机密钥文件和密码生成器 。 -- 至此 GPG 和 EPD 文件格式 。 -- 通过 CURL 自动从远程远程仓库下载密钥 。 -- 密钥文件能够存储在加密文件中 。如果生效 ,你不需要每次打开文件都指定密钥文件 。 -- 提供只读模式来保护文件不被修改 。 -- 可加密二进制文件 。例如 图片 ,视屏 ,档案 。 +如何在 Ubuntu 16.04 上安装和使用 Encryptpad +============== + +EncryptPad 是一个自由开源软件,它通过简单方便的图形界面和命令行接口来查看和修改加密的文本,它使用 OpenPGP RFC 4880 文件格式。通过 EncryptPad,你可以很容易的加密或者解密文件。你能够像保存密码、信用卡信息等私人信息,并使用密码或者密钥文件来访问。 + +### 特性 + +- 支持 windows、Linux 和 Max OS。 +- 可定制的密码生成器,可生成健壮的密码。 +- 随机的密钥文件和密码生成器。 +- 支持 GPG 和 EPD 文件格式。 +- 能够通过 CURL 自动从远程远程仓库下载密钥。 +- 密钥文件的路径能够存储在加密的文件中。如果这样做的话,你不需要每次打开文件都指定密钥文件。 +- 提供只读模式来防止文件被修改。 +- 可加密二进制文件,例如图片、视频、归档等。 + + +在这份教程中,我们将学习如何在 Ubuntu 16.04 中安装和使用 EncryptPad。 + +### 环境要求 + +- 在系统上安装了 Ubuntu 16.04 桌面版本。 +- 在系统上有 `sudo` 的权限的普通用户。 + +### 安装 EncryptPad + +在默认情况下,EncryPad 在 Ubuntu 16.04 的默认仓库是不存在的。你需要安装一个额外的仓库。你能够通过下面的命令来添加它 : ``` -在这份引导说明中 ,我们将学习如何在 Ubuntu 16.04 中安装和使用 EncryptPad 。 +sudo apt-add-repository ppa:nilaimogard/webupd8 ``` -## 环境要求 -- 在系统上安装了 Ubuntu 16.04 桌面版本 。 -- 用户在系统上有 sudo 的权限 。 -## 安装 EncryptPad -在默认情况下 ,EncryPad 在 Ubuntu 16.04 的默认仓库是不存在的 。你需要安装一个额外的仓库 。你能够通过下面的命令来添加它 : -- **sudo apt-add-repository ppa:nilaimogard/webupd8** +下一步,用下面的命令来更新仓库: - 下一步 ,用下面的命令来更新仓库 : -- **sudo apt-get update -y** - - 最后一步 ,通过下面命令安装 EncryptPAd : -- **sudo apt-get install encryptpad encryptcli -y** - -当 EncryptPad 安装完成 ,你需要将它固定到 Ubuntu 的仪表板上 。 - -## 使用 EncryptPad 生成密钥和密码 ``` -现在 ,去 Ubunntu Dash 上输入 encryptpad ,你能够在你的屏幕上看到下面的图片 : +sudo apt-get update -y ``` + +最后一步,通过下面命令安装 EncryptPad: + +``` +sudo apt-get install encryptpad encryptcli -y +``` + +当 EncryptPad 安装完成后,你可以在 Ubuntu 的 Dash 上找到它。 + +### 使用 EncryptPad 生成密钥和密码 + +现在,在 Ubunntu Dash 上输入 `encryptpad`,你能够在你的屏幕上看到下面的图片 : + [![Ubuntu DeskTop][1]][2] -``` -下一步 ,点击 EncryptPad 的图标 。你能够看到 EncryptPad 的界面 ,有一个简单的文本编辑器以及顶部菜单栏 。 -``` +下一步,点击 EncryptPad 的图标。你能够看到 EncryptPad 的界面,它是一个简单的文本编辑器,带有顶部菜单栏。 + [![EncryptPad screen][3]][4] -``` -首先 ,你需要产生一个密钥和密码来给将来加密/解密任务使用 。点击顶部菜单栏中的 Encryption->Generate Key ,你会看见下面的界面 : -``` -[![Generate key][5]][6] -``` -选择文件保存的路径 ,点击 OK 按钮 ,你将看到下面的界面 。 -``` -[![select path][7]][8] -``` -输入密钥文件的密码 ,点击 OK 按钮 ,你将看到下面的界面 : -``` -[![last step][9]][10] -``` -点击 yes 按钮来完成进程 。 -``` -## 加密和解密文件 -``` -现在 ,密钥文件和密码都已经生成了 。现在可以执行加密和解密操作了 。在这个文件编辑器中打开一个文件文件 ,点击加密图标 ,你会看见下面的界面 : -``` -[![Encry operation][11]][12] -``` -提供需要加密的文件和指定输出的文件 ,提供密码和前面产生的密钥文件 。点击 Start 按钮来开始加密的进程 。当文件被成功的加密 ,会出现下面的界面 : -```` -[![Success Encrypt][13]][14] -``` -文件已经被密码和密钥加密了 。 -``` +首先,你需要生成一个密钥文件和密码用于加密/解密任务。点击顶部菜单栏中的 “Encryption->Generate Key”,你会看见下面的界面: + +[![Generate key][5]][6] + +选择文件保存的路径,点击 “OK” 按钮,你将看到下面的界面: + +[![select path][7]][8] + +输入密钥文件的密码,点击 “OK” 按钮 ,你将看到下面的界面: + +[![last step][9]][10] + +点击 “yes” 按钮来完成该过程。 + +### 加密和解密文件 + +现在,密钥文件和密码都已经生成了。可以执行加密和解密操作了。在这个文件编辑器中打开一个文件文件,点击 “encryption” 图标 ,你会看见下面的界面: + +[![Encry operation][11]][12] + +提供需要加密的文件和指定输出的文件,提供密码和前面产生的密钥文件。点击 “Start” 按钮来开始加密的进程。当文件被成功的加密,会出现下面的界面: + +[![Success Encrypt][13]][14] + +文件已经被该密码和密钥文件加密了。 + +如果你想解密被加密后的文件,打开 EncryptPad ,点击 “File Encryption” ,选择 “Decryption” 操作,提供加密文件的位置和你要保存输出的解密文件的位置,然后提供密钥文件地址,点击 “Start” 按钮,它将要求你输入密码,输入你先前加密使用的密码,点击 “OK” 按钮开始解密过程。当该过程成功完成,你会看到 “File has been decrypted successfully” 的消息 。 + -``` -如果你想解密被加密后的文件 ,打开 EncryptPad ,点击 File Encryption ,选择 Decryptio 操作 ,提供加密文件的地址和输出解密文件的地址 ,提供密钥文件地址 ,点击 Start 按钮 ,如果请求输入密码 ,输入你先前加密使用的密码 ,点击 OK 按钮开始解密过程 。当过程成功完成 ,你会看到 “ File has been decrypted successfully message ” 。 -``` [![decrypt ][16]][17] [![][18]][18] [![][13]] -**注意** -``` -如果你遗忘了你的密码或者丢失了密钥文件 ,没有其他的方法打开你的加密信息 。对于 EncrypePad 支持的格式是没有后门的 。 -``` +**注意:** + +如果你遗忘了你的密码或者丢失了密钥文件,就没有其他的方法可以打开你的加密信息了。对于 EncrypePad 所支持的格式是没有后门的。 -------------------------------------------------------------------------------- +via: https://www.howtoforge.com/tutorial/how-to-install-and-use-encryptpad-on-ubuntu-1604/ + +作者:[Hitesh Jethva][a] +译者:[singledo](https://github.com/singledo) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + [a]:https://www.howtoforge.com [1]:https://www.howtoforge.com/images/how_to_install_and_use_encryptpad_on_ubuntu_1604/Screenshot-of-encryptpad-dash.png From df2d97318394687aff101f9ec6bff0142a220962 Mon Sep 17 00:00:00 2001 From: wxy Date: Sat, 24 Feb 2018 11:16:27 +0800 Subject: [PATCH 007/296] PUB:20171214 How to install and use encryptpad on ubuntu 16.04.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @singledo https://linux.cn/article-9377-1.html 这篇翻译不够认真,望继续努力。 --- .../20171214 How to install and use encryptpad on ubuntu 16.04.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {translated/tech => published}/20171214 How to install and use encryptpad on ubuntu 16.04.md (100%) diff --git a/translated/tech/20171214 How to install and use encryptpad on ubuntu 16.04.md b/published/20171214 How to install and use encryptpad on ubuntu 16.04.md similarity index 100% rename from translated/tech/20171214 How to install and use encryptpad on ubuntu 16.04.md rename to published/20171214 How to install and use encryptpad on ubuntu 16.04.md From 8b4b118966820ebe73a802372af0c3cd2dcbcec9 Mon Sep 17 00:00:00 2001 From: wxy Date: Sat, 24 Feb 2018 11:36:40 +0800 Subject: [PATCH 008/296] PRF&PUB:20171203 Increase Torrent Speed - Here Is Why It Will Never Work.md @lujun9972 --- ... Speed - Here Is Why It Will Never Work.md | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) rename {translated/tech => published}/20171203 Increase Torrent Speed - Here Is Why It Will Never Work.md (80%) diff --git a/translated/tech/20171203 Increase Torrent Speed - Here Is Why It Will Never Work.md b/published/20171203 Increase Torrent Speed - Here Is Why It Will Never Work.md similarity index 80% rename from translated/tech/20171203 Increase Torrent Speed - Here Is Why It Will Never Work.md rename to published/20171203 Increase Torrent Speed - Here Is Why It Will Never Work.md index 127bb21066..cbb2dda3e1 100644 --- a/translated/tech/20171203 Increase Torrent Speed - Here Is Why It Will Never Work.md +++ b/published/20171203 Increase Torrent Speed - Here Is Why It Will Never Work.md @@ -1,23 +1,22 @@ -Torrent 提速 - 为什么总是无济于事 +Torrent 提速为什么总是无济于事 ====== -![](http://www.theitstuff.com/wp-content/uploads/2017/11/increase-torrent-speed.jpg) +![](http://www.theitstuff.com/wp-content/uploads/2017/11/increase-torrent-speed.jpg) + 是不是总是想要 **更快的 torrent 速度**?不管现在的速度有多块,但总是无法对此满足。我们对 torrent 速度的痴迷使我们经常从包括 YouTube 视频在内的许多网站上寻找并应用各种所谓的技巧。但是相信我,从小到大我就没发现哪个技巧有用过。因此本文我们就就来看看,为什么尝试提高 torrent 速度是行不通的。 -## 影响速度的因素 +### 影响速度的因素 -### 本地因素 +#### 本地因素 -从下图中可以看到 3 台电脑分别对应的 A,B,C 三个用户。A 和 B 本地相连,而 C 的位置则比较远,它与本地之间有 1,2,3 三个连接点。 +从下图中可以看到 3 台电脑分别对应的 A、B、C 三个用户。A 和 B 本地相连,而 C 的位置则比较远,它与本地之间有 1、2、3 三个连接点。 [![][1]][2] 若用户 A 和用户 B 之间要分享文件,他们之间直接分享就能达到最大速度了而无需使用 torrent。这个速度跟互联网什么的都没有关系。 + 网线的性能 - + 网卡的性能 - + 路由器的性能 当谈到 torrent 的时候,人们都是在说一些很复杂的东西,但是却总是不得要点。 @@ -30,7 +29,7 @@ Torrent 提速 - 为什么总是无济于事 即使你把目标降到 30 Megabytes,然而你连接到路由器的电缆/网线的性能最多只有 100 megabits 也就是 10 MegaBytes。这是一个纯粹的瓶颈问题,由一个薄弱的环节影响到了其他强健部分,也就是说这个传输速率只能达到 10 Megabytes,即电缆的极限速度。现在想象有一个 torrent 即使能够用最大速度进行下载,那也会由于你的硬件不够强大而导致瓶颈。 -### 外部因素 +#### 外部因素 现在再来看一下这幅图。用户 C 在很遥远的某个地方。甚至可能在另一个国家。 @@ -40,24 +39,23 @@ Torrent 提速 - 为什么总是无济于事 第二,由于 C 与本地之间多个有连接点,其中一个点就有可能成为瓶颈所在,可能由于繁重的流量和相对薄弱的硬件导致了缓慢的速度。 -### Seeders( 译者注:做种者) 与 Leechers( 译者注:只下载不做种的人) +#### 做种者与吸血者 -关于此已经有了太多的讨论,总的想法就是搜索更多的种子,但要注意上面的那些因素,一个很好的种子提供者但是跟我之间的连接不好的话那也是无济于事的。通常,这不可能发生,因为我们也不是唯一下载这个资源的人,一般都会有一些在本地的人已经下载好了这个文件并已经在做种了。 +关于此已经有了太多的讨论,总的想法就是搜索更多的种子,但要注意上面的那些因素,有一个很好的种子提供者,但是跟我之间的连接不好的话那也是无济于事的。通常,这不可能发生,因为我们也不是唯一下载这个资源的人,一般都会有一些在本地的人已经下载好了这个文件并已经在做种了。 -## 结论 +### 结论 我们尝试搞清楚哪些因素影响了 torrent 速度的好坏。不管我们如何用软件进行优化,大多数时候是这是由于物理瓶颈导致的。我从来不关心那些软件,使用默认配置对我来说就够了。 希望你会喜欢这篇文章,有什么想法敬请留言。 - -------------------------------------------------------------------------------- via: http://www.theitstuff.com/increase-torrent-speed-will-never-work 作者:[Rishabh Kandari][a] 译者:[lujun9972](https://github.com/lujun9972) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 From 47f9a5d9d1f79dbd9198ecbbc6b4d2be7e7b257d Mon Sep 17 00:00:00 2001 From: ChenYi <31087327+cyleft@users.noreply.github.com> Date: Sat, 24 Feb 2018 12:03:48 +0800 Subject: [PATCH 009/296] translated by cyleft --- ...nstall Gogs Go Git Service on Ubuntu 16.04 | 405 ++++++++++++++++++ 1 file changed, 405 insertions(+) create mode 100644 translated/tech/20180209 How to Install Gogs Go Git Service on Ubuntu 16.04 diff --git a/translated/tech/20180209 How to Install Gogs Go Git Service on Ubuntu 16.04 b/translated/tech/20180209 How to Install Gogs Go Git Service on Ubuntu 16.04 new file mode 100644 index 0000000000..6923c0e332 --- /dev/null +++ b/translated/tech/20180209 How to Install Gogs Go Git Service on Ubuntu 16.04 @@ -0,0 +1,405 @@ +如何在 Ubuntu 16.04 上使用 Gogs 安装 Go 语言编写的 Git 服务器 +====== + +Gogs 是由 Go 语言编写,提供开源且免费的 Git 服务。Gogs 是一款无痛式自托管的 Git 服务器,能在尽可能小的硬件资源开销上搭建并运行您的私有 Git 服务器。Gogs 的网页界面和 GitHub 十分相近,且提供 MySQL、PostgreSQL 和 SQLite 数据库支持。 + +在本教程中,我们将使用 Gogs 在 Ununtu 16.04 上按步骤,指导您安装和配置您的私有 Git 服务器。这篇教程中涵盖了如何在 Ubuntu 上安装 Go 语言、PostgreSQL 和安装并且配置 Nginx 网页服务器作为 Go 应用的反向代理的细节内容。 + +### 搭建环境 + + * Ubuntu 16.04 + * Root 权限 + +### 我们将会接触到的事物 + + 1. 更新和升级系统 + 2. 安装和配置 PostgreSQL + 3. 安装 Go 和 Git + 4. 安装 Gogs + 5. 配置 Gogs + 6. 运行 Gogs 服务器 + 7. 安装和配置 Nginx 反向代理 + 8. 测试 + +### 步骤 1 - 更新和升级系统 +继续之前,更新 Ubuntu 所有的库,升级所有包。 + +运行下面的 apt 命令 +``` +sudo apt update +sudo apt upgrade +``` + +### 步骤 2 - 安装和配置 PostgreSQL + +Gogs 提供 MySQL、PostgreSQL、SQLite 和 TiDB 数据库系统支持。 + +此步骤中,我们将使用 PostgreSQL 作为 Gogs 程序的数据库。 + +使用下面的 apt 命令安装 PostgreSQL。 +``` +sudo apt install -y postgresql postgresql-client libpq-dev +``` + +安装完成之后,启动 PostgreSQL 服务并设置为开机启动。 +``` +systemctl start postgresql +systemctl enable postgresql +``` + +此时 PostgreSQL 数据库在 Ubuntu 系统上完成安装了。 + +之后,我们需要为 Gogs 创建数据库和用户。 + +使用 'postgres' 用户登陆并运行 ‘psql’ 命令获取 PostgreSQL 操作界面. +``` +su - postgres +psql +``` + +创建一个名为 ‘git’ 的新用户,给予此用户 ‘CREATEDB’ 权限。 +``` +CREATE USER git CREATEDB; +\password git +``` + +创建名为 ‘gogs_production’ 的数据库,设置 ‘git’ 用户作为其所有者。 +``` +CREATE DATABASE gogs_production OWNER git; +``` + +[![创建 Gogs 数据库][1]][2] + +作为 Gogs 安装时的 ‘gogs_production’ PostgreSQL 数据库和 ‘git’ 用户已经创建完毕。 + +### 步骤 3 - 安装 Go 和 Git + +使用下面的 apt 命令从库中安装 Git。 +``` +sudo apt install git +``` + +此时,为系统创建名为 ‘git’ 的新用户。 +``` +sudo adduser --disabled-login --gecos 'Gogs' git +``` + +登陆 ‘git’ 账户并且创建名为 ‘local’ 的目录。 +``` +su - git +mkdir -p /home/git/local +``` + +切换到 ‘local’ 目录,依照下方所展示的内容,使用 wget 命令下载 ‘Go’(最新版)。 +``` +cd ~/local +wget +``` + +[![安装 Go 和 Git][3]][4] + +解压并且删除 go 的压缩文件。 +``` +tar -xf go1.9.2.linux-amd64.tar.gz +rm -f go1.9.2.linux-amd64.tar.gz +``` + +‘Go’ 二进制文件已经被下载到 ‘~/local/go’ 目录。此时我们需要设置环境变量 - 设置 ‘GOROOT’ 和 ‘GOPATH’ 目录到系统环境,这样,我们就可以在 ‘git’ 用户下执行 ‘go’ 命令。 + +执行下方的命令。 +``` +cd ~/ +echo 'export GOROOT=$HOME/local/go' >> $HOME/.bashrc +echo 'export GOPATH=$HOME/go' >> $HOME/.bashrc +echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> $HOME/.bashrc +``` + +之后通过运行 'source ~/.bashrc' 重载 Bash,如下: +``` +source ~/.bashrc +``` + +确定您使用的 Bash 是默认的 shell。 + +[![安装 Go 编程语言][5]][6] + +现在运行 'go' 的版本查看命令。 +``` +go version +``` + +之后确保您得到下图所示的结果。 + +[![检查 go 版本][7]][8] + +现在,Go 已经安装在系统的 ‘git’ 用户下了。 + +### 步骤 4 - 使用 Gogs 安装 Git 服务 + +使用 ‘git’ 用户登陆并且使用 ‘go’ 命令从 GitHub 下载 ‘Gogs’。 +``` +su - git +go get -u github.com/gogits/gogs +``` + +此命令将在 ‘GOPATH/src’ 目录下载 Gogs 的所有源代码。 + +切换至 '$GOPATH/src/github.com/gogits/gogs' 目录,并且使用下列命令搭建 gogs。 +``` +cd $GOPATH/src/github.com/gogits/gogs +go build +``` + +确保您没有捕获到错误。 + +现在使用下面的命令运行 Gogs Go Git 服务器。 +``` +./gogs web +``` + +此命令将会默认运行 Gogs 在 3000 端口上。 + +[![安装 Gogs Go Git 服务][9]][10] + +打开网页浏览器,键入您的 IP 地址和端口号,我的是 + +您应该会得到于下方一致的反馈。 + +[![Gogs 网页服务器][11]][12] + +Gogs 已经在您的 Ubuntu 系统上安装完毕。现在返回到您的终端,并且键入 'Ctrl + c' 中止服务。 + +### 步骤 5 - 配置 Gogs Go Git 服务器 + +本步骤中,我们将为 Gogs 创建惯例配置。 + +进入 Gogs 安装目录并新建 ‘custom/conf’ 目录。 +``` +cd $GOPATH/src/github.com/gogits/gogs +mkdir -p custom/conf/ +``` + +复制默认的配置文件到 custom 目录,并使用 [vim][13] 修改。 +``` +cp conf/app.ini custom/conf/app.ini +vim custom/conf/app.ini +``` + +在 ‘ **[server]** ’ 选项中,修改 ‘HOST_ADDR’ 为 ‘127.0.0.1’. +``` +[server] + PROTOCOL = http + DOMAIN = localhost + ROOT_URL = %(PROTOCOL)s://%(DOMAIN)s:%(HTTP_PORT)s/ + HTTP_ADDR = 127.0.0.1 + HTTP_PORT = 3000 + +``` + +在 ‘ **[database]** ’ 选项中,按照您的数据库信息修改。 +``` +[database] + DB_TYPE = postgres + HOST = 127.0.0.1:5432 + NAME = gogs_production + USER = git + PASSWD = [email protected]# + +``` + +保存并退出。 + +运行下面的命令验证配置项。 +``` +./gogs web +``` + +并且确保您得到如下的结果。 + +[![配置服务器][14]][15] + +Gogs 现在已经按照自定义配置下运行在 ‘localhost’ 的 3000 端口上了。 + +### 步骤 6 - 运行 Gogs 服务器 + +这一步,我们将在 Ubuntu 系统上配置 Gogs 服务器。我们会在 ‘/etc/systemd/system’ 目录下创建一个新的服务器配置文件 ‘gogs.service’。 + +切换到 ‘/etc/systemd/system’ 目录,使用 [vim][13] 创建服务器配置文件 ‘gogs.service’。 +``` +cd /etc/systemd/system +vim gogs.service +``` + +粘贴下面的代码到 gogs 服务器配置文件中。 +``` +[Unit] + Description=Gogs + After=syslog.target + After=network.target + After=mariadb.service mysqld.service postgresql.service memcached.service redis.service + + [Service] + # Modify these two values and uncomment them if you have + # repos with lots of files and get an HTTP error 500 because + # of that + ### + #LimitMEMLOCK=infinity + #LimitNOFILE=65535 + Type=simple + User=git + Group=git + WorkingDirectory=/home/git/go/src/github.com/gogits/gogs + ExecStart=/home/git/go/src/github.com/gogits/gogs/gogs web + Restart=always + Environment=USER=git HOME=/home/git + + [Install] + WantedBy=multi-user.target + +``` + +之后保存并且退出。 + +现在可以重载系统服务器。 +``` +systemctl daemon-reload +``` + +使用下面的命令开启 gogs 服务器并设置为开机启动。 +``` +systemctl start gogs +systemctl enable gogs +``` + +[![运行 Gogs 服务器][16]][17] + +Gogs 服务器现在已经运行在 Ubuntu 系统上了。 + +使用下面的命令检测: +``` +netstat -plntu +systemctl status gogs +``` + +您应该会得到下图所示的结果。 + +[![Gogs is listening on the network interface][18]][19] + +### 步骤 7 - 为 Gogs 安装和配置 Nginx 反向代理 + +在本步中,我们将为 Gogs 安装和配置 Nginx 反向代理。我们会在自己的库中调用 Nginx 包。 + +使用下面的命令添加 Nginx 库。 +``` +sudo add-apt-repository -y ppa:nginx/stable +``` + +此时更新所有的库并且使用下面的命令安装 Nginx。 +``` +sudo apt update +sudo apt install nginx -y +``` + +之后,进入 ‘/etc/nginx/sites-available’ 目录并且创建虚拟主机文件 ‘gogs’。 +``` +cd /etc/nginx/sites-available +vim gogs +``` + +粘贴下面的代码到配置项。 +``` +server { +     listen 80; +     server_name git.hakase-labs.co; + +     location / { +         proxy_pass http://localhost:3000; +     } + } + +``` + +保存退出。 + +**注意:** +使用您的域名修改 ‘server_name’ 项。 + +现在激活虚拟主机并且测试 nginx 配置。 +``` +ln -s /etc/nginx/sites-available/gogs /etc/nginx/sites-enabled/ +nginx -t +``` + +确保没有抛错,重启 Nginx 服务器。 +``` +systemctl restart nginx +``` + +[![安装和配置 Nginx 反向代理][20]][21] + +### 步骤 8 - 测试 + +打开您的网页浏览器并且输入您的 gogs URL,我的是 + +现在您将进入安装界面。在页面的顶部,输入您所有的 PostgreSQL 数据库信息。 + +[![Gogs 安装][22]][23] + +之后,滚动到底部,点击 ‘Admin account settings’ 下拉选项。 + +输入您的管理者用户名和邮箱。 + +[![键入 gogs 安装设置][24]][25] + +之后点击 ‘Install Gogs’ 按钮。 + +然后您将会被重定向到下图显示的 Gogs 用户面板。 + +[![Gogs 面板][26]][27] + +下面是 Gogs ‘Admin Dashboard(管理员面板)’。 + +[![浏览 Gogs 面板][28]][29] + +现在,Gogs 已经通过 PostgreSQL 数据库和 Nginx 网页服务器在您的 Ubuntu 16.04 上完成安装。 + +-------------------------------------------------------------------------------- + +via: https://www.howtoforge.com/tutorial/how-to-install-gogs-go-git-service-on-ubuntu-1604/ + +作者:[Muhammad Arul][a] +译者:[CYLeft](https://github.com/CYLeft) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.howtoforge.com/tutorial/server-monitoring-with-shinken-on-ubuntu-16-04/ +[1]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/1.png +[2]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/big/1.png +[3]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/2.png +[4]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/big/2.png +[5]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/3.png +[6]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/big/3.png +[7]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/4.png +[8]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/big/4.png +[9]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/5.png +[10]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/big/5.png +[11]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/6.png +[12]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/big/6.png +[13]:https://www.howtoforge.com/vim-basics +[14]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/7.png +[15]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/big/7.png +[16]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/8.png +[17]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/big/8.png +[18]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/9.png +[19]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/big/9.png +[20]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/10.png +[21]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/big/10.png +[22]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/11.png +[23]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/big/11.png +[24]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/12.png +[25]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/big/12.png +[26]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/13.png +[27]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/big/13.png +[28]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/14.png +[29]:https://www.howtoforge.com/images/how_to_install_gogs_go_git_service_on_ubuntu_1604/big/14.png From c307cba06bbf39c47aba668239df8e25ae3e29df Mon Sep 17 00:00:00 2001 From: wxy Date: Sat, 24 Feb 2018 12:52:42 +0800 Subject: [PATCH 010/296] PRF:20180126 Creating an Adventure Game in the Terminal with ncurses.md @leemeans --- ...nture Game in the Terminal with ncurses.md | 324 ------------------ ...nture Game in the Terminal with ncurses.md | 310 +++++++++++++++++ 2 files changed, 310 insertions(+), 324 deletions(-) delete mode 100644 translated/20180126 Creating an Adventure Game in the Terminal with ncurses.md create mode 100644 translated/tech/20180126 Creating an Adventure Game in the Terminal with ncurses.md diff --git a/translated/20180126 Creating an Adventure Game in the Terminal with ncurses.md b/translated/20180126 Creating an Adventure Game in the Terminal with ncurses.md deleted file mode 100644 index ed8f875074..0000000000 --- a/translated/20180126 Creating an Adventure Game in the Terminal with ncurses.md +++ /dev/null @@ -1,324 +0,0 @@ -通过ncurses在终端创建一个冒险游戏 -====== -怎样使用curses函数读取键盘并操作屏幕。 - -我[之前的文章][1]介绍了ncurses库并提供了一个简单的程序展示一些将文本放到屏幕上的一些curses函数。 - -### 探险 - -当我逐渐长大,家里有了一台苹果2电脑。我和我兄弟正是在这台电脑上自学了如何用AppleSoft BASIC写程序。我在写了一些数学智力游戏之后,继续创造游戏。作为80年代的人,我已经是龙与地下城桌游的粉丝,在游戏中角色扮演一个追求打败怪物并在陌生土地上抢掠的战士或者男巫。所以我创建一个基本的冒险游戏也在情理之中。 - -AppleSoft BASIC支持一种简洁的特性:在标准分辨率图形模式(GR模式)下,你可以检测屏幕上特定点的颜色。这为创建一个冒险游戏提供了捷径。比起创建并更新周期性传送到屏幕的内存地图,我现在可以依赖GR模式为我维护地图,我的程序还可以当玩家字符在屏幕四处移动的时候查询屏幕。通过这种方式,我让电脑完成了大部分艰难的工作。因此,我的自顶向下的冒险游戏使用了块状的GR模式图形来展示我的游戏地图。 - -我的冒险游戏使用了一张简单的地图,上面有一大片绿地伴着山脉从中间蔓延向下和一个在左上方的大湖。我要粗略地为桌游战役绘制这个地图,其中包含一个允许玩家穿过到远处的狭窄通道。 - -![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/quest-map.jpg) - -图1.一个有湖和山的简单桌游地图 - -你可以用curses绘制这个地图,并用字符代表草地、山脉和水。接下来,我描述怎样使用curses那样做以及如何在Linux终端创建和进行类似的一个冒险游戏? - -### 构建程序 - -在我的上一篇文章,我提到了大多数curses程序以相同的一组指令获取终端类型和设置curses环境: - -``` -initscr(); -cbreak(); -noecho(); - -``` - -在这个程序,我添加了另外的语句: - -``` -keypad(stdscr, TRUE); - -``` - -这里的TRUE标志允许curses从用户终端读取小键盘和功能键。如果你想要在你的程序中使用上下左右方向键,你需要使用这里的keypad(stdscr, TRUE)。 - -这样做了之后,你可以你可以开始在终端屏幕上绘图了。curses函数包括了一系列方法在屏幕上绘制文本。在我之前的文章中,我展示了addch()和addstr()函数以及他们对应的在添加文本之前先移动到指定屏幕位置的副本mvaddch()和mvaddstr()函数。为了创建这个冒险游戏,你可以使用另外一组函数:vline()和hline(),以及它们对应的函数mvvline()和mvhline()。这些mv函数接收屏幕坐标,一个要绘制的字符和要重复此字符的次数。例如,mvhline(1, 2, '-', 20)将会绘制一条开始于第一行第二列并由20个横线组成的线段。 - -为了以编程方式绘制地图到终端,让我们先定义这个draw_map()函数: - -``` -#define GRASS ' ' -#define EMPTY '.' -#define WATER '~' -#define MOUNTAIN '^' -#define PLAYER '*' - -void draw_map(void) -{ - int y, x; - - /* 绘制探索地图 */ - - /* 背景 */ - - for (y = 0; y < LINES; y++) { - mvhline(y, 0, GRASS, COLS); - } - - /* 山和山道 */ - - for (x = COLS / 2; x < COLS * 3 / 4; x++) { - mvvline(0, x, MOUNTAIN, LINES); - } - - mvhline(LINES / 4, 0, GRASS, COLS); - - /* 湖 */ - - for (y = 1; y < LINES / 2; y++) { - mvhline(y, 1, WATER, COLS / 3); - } -} - -``` - -在绘制这副地图时,记住填充大块字符到屏幕使用的mvvline()和mvhline()函数。我绘制从0列开始的字符水平线(mvhline)以创建草地区域,直到整个屏幕的高度和宽度。我绘制从0行开始的多条垂直线(mvvline)在此上添加了山脉,绘制单行水平线添加了一条山道(mvhline)。并且,我通过绘制一系列短水平线(mvhline)创建了湖。这种绘制重叠方块的方式看起来似乎并没有效率,但是记住在我们调用refresh()函数之前curses并不会真正更新屏幕。 - -绘制完地图,创建游戏就还剩下进入循环让程序等待用户按下上下左右方向键中的一个然后让玩家图标正确移动了。如果玩家想要移动的地方是空的,就应该允许玩家到那里。 - -你可以把curses当做捷径使用。比起在程序中实例化一个版本的地图并复制到屏幕(这么复杂),你可以让屏幕为你跟踪所有东西。inch()函数和相关联的mvinch()函数允许你探测屏幕的内容。这让你可以查询curses以了解玩家想要移动到的位置是否被水填满或者被山阻挡。这样做你需要一个之后会用到的一个帮助函数: - -``` -int is_move_okay(int y, int x) -{ - int testch; - - /* 如果要进入的位置可以进入,返回true */ - - testch = mvinch(y, x); - return ((testch == GRASS) || (testch == EMPTY)); -} - -``` - -如你所见,这个函数探测行x、列y并在空间未被占据的时候返回true,否则返回false。 - -这样我们写移动循环就很容易了:从键盘获取一个键值然后根据是上下左右键移动用户字符。这里是一个简单版本的这种循环: - -``` - - do { - ch = getch(); - - /* 测试输入的值并获取方向 */ - - switch (ch) { - case KEY_UP: - if ((y > 0) && is_move_okay(y - 1, x)) { - y = y - 1; - } - break; - case KEY_DOWN: - if ((y < LINES - 1) && is_move_okay(y + 1, x)) { - y = y + 1; - } - break; - case KEY_LEFT: - if ((x > 0) && is_move_okay(y, x - 1)) { - x = x - 1; - } - break; - case KEY_RIGHT - if ((x < COLS - 1) && is_move_okay(y, x + 1)) { - x = x + 1; - } - break; - } - } - while (1); - -``` - -为了在游戏中使用(这个循环),你需要在循环里添加一些代码来启用其它的键(例如传统的移动键WASD)以提供方法供用户退出游戏和在屏幕上四处移动。这里是完整的程序: - -``` - -/* quest.c */ - -#include -#include - -#define GRASS ' ' -#define EMPTY '.' -#define WATER '~' -#define MOUNTAIN '^' -#define PLAYER '*' - -int is_move_okay(int y, int x); -void draw_map(void); - -int main(void) -{ - int y, x; - int ch; - - /* 初始化curses */ - - initscr(); - keypad(stdscr, TRUE); - cbreak(); - noecho(); - - clear(); - - /* 初始化探索地图 */ - - draw_map(); - - /* 在左下角初始化玩家 */ - - y = LINES - 1; - x = 0; - - do { - /* 默认获得一个闪烁的光标--表示玩家字符 */ - - mvaddch(y, x, PLAYER); - move(y, x); - refresh(); - - ch = getch(); - - /* 测试输入的键并获取方向 */ - - switch (ch) { - case KEY_UP: - case 'w': - case 'W': - if ((y > 0) && is_move_okay(y - 1, x)) { - mvaddch(y, x, EMPTY); - y = y - 1; - } - break; - case KEY_DOWN: - case 's': - case 'S': - if ((y < LINES - 1) && is_move_okay(y + 1, x)) { - mvaddch(y, x, EMPTY); - y = y + 1; - } - break; - case KEY_LEFT: - case 'a': - case 'A': - if ((x > 0) && is_move_okay(y, x - 1)) { - mvaddch(y, x, EMPTY); - x = x - 1; - } - break; - case KEY_RIGHT: - case 'd': - case 'D': - if ((x < COLS - 1) && is_move_okay(y, x + 1)) { - mvaddch(y, x, EMPTY); - x = x + 1; - } - break; - } - } - while ((ch != 'q') && (ch != 'Q')); - - endwin(); - - exit(0); -} - -int is_move_okay(int y, int x) -{ - int testch; - - /* 当空间可以进入时返回true */ - - testch = mvinch(y, x); - return ((testch == GRASS) || (testch == EMPTY)); -} - -void draw_map(void) -{ - int y, x; - - /* 绘制探索地图 */ - - /* 背景 */ - - for (y = 0; y < LINES; y++) { - mvhline(y, 0, GRASS, COLS); - } - - /* 山脉和山道 */ - - for (x = COLS / 2; x < COLS * 3 / 4; x++) { - mvvline(0, x, MOUNTAIN, LINES); - } - - mvhline(LINES / 4, 0, GRASS, COLS); - - /* 湖 */ - - for (y = 1; y < LINES / 2; y++) { - mvhline(y, 1, WATER, COLS / 3); - } -} - -``` - -在完整的程序清单中,你可以看见使用curses函数创建游戏的完整布置: - -1) 初始化curses环境。 - -2) 绘制地图。 - -3) 初始化玩家坐标(左下角) - -4) 循环: - -* 绘制玩家字符。 - -* 从键盘获取键值。 - -* 对应地上下左右调整玩家坐标。 - -* 重复。 - -5) 完成时关闭curses环境并退出。 - -### 开始玩 - -当你运行游戏时,玩家的字符在左下角初始化。当玩家在游戏区域四处移动的时候,程序创建了“一串”点。这样可以展示玩家经过了的点,让玩家避免经过不必要的路径。 - -![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/quest-start.png) - -图2\. 初始化在左下角的玩家 - -![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/quest-1.png) - -图3\. 玩家可以在游戏区域四处移动,例如湖周围和山的通道 - -为了创建上面这样的完整冒险游戏,你可能需要在他/她的字符在游戏区域四处移动的时候随机创建不同的怪物。你也可以创建玩家可以发现在打败敌人后可以掠夺的特殊道具,这些道具应能提高玩家的能力。 - -但是作为起点,这是一个展示如何使用curses函数读取键盘和操纵屏幕的好程序。 - -### 下一步 - -这是一个如何使用curses函数更新和读取屏幕和键盘的简单例子。按照你的程序需要做什么,curses可以做得更多。在下一篇文章中,我计划展示如何更新这个简单程序以使用颜色。同时,如果你想要学习更多curses,我鼓励你去读位于Linux文档计划的Pradeep Padala之[如何使用NCURSES编程][2]。 - - --------------------------------------------------------------------------------- - -via: http://www.linuxjournal.com/content/creating-adventure-game-terminal-ncurses - -作者:[Jim Hall][a] -译者:[Leemeans](https://github.com/leemeans) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://www.linuxjournal.com/users/jim-hall -[1]:http://www.linuxjournal.com/content/getting-started-ncurses -[2]:http://tldp.org/HOWTO/NCURSES-Programming-HOWTO diff --git a/translated/tech/20180126 Creating an Adventure Game in the Terminal with ncurses.md b/translated/tech/20180126 Creating an Adventure Game in the Terminal with ncurses.md new file mode 100644 index 0000000000..5544e8bac0 --- /dev/null +++ b/translated/tech/20180126 Creating an Adventure Game in the Terminal with ncurses.md @@ -0,0 +1,310 @@ +通过 ncurses 在终端创建一个冒险游戏 +====== + +怎样使用 curses 函数读取键盘并操作屏幕。 + +我[之前的文章][1]介绍了 ncurses 库,并提供了一个简单的程序展示了一些将文本放到屏幕上的 curses 函数。在接下来的文章中,我将介绍如何使用其它的 curses 函数。 + +### 探险 + +当我逐渐长大,家里有了一台苹果 II 电脑。我和我兄弟正是在这台电脑上自学了如何用 AppleSoft BASIC 写程序。我在写了一些数学智力游戏之后,继续创造游戏。作为 80 年代的人,我已经是龙与地下城桌游的粉丝,在游戏中角色扮演一个追求打败怪物并在陌生土地上抢掠的战士或者男巫,所以我创建一个基本的冒险游戏也在情理之中。 + +AppleSoft BASIC 支持一种简洁的特性:在标准分辨率图形模式(GR 模式)下,你可以检测屏幕上特定点的颜色。这为创建一个冒险游戏提供了捷径。比起创建并更新周期性传送到屏幕的内存地图,我现在可以依赖 GR 模式为我维护地图,我的程序还可以在玩家的角色(LCTT 译注:此处 character 双关一个代表玩家的角色,同时也是一个字符)在屏幕四处移动的时候查询屏幕。通过这种方式,我让电脑完成了大部分艰难的工作。因此,我的自顶向下的冒险游戏使用了块状的 GR 模式图形来展示我的游戏地图。 + +我的冒险游戏使用了一张简单的地图,上面有一大片绿地伴着山脉从中间蔓延向下和一个在左上方的大湖。我要粗略地为桌游战役绘制这个地图,其中包含一个允许玩家穿过到远处的狭窄通道。 + +![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/quest-map.jpg) + +*图 1. 一个有湖和山的简单桌游地图* + +你可以用 curses 绘制这个地图,并用字符代表草地、山脉和水。接下来,我描述怎样使用 curses 那样做,以及如何在 Linux 终端创建和进行类似的一个冒险游戏。 + +### 构建程序 + +在我的上一篇文章,我提到了大多数 curses 程序以相同的一组指令获取终端类型和设置 curses 环境: + +``` +initscr(); +cbreak(); +noecho(); +``` + +在这个程序,我添加了另外的语句: + +``` +keypad(stdscr, TRUE); +``` + +这里的 `TRUE` 标志允许 curses 从用户终端读取小键盘和功能键。如果你想要在你的程序中使用上下左右方向键,你需要使用这里的 `keypad(stdscr, TRUE)`。 + +这样做了之后,你现在可以开始在终端屏幕上绘图了。curses 函数包括了一系列在屏幕上绘制文本的方法。在我之前的文章中,我展示了 `addch()` 和 `addstr()` 函数以及在添加文本之前先移动到指定屏幕位置的对应函数 `mvaddch()` 和 `mvaddstr()`。为了在终端上创建这个冒险游戏的地图,你可以使用另外一组函数:`vline()` 和 `hline()`,以及它们对应的函数 `mvvline()` 和 `mvhline()`。这些 mv 函数接受屏幕坐标、一个要绘制的字符和要重复此字符的次数的参数。例如,`mvhline(1, 2, '-', 20)` 将会绘制一条开始于第一行第二列并由 20 个横线组成的线段。 + +为了以编程方式绘制地图到终端屏幕上,让我们先定义这个 `draw_map()` 函数: + +``` +#define GRASS ' ' +#define EMPTY '.' +#define WATER '~' +#define MOUNTAIN '^' +#define PLAYER '*' + +void draw_map(void) +{ + int y, x; + + /* 绘制探索地图 */ + + /* 背景 */ + + for (y = 0; y < LINES; y++) { + mvhline(y, 0, GRASS, COLS); + } + + /* 山和山道 */ + + for (x = COLS / 2; x < COLS * 3 / 4; x++) { + mvvline(0, x, MOUNTAIN, LINES); + } + + mvhline(LINES / 4, 0, GRASS, COLS); + + /* 湖 */ + + for (y = 1; y < LINES / 2; y++) { + mvhline(y, 1, WATER, COLS / 3); + } +} + +``` + +在绘制这副地图时,记住填充大块字符到屏幕所使用的 `mvvline()` 和 `mvhline()` 函数。我绘制从 0 列开始的字符水平线(`mvhline`)以创建草地区域,直到占满整个屏幕的高度和宽度。我绘制从 0 行开始的多条垂直线(`mvvline`)在此上添加了山脉,绘制单行水平线添加了一条山道(`mvhline`)。并且,我通过绘制一系列短水平线(`mvhline`)创建了湖。这种绘制重叠方块的方式看起来似乎并没有效率,但是记住在我们调用 `refresh()` 函数之前 curses 并不会真正更新屏幕。 + +绘制完地图,创建游戏就还剩下进入循环让程序等待用户按下上下左右方向键中的一个然后让玩家图标正确移动了。如果玩家想要移动的地方是空的,就应该允许玩家到那里。 + +你可以把 curses 当做捷径使用。比起在程序中实例化一个版本的地图并复制到屏幕这么复杂,你可以让屏幕为你跟踪所有东西。`inch()` 函数和相关联的 `mvinch()` 函数允许你探测屏幕的内容。这让你可以查询 curses 以了解玩家想要移动到的位置是否被水填满或者被山阻挡。这样做你需要一个之后会用到的一个帮助函数: + +``` +int is_move_okay(int y, int x) +{ + int testch; + + /* 如果要进入的位置可以进入,返回 true */ + + testch = mvinch(y, x); + return ((testch == GRASS) || (testch == EMPTY)); +} +``` + +如你所见,这个函数探测行 `x`、列 `y` 并在空间未被占据的时候返回 `true`,否则返回 `false`。 + +这样我们写移动循环就很容易了:从键盘获取一个键值然后根据是上下左右键移动用户字符。这里是一个这种循环的简单版本: + +``` + + do { + ch = getch(); + + /* 测试输入的值并获取方向 */ + + switch (ch) { + case KEY_UP: + if ((y > 0) && is_move_okay(y - 1, x)) { + y = y - 1; + } + break; + case KEY_DOWN: + if ((y < LINES - 1) && is_move_okay(y + 1, x)) { + y = y + 1; + } + break; + case KEY_LEFT: + if ((x > 0) && is_move_okay(y, x - 1)) { + x = x - 1; + } + break; + case KEY_RIGHT + if ((x < COLS - 1) && is_move_okay(y, x + 1)) { + x = x + 1; + } + break; + } + } + while (1); +``` + +为了在游戏中使用这个循环,你需要在循环里添加一些代码来启用其它的键(例如传统的移动键 WASD),以提供让用户退出游戏和在屏幕上四处移动的方法。这里是完整的程序: + +``` +/* quest.c */ + +#include +#include + +#define GRASS ' ' +#define EMPTY '.' +#define WATER '~' +#define MOUNTAIN '^' +#define PLAYER '*' + +int is_move_okay(int y, int x); +void draw_map(void); + +int main(void) +{ + int y, x; + int ch; + + /* 初始化curses */ + + initscr(); + keypad(stdscr, TRUE); + cbreak(); + noecho(); + + clear(); + + /* 初始化探索地图 */ + + draw_map(); + + /* 在左下角初始化玩家 */ + + y = LINES - 1; + x = 0; + + do { + /* 默认获得一个闪烁的光标--表示玩家字符 */ + + mvaddch(y, x, PLAYER); + move(y, x); + refresh(); + + ch = getch(); + + /* 测试输入的键并获取方向 */ + + switch (ch) { + case KEY_UP: + case 'w': + case 'W': + if ((y > 0) && is_move_okay(y - 1, x)) { + mvaddch(y, x, EMPTY); + y = y - 1; + } + break; + case KEY_DOWN: + case 's': + case 'S': + if ((y < LINES - 1) && is_move_okay(y + 1, x)) { + mvaddch(y, x, EMPTY); + y = y + 1; + } + break; + case KEY_LEFT: + case 'a': + case 'A': + if ((x > 0) && is_move_okay(y, x - 1)) { + mvaddch(y, x, EMPTY); + x = x - 1; + } + break; + case KEY_RIGHT: + case 'd': + case 'D': + if ((x < COLS - 1) && is_move_okay(y, x + 1)) { + mvaddch(y, x, EMPTY); + x = x + 1; + } + break; + } + } + while ((ch != 'q') && (ch != 'Q')); + + endwin(); + + exit(0); +} + +int is_move_okay(int y, int x) +{ + int testch; + + /* 当空间可以进入时返回true */ + + testch = mvinch(y, x); + return ((testch == GRASS) || (testch == EMPTY)); +} + +void draw_map(void) +{ + int y, x; + + /* 绘制探索地图 */ + + /* 背景 */ + + for (y = 0; y < LINES; y++) { + mvhline(y, 0, GRASS, COLS); + } + + /* 山脉和山道 */ + + for (x = COLS / 2; x < COLS * 3 / 4; x++) { + mvvline(0, x, MOUNTAIN, LINES); + } + + mvhline(LINES / 4, 0, GRASS, COLS); + + /* 湖 */ + + for (y = 1; y < LINES / 2; y++) { + mvhline(y, 1, WATER, COLS / 3); + } +} +``` + +在完整的程序清单中,你可以看见使用 curses 函数创建游戏的完整布置: + +1. 初始化 curses 环境。 +2. 绘制地图。 +3. 初始化玩家坐标(左下角) +4. 循环: + * 绘制玩家的角色。 + * 从键盘获取键值。 + * 对应地上下左右调整玩家坐标。 + * 重复。 +5. 完成时关闭curses环境并退出。 + +### 开始玩 + +当你运行游戏时,玩家的字符在左下角初始化。当玩家在游戏区域四处移动的时候,程序创建了“一串”点。这样可以展示玩家经过了的点,让玩家避免经过不必要的路径。 + +![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/quest-start.png) + +*图 2. 初始化在左下角的玩家* + +![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/quest-1.png) + +*图 3. 玩家可以在游戏区域四处移动,例如湖周围和山的通道* + +为了创建上面这样的完整冒险游戏,你可能需要在他/她的角色在游戏区域四处移动的时候随机创建不同的怪物。你也可以创建玩家可以发现在打败敌人后可以掠夺的特殊道具,这些道具应能提高玩家的能力。 + +但是作为起点,这是一个展示如何使用 curses 函数读取键盘和操纵屏幕的好程序。 + +### 下一步 + +这是一个如何使用 curses 函数更新和读取屏幕和键盘的简单例子。按照你的程序需要做什么,curses 可以做得更多。在下一篇文章中,我计划展示如何更新这个简单程序以使用颜色。同时,如果你想要学习更多 curses,我鼓励你去读位于 Linux 文档计划的 Pradeep Padala 写的[如何使用 NCURSES 编程][2]。 + +-------------------------------------------------------------------------------- + +via: http://www.linuxjournal.com/content/creating-adventure-game-terminal-ncurses + +作者:[Jim Hall][a] +译者:[Leemeans](https://github.com/leemeans) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://www.linuxjournal.com/users/jim-hall +[1]:http://www.linuxjournal.com/content/getting-started-ncurses +[2]:http://tldp.org/HOWTO/NCURSES-Programming-HOWTO From 97e62add979b200fb40b1d0e18e1c450aac69883 Mon Sep 17 00:00:00 2001 From: wxy Date: Sat, 24 Feb 2018 13:24:20 +0800 Subject: [PATCH 011/296] PRF:20180131 Fastest way to unzip a zip file in Python.md @leemeans --- ...stest way to unzip a zip file in Python.md | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/translated/tech/20180131 Fastest way to unzip a zip file in Python.md b/translated/tech/20180131 Fastest way to unzip a zip file in Python.md index e3c7ee8815..be7e06bf04 100644 --- a/translated/tech/20180131 Fastest way to unzip a zip file in Python.md +++ b/translated/tech/20180131 Fastest way to unzip a zip file in Python.md @@ -1,16 +1,18 @@ -Python中最快解压zip文件的方法 +Python 中最快解压 zip 文件的方法 ====== -假设(现在的)上下文(context,计算机术语,此处意为业务情景)是这样的:一个zip文件被上传到一个[web服务][1]中,然后Python需要解压这个zip文件然后分析和处理其中的每个文件。这个特殊的应用查看每个文件各自的名称和大小 ,并和已经上传到AWS S3上的文件进行比较,如果文件(和AWS S3上的相比)有所不同或者文件本身更新,那么就将它上传到AWS S3。 + +假设现在的上下文(LCTT 译注:context,计算机术语,此处意为业务情景)是这样的:一个 zip 文件被上传到一个[Web 服务][1]中,然后 Python 需要解压这个 zip 文件然后分析和处理其中的每个文件。这个特殊的应用查看每个文件各自的名称和大小,并和已经上传到 AWS S3 上的文件进行比较,如果文件(和 AWS S3 上的相比)有所不同或者文件本身更新,那么就将它上传到 AWS S3。 [![Uploads today][2]][3] -挑战在于这些zip文件太大了。他们的平均大小是560MB但是其中一些大于1GB。这些文件中大多数是文本文件,但是其中同样也有一些巨大的二进制文件。不同寻常的是,每个zip文件包含100个文件但是其中1-3个文件却占据了多达95%的zip文件大小。 +挑战在于这些 zip 文件太大了。它们的平均大小是 560MB 但是其中一些大于 1GB。这些文件中大多数是文本文件,但是其中同样也有一些巨大的二进制文件。不同寻常的是,每个 zip 文件包含 100 个文件但是其中 1-3 个文件却占据了多达 95% 的 zip 文件大小。 -最开始我尝试在内存中解压文件,并且每次只处理一个文件。在各种内存爆炸和EC2耗尽内存的情况下,这个方法壮烈失败了。我觉得这个方法应该有用。最开始你有1GB文件在RAM中,然后你现在解压每个文件并有了大约2-3GB放在了内存中。所以,在很多次测试之后,解决方案是将这些zip文件提取(dump)到磁盘上(在临时目录`/tmp`中)然后遍历这些文件。这次情况好多了但是我仍然注意到了整个解压过程花费了巨量的时间。**是否可能有方法优化呢?** +最开始我尝试在内存中解压文件,并且每次只处理一个文件。在各种内存爆炸和 EC2 耗尽内存的情况下,这个方法壮烈失败了。我觉得这个原因是这样的。最开始你有 1GB 文件在内存中,然后你现在解压每个文件,在内存中大约就要占用 2-3GB。所以,在很多次测试之后,解决方案是将这些 zip 文件复制到磁盘上(在临时目录 `/tmp` 中),然后遍历这些文件。这次情况好多了但是我仍然注意到了整个解压过程花费了巨量的时间。**是否可能有方法优化呢?** -### 原始函数(baseline function) +### 原始函数 + +首先是下面这些模拟对 zip 文件中文件实际操作的普通函数: -首先是下面这些模拟对zip文件中文件实际操作的普通函数: ``` def _count_file(fn): with open(fn, 'rb') as f: @@ -26,9 +28,10 @@ def _count_file_object(f): for line in f: total += len(line) return total - ``` -这里是可能最简单的另一个(函数): + +这里是可能最简单的另一个函数: + ``` def f1(fn, dest): with open(fn, 'rb') as f: @@ -41,14 +44,14 @@ def f1(fn, dest): fn = os.path.join(root, file_) total += _count_file(fn) return total - ``` -如果我更仔细地分析一下,我(将会)发现这个函数花费时间40%运行`extractall`,60%的时间在执行读取文件长度的循环。 +如果我更仔细地分析一下,我将会发现这个函数花费时间 40% 运行 `extractall`,60% 的时间在遍历各个文件并读取其长度。 ### 第一步尝试 -我的第一步尝试是使用线程。先创建一个`zipfile.ZipFile`的实例,展开每个文件名到其中然后为每一个名称开始一个线程。每个线程都给它一个函数来做"实质工作"(在这个基础测试(benchmark)中,就是遍历每个文件然后获取它的名称)。实际(业务中)的函数进行的工作是复杂的S3,Redis和PostgreSQL操作,但是在我的基准测试中我只需要制作一个可以找出文件长度的函数就好了。线程池函数: +我的第一步尝试是使用线程。先创建一个 `zipfile.ZipFile` 的实例,展开其中的每个文件名,然后为每一个文件开始一个线程。每个线程都给它一个函数来做“实质工作”(在这个基准测试中,就是遍历每个文件然后获取它的名称)。实际业务中的函数进行的工作是复杂的 S3、Redis 和 PostgreSQL 操作,但是在我的基准测试中我只需要制作一个可以找出文件长度的函数就好了。线程池函数: + ``` def f2(fn, dest): @@ -76,11 +79,12 @@ def f2(fn, dest): return total ``` -**结果:加速~10%** +**结果:加速 ~10%** ### 第二步尝试 -所以可能是GIL(译者注:Global Interpreter Lock,一种全局锁,CPython中的一个概念)阻碍了我。最自然的想法是尝试使用multiprocessing在多个CPU上分配工作。但是这样做有缺点,那就是你不能传递一个非可pickle序列化的对象(译注:意为只有可pickle序列化的对象可以被传递),所以你只能发送文件名到之后的函数中: +所以可能是 GIL(LCTT 译注:Global Interpreter Lock,一种全局锁,CPython 中的一个概念)阻碍了我。最自然的想法是尝试使用多线程在多个 CPU 上分配工作。但是这样做有缺点,那就是你不能传递一个非可 pickle 序列化的对象(LCTT 译注:意为只有可 pickle 序列化的对象可以被传递),所以你只能发送文件名到之后的函数中: + ``` def unzip_member_f3(zip_filepath, filename, dest): with open(zip_filepath, 'rb') as f: @@ -111,36 +115,34 @@ def f3(fn, dest): return total ``` -**结果: 加速~300%** +**结果: 加速 ~300%** ### 这是作弊 -使用处理器池的问题是这样需要存储在磁盘上的原始`.zip`文件。所以为了在我的web服务器上使用这个解决方案,我首先得要将内存中的ZIP文件保存到磁盘,然后调用这个函数。这样做的代价我不是很清楚但是应该不低。 +使用处理器池的问题是这样需要存储在磁盘上的原始 `.zip` 文件。所以为了在我的 web 服务器上使用这个解决方案,我首先得要将内存中的 zip 文件保存到磁盘,然后调用这个函数。这样做的代价我不是很清楚但是应该不低。 -好吧,再翻翻(poke around)看又没有损失(Well, it doesn't hurt to poke around)。可能,解压过程加速到足以弥补这样做的损失了吧。 +好吧,再翻翻看又没有损失。可能,解压过程加速到足以弥补这样做的损失了吧。 -但是一定记住!这个优化取决于使用所有可用的CPU。如果一些其他的CPU需要执行在`gunicorn`中的其它事务呢?这时,这些其他进程必须等待,直到有CPU可用。由于在这个服务器上有其他的事务正在进行,我不是很确定我想要在进程中接管所有其他CPU。 +但是一定记住!这个优化取决于使用所有可用的 CPU。如果一些其它的 CPU 需要执行在 `gunicorn` 中的其它事务呢?这时,这些其它进程必须等待,直到有 CPU 可用。由于在这个服务器上有其他的事务正在进行,我不是很确定我想要在进程中接管所有其他 CPU。 ### 结论 -一步一步地做(这个任务)这个过程感觉挺好的。你被限制在一个CPU上但是表现仍然特别好。同样地,一定要看看在`f1`和`f2`两段代码之间的不同之处!利用`concurrent.futures`池类你可以获取可以使用的CPU的个数,但是这样做同样给人感觉不是很好。如果你在虚拟环境中获取的个数是错的呢?或者可用的个数太低以致无法从负载分配获取好处并且现在你仅仅是为了移动负载而支付营运开支呢? +一步一步地做这个任务的这个过程感觉挺好的。你被限制在一个 CPU 上但是表现仍然特别好。同样地,一定要看看在`f1` 和 `f2` 两段代码之间的不同之处!利用 `concurrent.futures` 池类你可以获取到允许使用的 CPU 的个数,但是这样做同样给人感觉不是很好。如果你在虚拟环境中获取的个数是错的呢?或者可用的个数太低以致无法从负载分配获取好处并且现在你仅仅是为了移动负载而支付营运开支呢? -我将会继续使用`zipfile.ZipFile(file_buffer).extractall(temp_dir)`。这个工作这样做已经足够好了。 +我将会继续使用 `zipfile.ZipFile(file_buffer).extractall(temp_dir)`。这个工作这样做已经足够好了。 ### 想试试手吗? -我使用一个`c5.4xlarge` EC2服务器来进行我的基准测试。文件可以从此处下载: +我使用一个 `c5.4xlarge` EC2 服务器来进行我的基准测试。文件可以从此处下载: + ``` wget https://www.peterbe.com/unzip-in-parallel/hack.unzip-in-parallel.py wget https://www.peterbe.com/unzip-in-parallel/symbols-2017-11-27T14_15_30.zip - ``` -这里的`.zip`文件有34MB。和在服务器上发生的已经小了很多。 - -`hack.unzip-in-parallel.py`文件里是一团糟。它包含了大量可怕的入侵和丑恶的事情,但是万幸这只是一个开始(译注:大概入侵没有完成)。 - +这里的 `.zip` 文件有 34MB。和在服务器上的相比已经小了很多。 +`hack.unzip-in-parallel.py` 文件里是一团糟。它包含了大量可怕的修正和丑陋的代码,但是这只是一个开始。 -------------------------------------------------------------------------------- @@ -148,7 +150,7 @@ via: https://www.peterbe.com/plog/fastest-way-to-unzip-a-zip-file-in-python 作者:[Peterbe][a] 译者:[Leemeans](https://github.com/leemeans) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 From 16e17004eb7b94d03963cb9c0e8f510512a21f7a Mon Sep 17 00:00:00 2001 From: wxy Date: Sat, 24 Feb 2018 13:56:18 +0800 Subject: [PATCH 012/296] PRF:20180103 How to preconfigure LXD containers with cloud-init.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @kaneg 恭喜你,完成了第一篇翻译! --- ...onfigure LXD containers with cloud-init.md | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/translated/tech/20180103 How to preconfigure LXD containers with cloud-init.md b/translated/tech/20180103 How to preconfigure LXD containers with cloud-init.md index 919efe4a26..4e70cd3bcb 100644 --- a/translated/tech/20180103 How to preconfigure LXD containers with cloud-init.md +++ b/translated/tech/20180103 How to preconfigure LXD containers with cloud-init.md @@ -1,12 +1,15 @@ -如何使用cloud-init来预配置LXD容器 +如何使用 cloud-init 来预配置 LXD 容器 ====== -当你正在创建LXD容器的时候,你希望它们能被预先配置好。例如在容器一启动就自动执行 **apt update**来安装一些软件包,或者运行一些命令。 -这篇文章将讲述如何用[**cloud-init**][1]来对[LXD容器进行进行早期初始化][2]。 + +当你正在创建 LXD 容器的时候,你希望它们能被预先配置好。例如在容器一启动就自动执行 `apt update`来安装一些软件包,或者运行一些命令。 + +这篇文章将讲述如何用 [cloud-init][1] 来对 [LXD 容器进行进行早期初始化][2]。 + 接下来,我们将创建一个包含cloud-init指令的LXD profile,然后启动一个新的容器来使用这个profile。 -### 如何创建一个新的LXD profile +### 如何创建一个新的 LXD profile -查看已经存在的profile: +查看已经存在的 profile: ```shell $ lxc profile list @@ -17,7 +20,7 @@ $ lxc profile list +---------|---------+ ``` -我们把名叫default的profile复制一份,然后在其内添加新的指令: +我们把名叫 `default` 的 profile 复制一份,然后在其内添加新的指令: ```shell $ lxc profile copy default devprofile @@ -32,7 +35,7 @@ $ lxc profile list +------------|---------+ ``` -我们就得到了一个新的profile: **devprofile**。下面是它的详情: +我们就得到了一个新的 profile: `devprofile`。下面是它的详情: ```yaml $ lxc profile show devprofile @@ -52,11 +55,12 @@ name: devprofile used_by: [] ``` -注意这几个部分: **config:** , **description:** , **devices:** , **name:** 和 **used_by:**,当你修改这些内容的时候注意不要搞错缩进。(译者注:因为这些内容是YAML格式的,缩进是语法的一部分) +注意这几个部分: `config:` 、 `description:` 、 `devices:` 、 `name:` 和 `used_by:`,当你修改这些内容的时候注意不要搞错缩进。(LCTT 译注:因为这些内容是 YAML 格式的,缩进是语法的一部分) -### 如何把cloud-init添加到LXD profile里 +### 如何把 cloud-init 添加到 LXD profile 里 + +[cloud-init][1] 可以添加到 LXD profile 的 `config` 里。当这些指令将被传递给容器后,会在容器第一次启动的时候执行。 -[cloud-init][1]可以添加到LXD profile的 **config** 里。当这些指令将被传递给容器后,会在容器第一次启动的时候执行。 下面是用在示例中的指令: ```yaml @@ -69,11 +73,9 @@ used_by: [] - [touch, /tmp/simos_was_here] ``` -**package_upgrade: true** 是指当容器第一次被启动时,我们想要**cloud-init** 运行 **sudo apt upgrade**。 -**packages:** 列出了我们想要自动安装的软件。然后我们设置了**locale** and **timezone**。在Ubuntu容器的镜像里,root用户默认的 locale 是**C.UTF-8**,而**ubuntu** 用户则是 **en_US.UTF-8**。此外,我们把时区设置为**Etc/UTC**。 -最后,我们展示了[如何使用**runcmd**来运行一个Unix命令][3]。 +`package_upgrade: true` 是指当容器第一次被启动时,我们想要 `cloud-init` 运行 `sudo apt upgrade`。`packages:` 列出了我们想要自动安装的软件。然后我们设置了 `locale` 和 `timezone`。在 Ubuntu 容器的镜像里,root 用户默认的 `locale` 是 `C.UTF-8`,而 `ubuntu` 用户则是 `en_US.UTF-8`。此外,我们把时区设置为 `Etc/UTC`。最后,我们展示了[如何使用 runcmd 来运行一个 Unix 命令][3]。 -我们需要关注如何将**cloud-init**指令插入LXD profile。 +我们需要关注如何将 `cloud-init` 指令插入 LXD profile。 我首选的方法是: @@ -110,15 +112,15 @@ name: devprofile used_by: [] ``` -### 如何使用LXD profile启动一个容器 +### 如何使用 LXD profile 启动一个容器 -使用profile **devprofile**来启动一个新容器: +使用 profile `devprofile` 来启动一个新容器: ``` $ lxc launch --profile devprofile ubuntu:x mydev ``` -然后访问该容器来查看我们的的指令是否生效: +然后访问该容器来查看我们的指令是否生效: ```shell $ lxc exec mydev bash @@ -139,7 +141,7 @@ root@mydev:~# ps ax root@mydev:~# ``` -如果我们连接得够快,通过**ps ax**将能够看到系统正在更新软件。我们可以从/var/log/cloud-init-output.log看到完整的日志: +如果我们连接得够快,通过 `ps ax` 将能够看到系统正在更新软件。我们可以从 `/var/log/cloud-init-output.log` 看到完整的日志: ``` Generating locales (this might take a while)... @@ -147,7 +149,7 @@ Generating locales (this might take a while)... Generation complete. ``` -以上可以看出locale已经被更改了。root 用户还是保持默认的**C.UTF-8**,只有非root用户**ubuntu**使用了新的locale。 +以上可以看出 `locale` 已经被更改了。root 用户还是保持默认的 `C.UTF-8`,只有非 root 用户 `ubuntu` 使用了新的`locale` 设置。 ``` Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease @@ -155,7 +157,7 @@ Get:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB] Get:3 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB] ``` -以上是安装软件包之前执行的**apt update**。 +以上是安装软件包之前执行的 `apt update`。 ``` The following packages will be upgraded: @@ -163,16 +165,18 @@ The following packages will be upgraded: 4 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 211 kB of archives. ``` -以上是在执行**package_upgrade: true**和安装软件包。 + +以上是在执行 `package_upgrade: true` 和安装软件包。 ``` The following NEW packages will be installed: binutils build-essential cpp cpp-5 dpkg-dev fakeroot g++ g++-5 gcc gcc-5 libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl ``` -以上是我们安装**build-essential**软件包的指令。 -**runcmd** 执行的结果如何? +以上是我们安装 `build-essential` 软件包的指令。 + +`runcmd` 执行的结果如何? ``` root@mydev:~# ls -l /tmp/ @@ -185,7 +189,7 @@ root@mydev:~# ### 结论 -当我们启动LXD容器的时候,我们常常需要默认启用一些配置,并且希望能够避免重复工作。通常解决这个问题的方法是创建LXD profile,然后把需要的配置添加进去。最后,当我们启动新的容器时,只需要应用该LXD profile即可。 +当我们启动 LXD 容器的时候,我们常常需要默认启用一些配置,并且希望能够避免重复工作。通常解决这个问题的方法是创建 LXD profile,然后把需要的配置添加进去。最后,当我们启动新的容器时,只需要应用该 LXD profile 即可。 -------------------------------------------------------------------------------- @@ -193,7 +197,7 @@ via: https://blog.simos.info/how-to-preconfigure-lxd-containers-with-cloud-init/ 作者:[Simos Xenitellis][a] 译者:[kaneg](https://github.com/kaneg) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 From 885daf886f4281ef88d5668241cc80683dc7ec35 Mon Sep 17 00:00:00 2001 From: darksun Date: Sat, 24 Feb 2018 14:10:26 +0800 Subject: [PATCH 013/296] =?UTF-8?q?=E9=80=89=E9=A2=98:=20How=20slowing=20d?= =?UTF-8?q?own=20made=20me=20a=20better=20leader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ow slowing down made me a better leader.md | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 sources/talk/20180220 How slowing down made me a better leader.md diff --git a/sources/talk/20180220 How slowing down made me a better leader.md b/sources/talk/20180220 How slowing down made me a better leader.md new file mode 100644 index 0000000000..bd1b9c0749 --- /dev/null +++ b/sources/talk/20180220 How slowing down made me a better leader.md @@ -0,0 +1,53 @@ +How slowing down made me a better leader +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/BUSINESS_leadership_brand.png?itok=YW1Syk4S) + +Early in my career, I thought the most important thing I could do was act. If my boss said jump, my reply was "how high?" + +But as I've grown as a leader and manager, I've realized that the most important traits I can offer are [patience][1] and listening. This patience and listening means I'm focusing on what's really important. I'm decisive, so I do not hesitate to act. Yet I've learned that my actions are more impactful when I consider input from multiple sources and offer advice on what we should be doing—not simply reacting to an immediate request. + +Practicing open leadership involves cultivating the patience and listening skills I need to collaborate on the [best plan of action, not just the quickest one][2]. It also gives me the tools I need to explain [why I'm saying "no"][3] (or, perhaps, "not now") to someone, so I can lead with transparency and confidence. + +If you're in software development and practice scrum, then the following argument might resonate with you: The patience and listening a manager displays are as important as her skills in sprint planning and running the sprint demo. Forget about them, and you'll lessen the impact you're able to have. + +### A focus on patience + +Focus and patience do not always come easily. Often, I find myself sitting in meetings and filling my notebook with action items. My default action can be to think: "We can simply do x and y will improve!" Then I remember that things are not so linear. + +I need to think about the other factors that can influence a situation. Pausing to take in data from multiple people and resources helps me flesh out a strategy that our organization needs for long-term success. It also helps me identify those shorter-term milestones that should lead us to deliver the business results I'm responsible for producing. + +Here's a great example from a time when patience wasn't something I valued as I should have—and how that hurt my performance. When I was based on North Carolina, I worked with someone based in Arizona. We didn't use video conferencing technologies, so I didn't get to observe her body language when we talked. While I was responsible for delivering the results for the project I led, she was one of the two people tasked with making sure I had adequate support. + +For whatever reason, when I talked with this person, when she asked me to do something, I did it. She would be providing input on my performance evaluation, so I wanted to make sure she was happy. At the time, I didn't possess the maturity to know I didn't need to make her happy; my focus should have been on other performance indicators. I should have spent more time listening and collaborating with her instead of picking up the first "action item" and working on it while she was still talking. + +After six months on the job, this person gave me some tough feedback. I was angry and sad. Didn't I do everything she'd asked? I had worked long hours, nearly seven days a week for six months. How dare she criticize my performance? + +Then, after I had my moment of anger followed by sadness, I thought about what she said. Her feedback was on point. + +The patience and listening a manager displays are as important as her skills in sprint planning and running the sprint demo. + +She had concerns about the project, and she held me accountable because I was responsible. We worked through the issues, and I learned that vital lesson about how to lead: Leadership does not mean "get it done right now." Leadership means putting together a strategy, then communicating and implementing plans in support of the strategy. It also means making mistakes and learning from these hiccups. + +### Lesson learned + +In hindsight, I realize I could have asked more questions to better understand the intent of her feedback. I also could have pushed back if the guidance from her did not align with other input I was receiving. By having the patience to listen to the various sources giving me input about the project, synthesizing what I learned, and creating a coherent plan for action, I would have been a better leader. I also would have had more purpose driving the work I was doing. Instead of reacting to a single data point, I would have been implementing a strategic plan. I also would have had a better performance evaluation. + +I eventually had some feedback for her. Next time we worked together, I didn't want to hear the feedback after six months. I wanted to hear the feedback earlier and more often so I could learn from the mistakes sooner. An ongoing discussion about the work is what should happen on any team. + +As I mature as a manager and leader, I hold myself to the same standards I ask my team to meet: Plan, work the plan, and reflect. Repeat. Don't let a fire drill created by an external force distract you from the plan you need to implement. Breaking work into small increments builds in space for reflections and adjustments to the plan. As Daniel Goleman writes, "Directing attention toward where it needs to go is a primal task of leadership." Don't be afraid of meeting this challenge. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/open-organization/18/2/open-leadership-patience-listening + +作者:[Angela Robertson][a] +译者:[译者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/arobertson98 +[1]:https://opensource.com/open-organization/16/3/my-most-difficult-leadership-lesson +[2]:https://opensource.com/open-organization/16/3/fastest-result-isnt-always-best-result +[3]:https://opensource.com/open-organization/17/5/saying-no-open-organization From 3938b3b830d570e08a396c635fd8ec74d10ec3fc Mon Sep 17 00:00:00 2001 From: darksun Date: Sat, 24 Feb 2018 14:12:18 +0800 Subject: [PATCH 014/296] =?UTF-8?q?=E9=80=89=E9=A2=98:=204=20consideration?= =?UTF-8?q?s=20when=20naming=20software=20development=20projects?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...en naming software development projects.md | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 sources/talk/20180220 4 considerations when naming software development projects.md diff --git a/sources/talk/20180220 4 considerations when naming software development projects.md b/sources/talk/20180220 4 considerations when naming software development projects.md new file mode 100644 index 0000000000..1e1add0b68 --- /dev/null +++ b/sources/talk/20180220 4 considerations when naming software development projects.md @@ -0,0 +1,91 @@ +4 considerations when naming software development projects +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/hello-name-sticker-badge-tag.png?itok=fAgbMgBb) + +Working on a new open source project, you're focused on the code—getting that great new idea released so you can share it with the world. And you'll want to attract new contributors, so you need a terrific **name** for your project. + +We've all read guides for creating names, but how do you go about choosing the right one? Keeping that cool science fiction reference you're using internally might feel fun, but it won't mean much to new users you're trying to attract. A better approach is to choose a name that's memorable to new users and developers searching for your project. + +Names set expectations. Your project's name should showcase its functionality in the ecosystem and explain to users what your story is. In the crowded open source software world, it's important not to get entangled with other projects out there. Taking a little extra time now, before sending out that big announcement, will pay off later. + +Here are four factors to keep in mind when choosing a name for your project. + +### What does your project's code do? + +Start with your project: What does it do? You know the code intimately—but can you explain what it does to a new developer? Can you explain it to a CTO or non-developer at another company? What kinds of problems does your project solve for users? + +Your project's name needs to reflect what it does in a way that makes sense to newcomers who want to use or contribute to your project. That means considering the ecosystem for your technology and understanding if there are any naming styles or conventions used for similar kinds of projects. Imagine that you're trying to evaluate someone else's project: Would the name be appealing to you? + +Any distribution channels you push to are also part of the ecosystem. If your code will be in a Linux distribution, [npm][1], [CPAN][2], [Maven][3], or in a Ruby Gem, you need to review any naming standards or common practices for that package manager. Review any similar existing names in that distribution channel, and get a feel for naming styles of other programs there. + +### Who are the users and developers you want to attract? + +The hardest aspect of choosing a new name is putting yourself in the shoes of new users. You built this project; you already know how powerful it is, so while your cool name may sound great, it might not draw in new people. You need a name that is interesting to someone new, and that tells the world what problems your project solves. + +Great names depend on what kind of users you want to attract. Are you building an [Eclipse][4] plugin or npm module that's focused on developers? Or an analytics toolkit that brings visualizations to the average user? Understanding your user base and the kinds of open source contributors you want to attract is critical. + +Great names depend on what kind of users you want to attract. + +Take the time to think this through. Who does your project most appeal to, and how can it help them do their job? What kinds of problems does your code solve for end users? Understanding the target user helps you focus on what users need, and what kind of names or brands they respond to. + +Take the time to think this through. Who does your project most appeal to, and how can it help them do their job? What kinds of problems does your code solve for end users? Understanding the target user helps you focus on what users need, and what kind of names or brands they respond to. + +When you're open source, this equation changes a bit—your target is not just users; it's also developers who will want to contribute code back to your project. You're probably a developer, too: What kinds of names and brands excite you, and what images would entice you to try out someone else's new project? + +Once you have a better feel of what users and potential contributors expect, use that knowledge to refine your names. Remember, you need to step outside your project and think about how the name would appeal to someone who doesn't know how amazing your code is—yet. Once someone gets to your website, does the name synchronize with what your product does? If so, move to the next step. + +### Who else is using similar names for software? + +Now that you've tried on a user's shoes to evaluate potential names, what's next? Figuring out if anyone else is already using a similar name. It sometimes feels like all the best names are taken—but if you search carefully, you'll find that's not true. + +The first step is to do a few web searches using your proposed name. Search for the name, plus "software", "open source", and a few keywords for the functionality that your code provides. Look through several pages of results for each search to see what's out there in the software world. + +The first step is to do a few web searches using your proposed name. + +Unless you're using a completely made-up word, you'll likely get a lot of hits. The trick is understanding which search results might be a problem. Again, put on the shoes of a new user to your project. If you were searching for this great new product and saw the other search results along with your project's homepage, would you confuse them? Are the other search results even software products? If your product solves a similar problem to other search results, that's a problem: Users may gravitate to an existing product instead of a new one. + +Unless you're using a completely made-up word, you'll likely get a lot of hits. The trick is understanding which search results might be a problem. Again, put on the shoes of a new user to your project. If you were searching for this great new product and saw the other search results along with your project's homepage, would you confuse them? Are the other search results even software products? If your product solves a similar problem to other search results, that's a problem: Users may gravitate to an existing product instead of a new one. + +Similar non-software product names are rarely an issue unless they are famous trademarks—like Nike or Red Bull, for example—where the companies behind them won't look kindly on anyone using a similar name. Using the same name as a less famous non-software product might be OK, depending on how big your project gets. + +### How big do you plan to grow your project? + +Are you building a new node module or command-line utility, but not planning a career around it? Is your new project a million-dollar business idea, and you're thinking startup? Or is it something in between? + +If your project is a basic developer utility—something useful that developers will integrate into their workflow—then you have enough data to choose a name. Think through the ecosystem and how a new user would see your potential names, and pick one. You don't need perfection, just a name you're happy with that seems right for your project. + +If you're planning to build a business around your project, use these tips to develop a shortlist of names, but do more vetting before announcing the winner. Use for a business or major project requires some level of registered trademark search, which is usually performed by a law firm. + +### Common pitfalls + +Finally, when choosing a name, avoid these common pitfalls: + + * Using an esoteric acronym. If new users don't understand the name, they'll have a hard time finding you. + + * Using current pop-culture references. If you want your project's appeal to last, pick a name that will last. + + * Failing to consider non-English speakers. Does the name have a specific meaning in another language that might be confusing? + + * Using off-color jokes or potentially unsavory references. Even if it seems funny to developers, it may fall flat for newcomers and turn away contributors. + + + + +Good luck—and remember to take the time to step out of your shoes and consider how a newcomer to your project will think of the name. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/2/choosing-project-names-four-key-considerations + +作者:[Shane Curcuru][a] +译者:[译者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/shane-curcuru +[1]:https://www.npmjs.com/ +[2]:https://www.cpan.org/ +[3]:https://maven.apache.org/ +[4]:https://www.eclipse.org/ From 0406114422439adee01bb3081a663b12569f3cce Mon Sep 17 00:00:00 2001 From: wxy Date: Sat, 24 Feb 2018 14:12:31 +0800 Subject: [PATCH 015/296] PRF:20070810 How to use lftp to accelerate ftp-https download speed on Linux-UNIX.md @geekpi --- ... ftp-https download speed on Linux-UNIX.md | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/translated/tech/20070810 How to use lftp to accelerate ftp-https download speed on Linux-UNIX.md b/translated/tech/20070810 How to use lftp to accelerate ftp-https download speed on Linux-UNIX.md index 9fa97d794b..8d4f37bf51 100644 --- a/translated/tech/20070810 How to use lftp to accelerate ftp-https download speed on Linux-UNIX.md +++ b/translated/tech/20070810 How to use lftp to accelerate ftp-https download speed on Linux-UNIX.md @@ -1,6 +1,7 @@ 如何使用 lftp 来加速 Linux/UNIX 上的 ftp/https 下载速度 ====== -lftp 是一个文件传输程序。它可以用复杂的 FTP, HTTP/HTTPS 和其他连接。如果指定了站点 URL,那么 lftp 将连接到该站点,否则会使用 open 命令建立连接。它是所有 Linux/Unix 命令行用户的必备工具。我目前写了一些关于[ Linux 下超快命令行下载加速器][1],比如 Axel 和 prozilla。lftp 是另一个能做相同的事,但有更多功能的工具。lftp 可以处理七种文件访问方式: + +`lftp` 是一个文件传输程序。它可以用复杂的 FTP、 HTTP/HTTPS 和其他连接。如果指定了站点 URL,那么 `lftp` 将连接到该站点,否则会使用 `open` 命令建立连接。它是所有 Linux/Unix 命令行用户的必备工具。我目前写了一些关于 [Linux 下超快命令行下载加速器][1],比如 Axel 和 prozilla。`lftp` 是另一个能做相同的事,但有更多功能的工具。`lftp` 可以处理七种文件访问方式: 1. ftp 2. ftps @@ -11,56 +12,62 @@ lftp 是一个文件传输程序。它可以用复杂的 FTP, HTTP/HTTPS 和其 7. sftp 8. file - - ### 那么 lftp 的独特之处是什么? - * lftp 中的每个操作都是可靠的,即任何非致命错误都被忽略,并且重复操作。所以如果下载中断,它会自动重新启动。即使 FTP 服务器不支持 REST 命令,lftp 也会尝试从开头检索文件,直到文件传输完成。 -  * lftp 具有类似 shell 的命令语法,允许你在后台并行启动多个命令。 -  * lftp 有一个内置镜像,可以下载或更新整个目录树。还有一个反向镜像(mittor -R),它可以上传或更新服务器上的目录树。镜像也可以在两个远程服务器之间同步目录,如果可用的话会使用 FXP。 - + * `lftp` 中的每个操作都是可靠的,即任何非致命错误都被忽略,并且重复进行操作。所以如果下载中断,它会自动重新启动。即使 FTP 服务器不支持 `REST` 命令,lftp 也会尝试从开头检索文件,直到文件传输完成。 +  * `lftp` 具有类似 shell 的命令语法,允许你在后台并行启动多个命令。 +  * `lftp` 有一个内置的镜像功能,可以下载或更新整个目录树。还有一个反向镜像功能(`mirror -R`),它可以上传或更新服务器上的目录树。镜像也可以在两个远程服务器之间同步目录,如果可用的话会使用 FXP。 ### 如何使用 lftp 作为下载加速器 -lftp 有 pget 命令。它能让你并行下载。语法是: -`lftp -e 'pget -n NUM -c url; exit'` -例如,使用 pget 分 5个部分下载 : +`lftp` 有 `pget` 命令。它能让你并行下载。语法是: + +``` +lftp -e 'pget -n NUM -c url; exit' +``` + +例如,使用 `pget` 分 5个部分下载 : + ``` $ cd /tmp $ lftp -e 'pget -n 5 -c http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.22.2.tar.bz2' ``` + 示例输出: + ``` 45108964 bytes transferred in 57 seconds (775.3K/s) lftp :~>quit - ``` 这里: - 1. pget - 并行下载文件 -  2. -n 5 - 将最大连接数设置为 5 -  3. -c - 如果当前目录存在 lfile.lftp-pget-status,则继续中断的传输 - - + 1. `pget` - 并行下载文件 +  2. `-n 5` - 将最大连接数设置为 5 +  3. `-c` - 如果当前目录存在 `lfile.lftp-pget-status`,则继续中断的传输 ### 如何在 Linux/Unix 中使用 lftp 来加速 ftp/https下载 -再尝试添加退出命令: -`$ lftp -e 'pget -n 10 -c https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.15.tar.xz; exit'` +再尝试添加 `exit` 命令: + +``` +$ lftp -e 'pget -n 10 -c https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.15.tar.xz; exit'` [Linux-lftp-command-demo][https://www.cyberciti.biz/tips/wp-content/uploads/2007/08/Linux-lftp-command-demo.mp4] ### 关于并行下载的说明 -请注意,通过使用下载加速器,你将增加远程服务器负载。另请注意,lftp 可能无法在不支持多点下载的站点上工作,或者防火墙阻止了此类请求。 +请注意,通过使用下载加速器,你将增加远程服务器负载。另请注意,`lftp` 可能无法在不支持多点下载的站点上工作,或者防火墙阻止了此类请求。 -NA 命令提供了许多其他功能。有关更多信息,请参考 [lftp][2] 的 man 页面: -`man lftp` +其它的命令提供了更多功能。有关更多信息,请参考 [lftp][2] 的 man 页面: + +``` +man lftp +``` ### 关于作者 -作者是 nixCraft 的创建者,经验丰富的系统管理员,也是 Linux 操作系统/Unix shell 脚本的培训师。他曾与全球客户以及IT、教育、国防和太空研究以及非营利部门等多个行业合作。在 [Twitter][9]、[Facebook][10]、[Google +][11] 上关注他。通过[我的 RSS/XML 订阅][5]获取**最新的系统管理、Linux/Unix 以及开源主题教程**。 +作者是 nixCraft 的创建者,经验丰富的系统管理员,也是 Linux 操作系统/Unix shell 脚本的培训师。他曾与全球客户以及IT、教育、国防和太空研究以及非营利部门等多个行业合作。在 [Twitter][9]、[Facebook][10]、[Google +][11] 上关注他。通过 [RSS/XML 订阅][5]获取最新的系统管理、Linux/Unix 以及开源主题教程。 -------------------------------------------------------------------------------- @@ -68,7 +75,7 @@ via: https://www.cyberciti.biz/tips/linux-unix-download-accelerator.html 作者:[Vivek Gite][a] 译者:[geekpi](https://github.com/geekpi) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 From 9bba890ede08d46f938e81ce8063618af3b2c06b Mon Sep 17 00:00:00 2001 From: darksun Date: Sat, 24 Feb 2018 14:13:43 +0800 Subject: [PATCH 016/296] =?UTF-8?q?=E9=80=89=E9=A2=98:=20How=20to=20format?= =?UTF-8?q?=20academic=20papers=20on=20Linux=20with=20groff=20-me?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...academic papers on Linux with groff -me.md | 265 ++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 sources/tech/20180220 How to format academic papers on Linux with groff -me.md diff --git a/sources/tech/20180220 How to format academic papers on Linux with groff -me.md b/sources/tech/20180220 How to format academic papers on Linux with groff -me.md new file mode 100644 index 0000000000..5131cad7f5 --- /dev/null +++ b/sources/tech/20180220 How to format academic papers on Linux with groff -me.md @@ -0,0 +1,265 @@ +How to format academic papers on Linux with groff -me +====== + +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/life_paperclips.png?itok=j48op49T) + +I was an undergraduate student when I discovered Linux in 1993. I was so excited to have the power of a Unix system right in my dorm room, but despite its many capabilities, Linux lacked applications. Word processors like LibreOffice and OpenOffice were years away. If you wanted to use a word processor, you likely booted your system into MS-DOS and used WordPerfect, the shareware GalaxyWrite, or a similar program. + +`nroff` and `troff`. They are different interfaces to the same system: `nroff` generates plaintext output, suitable for screens or line printers, and `troff` generates very pretty output, usually for printing on a laser printer. + +That was my method, since I needed to write papers for my classes, but I preferred staying in Linux. I knew from our "big Unix" campus computer lab that Unix systems provided a set of text-formatting programs calledand. They are different interfaces to the same system:generates plaintext output, suitable for screens or line printers, andgenerates very pretty output, usually for printing on a laser printer. + +On Linux, `nroff` and `troff` are combined as GNU troff, more commonly known as [groff][1]. I was happy to see a version of groff included in my early Linux distribution, so I set out to learn how to use it to write class papers. The first macro set I learned was the `-me` macro package, a straightforward, easy to learn macro set. + +The first thing to know about `groff` is that it processes and formats text according to a set of macros. A macro is usually a two-character command, set on a line by itself, with a leading dot. A macro might carry one or more options. When `groff` encounters one of these macros while processing a document, it will automatically format the text appropriately. + +Below, I'll share the basics of using `groff -me` to write simple documents like class papers. I won't go deep into the details, like how to create nested lists, keeps and displays, tables, and figures. + +### Paragraphs + +Let's start with an easy example you see in almost every type of document: paragraphs. Paragraphs can be formatted with the first line either indented or not (i.e., flush against the left margin). Many printed documents, including academic papers, magazines, journals, and books, use a combination of the two types, with the first (leading) paragraph in a document or chapter flush left and all other (regular) paragraphs indented. In `groff -me`, you can use both paragraph types: leading paragraphs (`.lp`) and regular paragraphs (`.pp`). +``` +.lp + +This is the first paragraph. + +.pp + +This is a standard paragraph. + +``` + +### Text formatting + +The macro to format text in bold is `.b` and to format in italics is `.i`. If you put `.b` or `.i` on a line by itself, then all text that comes after it will be in bold or italics. But it's more likely you just want to put one or a few words in bold or italics. To make one word bold or italics, put that word on the same line as `.b` or `.i`, as an option. To format multiple words in **bold** or italics, enclose your text in quotes. +``` +.pp + +You can do basic formatting such as + +.i italics + +or + +.b "bold text." + +``` + +In the above example, the period at the end of **bold text** will also be in bold type. In most cases, that's not what you want. It's more correct to only have the words **bold text** in bold, but not the trailing period. To get the effect you want, you can add a second argument to `.b` or `.i` to indicate any text that should trail the bolded or italicized text, but in normal type. For example, you might do this to ensure that the trailing period doesn't show up in bold type. +``` +.pp + +You can do basic formatting such as + +.i italics + +or + +.b "bold text" . + +``` + +### Lists + +With `groff -me`, you can create two types of lists: bullet lists (`.bu`) and numbered lists (`.np`). +``` +.pp + +Bullet lists are easy to make: + +.bu + +Apple + +.bu + +Banana + +.bu + +Pineapple + +.pp + +Numbered lists are as easy as: + +.np + +One + +.np + +Two + +.np + +Three + +.pp + +Note that numbered lists will reset at the next pp or lp. + +``` + +### Subheads + +If you're writing a long paper, you might want to divide your content into sections. With `groff -me`, you can create numbered headings (`.sh`) and unnumbered headings (`.uh`). In either, enclose the section title in quotes as an argument. For numbered headings, you also need to provide the heading level: `1` will give a first-level heading (e.g., 1.). Similarly, `2` and `3` will give second and third level headings, such as 2.1 or 3.1.1. +``` +.uh Introduction + +.pp + +Provide one or two paragraphs to describe the work + +and why it is important. + +.sh 1 "Method and Tools" + +.pp + +Provide a few paragraphs to describe how you + +did the research, including what equipment you used + +``` + +### Smart quotes and block quotes + +It's standard in any academic paper to cite other people's work as evidence. If you're citing a brief quote to highlight a key message, you can just type quotes around your text. But groff won't automatically convert your quotes into the "smart" or "curly" quotes used by modern word processing systems. To create them in `groff -me`, insert an inline macro to create the left quote (`\*(lq`) and right quote mark (`\*(rq`). +``` +.pp + +Christine Peterson coined the phrase \*(lqopen source.\*(rq + +``` + +There's also a shortcut in `groff -me` to create these quotes (`.q`) that I find easier to use. +``` +.pp + +Christine Peterson coined the phrase + +.q "open source." + +``` + +If you're citing a longer quote that spans several lines, you'll want to use a block quote. To do this, insert the blockquote macro (`.(q`) at the beginning and end of the quote. +``` +.pp + +Christine Peterson recently wrote about open source: + +.(q + +On April 7, 1998, Tim O'Reilly held a meeting of key + +leaders in the field. Announced in advance as the first + +.q "Freeware Summit," + +by April 14 it was referred to as the first + +.q "Open Source Summit." + +.)q + +``` + +### Footnotes + +To insert a footnote, include the footnote macro (`.(f`) before and after the footnote text, and use an inline macro (`\**`) to add the footnote mark. The footnote mark should appear both in the text and in the footnote itself. +``` +.pp + +Christine Peterson recently wrote about open source:\** + +.(f + +\**Christine Peterson. + +.q "How I coined the term open source." + +.i "OpenSource.com." + +1 Feb 2018. + +.)f + +.(q + +On April 7, 1998, Tim O'Reilly held a meeting of key + +leaders in the field. Announced in advance as the first + +.q "Freeware Summit," + +by April 14 it was referred to as the first + +.q "Open Source Summit." + +.)q + +``` + +### Cover page + +Most class papers require a cover page containing the paper's title, your name, and the date. Creating a cover page in `groff -me` requires some assembly. I find the easiest way is to use centered blocks of text and add extra lines between the title, name, and date. (I prefer to use two blank lines between each.) At the top of your paper, start with the title page (`.tp`) macro, insert five blank lines (`.sp 5` ), then add the centered text (`.(c`), and extra blank lines (`.sp 2`). +``` +.tp + +.sp 5 + +.(c + +.b "Writing Class Papers with groff -me" + +.)c + +.sp 2 + +.(c + +Jim Hall + +.)c + +.sp 2 + +.(c + +February XX, 2018 + +.)c + +.bp + +``` + +The last macro (`.bp`) tells groff to add a page break after the title page. + +### Learning more + +Those are the essentials of writing professional-looking a paper in `groff -me` with leading and indented paragraphs, bold and italics text, bullet and numbered lists, numbered and unnumbered section headings, block quotes, and footnotes. + +I've included a sample groff file to demonstrate all of this formatting. Save the `lorem-ipsum.me` file to your system and run it through groff. The `-Tps` option sets the output type to PostScript so you can send the document to a printer or convert it to a PDF file using the `ps2pdf` program. +``` +groff -Tps -me lorem-ipsum.me > lorem-ipsum.me.ps + +ps2pdf lorem-ipsum.me.ps lorem-ipsum.me.pdf + +``` + +If you'd like to use more advanced functions in `groff -me`, refer to Eric Allman's "Writing Papers with Groff using `−me`," which you should find on your system as `meintro.me` in groff's `doc` directory. It's a great reference document that explains other ways to format papers using the `groff -me` macros. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/18/2/how-format-academic-papers-linux-groff-me + +作者:[Jim Hall][a] +译者:[译者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/jim-hall +[1]:https://www.gnu.org/software/groff/ From a1e57f69aa80d964095a584e9d930f7a9ada16e2 Mon Sep 17 00:00:00 2001 From: darksun Date: Sat, 24 Feb 2018 14:22:30 +0800 Subject: [PATCH 017/296] =?UTF-8?q?=E9=80=89=E9=A2=98:=20The=20List=20Of?= =?UTF-8?q?=20Useful=20Bash=20Keyboard=20Shortcuts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... List Of Useful Bash Keyboard Shortcuts.md | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 sources/tech/20180217 The List Of Useful Bash Keyboard Shortcuts.md diff --git a/sources/tech/20180217 The List Of Useful Bash Keyboard Shortcuts.md b/sources/tech/20180217 The List Of Useful Bash Keyboard Shortcuts.md new file mode 100644 index 0000000000..beba179fee --- /dev/null +++ b/sources/tech/20180217 The List Of Useful Bash Keyboard Shortcuts.md @@ -0,0 +1,161 @@ +The List Of Useful Bash Keyboard Shortcuts +====== +![](https://www.ostechnix.com/wp-content/uploads/2018/02/Bash-720x340.jpg) + +Nowadays, I spend more time in Terminal, trying to accomplish more in CLI than GUI. I learned many BASH tricks over time. And, here is the list of useful of BASH shortcuts that every Linux users should know to get things done faster in their BASH shell. I won’t claim that this list is a complete list of BASH shortcuts, but just enough to move around your BASH shell faster than before. Learning how to navigate faster in BASH Shell not only saves some time, but also makes you proud of yourself for learning something worth. Well, let’s get started. + +### List Of Useful Bash Keyboard Shortcuts + +#### ALT key shortcuts + +1\. **ALT+A** – Go to the beginning of a line. + +2\. **ALT+B** – Move one character before the cursor. + +3\. **ALT+C** – Suspends the running command/process. Same as CTRL+C + +4\. **ALT+D** – Closes the empty Terminal (I.e it closes the Terminal when there is nothing typed). Also deletes all chracters after the cursor. + +5\. **ALT+F** – Move forward one character. + +6\. **ALT+T** – Swaps the last two words. + +7\. **ALT+U** – Capitalize all characters in a word after the cursor. + +8\. **ALT+L** – Uncaptalize all characters in a word after the cursor. + +9\. **ALT+R** – Undo any changes to a command that you have brought from the history if you’ve edited it. + +As you see in the above output, I have pulled a command using reverse search and changed the last characters in that command and revert the changes using **ALT+R**. + +10\. **ALT+.** (note the dot at the end) – Use the last word of the previous command. + +If you want to use the same options for multiple commands, you can use this shortcut to bring back the last word of previous command. For instance, I need to short the contents of a directory using “ls -r” command. Also, I want to view my Kernel version using “uname -r”. In both commands, the common word is “-r”. This is where ALT+. shortcut comes in handy. First run, ls -r command to do reverse shorting and use the last word “-r” in the nex command i.e uname. + +#### CTRL key shortcuts + +1\. **CTRL+A** – Quickly move to the beginning of line. + +Let us say you’re typing a command something like below. While you’re at the N’th line, you noticed there is a typo in the first character +``` +$ gind . -mtime -1 -type + +``` + +Did you notice? I typed “gind” instead of “find” in the above command. You can correct this error by pressing the left arrow all the way to the first letter and replace “g” with “f”. Alternatively, just hit the **CTRL+A** or **Home** key to instantly go to the beginning of the line and replace the misspelled character. This will save you a few seconds. + +2\. **CTRL+B** – To move backward one character. + +This shortcut key can move the cursor backward one character i.e one character before the cursor. Alternatively, you can use LEFT arrow to move backward one character. + +3\. **CTRL+C** – Stop the currently running command + +If a command takes too long to complete or if you mistakenly run it, you can forcibly stop or quit the command by using **CTRL+C**. + +4\. **CTRL+D** – Delete one character backward. + +If you have a system where the BACKSPACE key isn’t working, you can use **CTRL+D** to delete one character backward. This shortcut also lets you logs out of the current session, similar to exit. + +5\. **CTRL+E** – Move to the end of line + +After you corrected any misspelled word in the start of a command or line, just hit **CTRL+E** to quickly move to the end of the line. Alternatively, you can use END key in your keyboard. + +6\. **CTRL+F** – Move forward one character + +If you want to move the cursor forward one character after another, just press **CTRL+F** instead of RIGHT arrow key. + +7\. **CTRL+G** – Leave the history searching mode without running the command. + +As you see in the above screenshot, I did the reverse search, but didn’t execute the command and left the history searching mode. + +8\. **CTRL+H** – Delete the characters before the cursor, same as BASKSPACE. + +9\. **CTRL+J** – Same as ENTER/RETURN key. + +ENTER key is not working? No problem! **CTRL+J** or **CTRL+M** can be used as an alternative to ENTER key. + +10\. **CTRL+K** – Delete all characters after the cursor. + +You don’t have to keep hitting the DELETE key to delete the characters after the cursor. Just press **CTRL+K** to delete all characters after the cursor. + +11\. **CTRL+L** – Clears the screen and redisplay the line. + +Don’t type “clear” to clear the screen. Just press CTRL+L to clear and redisplay the currently typed line. + +12\. **CTRL+M** – Same as CTRL+J or RETURN. + +13\. **CTRL+N** – Display next line in command history. + +You can also use DOWN arrow. + +14\. **CTRL+O** – Run the command that you found using reverse search i.e CTRL+R. + +15\. **CTRL+P** – Displays the previous line in command history. + +You can also use UP arrow. + +16\. **CTRL+R** – Searches the history backward (Reverse search). + +17\. **CTRL+S** – Searches the history forward. + +18\. **CTRL+T** – Swaps the last two characters. + +This is one of my favorite shortcut. Let us say you typed “sl” instead of “ls”. No problem! This shortcut will transposes the characters as in the below screenshot. + +![][2] + +19\. **CTRL+U** – Delete all characters before the cursor (Kills backward from point to the beginning of line). + +This shortcut will delete all typed characters backward at once. + +20\. **CTRL+V** – Makes the next character typed verbatim + +21\. **CTRL+W** – Delete the words before the cursor. + +Don’t confuse it with CTRL+U. CTRL+W won’t delete everything behind a cursor, but a single word. + +![][3] + +22\. **CTRL+X** – Lists the possible filename completions of the current word. + +23\. **CTRL+XX** – Move between start of command line and current cursor position (and back again). + +24\. **CTRL+Y** – Retrieves last item that you deleted or cut. + +Remember, we deleted a word “-al” using CTRL+W in the 21st command. You can retrieve that word instantly using CTRL+Y. + +![][4] + +See? I didn’t type “-al”. Instead, I pressed CTRL+Y to retrieve it. + +25\. **CTRL+Z** – Stops the current command. + +You may very well know this shortcut. It kills the currently running command. You can resume it with **fg** in the foreground or **bg** in the background. + +26\. **CTRL+[** – Equivalent to ESC key. + +#### Miscellaneous + +1\. **!!** – Repeats the last command. + +2\. **ESC+t** – Swaps the last tow words. + +That’s all I have in mind now. I will keep adding more if I came across any Bash shortcut keys in future. If you think there is a mistake in this article, please do notify me in the comments section below. I will update it asap. + +Cheers! + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/list-useful-bash-keyboard-shortcuts/ + +作者:[SK][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[2]:http://www.ostechnix.com/wp-content/uploads/2018/02/CTRLT-1.gif +[3]:http://www.ostechnix.com/wp-content/uploads/2018/02/CTRLW-1.gif +[4]:http://www.ostechnix.com/wp-content/uploads/2018/02/CTRLY-1.gif From fb10104b40494f4a73609332156c44cabc68aca1 Mon Sep 17 00:00:00 2001 From: yizhuyan Date: Sat, 24 Feb 2018 14:31:01 +0800 Subject: [PATCH 018/296] Create 20180131 10 things I love about Vue.md --- .../20180131 10 things I love about Vue.md | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 translated/tech/20180131 10 things I love about Vue.md diff --git a/translated/tech/20180131 10 things I love about Vue.md b/translated/tech/20180131 10 things I love about Vue.md new file mode 100644 index 0000000000..16fae2d64f --- /dev/null +++ b/translated/tech/20180131 10 things I love about Vue.md @@ -0,0 +1,138 @@ +#我喜欢Vue的10个方面 +============================================================ + +![](https://cdn-images-1.medium.com/max/1600/1*X4ipeKVYzmY2M3UPYgUYuA.png) + + + + +我喜欢Vue。当我在2016年第一次接触它时,也许那时我已有了JavaScript框架疲劳的观点,因为我已经具有Backbone, Angular, React等框架的经验 +而且我也没有过度的热情去尝试一个新的框架。直到我在hacker news上读到一份评论,其描述Vue是类似于“新jquery”的JavaScript框架,从而激发了我的好奇心。在那之前,我已经相当满意React这个框架,它是一个很好的框架,基于可靠的设计原则,围绕着视图模板,虚拟DOM和状态响应等技术。而Vue也提供了这些重要的内容。在这篇文章中,我旨在解释为什么Vue适合我,为什么在上文中那些我尝试过的框架中选择它。也许你将同意我的一些观点,但至少我希望能够给大家关于使用Vue开发现代JavaScript应用的一些灵感。 + +##1\. 极少的模板语法 + +Vue默认提供的视图模板语法是极小的,简洁的和可扩展的。像其他Vue部分一样,可以很简单的使用类似JSX一样语法而不使用标准的模板语法(甚至有官方文档说明如何这样做),但是我觉得没必要这么做。关于JSX有好的方面,也有一些有依据的批评,如混淆了JavaScript和HTML,使得很容易在模板中编写出复杂的代码,而本来应该分开写在不同的地方的。 + +Vue没有使用标准的HTML来编写视图模板,而是使用极少的模板语法来处理简单的事情,如基于视图数据迭代创建元素。 +``` + + + + + +``` + + +我也喜欢Vue提供的简短绑定语法,“:”用于在模板中绑定数据变量,“@”用于绑定事件。这是一个细节,但写起来很爽而且能够让你的组件代码简洁。 + +##2\. 单文件组件 + +大多数人使用Vue,都使用“单文件组件”。本质上就是一个.vue文件对应一个组件,其中包含三部分(CSS,HTML和JavaScript) + +这种技术结合是对的。它让人很容易理解每个组件在一个单独的地方,同时也非常好的鼓励了大家保持每个组件代码的简短。如果你的组件中JavaScript,CSS和HTML代码占了很多行,那么就到了进一步模块化的时刻了。 + +在使用Vue组件中的 -``` - - -I also like the short-bindings provided by Vue, ‘:’ for binding data variables into your template and ‘@’ for binding to events. It’s a small thing, but it feels nice to type and keeps your components succinct. - -2\. Single File Components - -When most people write Vue, they do so using ‘single file components’. Essentially it is a file with the suffix .vue containing up to 3 parts (the css, html and javascript) for each component. - -This coupling of technologies feels right. It makes it easy to understand each component in a single place. It also has the nice side effect of encouraging you to keep your code short for each component. If the JavaScript, CSS and HTML for your component is taking up too many lines then it might be time to modularise further. - -When it comes to the