Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2019-10-11 09:53:12 +08:00
commit 730fe42b0e
11 changed files with 774 additions and 555 deletions

View File

@ -1,8 +1,8 @@
[#]: collector: (lujun9972)
[#]: translator: (wxy)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-11444-1.html)
[#]: subject: (7 steps to securing your Linux server)
[#]: via: (https://opensource.com/article/19/10/linux-server-security)
[#]: author: (Patrick H. Mullins https://opensource.com/users/pmullins)
@ -12,7 +12,7 @@
> 通过七个简单的步骤来加固你的 Linux 服务器。
![computer servers processing data][1]
![](https://img.linux.net.cn/data/attachment/album/201910/11/094107k8skl8wwxq62pzld.jpg)
这篇入门文章将向你介绍基本的 Linux 服务器安全知识。虽然主要针对 Debian/Ubuntu但是你可以将此处介绍的所有内容应用于其他 Linux 发行版。我也鼓励你研究这份材料,并在适用的情况下进行扩展。
@ -86,7 +86,7 @@ PermitRootLogin no
AddressFamily inet
```
重新启动 SSH 服务以启用你的更改。请注意,在重新启动 SSH 服务之前,与服务器建立两个活动连接是一个好主意。有了这些额外的连接,你可以在重新启动出错的情况下修复所有问题。
重新启动 SSH 服务以启用你的更改。请注意,在重新启动 SSH 服务之前,与服务器建立两个活动连接是一个好主意。有了这些额外的连接,你可以在重新启动 SSH 服务出错的情况下修复所有问题。
在 Ubuntu 上:
@ -102,7 +102,7 @@ $ sudo systemctl restart sshd
### 5、启用防火墙
现在你需要安装防火墙、启用防火墙并对其进行配置以仅允许你指定的网络流量。Ubuntu 上的)[简单的防火墙][3]UFW是一个易用的 iptables 界面,可大大简化防火墙的配置过程。
现在,你需要安装防火墙、启用防火墙并对其进行配置,以仅允许你指定的网络流量通过Ubuntu 上的)[简单的防火墙][3]UFW是一个易用的 iptables 界面,可大大简化防火墙的配置过程。
你可以通过以下方式安装 UFW
@ -140,7 +140,7 @@ $ sudo ufw disable
你还可以(在 RHEL/CentOS 上)使用 [firewall-cmd][4],它已经安装并集成到某些发行版中。
### 6、安 Fail2ban
### 6、安 Fail2ban
[Fail2ban][5] 是一种用于检查服务器日志以查找重复或自动攻击的应用程序。如果找到任何攻击,它会更改防火墙以永久地或在指定的时间内阻止攻击者的 IP 地址。
@ -170,13 +170,13 @@ $ sudo fail2ban-client status ssh
### 7、移除无用的网络服务
几乎所有 Linux 服务器操作系统都启用了一些面向网络的服务。你可能希望保留其中大多数,然而,有一些你或许希望删除。你可以使用 `ss` 命令查看所有正在运行的网络服务LCTT 译注:应该是只保留少部分,而所有可用确认无关的、无用的服务都应该停用或删除。)
几乎所有 Linux 服务器操作系统都启用了一些面向网络的服务。你可能希望保留其中大多数,然而,有一些你或许希望删除。你可以使用 `ss` 命令查看所有正在运行的网络服务LCTT 译注:应该是只保留少部分,而所有确认无关的、无用的服务都应该停用或删除。)
```
$ sudo ss -atpu
```
`ss` 的输出将取决于你的操作系统。这是一个可能的示例。它显示 SSH`sshd`)和 Ngnix`nginx`)服务正在侦听网络并准备连接:
`ss` 的输出取决于你的操作系统。下面是一个示例,它显示 SSH`sshd`)和 Ngnix`nginx`)服务正在侦听网络并准备连接:
```
tcp LISTEN 0 128 *:http *:* users:(("nginx",pid=22563,fd=7))
@ -185,7 +185,7 @@ tcp LISTEN 0 128 *:ssh *:* users:(("sshd",pid=685,fd=3))
删除未使用的服务的方式因你的操作系统及其使用的程序包管理器而异。
删除 Debian / Ubuntu 上未使用的服务:
在 Debian / Ubuntu 上删除未使用的服务:
```
$ sudo apt purge <service_name>
@ -201,7 +201,7 @@ $ sudo yum remove <service_name>
### 总结
本教程介绍了加固 Linux 服务器所需的最起码的措施。可以并且应该根据服务器的使用方式启用其他安全层。这些安全层可以包括诸如各个应用程序配置、入侵检测软件IDS以及启用访问控制例如双因素身份验证之类的东西。
本教程介绍了加固 Linux 服务器所需的最起码的措施。应该根据服务器的使用方式启用其他安全层。这些安全层可以包括诸如各个应用程序配置、入侵检测软件IDS以及启用访问控制例如双因素身份验证之类的东西。
--------------------------------------------------------------------------------
@ -210,7 +210,7 @@ via: https://opensource.com/article/19/10/linux-server-security
作者:[Patrick H. Mullins][a]
选题:[lujun9972][b]
译者:[wxy](https://github.com/wxy)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -0,0 +1,87 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (“Open Standards Are The Key To Expanding IoT Innovation In India Market”)
[#]: via: (https://opensourceforu.com/2019/10/open-standards-are-the-key-to-expanding-iot-innovation-in-india-market/)
[#]: author: (Ankita KS https://opensourceforu.com/author/ankita-ks/)
“Open Standards Are The Key To Expanding IoT Innovation In India Market”
======
[![][1]][2]
_With IoT creating a new digital realm today, it brings along intense connectivity requirements and standards for them to communicate with other devices through a common protocol. For these reasons, interoperability is the most defining and crucial element in the Internet of Things. To understand the landscape of IoT in India, the standards and interoperability challenges and the solutions for that **Ankita KS, Senior Technology Journalist** from **EFY group** spoke to **Dr. Aloknath De, Corporate Vice President**, and **Chief Technology Officer, Samsung R&amp;D Institute India Bangalore**. Excerpts follow.._
**Q: Many opine that IoT is just a buzzword coined to create hype by marketers? Do you agree with that line of thought? Or do you feel that IoT is opening an entirely new market?**
**A.** IoT is not hype; so, I could not disagree more with that line of thought. I view IoT not only as Internet of Things, but also as Integration of Technologies. It allows multiple protocols for connectivity, various cloud technologies and humongous amounts of sensor data. Also, as multiple stakeholders are involved in this process of integration, every stakeholder has to be brought together, business cases have to be analyzed and revenue models have to be evolved. This process is time-consuming and takes efforts to fructify.
**Q: In the past year what are the new developments in R&amp;D with respect to IoT globally?**
**A.** Globally, different IoT technologies have emerged and some have been embraced. You can see new types of devices getting connected to the internet; this would not have been thought of 5 years ago. In the Home context, I group these IoT devices into three broad classes. First is the Elephant Class comprising of large appliances like Refrigerator, washing machine, AC, Television which sits in its primary location. Second is the Horse Class comprising of Speaker, Smartphone, Smart Watch that “trots” with the person. And the Third is the Rat Class comprising of smaller sensors like the thermostat, door sensor, occupancy sensor. Some of these devices do not benefit always from data, but they enrich the IoT system by feeding sensor data. Like the Smart Home scenario, we can also define devices in the context of Manufacturing, Industry and other verticals.
Standards are emerging to cover multiple layers in IoT. Plug-fests are being done across the globe to test interoperability. Companies are investing in R&amp;D to make devices smarter, securer and interoperable. Also, a trend is emerging in the control of home appliances over voice interactions. IoT in R&amp;D is changing gears from mere automation to predictive services. Sense, Analyze, React paradigm is shifting to Sense, Analyze and Proact.
**Q. Are you satisfied at the rate of deployment of IoT solutions in India?**
**A.** Both Yes and No. The rate of deployment of IoT is different for different verticals. For some verticals, like Smart Home, Smart Manufacturing and Smart Logistics, its relatively going good. You can see smart security and surveillance being adopted in apartment complexes; predictive maintenance being adopted for heavy machinery in the industries; asset tracking and monitoring being adopted in Smart Logistics.
Whereas for some verticals like Smart Cities initial steps have been taken. And then some verticals require more attention to resolve major technical challenges like Connected Healthcare (e.g. electronic health records, health regulations) and Smart Agriculture (e.g. Open spaces, placement of sensors, etc.). Overall, the Indian IoT market is still at its infancy; I would say in the exploratory phase with use cases being piloted primarily in the Home, Manufacturing and Logistics verticals.
**Q. How do you see the IoT market (in India) evolving in the next 2-3 years?**
**A.** In the next 2-3 years, we expect the number of connected devices in India to increase significantly with demand generating from both consumer and industrial applications. Nasscom predicts that there will be 2.7 billion connected devices by 2020, leading to an economic impact of up to $15B USD. Indian IoT market will represent more than 5% of the global market size. However, more than half of this market growth is locked by the lack of interoperability standards. Standards will play a major role in bringing in the required interoperability and reducing the lead time to develop IoT solutions and services. Smaller companies including startups will join hands with the MNCs to participate in a bigger ecosystem as IoT is purely an ecosystem play rather than an individual company trying to solve problems.
**Q. Which industry segments do you believe will be driving a larger chunk of demand for IoT in India? Why?**
**A.** On the consumer side, Smart Home and Building has been driving the demand for IoT as of today. Real Estate developers are offering Smart Homes with lighting automation and security as primary solutions. Access control, Smart Street Lighting, Common area surveillance are some primary use cases which are being deployed in a real-world scenario.
On the Enterprise side, Smart Manufacturing and Logistics drive major demand. Predictive maintenance of machinery is a high revenue-driven business case helping in the drastic reduction of losses by tracking the downtime/uptime of machinery. Asset tracking and management have been there for a while but with multiple IoT sensors coming in like temperature, moisture, weight, etc., the continuous monitoring and tracking of the assets has improved inaccuracy.
**Q. Almost everyone agrees that there is a dire need for standards for the IoT ecosystem to develop. And this is being stated for quite some time now. Whats causing the delay? Whats missing that needs to happen?**
**A.** India has moved from what and why to how in its IoT journey and evolution. IoT standards are still a work in progress in terms of its adoption. There are multiple standards available in the market with overlapping functionalities using different technical approaches battling out for IoT dominance. Some technologies are less proven than the others and so the goal of the standards body has to be to legitimize the technology and make customers feel safe in adopting it. Open standards are the key to expanding IoT innovation in India market. With open standards, there is a higher chance of finding the right resources to integrate the required technology into a successful IoT solution.
**Q. For someone new to the concept—how would you explain the challenges caused by the lack of standards (interoperability)?**
**A.** With the rise of connected things and machines, there will be billions of connected devices including sensors, appliances, and machinery, etc. generating terabytes of data. Security becomes one of the biggest concerns with this much number of devices and data. Also, the IoT market has become so fragmented that it has led to the development of multiple vertical-specific standards, various connectivity protocols and smaller groups working towards solving individual problems. What the industry needs is a secure consolidation of standards to achieve true interoperability.
**Q. What are the key areas in which standards needed first?**
**A.** Smart Manufacturing and Industry 4.0 would need the standards first. The Industrial Internet Consortium has already started working towards defining the standards for the industry vertical. It also has a liaison with the Open Connectivity Foundation to combine the best of both the frameworks. Smart Homes in India would not work in the Do-It-Yourself mode at least in the coming 2-3 years. The market penetration will happen primarily through the Real Estate Builders (B2B2C) working closely with System Integrators. So, the devices going into the homes needs to be standardized for seamless deployment of the smart home solution. Connected Health would be next and Agriculture a good to have.
**Q. Would there be a need for different standards for different nations (e.g. India) or would it better to adopt global standards?**
**A.** Significant portions of Standards are applicable globally. However, every nation has its own set of requirements. For example, a connected fan is something which could be found only in India and other emerging countries. But building a standard from scratch for a specific country needs a lot of resources, time and investment. Bringing in best practices from global markets opens up a lot of opportunities for companies to learn from and also customize based on the country-specific requirements on top of the established core framework. Also, companies get access to a bigger global ecosystem by adopting global standards.
Global standards are working together in a unified approach to address specific requirements and bring in the best of both through consolidation. One such example is the Asymmetrical bridge function between oneM2M and OCF exposing proximal OCF devices to distal oneM2M devices. While OCF is a device-centric common addressing framework with the current focus on Smart Home, oneM2M is a cloud service layer with a focus on Smart Cities; Working in tandem, they open up a whole new set of use cases and standards interworking.
**Q. How does OCF aim to solve this challenge of standards &amp; interoperability?**
**A.** OCF stands for Open Connectivity Foundation. It is an open-source consortium that delivers “just-works” interconnectivity for developers, manufacturers, and end-users. Through a common communication framework, OCF connects and manages information flow intelligently among devices. This framework is agnostic of device form factor, the operating system, manufacturer or even service provider
**Q. What category of standards is OCF working on? And thats not within OCFs domain, but important for the IoT eco-system?**
**A.** OCFs current focus is developing Standards for Smart Home and Buildings. It aims to build Standards for Health, Automotive, and Industry; possibly in conjunction with partners going forward. But OCFs common addressing scheme and the core framework enables it to be easily adapted into other verticals
**Q. What is the main vision and objectives behind OCF India Forum?**
**A.** OCF India Forum is a local chapter of OCF established in April 2019 with 45+ member companies and Nasscom CoE IoT as its Executive Office. The OCF India Steering Committee comprises of representatives from Nasscom, Samsung, Intel, L&amp;T Technology Services and Granite River Labs.
OCF Indias vision and objectives are twofold, one is to facilitate small size companies including SMEs &amp; startups to easily build interoperable IoT products using the Open Source implementation of OCF spec (IoTivity) The second is to build &amp; Engage the Indian IoT Ecosystem including Industry, Startups, University, Government, Dev community to work towards a common cause of IoT Standardization.
**Q. What should happen within the next year, and the next three years—to indicate that OCF India is succeeding in its charter?**
**A.** Within a year more companies joining OCF India Forum; with 50 in 2019 and overall 100+ by 2020 and the developer community contributing actively into IoTivity. In the next 3 years, Indian MNCs will be adopting OCF to create a bigger IoT ecosystem for the startups. OCF is recognized as a National Standard alongside oneM2M covering proximal and distal devices and OCF will have a certification lab in India.
**Q. What role are partners like NASSCOM playing in enabling OCF India to achieve its mission?**
**A.** The Center of Excellence (CoE) for IoT is a joint an initiative of Nasscom, MeiTy, and ERNET. It was established in India to jump-start the Indian IoT ecosystem by helping IoT startups to leverage cutting edge technology &amp; build market-ready products. Nasscom CoE IoT will serve as the Executive Office of OCF India Forum. Having a neutral entity represent and drive the Standards the initiative encourages faster ecosystem growth and adoption. With a well-established network of Industry, Academia, Startups and Government, Nasscom CoE IoT will help OCF India towards a much-focused ecosystem engagement drive.
**Q. Any initiatives executed, and any planned in the near future—by OCF India?**
**A.** OCF India has been participating in IoT events across India since 2018 in the form of Seminar, Exhibition Booth &amp; Workshop; To name a few IoTShow 2019, 3rd IoT India Expo 2019, 7th IoT Symposium 2018. Series of hands-on workshops are planned to engage the govt and dev community. Also, in line are some of the premiere IoT events in India where OCF India will participate this year like IoT India Congress 2019, IoTNext 2019. The Flagship event “OCF India Day” co-located with Open Source India 2019
--------------------------------------------------------------------------------
via: https://opensourceforu.com/2019/10/open-standards-are-the-key-to-expanding-iot-innovation-in-india-market/
作者:[Ankita KS][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensourceforu.com/author/ankita-ks/
[b]: https://github.com/lujun9972
[1]: https://i0.wp.com/opensourceforu.com/wp-content/uploads/2019/09/samsung-aloknath.jpg?resize=640%2C360&ssl=1 (samsung-aloknath)
[2]: https://i0.wp.com/opensourceforu.com/wp-content/uploads/2019/09/samsung-aloknath.jpg?fit=640%2C360&ssl=1

View File

@ -0,0 +1,153 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Top 10 open source video players for Linux)
[#]: via: (https://opensourceforu.com/2019/10/top-10-open-source-video-players-for-linux/)
[#]: author: (Stella Aldridge https://opensourceforu.com/author/stella-aldridge/)
Top 10 open source video players for Linux
======
[![][1]][2]
_Choosing the right video player can help ensure that you get the optimum viewing experience, and give you the tools to [create a video website][3]. You can even allow you to customize the videos you are watching to your personal preferences too._
So to help enable you to pick the best player for your needs, weve curated a list of the top open source video players for Linux.
Lets take a look:
**1\. XBMC Kodi Media Center**
This is a flexible cross-platform player, written with C++ as core and with Python Scripts as add ons are available. The benefits of using Kodi include:
* Available in over 69 languages
* Users can play audio and video files and media player files from the network and local storage
* Can be used alongside JeOS in devices such as Smart TV and set-top boxes as an application suite
* Theres loads of impressive add ons such as video and audio streaming plugins, themes, screensaver and more
* It supports multiple formats such as MPEG-1,2,4, RealVideo, HVC, HEVC and so on
**2\. VLC Media Player**
This player was a no brainer for this list due to its impressive power and availability on a range of operating systems. It is written in C, C++ and Objective C and users can eliminate the need for figuring out plugins thanks to its extensive support of decoding libraries. The benefits of VLC Media Player include:
* Provides support for DVD players on Linux
* Ability to play .iso files
* Enables high definition recordings of D-VHS tapes to be played
* Can be run from a USB flash drive or external drive directly
* API support and browser support (via plugin)
**3\. Bomi (CMPlayer)**
This flexible and highly powered player ticks most of the boxes of a general user, and its positives are:
* Simple to use graphical user interface (GUI)
* Impressive playback ability
* Option to resume playback
* Supports subtitles and can render multiple subtitle files
**[![][4]][5]4\. Miro Music and Video Player**
Previously called Democracy Player (DTV), Miro was redeveloped by Participatory Culture Foundation and is a good cross-platform player for both video and audio. Its impressive because:
* Supportive of some HD Audio and Video
* Available in over 40 languages
* Can play numerous file formats, e.g., QuickTime, WMV, MPEG files, Audio Video Interface (AVI), XVID
* Can notify the user and download a video automatically once available
**5\. SMPlayer**
This cross-platform media player, written only using Qt library in C++ is a powerful, multi-functional player. We like it because:
* It has multi-language options
* Supportive of all default formats
* Supportive of EDL files, and you can configure subtitles fetched from the Internet
* A variety of Skins that can be downloaded from the Internet
* Multiple speed playback
**6\. MPV Player**
Written in C, Objective-C, Lua, and Python, its free, easy to use and has lots of new features which make it enjoyable to use. The main plus points are:
* Can be compiled as a library which uncovers client APIs which leads to increased control
* Functionality that allows Media Encoding
* Smooth-motion
**7\. Deepin Movie**
This player is an excellent example of an open source media player which has lots of positives, including:
* The ability to complete all play operations by keyboard
* Video files in various formats can be played through this player with ease
* The streaming function allows users to enjoy many online video resources
**8\. Gnome Videos**
Previously called Totem, for those with Gnome desktop environments, this is the player of choice.
Written purely in C this was built by using GStreamer multimedia framework for playback, and the other version (&gt; 2.7.1) was then configured using xine libraries as a backend. Its great because:
It has an impressive ability to support numerous formats including:
* SHOUTcast, SMIL, M3U, Windows Media Player format and more
* You can adjust light settings such as brightness and contrast during playback
* Loads SubRip subtitles
* Supports for direct video playback from Internet channels such as Apple
**9\. Xine Multimedia Player**
An additional cross-platform multimedia player in our list written in C. Its a good all-round player because:
* It supports physical media as well as Video Devices. Think 3gp, Matroska, MOV, Mp4, Audio formats,
* Network Protocols, V4L, DVB, and PVR to name but a few
* It can correct the synchronization of audio and video streams manually
**10\. ExMPlayer**
Last but not least, ExMPlayer is a stunning, powerfully built GUI front-end for MPlayer. Its benefits include:
* Can play any media format
* Supports network streaming and subtitles
* Easy to use an audio converter
* High-quality audio extraction without compromising on sound quality
The abovementioned video players work well on Linux. We would recommend you to try them out and choose the most suitable for you.
--------------------------------------------------------------------------------
via: https://opensourceforu.com/2019/10/top-10-open-source-video-players-for-linux/
作者:[Stella Aldridge][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensourceforu.com/author/stella-aldridge/
[b]: https://github.com/lujun9972
[1]: https://i2.wp.com/opensourceforu.com/wp-content/uploads/2019/10/Depositphotos_50337841_l-2015.jpg?resize=696%2C585&ssl=1 (Depositphotos_50337841_l-2015)
[2]: https://i2.wp.com/opensourceforu.com/wp-content/uploads/2019/10/Depositphotos_50337841_l-2015.jpg?fit=900%2C756&ssl=1
[3]: https://www.ning.com/create-video-website/
[4]: https://i2.wp.com/opensourceforu.com/wp-content/uploads/2019/10/Depositphotos_20380441_l-2015.jpg?resize=350%2C231&ssl=1
[5]: https://i2.wp.com/opensourceforu.com/wp-content/uploads/2019/10/Depositphotos_20380441_l-2015.jpg?ssl=1

View File

@ -1,118 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (3 quick tips for working with Linux files)
[#]: via: (https://www.networkworld.com/article/3440035/3-quick-tips-for-working-with-linux-files.html)
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
3 quick tips for working with Linux files
======
Linux provides lots of commands for finding, counting, and renaming files. Here's a look at some useful choices.
[GotCredit][1] [(CC BY 2.0)][2]
Linux provides a wide variety of commands for working with files — commands that can save you time and make your work a lot less tedious.
### Finding files
When you're looking for files, the **find** command is probably going to be the first command to come to mind, but sometimes a well-crafted **ls** command works even better. Want to remember what you called that script you were working on last night before you fled the office and drove home? Easy! Use an **ls** command with the **-ltr** options. The last files listed will be the ones most recently created or updated.
```
$ ls -ltr ~/bin | tail -3
-rwx------ 1 shs shs 229 Sep 22 19:37 checkCPU
-rwx------ 1 shs shs 285 Sep 22 19:37 ff
-rwxrw-r-- 1 shs shs 1629 Sep 22 19:37 test2
```
A command like this one will list only the files that were updated today:
```
$ ls -al --time-style=+%D | grep `date +%D`
drwxr-xr-x 60 shs shs 69632 09/23/19 .
drwxrwxr-x 2 shs shs 8052736 09/23/19 bin
-rw-rw-r-- 1 shs shs 506 09/23/19 stats
```
If the files you're looking for might not be in the current directory, the **find** command is going to provide better options than **ls**, but it can also result in a lot more output than you want to peruse. In this command, we're avoiding searching in directories that do _not_ begin with dots (many of those get updates all the time), specifying that we want to find files (i.e., not directories) and requesting that we only be shown files that were updated within the last day (-mtime -1).
```
$ find . -not -path '*/\.*' -type f -mtime -1 -ls
917517 0 -rwxrw-r-- 1 shs shs 683 Sep 23 11:00 ./newscript
```
Notice how the **-not** option reverses the **-path** specification, so our search doesn't dive into subdirectories that begin with dots.
If you want to find only the largest files and directories, you can use a command like this **du** command that lists the contents of the current directory by size. Pipe the output to **tail** to see only the largest few.
```
$ du -kx | egrep -v "\./.+/" | sort -n | tail -5
918984 ./reports
1053980 ./notes
1217932 ./.cache
31470204 ./photos
39771212 .
```
The **-k** option gets **du** to list file sizes in blocks, while **x** keeps it from traversing directories that are on other file systems (e.g., referenced through symbolic links). The fact that the **du** listing starts with the file sizes allows the sort by size (sort -n) to work.
### Counting files
Counting files in any particular directory is fairly easy with the **find** command. You just have to remember that find will recurse into subdirectories and will count the files in those subdirectories along with those in the current directory. In this command, we are counting files in one particular user's home directory. Depending on permissions on home directories, this may require the use of **sudo**. Remember that the first argument is the starting point for the search — in this case, the specified user's home directory.
```
$ find ~username -type f 2>/dev/null | wc -l
35624
```
Note that we're sending error output from the **find** command above to the bit bucket to avoid trying to search directories like ~username/.cache that we likely cannot search and the content of which is probably not of interest.
When needed, you can constrain **find** to a single directory using the **maxdepth 1** option:
```
$ find /home/shs -maxdepth 1 -type f | wc -l
387
```
### Renaming files
Files are easy to rename with the **mv** command, but sometimes you will want to rename large collections of files and likely won't want to spend a lot of time doing it. To change all the blanks that you might find in file names in the current directory to underscores, for example, you could use a command like this:
```
$ rename 's/ /_/g' *
```
The **g** in this command, as you likely suspect, means "global." That means the command will change _all_ blanks in a file name to underscores, not just the first one.
To drop the .txt extension from text files, you could use a command like this:
```
$ rename 's/.txt//g' *
```
### Wrap-up
The Linux command line provides a lot of useful options for manipulating files. Please suggest other commands that you find especially useful.
**[ Two-Minute Linux Tips: [Learn how to master a host of Linux commands in these 2-minute video tutorials][3] ]**
Join the Network World communities on [Facebook][4] and [LinkedIn][5] to comment on topics that are top of mind.
--------------------------------------------------------------------------------
via: https://www.networkworld.com/article/3440035/3-quick-tips-for-working-with-linux-files.html
作者:[Sandra Henry-Stocker][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/
[b]: https://github.com/lujun9972
[1]: https://www.flickr.com/photos/gotcredit/33756797815/in/photolist-TqYpVr-ot3MbP-8GVk75-bDgdSV-d8UqyY-8A1Nvm-bDgHMT-3StdY-c3CSTq-9gXm8m-piEdt6-9Jme84-ao7jBT-9gUejH-9gpPtR-XzrMMD-bqn8Qs-bDa1AK-oV87g2-bqn8SE-7hKg3v-CyDj5-bDgHKF-ppTzHf-84Czrj-dWf3MY-eDXW3i-5nTPZb-oaFrev-bqf6Rw-58EpAQ-5bd2t8-9eyUFb-5zNBi9-6geKFz-ngaqHa-6zDJtt-bvJrAQ-28v4k1Y-6s2qrs-3fPsLz-hDNitm-4nfhZC-7dZYt1-PUTxVi-4nuP2y-bDgdVg-96HPjm-bce6J8-5Mnhy
[2]: https://creativecommons.org/licenses/by/2.0/legalcode
[3]: https://www.youtube.com/playlist?list=PL7D2RMSmRO9J8OTpjFECi8DJiTQdd4hua
[4]: https://www.facebook.com/NetworkWorld/
[5]: https://www.linkedin.com/company/network-world

View File

@ -1,152 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (3 command line games for learning Bash the fun way)
[#]: via: (https://opensource.com/article/19/10/learn-bash-command-line-games)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
3 command line games for learning Bash the fun way
======
Learning useful Bash skills can be fun with these command line games.
![connecting yellow dots in a maze][1]
Learning is hard work, and nobody likes work. That means no matter how easy it is to learn Bash, it still might feel like work to you. Unless, of course, you learn through gaming.
You wouldn't think there would be many games out there to teach you how to use a Bash terminal, and you'd be right. Serious PC gamers know that the Fallout series features terminal-based computers in the vaults, which helps normalize the idea of interfacing with a computer through text, but in spite of featuring applications more or less like [Alpine][2] or [Emacs][3], playing Fallout doesn't teach you commands or applications you can use in real life. The Fallout series was never ported to Linux directly (although it is playable through Steam's open source [Proton][4]. The modern entries into the [Wasteland series][5] that served as predecessors to Fallout, however, do target Linux, so if you want to experience in-game terminals, you can play [Wasteland 2][6] and [Wasteland 3][7] on your Linux gaming PC. The [Shadowrun][8] series also targets Linux, and it features a lot of terminal-based interactions, although it's admittedly often overshadowed by blazing [hot sim][9] sequences. 
While those games take a fun approach to computer terminals, and they run on open source systems, none are open source themselves. There are, however, at least two games that take a serious, and seriously fun, approach to teaching people how to interact with systems through text commands. And best of all, they're open source.
### Bashcrawl
You may have heard of [Colossal Cave Adventure][10], an old text-based, interactive game in the style of "choose your own adventure" books. Early computerists played these obsessively at the DOS or ProDOS command line, struggling to find the right combination of valid syntax and zany fantasy logic (as interpreted by a sardonic hacker) to beat the game. Imagine how productive such a struggle could be if the challenge, aside from exploring a virtual medieval dungeon, was to recall valid Bash commands. That's the pitch for **[Bashcrawl][11]**, a Bash-based dungeon crawl you play by learning and using Bash commands.
In Bashcrawl, a "dungeon" is created in the form of directories and files on your computer. You explore the dungeon by using the **cd** command to change directory into each room of the dungeon. As you [proceed through directories][12], you examine files with **[ls -F][13]**, read files with **[cat][14]**, [set variables][15] to collect treasure, and run scripts to fight monsters. Everything you do in the game is a valid Bash command that you can use later in real life, and playing the game provides Bash practice because the "game" is made out of actual directories and files on your computer.
```
$ cd entrance/
$ ls
cellar  scroll
$ cat scroll
It is pitch black in these catacombs.
You have a magical spell that lists all items in a room.
To see in the dark, type:     ls
To move around, type:         cd &lt;directory&gt;
Try looking around this room.
Then move into one of the next rooms.
EXAMPLE:
$ ls
$ cd cellar
Remember to cast ``ls`` when you get into the next room!
$
```
#### Install Bashcrawl
Before you can play Bashcrawl, you must have Bash or [Zsh][16] on your system. Linux, BSD, and MacOS ship with Bash included. Windows users can download and install [Cygwin][17] or [WSL][18] or [try Linux][19].
To install Bashcrawl, navigate to [GitLab][11] in Firefox or your web browser of choice. On the right side of the page, click the **Download** icon (to the right of the **Find file** button).
In the **Download** pop-up menu, click the **Zip** button to download the latest version of the game.
* * *
* * *
* * *
**![Download a zip from Gitlab][20]**
Once it's downloaded, unzip the archive.
Alternatively, if you want to start working in the terminal right away, you can use [Git][21]:
```
`$ git clone https://gitlab.com/slackermedia/bashcrawl.git bashcrawl`
```
#### Getting started
As with almost any new software package you download, the first thing you must do is read the README file. You can do this by double-clicking on the **README.md** file in the **bashcrawl** directory. On a Mac, your computer may not know what application to use to open the file; you can use any text editor or LibreOffice. **README.md** tells you exactly how to start playing the game, including how to get to the game in your terminal and the first command you must issue to start the game. If you fail to read the README file, the game wins by default (although it can't tell you that because you won't have played it).
Bashcrawl isn't meant to be overly clever or advanced. On the contrary, it's as simple as it possibly can be in the interest of being transparent to new users. Ideally, a new Bash user can learn some of the basics of Bash from the game, and then stumble upon the mechanics of the game, including the simple scripts that make it run, and learn still more Bash. Additionally, new Bash users can design their own dungeon by following the examples of Bashcrawl's existing content, and there's no better way to learn to code than to make a game.
### Command Line Heroes: BASH
Bashcrawl is meant for absolute beginners. If you use Bash on a regular basis, you'll very likely try to outsmart Bashcrawl by looking at files in ways that a beginner doesn't know yet. If you're an intermediate or advanced Bash user, then you should try **[Command Line Heroes: BASH][22]**.
The game is simple: Type in as many valid commands you can think of during a given amount of time. It sounds simple. As a Bash user, you use lots of commands every day. As a Linux user, you know where to find lists of commands; the **util-linux** package alone contains over 100 commands! The question is, are any of those commands available at your fingertips under the pressure of a countdown?
![Command Line Heroes: BASH][23]
This game sounds simple because it is! In principle, it's similar to flashcards, only in reverse. In practice, it's a fun way to test your knowledge and recall. And of course, it's open source, having been developed by the creators of [Open Jam][24].
#### Installing
You can play Command Line Heroes: Bash [online][25], or you can download the source code from [GitHub][26].
The game is written in Node.js, so unless you want to help develop the game, it makes sense to just play it online.
### Minesweeper in Bash
If you're an advanced Bash user, and you've written several Bash scripts, then you're probably beyond just learning Bash. For a real challenge, you might try programming a game instead of playing one. With a little thought and an afternoon or three of work, the popular game **Minesweeper** can be implemented entirely in Bash. You can try writing the game yourself first, then refer to [Abhishek Tamrakar's][27] article for an overview of how he accomplished it.
![][28]
Sometimes programming doesn't have a purpose but to educate. Programming a game in Bash may not be the project you'll stake your online reputation on, but the process can be fun and enlightening. And facing a problem you never expected to face is a great way to learn new tricks.
### Learn Bash; have fun
Regardless of how you approach learning it, Bash is a powerful interface because it gives you the ability to direct your computer to do what you want without going through the "middleman" interface of a GUI application. Sometimes a GUI is very helpful, but other times you want to graduate from something you know all too well and move to something you can do quickly or through automation. Because Bash is text-based, it's easy to script, making it a great starting point for automated jobs.
Learn Bash to start becoming a power user. But make sure you have fun doing it.
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/10/learn-bash-command-line-games
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/LAW_maze.png?itok=mZ5LP4-X (connecting yellow dots in a maze)
[2]: https://opensource.com/article/17/10/alpine-email-client
[3]: http://www.gnu.org/software/emacs
[4]: https://github.com/ValveSoftware/Proton/
[5]: https://www.gog.com/game/wasteland_the_classic_original
[6]: https://www.inxile-entertainment.com/wasteland2
[7]: https://www.inxile-entertainment.com/wasteland3
[8]: http://harebrained-schemes.com/games/
[9]: https://forums.shadowruntabletop.com/index.php?topic=21804.0
[10]: https://opensource.com/article/18/12/linux-toy-adventure
[11]: https://gitlab.com/slackermedia/bashcrawl
[12]: https://opensource.com/article/19/8/understanding-file-paths-linux
[13]: https://opensource.com/article/19/7/master-ls-command
[14]: https://opensource.com/article/19/2/getting-started-cat-command
[15]: https://opensource.com/article/19/8/using-variables-bash
[16]: https://opensource.com/article/19/9/getting-started-zsh
[17]: https://www.cygwin.com/
[18]: https://docs.microsoft.com/en-us/windows/wsl/wsl2-about
[19]: https://opensource.com/article/19/7/ways-get-started-linux
[20]: https://opensource.com/sites/default/files/images/education/screenshot_from_2019-09-28_10-49-49.png (Download a zip from Gitlab)
[21]: https://opensource.com/life/16/7/stumbling-git
[22]: https://www.redhat.com/en/command-line-heroes/bash/index.html?extIdCarryOver=true&sc_cid=701f2000001OH79AAG
[23]: https://opensource.com/sites/default/files/uploads/commandlineheroes-bash.jpg (Command Line Heroes: BASH)
[24]: http://openjam.io/
[25]: https://www.redhat.com/en/command-line-heroes/bash/index.html
[26]: https://github.com/CommandLineHeroes/clh-bash/
[27]: https://opensource.com/article/19/9/advanced-bash-building-minesweeper
[28]: https://opensource.com/sites/default/files/uploads/extractmines.png

View File

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

View File

@ -1,245 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (heguangzhi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to manage Go projects with GVM)
[#]: via: (https://opensource.com/article/19/10/introduction-gvm)
[#]: author: (Chris Collins https://opensource.com/users/clcollins)
How to manage Go projects with GVM
======
Manage Go environments, including installing multiple versions and
managing modules, with Go Version Manager.
![Woman programming][1]
Go Version Manager ([GVM][2]) is an open source tool for managing Go environments. It supports installing multiple versions of Go and managing modules per-project using GVM "pkgsets." Developed originally by [Josh Bussdieker][3], GVM (like its Ruby counterpart, RVM) allows you to create a development environment for each project or group of projects, segregating the different Go versions and package dependencies to allow for more flexibility and prevent versioning issues.
There are several options for managing Go packages, including Go 1.11 Modules, built right into Go. I find GVM to be simple and intuitive, and even if I didn't use it to manage packages, I'd still use it to manage Go versions.
### Installing GVM
Installing GVM is straightforward. The [GVM repository][4] installation documentation instructs you to download the installer script and pipe it to Bash:
```
`bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)`
```
Despite the growing adoption of this kind of installation method, it's still good practice to take a look at what the installer is doing before you do it. In the case of GVM, the installer script:
1. Checks some dependencies
2. Clones the GVM repo
3. Uses shell scripts to:
* Install Go
* Manage the GOPATH environment
* Add a line to your bashrc, zshrc, or profile
If you want to double-check what it's doing, you can clone the repo and review the shell scripts, then run **./binscripts/gvm-installer** to set it up using the local scripts.
_Note:_ Since GVM can be used to download and compile new Go versions, there are some expected dependencies like Make, Git, and Curl. You can find the complete list for your distribution in [GVM's README][5].
### Installing and managing Go versions with GVM
Once GVM is installed, you can start using it to install and manage different versions of Go. The **gvm listall** command shows the available versions of Go that can be downloaded and compiled:
```
[chris@marvin ]$ gvm listall
$ gvm listall
gvm gos (available)
   go1
   go1.0.1
   go1.0.2
   go1.0.3
&lt;output truncated&gt;
```
Installing a specific Go version is as easy as **gvm install &lt;version&gt;**, where **&lt;version&gt;** is one of the ones returned by the **gvm listall** command.
Say you're working on a project that uses Go version 1.12.8. You can install it with **gvm install go1.12.8**:
```
[chris@marvin]$ gvm install go1.12.8
Installing go1.12.8...
 * Compiling...
go1.12.8 successfully installed!
```
Enter **gvm list**, and you see Go version 1.12.8 is installed along with the system Go version (the version that comes packed using your OS's package manager):
```
[chris@marvin]$ gvm list
gvm gos (installed)
   go1.12.8
=&gt; system
```
GVM is still using the system version of Go, denoted by the **=&gt;** symbol next to it. You can switch your environment to use the newly installed go1.12.8 with the **gvm use** command:
```
[chris@marvin]$ gvm use go1.12.8
Now using version go1.12.8
[chris@marvin]$ go version
go version go1.12.8 linux/amd64
```
GVM makes it extremely simple to manage installed versions of Go, but it gets even better!
### Using GVM pkgset
Out of the box, Go has a brilliant—and frustrating—way of managing packages and modules. By default, if you **go get** a package, it is downloaded into the **src** and **pkg** directories in your **$GOPATH**; then it can be included in your Go program by using **import**. This makes it easy to get packages, especially for unprivileged users, without requiring **sudo** or root privileges (much like **pip install --user** in Python). The tradeoff, however, is the difficulty in managing different versions of the same packages across different projects.
There are a number of ways to try fixing or mitigating the issue, including the experimental Go Modules (preliminary support added in Go v1.11) and [go dep][6] (an "official experiment" and ongoing alternative to Go Modules). Before I discovered GVM, I would build and test Go projects in their own Docker containers to ensure segregation.
GVM elegantly accomplishes management and segregation of packages between projects by using "pkgsets" to append a new directory for projects to the default **$GOPATH** for the version of Go installed, much like **$PATH** works on Unix/Linux systems.
It is easiest to visualize how this works in action. First, install a new version of Go, v1.12.9:
```
[chris@marvin]$ echo $GOPATH
/home/chris/.gvm/pkgsets/go1.12.8/global
[chris@marvin]$ gvm install go1.12.9
Installing go1.12.9...
 * Compiling...
go1.12.9 successfully installed
[chris@marvin]$ gvm use go1.12.9
Now using version go1.12.9
```
When GVM is told to use a new version, it changes to a new **$GOPATH**, which corresponds to a default **gloabl** pkgset for that version:
```
[chris@marvin]$ echo $GOPATH
/home/chris/.gvm/pkgsets/go1.12.9/global
[chris@marvin]$ gvm pkgset list
gvm go package sets (go1.12.9)
=&gt;  global
```
Packages in the global pkgset are available to any project using this specific version of Go, although by default there are no extra packages installed.
Now, suppose you're starting a new project, and it needs a specific package. First, use GVM to create a new pkgset called **introToGvm**:
```
[chris@marvin]$ gvm pkgset create introToGvm
[chris@marvin]$ gvm pkgset use introToGvm
Now using version go1.12.9@introToGvm
[chris@marvin]$ gvm pkgset list
gvm go package sets (go1.12.9)
    global
=&gt;  introToGvm
```
As mentioned above, a new directory for the pkgset is prepended to the **$GOPATH**:
```
[chris@marvin]$ echo $GOPATH
/home/chris/.gvm/pkgsets/go1.12.9/introToGvm:/home/chris/.gvm/pkgsets/go1.12.9/global
```
Change directories into the **introToGvm** path that was prepended and examine the directory structure—and take the opportunity to have some fun with **awk** and **bash** as you do:
```
[chris@marvin]$ cd $( awk -F':' '{print $1}' &lt;&lt;&lt; $GOPATH )
[chris@marvin]$ pwd
/home/chris/.gvm/pkgsets/go1.12.9/introToGvm
[chris@marvin]$ ls
overlay  pkg  src
```
Notice that the new directory looks a lot like a normal **$GOPATH**. New Go packages can be downloaded using the same **go get** command you'd normally use with Go, and they are added to the pkgset.
As an example, use the following to get the **gorilla/mux** package, then examine the directory structure of the pkgset:
```
[chris@marvin]$ go get github.com/gorilla/mux
[chris@marvin]$ tree
[chris@marvin introToGvm ]$ tree
.
├── overlay
  ├── bin
  └── lib
      └── pkgconfig
├── pkg
  └── linux_amd64
      └── github.com
          └── gorilla
              └── mux.a
src/
└── github.com
    └── gorilla
        └── mux
            ├── AUTHORS
            ├── bench_test.go
            ├── context.go
            ├── context_test.go
            ├── doc.go
            ├── example_authentication_middleware_test.go
            ├── example_cors_method_middleware_test.go
            ├── example_route_test.go
            ├── go.mod
            ├── LICENSE
            ├── middleware.go
            ├── middleware_test.go
            ├── mux.go
            ├── mux_test.go
            ├── old_test.go
            ├── README.md
            ├── regexp.go
            ├── route.go
            └── test_helpers.go
```
As you can see, **gorilla/mux** was added to the pkgset **$GOPATH** directory as expected and can now be used with projects that use this pkgset.
### GVM makes Go management a breeze
GVM is an intuitive and non-intrusive way to manage Go versions and packages. It can be used on its own or in combination with other Go module management techniques and make use of GVM's Go version management capabilities. Segregating projects by Go version and package dependency makes development easier and leads to fewer complications with managing version conflicts, and GVM makes this a breeze.
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/10/introduction-gvm
作者:[Chris Collins][a]
选题:[lujun9972][b]
译者:[heguangzhi](https://github.com/heguangzhi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/clcollins
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming-code-keyboard-laptop-music-headphones.png?itok=EQZ2WKzy (Woman programming)
[2]: https://github.com/moovweb/gvm
[3]: https://github.com/jbussdieker
[4]: https://github.com/moovweb/gvm#installing
[5]: https://github.com/moovweb/gvm/blob/master/README.md
[6]: https://golang.github.io/dep/

View File

@ -0,0 +1,115 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (3 quick tips for working with Linux files)
[#]: via: (https://www.networkworld.com/article/3440035/3-quick-tips-for-working-with-linux-files.html)
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
处理 Linux 文件的 3 个提示
======
Linux 提供了许多用于查找、计数和重命名文件的命令。这有一些有用的选择。
[GotCredit][1] [(CC BY 2.0)][2]
Linux 提供了多种用于处理文件的命令,这些命令可以节省你的时间,并使你的工作不那么繁琐。
### 查找文件
当你查找文件时,**find** 可能会是第一个想到的命令,但是有时精心设计的 **ls** 命令会更好。想知道你昨天离开办公室回家前调用的脚本么?简单!使用 **ls** 命令并加上 **-ltr** 选项。最后一个列出的将是最近创建或更新的文件。
```
$ ls -ltr ~/bin | tail -3
-rwx------ 1 shs shs 229 Sep 22 19:37 checkCPU
-rwx------ 1 shs shs 285 Sep 22 19:37 ff
-rwxrw-r-- 1 shs shs 1629 Sep 22 19:37 test2
```
像这样的命令将仅列出今天更新的文件:
```
$ ls -al --time-style=+%D | grep `date +%D`
drwxr-xr-x 60 shs shs 69632 09/23/19 .
drwxrwxr-x 2 shs shs 8052736 09/23/19 bin
-rw-rw-r-- 1 shs shs 506 09/23/19 stats
```
如果你要查找的文件可能不在当前目录中,那么 **find** 将比 **ls** 提供更好的选项但它可能会输出比你想要的更多。在此命令中我们_不_搜索以点开头的目录它们很多一直在更新指定我们要查找的文件即不是目录并要求仅显示最近一天 -mtime -1 更新的文件。
```
$ find . -not -path '*/\.*' -type f -mtime -1 -ls
917517 0 -rwxrw-r-- 1 shs shs 683 Sep 23 11:00 ./newscript
```
注意 **-not ** 选项反转了 **-path** 的行为,因此我们不会搜索以点开头的子目录。
如果只想查找最大的文件和目录,那么可以使用类似 **du** 这样的命令,它会按大小列出当前目录的内容。将输出通过管道传输到 **tail**,仅查看最大的几个。
```
$ du -kx | egrep -v "\./.+/" | sort -n | tail -5
918984 ./reports
1053980 ./notes
1217932 ./.cache
31470204 ./photos
39771212 .
```
**-k** 选项让 **du** 以块列出文件大小,而 **x** 可防止其遍历其他文件系统上的目录(例如,通过符号链接引用)。事实上,**du** 会先列出文件大小这样可以按照大小排序sort -n
### 文件计数
使用 **find** 命令可以很容易地计算任何特定目录中的文件。你只需要记住find 会递归到子目录中,并将这些子目录中的文件与当前目录中的文件一起计数。在此命令中,我们计数一个特定用户的家目录中的文件。根据家目录的权限,这可能需要使用 **sudo**。请记住,第一个参数是搜索的起点。这里指定的是用户的家目录。
```
$ find ~username -type f 2>/dev/null | wc -l
35624
```
请注意,我们正在将上面 **find** 命令的错误输出发送到 /dev/null以避免搜索类似 \~username/.cache 这类无法搜索并且对它的内容也不感兴趣的文件夹
必要时,你可以使用 **maxdepth 1** 选项将 **find** 限制在单个目录中:
```
$ find /home/shs -maxdepth 1 -type f | wc -l
387
```
### 重命名文件
使用 **mv** 命令可以很容易地重命名文件,但是有时你会想重命名大量文件,并且不想花费大量时间。例如,要将你在当前目录的文件名中找到的所有空格更改为下划线,你可以使用如下命令:
```
$ rename 's/ /_/g' *
```
如你怀疑的那样,此命令中的 **g** 表示“全局”。这意味着该命令会将文件名中的_所有_空格更改为下划线而不仅仅是第一个。
要从文本文件中删除 .txt 扩展名,可以使用如下命令:
```
$ rename 's/.txt//g' *
```
### 总结
Linux 命令行提供了许多用于处理文件的有用选择。请提出你认为特别有用的其他命令。
在 [Facebook][4] 和 [LinkedIn][5] 加入 Network World 社区,评论热门主题。
--------------------------------------------------------------------------------
via: https://www.networkworld.com/article/3440035/3-quick-tips-for-working-with-linux-files.html
作者:[Sandra Henry-Stocker][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/
[b]: https://github.com/lujun9972
[1]: https://www.flickr.com/photos/gotcredit/33756797815/in/photolist-TqYpVr-ot3MbP-8GVk75-bDgdSV-d8UqyY-8A1Nvm-bDgHMT-3StdY-c3CSTq-9gXm8m-piEdt6-9Jme84-ao7jBT-9gUejH-9gpPtR-XzrMMD-bqn8Qs-bDa1AK-oV87g2-bqn8SE-7hKg3v-CyDj5-bDgHKF-ppTzHf-84Czrj-dWf3MY-eDXW3i-5nTPZb-oaFrev-bqf6Rw-58EpAQ-5bd2t8-9eyUFb-5zNBi9-6geKFz-ngaqHa-6zDJtt-bvJrAQ-28v4k1Y-6s2qrs-3fPsLz-hDNitm-4nfhZC-7dZYt1-PUTxVi-4nuP2y-bDgdVg-96HPjm-bce6J8-5Mnhy
[2]: https://creativecommons.org/licenses/by/2.0/legalcode
[4]: https://www.facebook.com/NetworkWorld/
[5]: https://www.linkedin.com/company/network-world

View File

@ -7,40 +7,40 @@
[#]: via: (https://www.2daygeek.com/bash-script-generate-linux-system-uptime-reports/)
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
Bash Script to Generate System Uptime Reports on Linux
生成 Linux 运行时间报告的 Bash 脚本
======
For some purposes you may need to collect the **[Linux system uptime][1]** report once a month.
出于一些原因,你可能需要每月收集一次**[Linux 系统运行时间][1]**报告。
If so, you can use one of the following **[bash scripts][2]** based on your requirements.
如果没错,你可以根据需要使用以下 **[bash 脚本][2]**之一。
Why should we collect this report?
我们为什么要收集这份报告?
Restarting the Linux server after a certain period of time is a good practice to fix some pending issues.
在一段时间后重启 Linux 服务器是解决某些未解决问题的好方法。
It is advisable to restart once in 180 days. But this period may vary depending on your companys policy.
建议每 180 天重新启动一次。但时间段也许取决于你公司的政策。
If you have been running the server for a long time without restarting.
如果你已经长时间运行服务器而没有重启。
This can lead to some performance issues or memory problems on the server, which I have noticed on many servers.
这可能导致服务器上出现一些性能或内存问题,我在许多服务器上都注意到了这一点。
These scripts provide all system uptime reports in one place.
这些脚本一次性提供了所有系统运行报告。
### What is Uptime Command
### 什么是 uptime 命令
uptime command will tell how long the system has been running. It gives a one line display of the following information.
uptime 命令将告诉你系统已经运行了多长时间。它在一行中显示以下信息。
The current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.
当前时间、系统运行了多长时间、当前登录了多少用户以及过去 1、5 和 15 分钟的平均系统负载。
### What Is tuptime?
### 什么是 tuptime?
[Tuptime][3] is a tool for report the historical and statistical running time of the system, keeping it between restarts. Like uptime command but with more interesting output.
[tuptime][3] 是用于报告系统的历史和统计运行时间的工具,可在重启之间保存。它类似于 uptime 命令,但输出更有趣。
### 1) Bash Script to Check Linux System Uptime
### 1)检查 Linux 系统运行时间的 Bash 脚本
This bash script will collect all the server uptime and send the report to the given email id.
该 bash 脚本将收集所有服务器正常运行时间,并将报告发送到给定的电子邮箱地址。
Please replace your email id instead of ours, otherwise you will not receive mails.
请替换为你的电子邮箱地址,而不是用我们的,否则你将不会收到邮件。
```
# vi /opt/scripts/system-uptime-script.sh
@ -55,19 +55,19 @@ done | column -t >> /tmp/uptime-report.out
cat /tmp/uptime-report.out | mail -s "Linux Servers Uptime Report" "[email protected]"
```
Set an executable permission to **“system-uptime-script.sh”** file.
**“system-uptime-script.sh”** 设置可执行权限。
```
$ chmod +x /opt/scripts/system-uptime-script.sh
```
Finally run the bash script to get the output.
最后运行 bash 脚本获取输出。
```
# sh /opt/scripts/system-uptime-script.sh
```
You will receive a report like the one below.
你将收到类似以下的报告。
```
# cat /tmp/uptime-report.out
@ -81,9 +81,9 @@ You will receive a report like the one below.
192.168.1.11: 23 days
```
### 2) Bash Script to Check If Linux System is Running Over 30 Days
### 2)检查 Linux 系统是否运行了 30 天以上的 Bash 脚本
This bash script collects server running over 30 days and sends the report to the given email id. You can change the days according to your needs.
此 bash 脚本会收集运行 30 天以上的服务器,并将报告发送到指定的邮箱地址。你可以根据需要更改天数。
```
# vi /opt/scripts/system-uptime-script-1.sh
@ -99,13 +99,13 @@ cat /tmp/uptime-report-1.out | awk ' $2 >= 30' > /tmp/uptime-report-2.out
cat /tmp/uptime-report-2.out | mail -s "Linux Servers Uptime Report" "[email protected]"
```
Set an executable permission to **“system-uptime-script-1.sh”** file.
**“system-uptime-script-1.sh”** 设置可执行权限。
```
$ chmod +x /opt/scripts/system-uptime-script-1.sh
```
Finally add a **[cronjob][4]** to automate this. It runs daily at 7AM.
最后添加一条 **[cronjob][4]** 来自动执行。它会在每天早上 7 点运行。
```
# crontab -e
@ -113,9 +113,9 @@ Finally add a **[cronjob][4]** to automate this. It runs daily at 7AM.
0 7 * * * /bin/bash /opt/scripts/system-uptime-script-1.sh
```
**Note:** You will receive an email alert at 7AM every day, which is for yesterdays date details.
**注意:** 你会在每天早上 7 点会收到一封电子邮件提醒,它是昨天的详情。
You will receive a report like the one below.
你将收到类似下面的报告。
```
# cat /tmp/uptime-report-2.out
@ -131,7 +131,7 @@ via: https://www.2daygeek.com/bash-script-generate-linux-system-uptime-reports/
作者:[Magesh Maruthamuthu][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -0,0 +1,147 @@
[#]: collector: (lujun9972)
[#]: translator: (wxy)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (3 command line games for learning Bash the fun way)
[#]: via: (https://opensource.com/article/19/10/learn-bash-command-line-games)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
Bash 学习的快乐之旅3 个命令行游戏
======
> 通过这些命令行游戏,学习有用的 Bash 技能也是一件乐事。
![connecting yellow dots in a maze][1]
学习是件艰苦的工作,然而没有人喜欢工作。这意味着无论学习 Bash 多么容易,它仍然对你来说就像工作一样。当然,除非你通过游戏来学习。
你不会觉得会有很多游戏可以教你如何使用 Bash 终端吧,这是对的。严肃的 PC 游戏玩家知道,《<ruby>辐射<rt>Fallout</rt></ruby>》系列在金库中配备了基于终端的计算机,这可以帮你理解通过文本与计算机进行交互是什么样子,但是尽管其功能的灵感或多或少地类似于 [Alpine][2] 或 [Emacs][3]可是玩《辐射》并不会教给你可以在现实生活中使用的命令或应用程序。《辐射》系列从未直接移植到Linux尽管可以通过 Steam 的开源的 [Proton][4] 来玩。)曾是《辐射》的前身的《<ruby>[废土][5]<rt>Wasteland</rt></ruby>》系列的最新作品确实是面向 Linux 的,因此,如果你想体验游戏中的终端,可以在你的 Linux 游戏计算机上玩《[废土 2][6]》和《[废土 3][7]》。《<ruby>[暗影狂奔][8]<rt>Shadowrun</rt></ruby>》系列也有面向 Linux 的版本,它有许多基于终端的交互,尽管公认 [hot sim][9] 序列常常使它黯然失色。
![](https://attackofthefanboy.com/wp-content/uploads/2018/11/fallout-terminal-computer-hacking-guide.jpg)
虽然这些游戏中采用了有趣的操作计算机终端的方式,并且可以在开源的系统上运行,但它们本身都不是开源的。不过,至少有两个游戏采用了严肃且非常有趣的方法来教人们如何通过文本命令与系统进行交互。最重要的是,它们是开源的。
### Bashcrawl
你可能听说过《<ruby>[巨洞探险][10]<rt>Colossal Cave Adventure</rt></ruby>》游戏,这是一款古老的基于文本的交互式游戏,其风格为“自由冒险”类。早期的计算机爱好者们在 DOS 或 ProDOS 命令行上痴迷地玩这些游戏,他们努力寻找有效语法和(如一个讽刺黑客所解释的)滑稽幻想逻辑的正确组合来击败游戏。想象一下,如果除了探索虚拟的中世纪地下城之外,挑战还在于回忆起有效的 Bash 命令,那么这样的挑战会多有成效。这就是 [Bashcrawl][11] 的基调,这是一个基于 Bash 的地下城探险游戏,你可以通过学习和使用 Bash 命令来玩。
在 Bashcrawl 中,“地下城”是以目录和文件的形式在你的计算机上创建的。你可以通过使用 `cd` 命令更改目录进入地下城的每个房间来探索它。当你[穿行目录][12]时,你可以用 [ls -F] [13] 来查看文件,用 [cat][14] 读取文件,[设置变量][15]来收集宝藏,并运行脚本来与怪物战斗。你在游戏中所做的一切操作都是有效的 Bash 命令,你可以稍后在现实生活中使用它,并且玩这个游戏提供了 Bash 体验,因为这个“游戏”是由计算机上的实际目录和文件组成的。
```
$ cd entrance/
$ ls
cellar  scroll
$ cat scroll
It is pitch black in these catacombs.
You have a magical spell that lists all items in a room.
To see in the dark, type:     ls
To move around, type:         cd &lt;directory&gt;
Try looking around this room.
Then move into one of the next rooms.
EXAMPLE:
$ ls
$ cd cellar
Remember to cast ``ls`` when you get into the next room!
$
```
#### 安装 Bashcrawl
在玩 Bashcrawl 之前,你的系统上必须有 Bash 或 [Zsh][16]。Linux、BSD 和 MacOS 都附带了 Bash。Windows 用户可以下载并安装 [Cygwin][17] 或 [WSL][18] 或[试试 Linux][19]。
要安装 Bashcrawl请在 Firefox 或你选择的 Web 浏览器中导航到这个 [GitLab 存储库][11]。在页面的右侧单击“下载”图标位于“Find file”按钮右侧。在“下载”弹出菜单中单击“zip”按钮以下载最新版本的游戏。
![Download a zip from Gitlab][20]
下载完成后,解压缩该存档文件。
另外,如果你想从终端中开始安装,则可以使用 [Git][21] 命令:
```
$ git clone https://gitlab.com/slackermedia/bashcrawl.git bashcrawl
```
#### 游戏入门
与你下载的几乎所有新的软件包一样,你必须做的第一件事是阅读 README 文件。你可以通过双击`bashcrawl` 目录中的 `README.md` 文件来阅读。在 Mac 上,你的计算机可能不知道要使用哪个应用程序打开该文件;你也可以使用任何文本编辑器或 LibreOffice 打开它。`README.md` 这个文件会具体告诉你如何开始玩游戏,包括如何在终端上进入游戏以及要开始游戏必须发出的第一条命令。如果你无法阅读 README 文件,那游戏就不战自胜了(尽管由于你没有玩而无法告诉你)。
Bashcrawl 并不意味着是给比较聪明或高级用户玩的。相反,为了对新用户透明,它尽可能简单。理想情况下,新的 Bash 用户可以从游戏中学习 Bash 的一些基础知识,然后会偶然发现一些游戏机制,包括使游戏运行的简单脚本,并学习到更多的 Bash 知识。此外,新的 Bash 用户可以按照 Bashcrawl 现有内容的示例设计自己的地下城,没有比编写游戏更好的学习编码的方法了。
### 命令行英雄BASH
Bashcrawl 适用于绝对初学者。如果你经常使用 Bash则很有可能会尝试通过以初学者尚不了解的方式查看 Bashcrawl 的文件,以胜过它。如果你是 Bash 的中级或高级用户,则应尝试一下 [命令行英雄BASH][22]。
这个游戏很简单在给定的时间内输入尽可能多的有效命令LCTT 译注BASH 也有“猛击”的意思)。听起来很简单。作为 Bash 用户,你每天都会使用许多命令。作为 Linux 用户,你知道在哪里可以找到命令列表。仅 util-linux 软件包就包含一百多个命令!问题是,在倒计时的压力下,你的指尖是否忙的过来输入这些命令?
![Command Line Heroes: BASH][23]
这个游戏听起来很简单,它确实也很简单!原则上,它与<ruby>闪卡<rt>flashcard</rt></ruby>相似,只是反过来而已。在实践中,这是测试你的知识和回忆的一种有趣方式。当然,它是开源的,是由 [Open Jam][24] 的开发者开发的。
#### 安装
你可以[在线][25]玩“命令行英雄BASH”或者你也可以从 [GitHub][26] 下载它的源代码。
这个游戏是用 Node.js 编写的,因此除非你想帮助开发该游戏,否则在线进行游戏就够了。
### 在 Bash 中扫雷
如果你是高级 Bash 用户,并且已经编写了多个 Bash 脚本,那么你可能不仅仅想学习 Bash。你可以尝试编写游戏而不是玩游戏这才是真的挑战。稍加思考用上一个下午或几个小时便可以完全在 Bash 中实现流行的游戏《扫雷》。你可以先尝试自己编写游戏,然后参阅 Abhishek Tamrakar 的[文章][27],以了解他如何完成该游戏的。
![][28]
有时编程没有目的而是为了教育。在 Bash 中编写游戏可能不是你可以在网上赢得声誉的项目,但是该过程可能会很有趣且很有启发性。面对一个你从未想到的问题,这是学习新技巧的好方法。
### 学习 Bash玩得开心
不管你如何学习它Bash 都是一个功能强大的界面,因为它使你能够指示计算机执行所需的操作,而无需通过图形界面的应用程序的“中间人”界面。有时,图形界面很有帮助,但有时你想离开那些已经非常了解的东西,然后转向可以快速或通过自动化来完成的事情。由于 Bash 基于文本,因此易于编写脚本,使其成为自动化作业的理想起点。
了解 Bash 以开始走向高级用户之路。但是请确保你乐在其中。
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/10/learn-bash-command-line-games
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[wxy](https://github.com/wxy)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/LAW_maze.png?itok=mZ5LP4-X (connecting yellow dots in a maze)
[2]: https://opensource.com/article/17/10/alpine-email-client
[3]: http://www.gnu.org/software/emacs
[4]: https://github.com/ValveSoftware/Proton/
[5]: https://www.gog.com/game/wasteland_the_classic_original
[6]: https://www.inxile-entertainment.com/wasteland2
[7]: https://www.inxile-entertainment.com/wasteland3
[8]: http://harebrained-schemes.com/games/
[9]: https://forums.shadowruntabletop.com/index.php?topic=21804.0
[10]: https://opensource.com/article/18/12/linux-toy-adventure
[11]: https://gitlab.com/slackermedia/bashcrawl
[12]: https://opensource.com/article/19/8/understanding-file-paths-linux
[13]: https://opensource.com/article/19/7/master-ls-command
[14]: https://opensource.com/article/19/2/getting-started-cat-command
[15]: https://opensource.com/article/19/8/using-variables-bash
[16]: https://opensource.com/article/19/9/getting-started-zsh
[17]: https://www.cygwin.com/
[18]: https://docs.microsoft.com/en-us/windows/wsl/wsl2-about
[19]: https://opensource.com/article/19/7/ways-get-started-linux
[20]: https://opensource.com/sites/default/files/images/education/screenshot_from_2019-09-28_10-49-49.png (Download a zip from Gitlab)
[21]: https://opensource.com/life/16/7/stumbling-git
[22]: https://www.redhat.com/en/command-line-heroes/bash/index.html?extIdCarryOver=true&sc_cid=701f2000001OH79AAG
[23]: https://opensource.com/sites/default/files/uploads/commandlineheroes-bash.jpg (Command Line Heroes: BASH)
[24]: http://openjam.io/
[25]: https://www.redhat.com/en/command-line-heroes/bash/index.html
[26]: https://github.com/CommandLineHeroes/clh-bash/
[27]: https://linux.cn/article-11430-1.html
[28]: https://opensource.com/sites/default/files/uploads/extractmines.png

View File

@ -0,0 +1,232 @@
[#]: collector: (lujun9972)
[#]: translator: (heguangzhi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to manage Go projects with GVM)
[#]: via: (https://opensource.com/article/19/10/introduction-gvm)
[#]: author: (Chris Collins https://opensource.com/users/clcollins)
如何用GVM管理Go项目
======
管理Go语言环境包括安装多个版本和使用Go版本管理器管理模块。
![正在编程的女人][1]
Go语言版本管理器([GVM][2])是管理Go语言环境的开源工具。GVM “pkgsets” 支持安装多个版本的Go并管理每个项目的模块。最初由[乔什·布斯迪克][3]开发GVM(像它的对手 Ruby RVM一样)允许你为每个项目或项目组创建一个开发环境分离不同的Go版本和包依赖关系以允许更大的灵活性和防止不同版本造成的问题。
有几种管理Go包的方式包括内置于Go中的Go1.11模块。我发现GVM简单直观即使我不用它来管理包我还是会用它来管理Go不同的版本的。
### 安装 GVM
安装GVM很简单。[GVM 存储库][4]安装文档指示你下载安装程序脚本并将其传送到Bash来安装:
```
`bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)`
```
尽管越来越多的人采用这种安装方法但是在安装之前先看看安装程序在做什么仍然是一个很好的想法。以GVM为例安装程序脚本:
1. 检查一些相关依赖性
2. 克隆 GVM 存储库
3. 使用 shell 脚本:
* 安装 Go 语言
* 管理 GOPATH 环境变量
* 向bashrc、zshrc或配置文件中添加一行内容
如果你想再次检查它在做什么,你可以克隆存储库并查看 shell 脚本,然后运行 **/binscripts/gvm-installer** 使用本地脚本进行设置。
_注意:_ 因为GVM可以用来下载和编译新的Go版本所以有一些预期的依赖关系如 Make、Git 和 Curl。您可以在[GVM的自述文件][5]中找到完整的分发列表。
### 使用 GVM 安装和管理 GO 版本
一旦安装了GVM你就可以使用它来安装和管理不同版本的Go。**gvm listall** 命令显示可下载和编译的可用版本的Go:
```
[chris@marvin ]$ gvm listall
$ gvm listall
gvm gos (available)
   go1
   go1.0.1
   go1.0.2
   go1.0.3
&lt;output truncated&gt;
```
安装特定的Go版本就像 **gvm install &lt;version&gt;** 一样简单,其中 **&lt;version&gt;** 是**gvm listall** 命令返回的内容之一。
假设你正在进行一个使用Go1.12.8 版本的项目。您可以使用 **gvm install go1.12.8** 安装这个版本:
```
[chris@marvin]$ gvm install go1.12.8
Installing go1.12.8...
 * Compiling...
go1.12.8 successfully installed!
```
输入 **gvm list**你会看到Go版本1.12.8 与系统Go版本(使用操作系统的软件包管理器打包的版本)一起并存:
```
[chris@marvin]$ gvm list
gvm gos (installed)
   go1.12.8
=&gt; system
```
GVM仍在使用系统版本的Go ,由 **=&gt;**符号表示。你可以使用 **gvm use** 命令切换你的环境以使用新安装的 go1.12.8:
```
[chris@marvin]$ gvm use go1.12.8
Now using version go1.12.8
[chris@marvin]$ go version
go version go1.12.8 linux/amd64
```
GVM使管理已安装版本的Go变得极其简单但它变得更好了
### 使用 GVM pkgset
开箱即用Go有一种出色而令人沮丧的管理包和模块的方式。默认情况下如果你 **go get** 包,它将被下载到 **$GOPATH** 目录中的 **src****pkg** 目录下 ,然后可以使用 **import** 将其包含在你的Go程序中。这使得获得软件包变得很容易特别是对于非特权用户而不需要**sudo**或root 特权(很像Python中的**pip install --user**)。然而,在不同的项目中管理相同包的不同版本是非常困难的。
有许多方法可以尝试修复或缓解这个问题包括实验性Go模块(Go 1.11版中增加了初步支持)和[Go dep][6](Go 模块的“官方实验”并且持续迭代)。在我发现GVM之前我会在他们自己的Docker容器中构建和测试Go项目以确保分离。
GVM通过使用“pkgsets”将项目的新目录附加到安装的Go版本的默认 **$GOPATH** 上,很好地实现了项目之间包的管理和隔离,就像 **$PATH** 在Unix/Linux系统上工作一样。
想象它如何运行的,例子如下。首先,安装新版 Go1.12.9:
```
[chris@marvin]$ echo $GOPATH
/home/chris/.gvm/pkgsets/go1.12.8/global
[chris@marvin]$ gvm install go1.12.9
Installing go1.12.9...
 * Compiling...
go1.12.9 successfully installed
[chris@marvin]$ gvm use go1.12.9
Now using version go1.12.9
```
当GVM被告知使用新版本时它会更改为新的 **$GOPATH**,默认**gloabl** pkgset 应用于该版本:
```
[chris@marvin]$ echo $GOPATH
/home/chris/.gvm/pkgsets/go1.12.9/global
[chris@marvin]$ gvm pkgset list
gvm go package sets (go1.12.9)
=&gt;  global
```
尽管默认情况下没有安装额外的包但是全局pkgset中的包对于使用该特定版本的Go的任何项目都是可用的。
现在,假设你正在启用一个新项目,它需要一个特定的包。首先,使用 GVM 创建一个新的pkgset名为 **introToGvm**:
```
[chris@marvin]$ gvm pkgset create introToGvm
[chris@marvin]$ gvm pkgset use introToGvm
Now using version go1.12.9@introToGvm
[chris@marvin]$ gvm pkgset list
gvm go package sets (go1.12.9)
    global
=&gt;  introToGvm
```
如上所述pkgset的一个新目录被添加到 **$GOPATH**:
```
[chris@marvin]$ echo $GOPATH
/home/chris/.gvm/pkgsets/go1.12.9/introToGvm:/home/chris/.gvm/pkgsets/go1.12.9/global
```
将目录更改为预先设置的 **introToGvm** 路径,检查目录结构,并像你使用**awk**和**bash** 一样。
```
[chris@marvin]$ cd $( awk -F':' '{print $1}' &lt;&lt;&lt; $GOPATH )
[chris@marvin]$ pwd
/home/chris/.gvm/pkgsets/go1.12.9/introToGvm
[chris@marvin]$ ls
overlay  pkg  src
```
请注意,新目录看起来很像普通的 **$GOPATH**。新的Go包使用 **go get** 命令下载并正常使用,且添加到 pkgset 中。
例如,使用以下命令获取 **gorilla/mux**然后检查pkgset的目录结构:
```
[chris@marvin]$ go get github.com/gorilla/mux
[chris@marvin]$ tree
[chris@marvin introToGvm ]$ tree
.
├── overlay
  ├── bin
  └── lib
      └── pkgconfig
├── pkg
  └── linux_amd64
      └── github.com
          └── gorilla
              └── mux.a
src/
└── github.com
    └── gorilla
        └── mux
            ├── AUTHORS
            ├── bench_test.go
            ├── context.go
            ├── context_test.go
            ├── doc.go
            ├── example_authentication_middleware_test.go
            ├── example_cors_method_middleware_test.go
            ├── example_route_test.go
            ├── go.mod
            ├── LICENSE
            ├── middleware.go
            ├── middleware_test.go
            ├── mux.go
            ├── mux_test.go
            ├── old_test.go
            ├── README.md
            ├── regexp.go
            ├── route.go
            └── test_helpers.go
```
如你所见,**gorilla/mux** 已按预期添加到 pkgset **$GOPATH** 目录中,现在可用于使用此 pkgset 项目了。
### GVM让 Go 管理变得轻而易举
GVM 是一种直观且非侵入性的管理 Go版本和包的方式。它可以单独使用也可以与其他 Go 模块管理技术结合使用,并利用 GVM Go 版本管理功能。按Go 版本和包依赖来分离项目使得开发更加容易并且减少了管理版本冲突的复杂性GVM让这变得轻而易举。
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/10/introduction-gvm
作者:[Chris Collins][a]
选题:[lujun9972][b]
译者:[heguangzhi](https://github.com/heguangzhi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/clcollins
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming-code-keyboard-laptop-music-headphones.png?itok=EQZ2WKzy (Woman programming)
[2]: https://github.com/moovweb/gvm
[3]: https://github.com/jbussdieker
[4]: https://github.com/moovweb/gvm#installing
[5]: https://github.com/moovweb/gvm/blob/master/README.md
[6]: https://golang.github.io/dep/