mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-21 02:10:11 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
5087e5b2e7
@ -0,0 +1,75 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (When IoT systems fail: The risk of having bad IoT data)
|
||||
[#]: via: (https://www.networkworld.com/article/3396230/when-iot-systems-fail-the-risk-of-having-bad-iot-data.html)
|
||||
[#]: author: (Fredric Paul https://www.networkworld.com/author/Fredric-Paul/)
|
||||
|
||||
When IoT systems fail: The risk of having bad IoT data
|
||||
======
|
||||
As the use of internet of things (IoT) devices grows, the data they generate can lead to significant savings for consumers and new opportunities for businesses. But what happens when errors inevitably crop up?
|
||||
![Oonal / Getty Images][1]
|
||||
|
||||
No matter what numbers you look at, it’s clear that the internet of things (IoT) continues to worm its way into more and more areas of personal and private life. That growth brings many benefits, but it also poses new risks. A big question is who takes responsibility when things go wrong.
|
||||
|
||||
Perhaps the biggest issue surrounds the use of IoT-generated data to personalize the offering and pricing of various products and services. [Insurance companies have long struggled with how best to use IoT data][2], but last year I wrote about how IoT sensors are beginning to be used to help home insurers reduce water damage losses. And some companies are looking into the potential for insurers to bid for consumers: business based on the risks (or lack thereof) revealed by their smart-home data.
|
||||
|
||||
But some of the biggest progress has come in the area of automobile insurance, where many automobile insurers already let customers install tracking devices in their cars in exchange for discounts for demonstrating safe-driving habits.
|
||||
|
||||
**[ Also read:[Finally, a smart way for insurers to leverage IoT in smart homes][3] ]**
|
||||
|
||||
### **The rise of usage-based insurance**
|
||||
|
||||
Called usage-based insurance (UBI), this “pay-as-you-drive” approach tracks speed, location, and other factors to assess risk and calculate auto insurance premiums. An estimated [50 million U.S. drivers][4] will have enrolled in UBI programs by 2020.
|
||||
|
||||
Not surprisingly, insurers love UBI because it helps them calculate their risks more precisely. In fact, [AIG Ireland is trying to get the country to require UBI for drivers under 25][5]. And demonstrably safe drivers are also often happy save some money. There has been pushback, of course, mostly from privacy advocates and groups who might have to pay more under this model.
|
||||
|
||||
### **What happens when something goes wrong?**
|
||||
|
||||
But there’s another, more worrisome, potential issue: What happens when the data provided by the IoT device is wrong or gets garbled somewhere along the way? Because despite all the automation, error-checking, and so on, occasional errors inevitably slip through the cracks.
|
||||
|
||||
Unfortunately, this isn’t just an academic concern that might someday accidentally cost some careful drivers a few extra bucks on their insurance. It’s already a real-world problem with serious consequences. And just like [the insurance industry still hasn’t figured out who should “own” data generated by customer-facing IoT devices][6], it’s not clear who would take responsibility for dealing with problems with that data.
|
||||
|
||||
Though not strictly an IoT issue, computer “glitches” allegedly led to Hertz rental cars erroneously being reported stolen and innocent renters being arrested and detained. The result? Criminal charges, years of litigation, and finger pointing. Lots and lots of finger pointing.
|
||||
|
||||
With that in mind, it’s easy to imagine, for example, an IoT sensor getting confused and indicating that a car was speeding even while safely under the speed limit. Think of the hassles of trying to fight _that_ in court, or arguing with your insurance company over it.
|
||||
|
||||
(Of course, there’s also the flip side of this problem: Consumers may find ways to hack the data shared by their IoT devices to fraudulently qualify for lower rates or deflect blame for an incident. There’s no real plan in place to deal with _that_ , either.)
|
||||
|
||||
### **Studying the need for government regulation**
|
||||
|
||||
Given the potential impacts of these issues, and the apparent lack of interest in dealing with them from the many companies involved, it seems legitimate to wonder if government intervention is warranted.
|
||||
|
||||
That could be one motivation behind the [reintroduction of the SMART (State of Modern Application, Research, and Trends of) IoT Act][7] by Rep. Bob Latta (R-Ohio). [The bill][8], stemming from a bipartisan IoT working group helmed by Latta and Rep. Peter Welch (D-Vt.), passed the House last fall but failed in the Senate. It would require the Commerce Department to study the state of the IoT industry and report back to the House Energy & Commerce and Senate Commerce Committee in two years.
|
||||
|
||||
In a statement, Latta said, “With a projected economic impact in the trillions of dollars, we need to look at the policies, opportunities, and challenges that IoT presents. The SMART IoT Act will make it easier to understand what the government is doing on IoT policy, what it can do better, and how federal policies can impact the research and discovery of cutting-edge technologies.”
|
||||
|
||||
The research is welcome, but the bill may not even pass. Even it does, with its two-year wait time, the IoT will likely evolve too fast for the government to keep up.
|
||||
|
||||
Join the Network World communities on [Facebook][9] and [LinkedIn][10] to comment on topics that are top of mind.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3396230/when-iot-systems-fail-the-risk-of-having-bad-iot-data.html
|
||||
|
||||
作者:[Fredric Paul][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/Fredric-Paul/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://images.idgesg.net/images/article/2018/08/cloud_connected_smart_cars_by_oonal_gettyimages-692819426_1200x800-100767788-large.jpg
|
||||
[2]: https://www.networkworld.com/article/3264655/most-insurance-carriers-not-ready-to-use-iot-data.html
|
||||
[3]: https://www.networkworld.com/article/3296706/finally-a-smart-way-for-insurers-to-leverage-iot-in-smart-homes.html
|
||||
[4]: https://www.businessinsider.com/iot-is-changing-the-auto-insurance-industry-2015-8
|
||||
[5]: https://www.iotforall.com/iot-data-is-disrupting-the-insurance-industry/
|
||||
[6]: https://www.sas.com/en_us/insights/articles/big-data/5-challenges-for-iot-in-insurance-industry.html
|
||||
[7]: https://www.multichannel.com/news/latta-re-ups-smart-iot-act
|
||||
[8]: https://latta.house.gov/uploadedfiles/smart_iot_116th.pdf
|
||||
[9]: https://www.facebook.com/NetworkWorld/
|
||||
[10]: https://www.linkedin.com/company/network-world
|
@ -0,0 +1,119 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Enterprise IoT: Companies want solutions in these 4 areas)
|
||||
[#]: via: (https://www.networkworld.com/article/3396128/the-state-of-enterprise-iot-companies-want-solutions-for-these-4-areas.html)
|
||||
[#]: author: (Fredric Paul https://www.networkworld.com/author/Fredric-Paul/)
|
||||
|
||||
Enterprise IoT: Companies want solutions in these 4 areas
|
||||
======
|
||||
Based on customer pain points, PwC identified four areas companies are seeking enterprise solutions for, including energy use and sustainability.
|
||||
![Jackie Niam / Getty Images][1]
|
||||
|
||||
Internet of things (IoT) vendors and pundits like to crow about the billions and billions of connected devices that make the IoT so ubiquitous and powerful. But how much of that installed base is really relevant to the enterprise?
|
||||
|
||||
To find out, I traded emails with Rob Mesirow, principal at [PwC’s Connected Solutions][2], the firm’s new one-stop-shop of IoT solutions, who suggests that consumer adoption may not paint a true picture of the enterprise opportunities. If you remove the health trackers and the smart thermostats from the market, he suggested, there are very few connected devices left.
|
||||
|
||||
So, I wondered, what is actually happening on the enterprise side of IoT? What kinds of devices are we talking about, and in what kinds of numbers?
|
||||
|
||||
**[ Read also:[Forget 'smart homes,' the new goal is 'autonomous buildings'][3] ]**
|
||||
|
||||
“When people talk about the IoT,” Mesirow told me, “they usually focus on [consumer devices, which far outnumber business devices][4]. Yet [connected buildings currently represent only 12% of global IoT projects][5],” he noted, “and that’s without including wearables and smart home projects.” (Mesirow is talking about buildings that “use various IoT devices, including occupancy sensors that determine when people are present in a room in order to keep lighting and temperature controls at optimal levels, lowering energy costs and aiding sustainability goals. Sensors can also detect water and gas leaks and aid in predictive maintenance for HVAC systems.”)
|
||||
|
||||
### 4 key enterprise IoT opportunities
|
||||
|
||||
More specifically, based on customer pain points, PwC’s Connected Solutions is focusing on a few key opportunities, which Mesirow laid out in a [blog post][6] earlier this year. (Not surprisingly, the opportunities seem tied to [the group’s products][7].)
|
||||
|
||||
“A lot of these solutions came directly from our customers’ request,” he noted. “We pre-qualify our solutions with customers before we build them.”
|
||||
|
||||
Let’s take a look at the top four areas, along with a quick reality check on how important they are and whether the technology is ready for prime time.
|
||||
|
||||
#### **1\. Energy use and sustainability**
|
||||
|
||||
The IoT makes it possible to manage buildings and spaces more efficiently, with savings of 25% or more. Occupancy sensors can tell whether anyone is actually in a room, adjusting lighting and temperature to saving money and conserve energy.
|
||||
|
||||
Connected buildings can also help determine when meeting spaces are available, which can boost occupancy at large businesses and universities by 40% while cutting infrastructure and maintenance costs. Other sensors, meanwhile, can detect water and gas leaks and aid in predictive maintenance for HVAC systems.
|
||||
|
||||
**Reality check:** Obviously, much of this technology is not new, but there’s a real opportunity to make it work better by integrating disparate systems and adding better analytics to the data to make planning more effective.
|
||||
|
||||
#### **2. Asset tracking
|
||||
|
||||
**
|
||||
|
||||
“Businesses can also use the IoT to track their assets,“ Mesirow told me, “which can range from trucks to hotel luggage carts to medical equipment. It can even assist with monitoring trash by alerting appropriate people when dumpsters need to be emptied.”
|
||||
|
||||
Asset trackers can instantly identify the location of all kinds of equipment (saving employee time and productivity), and they can reduce the number of lost, stolen, and misplaced devices and machines as well as provide complete visibility into the location of your assets.
|
||||
|
||||
Such trackers can also save employees from wasting time hunting down the devices and machines they need. For example, PwC noted that during an average hospital shift, more than one-third of nurses spend at least an hour looking for equipment such as blood pressure monitors and insulin pumps. Just as important, location tracking often improves asset optimization, reduced inventory needs, and improved customer experience.
|
||||
|
||||
**Reality check:** Asset tracking offers clear value. The real question is whether a given use case is cost effective or not, as well as how the data gathered will actually be used. Too often, companies spend a lot of money and effort tracking their assets, but don’t do much with the information.
|
||||
|
||||
#### **3\. Security and compliance**
|
||||
|
||||
Connected solutions can create better working environments, Mesirow said. “In a hotel, for example, these smart devices can ensure that air and water quality is up to standards, provide automated pest traps, monitor dumpsters and recycling bins, detect trespassers, determine when someone needs assistance, or discover activity in an unauthorized area. Monitoring the water quality of hotel swimming pools can lower chemical and filtering costs,” he said.
|
||||
|
||||
Mesirow cited an innovative use case where, in response to workers’ complaints about harassment, hotel operators—in conjunction with the [American Hotel and Lodging Association][8]—are giving their employees portable devices that alert security staff when workers request assistance.
|
||||
|
||||
**Reality check:** This seems useful, but the ROI might be difficult to calculate.
|
||||
|
||||
#### **4\. Customer experience**
|
||||
|
||||
According to PwC, “Sensors, facial recognition, analytics, dashboards, and notifications can elevate and even transform the customer experience. … Using connected solutions, you can identify and reward your best customers by offering perks, reduced wait times, and/or shorter lines.”
|
||||
|
||||
Those kinds of personalized customer experiences can potentially boost customer loyalty and increase revenue, Mesirow said, adding that the technology can also make staff deployments more efficient and “enhance safety by identifying trespassers and criminals who are tampering with company property.”
|
||||
|
||||
**Reality check:** Creating a great customer experience is critical for businesses today, and this kind of personalized targeting promises to make it more efficient and effective. However, it has to be done in a way that makes customers comfortable and not creeped out. Privacy concerns are very real, especially when it comes to working with facial recognition and other kinds of surveillance technology. For example, [San Francisco recently banned city agencies from using facial recognition][9], and others may follow.
|
||||
|
||||
**More on IoT:**
|
||||
|
||||
* [What is the IoT? How the internet of things works][10]
|
||||
* [What is edge computing and how it’s changing the network][11]
|
||||
* [Most powerful Internet of Things companies][12]
|
||||
* [10 Hot IoT startups to watch][13]
|
||||
* [The 6 ways to make money in IoT][14]
|
||||
* [What is digital twin technology? [and why it matters]][15]
|
||||
* [Blockchain, service-centric networking key to IoT success][16]
|
||||
* [Getting grounded in IoT networking and security][17]
|
||||
* [Building IoT-ready networks must become a priority][18]
|
||||
* [What is the Industrial IoT? [And why the stakes are so high]][19]
|
||||
|
||||
|
||||
|
||||
Join the Network World communities on [Facebook][20] and [LinkedIn][21] to comment on topics that are top of mind.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3396128/the-state-of-enterprise-iot-companies-want-solutions-for-these-4-areas.html
|
||||
|
||||
作者:[Fredric Paul][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/Fredric-Paul/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://images.idgesg.net/images/article/2019/02/iot_internet_of_things_by_jackie_niam_gettyimages-996958260_2400x1600-100788446-large.jpg
|
||||
[2]: https://digital.pwc.com/content/pwc-digital/en/products/connected-solutions.html#get-connected
|
||||
[3]: https://www.networkworld.com/article/3309420/forget-smart-homes-the-new-goal-is-autonomous-buildings.html
|
||||
[4]: https://www.statista.com/statistics/370350/internet-of-things-installed-base-by-category/)
|
||||
[5]: https://iot-analytics.com/top-10-iot-segments-2018-real-iot-projects/
|
||||
[6]: https://www.digitalpulse.pwc.com.au/five-unexpected-ways-internet-of-things/
|
||||
[7]: https://digital.pwc.com/content/pwc-digital/en/products/connected-solutions.html
|
||||
[8]: https://www.ahla.com/
|
||||
[9]: https://www.nytimes.com/2019/05/14/us/facial-recognition-ban-san-francisco.html
|
||||
[10]: https://www.networkworld.com/article/3207535/internet-of-things/what-is-the-iot-how-the-internet-of-things-works.html
|
||||
[11]: https://www.networkworld.com/article/3224893/internet-of-things/what-is-edge-computing-and-how-it-s-changing-the-network.html
|
||||
[12]: https://www.networkworld.com/article/2287045/internet-of-things/wireless-153629-10-most-powerful-internet-of-things-companies.html
|
||||
[13]: https://www.networkworld.com/article/3270961/internet-of-things/10-hot-iot-startups-to-watch.html
|
||||
[14]: https://www.networkworld.com/article/3279346/internet-of-things/the-6-ways-to-make-money-in-iot.html
|
||||
[15]: https://www.networkworld.com/article/3280225/internet-of-things/what-is-digital-twin-technology-and-why-it-matters.html
|
||||
[16]: https://www.networkworld.com/article/3276313/internet-of-things/blockchain-service-centric-networking-key-to-iot-success.html
|
||||
[17]: https://www.networkworld.com/article/3269736/internet-of-things/getting-grounded-in-iot-networking-and-security.html
|
||||
[18]: https://www.networkworld.com/article/3276304/internet-of-things/building-iot-ready-networks-must-become-a-priority.html
|
||||
[19]: https://www.networkworld.com/article/3243928/internet-of-things/what-is-the-industrial-iot-and-why-the-stakes-are-so-high.html
|
||||
[20]: https://www.facebook.com/NetworkWorld/
|
||||
[21]: https://www.linkedin.com/company/network-world
|
@ -1,233 +0,0 @@
|
||||
Translating by MjSeve
|
||||
|
||||
ddgr – A Command Line Tool To Search DuckDuckGo From The Terminal
|
||||
======
|
||||
Bash tricks are really awesome in Linux that makes everything is possible in Linux.
|
||||
|
||||
It really works well for developers or system admins because they are spending most of the time with terminal. Did you know why they are preferring this tricks?
|
||||
|
||||
These trick will improve their productivity and also make them to work fast.
|
||||
|
||||
### What Is ddgr
|
||||
|
||||
[ddgr][1] is a command-line utility to search DuckDuckGo from the terminal. ddgr works out of the box with several text-based browsers if the BROWSER environment variable is set.
|
||||
|
||||
Make sure your system should have installed any text-based browsers. You may know about [googler][2] that allow users to perform Google searches from the Linux command line.
|
||||
|
||||
It’s highly popular among cmdline users and they are expect the similar utility for privacy-aware DuckDuckGo, that’s why ddgr came to picture.
|
||||
|
||||
Unlike the web interface, you can specify the number of search results you would like to see per page.
|
||||
|
||||
**Suggested Read :**
|
||||
**(#)** [Googler – Google Search From The Linux Command Line][2]
|
||||
**(#)** [Buku – A Powerful Command-line Bookmark Manager for Linux][3]
|
||||
**(#)** [SoCLI – Easy Way To Search And Browse Stack Overflow From The Terminal][4]
|
||||
**(#)** [RTV (Reddit Terminal Viewer) – A Simple Terminal Viewer For Reddit][5]
|
||||
|
||||
### What Is DuckDuckGo
|
||||
|
||||
DDG stands for DuckDuckGo. DuckDuckGo (DDG) is an Internet search engine that really protecting users search and privacy.
|
||||
|
||||
They didn’t filter users personalized search results and It’s showing the same search results to all users for a given search term.
|
||||
|
||||
Most of the users prefer google search engine, if you really worrying about privacy then you can blindly go with DuckDuckGo.
|
||||
|
||||
### ddgr Features
|
||||
|
||||
* Fast and clean (no ads, stray URLs or clutter), custom color
|
||||
* Designed to deliver maximum readability at minimum space
|
||||
* Specify the number of search results to show per page
|
||||
* Navigate result pages from omniprompt, open URLs in browser
|
||||
* Search and option completion scripts for Bash, Zsh and Fish
|
||||
* DuckDuckGo Bang support (along with completion)
|
||||
* Open the first result directly in browser (as in I’m Feeling Ducky)
|
||||
* Non-stop searches: fire new searches at omniprompt without exiting
|
||||
* Keywords (e.g. filetype:mime, site:somesite.com) support
|
||||
* Limit search by time, specify region, disable safe search
|
||||
* HTTPS proxy support, Do Not Track set, optionally disable User Agent
|
||||
* Support custom url handler script or cmdline utility
|
||||
* Comprehensive documentation, man page with handy usage examples
|
||||
* Minimal dependencies
|
||||
|
||||
|
||||
|
||||
### Prerequisites
|
||||
|
||||
ddgr requires Python 3.4 or later. So, make sure you system should have Python 3.4 or later version.
|
||||
```
|
||||
$ python3 --version
|
||||
Python 3.6.3
|
||||
|
||||
```
|
||||
|
||||
### How To Install ddgr In Linux
|
||||
|
||||
We can easily install ddgr using the following command based on the distributions.
|
||||
|
||||
For **`Fedora`** , use [DNF Command][6] to install ddgr.
|
||||
```
|
||||
# dnf install ddgr
|
||||
|
||||
```
|
||||
|
||||
Alternatively we can use [SNAP Command][7] to install ddgr.
|
||||
```
|
||||
# snap install ddgr
|
||||
|
||||
```
|
||||
|
||||
For **`LinuxMint/Ubuntu`** , use [APT-GET Command][8] or [APT Command][9] to install ddgr.
|
||||
```
|
||||
$ sudo add-apt-repository ppa:twodopeshaggy/jarun
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get install ddgr
|
||||
|
||||
```
|
||||
|
||||
For **`Arch Linux`** based systems, use [Yaourt Command][10] or [Packer Command][11] to install ddgr from AUR repository.
|
||||
```
|
||||
$ yaourt -S ddgr
|
||||
or
|
||||
$ packer -S ddgr
|
||||
|
||||
```
|
||||
|
||||
For **`Debian`** , use [DPKG Command][12] to install ddgr.
|
||||
```
|
||||
# wget https://github.com/jarun/ddgr/releases/download/v1.2/ddgr_1.2-1_debian9.amd64.deb
|
||||
# dpkg -i ddgr_1.2-1_debian9.amd64.deb
|
||||
|
||||
```
|
||||
|
||||
For **`CentOS 7`** , use [YUM Command][13] to install ddgr.
|
||||
```
|
||||
# yum install https://github.com/jarun/ddgr/releases/download/v1.2/ddgr-1.2-1.el7.3.centos.x86_64.rpm
|
||||
|
||||
```
|
||||
|
||||
For **`opensuse`** , use [zypper Command][14] to install ddgr.
|
||||
```
|
||||
# zypper install https://github.com/jarun/ddgr/releases/download/v1.2/ddgr-1.2-1.opensuse42.3.x86_64.rpm
|
||||
|
||||
```
|
||||
|
||||
### How To Launch ddgr
|
||||
|
||||
Enter the `ddgr` command without any option on terminal to bring DuckDuckGo search. You will get the same output similar to below.
|
||||
```
|
||||
$ ddgr
|
||||
|
||||
```
|
||||
|
||||
![][16]
|
||||
|
||||
### How To Search Using ddgr
|
||||
|
||||
We can initiate the search through two ways. Either from omniprompt or directly from terminal. You can search any phrases which you want.
|
||||
|
||||
Directly from terminal.
|
||||
```
|
||||
$ ddgr 2daygeek
|
||||
|
||||
```
|
||||
|
||||
![][17]
|
||||
|
||||
From `omniprompt`.
|
||||
![][18]
|
||||
|
||||
### Omniprompt Shortcut
|
||||
|
||||
Enter `?` to obtain the `omniprompt`, which will show you list of keywords and shortcut to work further with ddgr.
|
||||
![][19]
|
||||
|
||||
### How To Move Next,Previous, and Fist Page
|
||||
|
||||
It allows user to move next page or previous page or first page.
|
||||
|
||||
* `n:` Move to next set of search results
|
||||
* `p:` Move to previous set of search results
|
||||
* `f:` Jump to the first page
|
||||
|
||||
|
||||
|
||||
![][20]
|
||||
|
||||
### How To Initiate A New Search
|
||||
|
||||
“ **d** ” option allow users to initiate a new search from omniprompt. For example, i searched about `2daygeek website` and now i’m going to initiate a new search with phrase “ **Magesh Maruthamuthu** “.
|
||||
|
||||
From `omniprompt`.
|
||||
```
|
||||
ddgr (? for help) d magesh maruthmuthu
|
||||
|
||||
```
|
||||
|
||||
![][21]
|
||||
|
||||
### Show Complete URLs In Search Result
|
||||
|
||||
By default it shows only an article heading, add the “ **x** ” option in search to show complete article urls in search result.
|
||||
```
|
||||
$ ddgr -n 5 -x 2daygeek
|
||||
|
||||
```
|
||||
|
||||
![][22]
|
||||
|
||||
### Limit Search Results
|
||||
|
||||
By default search results shows 10 results per page. If you want to limit the page results for your convenience, you can do by passing `--num or -n` argument with ddgr.
|
||||
```
|
||||
$ ddgr -n 5 2daygeek
|
||||
|
||||
```
|
||||
|
||||
![][23]
|
||||
|
||||
### Website Specific Search
|
||||
|
||||
To search specific pages from the particular website, use the below format. This will fetch the results for given keywords from the website. For example, We are going search about “ **Package Manager** ” from 2daygeek website. See the results.
|
||||
```
|
||||
$ ddgr -n 5 --site 2daygeek "package manager"
|
||||
|
||||
```
|
||||
|
||||
![][24]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/ddgr-duckduckgo-search-from-the-command-line-in-linux/
|
||||
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.2daygeek.com/author/magesh/
|
||||
[1]:https://github.com/jarun/ddgr
|
||||
[2]:https://www.2daygeek.com/googler-google-search-from-the-command-line-on-linux/
|
||||
[3]:https://www.2daygeek.com/buku-command-line-bookmark-manager-linux/
|
||||
[4]:https://www.2daygeek.com/socli-search-and-browse-stack-overflow-from-linux-terminal/
|
||||
[5]:https://www.2daygeek.com/rtv-reddit-terminal-viewer-a-simple-terminal-viewer-for-reddit/
|
||||
[6]:https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/
|
||||
[7]:https://www.2daygeek.com/snap-command-examples/
|
||||
[8]:https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[9]:https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[10]:https://www.2daygeek.com/install-yaourt-aur-helper-on-arch-linux/
|
||||
[11]:https://www.2daygeek.com/install-packer-aur-helper-on-arch-linux/
|
||||
[12]:https://www.2daygeek.com/dpkg-command-to-manage-packages-on-debian-ubuntu-linux-mint-systems/
|
||||
[13]:https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/
|
||||
[14]:https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/
|
||||
[15]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[16]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux1.png
|
||||
[17]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-3.png
|
||||
[18]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-2.png
|
||||
[19]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-4.png
|
||||
[20]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-5a.png
|
||||
[21]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-6a.png
|
||||
[22]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-7a.png
|
||||
[23]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-8.png
|
||||
[24]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-9a.png
|
@ -1,68 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (4 open source apps for plant-based diets)
|
||||
[#]: via: (https://opensource.com/article/19/4/apps-plant-based-diets)
|
||||
[#]: author: (Joshua Allen Holm https://opensource.com/users/holmja)
|
||||
|
||||
4 open source apps for plant-based diets
|
||||
======
|
||||
These apps make it easier for vegetarians and vegans—and omnivores who
|
||||
want to eat healthier—to find food they can eat.
|
||||
![][1]
|
||||
|
||||
Reducing your consumption of meat, dairy, and processed foods is better for the planet and better for your health. Changing your diet can be difficult, but several open source Android applications can help you switch to a more plant-based diet. Whether you are taking part in [Meatless Monday][2], following Mark Bittman's [Vegan Before 6:00][3] guidelines, or switching entirely to a [whole-food, plant-based diet][4], these apps can aid you on your journey by helping you figure out what to eat, discover vegan- and vegetarian-friendly restaurants, and easily communicate your dietary preferences to others. All of these apps are open source and available from the [F-Droid repository][5].
|
||||
|
||||
### Daily Dozen
|
||||
|
||||
![Daily Dozen app][6]
|
||||
|
||||
The [Daily Dozen][7] app provides a checklist of items that Michael Greger, MD, FACLM, recommends as part of a healthy diet and lifestyle. Dr. Greger recommends consuming a whole-food, plant-based diet consisting of diverse foods and supported by daily exercise. This app lets you keep track of how many servings of each type of food you have eaten, how many servings of water (or other approved beverage, such as tea) you drank, and if you exercised each day. Each category of food provides serving sizes and lists of foods that fall under that category; for example, the Cruciferous Vegetable category includes bok choy, broccoli, brussels sprouts, and many other suggestions.
|
||||
|
||||
### Food Restrictions
|
||||
|
||||
![Food Restrictions app][8]
|
||||
|
||||
[Food Restrictions][9] is a simple app that can help you communicate your dietary restrictions to others, even if those people do not speak your language. Users can enter their food restrictions for seven different categories: chicken, beef, pork, fish, cheese, milk, and peppers. There is an "I don't eat" and an "I'm allergic" option for each of those categories. The "don't eat" option shows the icon with a red X over it. The "allergic" option displays the X and a small skull icon. The same information can be displayed using text instead of icons, but the text is only available in English and Portuguese. There is also an option for displaying a text message that says the user is vegetarian or vegan, which summarizes those dietary restrictions more succinctly and more accurately than the pick-and-choose options. The vegan text clearly mentions not eating eggs and honey, which are not options in the pick-and-choose method. However, just like the text version of the pick-and-choose option, these sentences are only available in English and Portuguese.
|
||||
|
||||
### OpenFoodFacts
|
||||
|
||||
![Open Food Facts app][10]
|
||||
|
||||
Avoiding unwanted ingredients when buying groceries can be frustrating, but [OpenFoodFacts][11] can help make the process easier. This app lets you scan the barcodes on products to get a report about the ingredients in a product and how healthy the product is. A product can still be very unhealthy even if it meets the criteria to be a vegan product. Having both the ingredients list and the nutrition facts lets you make informed choices when shopping. The only drawback for this app is that the data is user contributed, so not every product is available, but you can contribute new items, if you want to give back to the project.
|
||||
|
||||
### OpenVegeMap
|
||||
|
||||
![OpenVegeMap app][12]
|
||||
|
||||
Find vegan and vegetarian restaurants in your neighborhood with the [OpenVegeMap][13] app. This app lets you search by either using your phone's current location or by entering an address. Restaurants are classified as Vegan only, Vegan friendly, Vegetarian only, Vegetarian friendly, Non-vegetarian, and Unknown. The app uses data from [OpenStreetMap][14] and user-contributed information about the restaurants, so be sure to double-check to make sure the information provided is up-to-date and accurate.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/4/apps-plant-based-diets
|
||||
|
||||
作者:[Joshua Allen Holm ][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/holmja
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003588_01_rd3os.combacktoschoolserieshe_rh_041x_0.png?itok=tfg6_I78
|
||||
[2]: https://www.meatlessmonday.com/
|
||||
[3]: https://www.amazon.com/dp/0385344740/
|
||||
[4]: https://nutritionstudies.org/whole-food-plant-based-diet-guide/
|
||||
[5]: https://f-droid.org/
|
||||
[6]: https://opensource.com/sites/default/files/uploads/daily_dozen.png (Daily Dozen app)
|
||||
[7]: https://f-droid.org/en/packages/org.nutritionfacts.dailydozen/
|
||||
[8]: https://opensource.com/sites/default/files/uploads/food_restrictions.png (Food Restrictions app)
|
||||
[9]: https://f-droid.org/en/packages/br.com.frs.foodrestrictions/
|
||||
[10]: https://opensource.com/sites/default/files/uploads/openfoodfacts.png (Open Food Facts app)
|
||||
[11]: https://f-droid.org/en/packages/openfoodfacts.github.scrachx.openfood/
|
||||
[12]: https://opensource.com/sites/default/files/uploads/openvegmap.png (OpenVegeMap app)
|
||||
[13]: https://f-droid.org/en/packages/pro.rudloff.openvegemap/
|
||||
[14]: https://www.openstreetmap.org/
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (zhang5788)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
497
sources/tech/20190527 20- FFmpeg Commands For Beginners.md
Normal file
497
sources/tech/20190527 20- FFmpeg Commands For Beginners.md
Normal file
@ -0,0 +1,497 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (20+ FFmpeg Commands For Beginners)
|
||||
[#]: via: (https://www.ostechnix.com/20-ffmpeg-commands-beginners/)
|
||||
[#]: author: (sk https://www.ostechnix.com/author/sk/)
|
||||
|
||||
20+ FFmpeg Commands For Beginners
|
||||
======
|
||||
|
||||
![FFmpeg Commands][1]
|
||||
|
||||
In this guide, I will be explaining how to use FFmpeg multimedia framework to do various audio, video transcoding and conversion operations with examples. I have compiled most commonly and frequently used 20+ FFmpeg commands for beginners. I will keep updating this guide by adding more examples from time to time. Please bookmark this guide and come back in a while to check for the updates. Let us get started, shall we? If you haven’t installed FFmpeg in your Linux system yet, refer the following guide.
|
||||
|
||||
* [**Install FFmpeg in Linux**][2]
|
||||
|
||||
|
||||
|
||||
### 20+ FFmpeg Commands For Beginners
|
||||
|
||||
The typical syntax of the FFmpeg command is:
|
||||
|
||||
```
|
||||
ffmpeg [global_options] {[input_file_options] -i input_url} ...
|
||||
{[output_file_options] output_url} ...
|
||||
```
|
||||
|
||||
We are now going to see some important and useful FFmpeg commands.
|
||||
|
||||
##### **1\. Getting audio/video file information**
|
||||
|
||||
To display your media file details, run:
|
||||
|
||||
```
|
||||
$ ffmpeg -i video.mp4
|
||||
```
|
||||
|
||||
**Sample output:**
|
||||
|
||||
```
|
||||
ffmpeg version n4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
|
||||
built with gcc 8.2.1 (GCC) 20181127
|
||||
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
|
||||
libavutil 56. 22.100 / 56. 22.100
|
||||
libavcodec 58. 35.100 / 58. 35.100
|
||||
libavformat 58. 20.100 / 58. 20.100
|
||||
libavdevice 58. 5.100 / 58. 5.100
|
||||
libavfilter 7. 40.101 / 7. 40.101
|
||||
libswscale 5. 3.100 / 5. 3.100
|
||||
libswresample 3. 3.100 / 3. 3.100
|
||||
libpostproc 55. 3.100 / 55. 3.100
|
||||
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
|
||||
Metadata:
|
||||
major_brand : isom
|
||||
minor_version : 512
|
||||
compatible_brands: isomiso2avc1mp41
|
||||
encoder : Lavf58.20.100
|
||||
Duration: 00:00:28.79, start: 0.000000, bitrate: 454 kb/s
|
||||
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 318 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
|
||||
Metadata:
|
||||
handler_name : ISO Media file produced by Google Inc. Created on: 04/08/2019.
|
||||
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
|
||||
Metadata:
|
||||
handler_name : ISO Media file produced by Google Inc. Created on: 04/08/2019.
|
||||
At least one output file must be specified
|
||||
```
|
||||
|
||||
As you see in the above output, FFmpeg displays the media file information along with FFmpeg details such as version, configuration details, copyright notice, build and library options etc.
|
||||
|
||||
If you don’t want to see the FFmpeg banner and other details, but only the media file information, use **-hide_banner** flag like below.
|
||||
|
||||
```
|
||||
$ ffmpeg -i video.mp4 -hide_banner
|
||||
```
|
||||
|
||||
**Sample output:**
|
||||
|
||||
![][3]
|
||||
|
||||
View audio, video file information using FFMpeg
|
||||
|
||||
See? Now, it displays only the media file details.
|
||||
|
||||
** **Recommended Download** – [**Free Guide: “Spotify Music Streaming: The Unofficial Guide”**][4]
|
||||
|
||||
##### **2\. Converting video files to different formats**
|
||||
|
||||
FFmpeg is powerful audio and video converter, so It’s possible to convert media files between different formats. Say for example, to convert **mp4 file to avi file** , run:
|
||||
|
||||
```
|
||||
$ ffmpeg -i video.mp4 video.avi
|
||||
```
|
||||
|
||||
Similarly, you can convert media files to any format of your choice.
|
||||
|
||||
For example, to convert youtube **flv** format videos to **mpeg** format, run:
|
||||
|
||||
```
|
||||
$ ffmpeg -i video.flv video.mpeg
|
||||
```
|
||||
|
||||
If you want to preserve the quality of your source video file, use ‘-qscale 0’ parameter:
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.webm -qscale 0 output.mp4
|
||||
```
|
||||
|
||||
To check list of supported formats by FFmpeg, run:
|
||||
|
||||
```
|
||||
$ ffmpeg -formats
|
||||
```
|
||||
|
||||
##### **3\. Converting video files to audio files**
|
||||
|
||||
To convert a video file to audio file, just specify the output format as .mp3, or .ogg, or any other audio formats.
|
||||
|
||||
The above command will convert **input.mp4** video file to **output.mp3** audio file.
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -vn output.mp3
|
||||
```
|
||||
|
||||
Also, you can use various audio transcoding options to the output file as shown below.
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -vn -ar 44100 -ac 2 -ab 320 -f mp3 output.mp3
|
||||
```
|
||||
|
||||
Here,
|
||||
|
||||
* **-vn** – Indicates that we have disabled video recording in the output file.
|
||||
* **-ar** – Set the audio frequency of the output file. The common values used are 22050, 44100, 48000 Hz.
|
||||
* **-ac** – Set the number of audio channels.
|
||||
* **-ab** – Indicates the audio bitrate.
|
||||
* **-f** – Output file format. In our case, it’s mp3 format.
|
||||
|
||||
|
||||
|
||||
##### **4\. Change resolution of video files**
|
||||
|
||||
If you want to set a particular resolution to a video file, you can use following command:
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -filter:v scale=1280:720 -c:a copy output.mp4
|
||||
```
|
||||
|
||||
Or,
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -s 1280x720 -c:a copy output.mp4
|
||||
```
|
||||
|
||||
The above command will set the resolution of the given video file to 1280×720.
|
||||
|
||||
Similarly, to convert the above file to 640×480 size, run:
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -filter:v scale=640:480 -c:a copy output.mp4
|
||||
```
|
||||
|
||||
Or,
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -s 640x480 -c:a copy output.mp4
|
||||
```
|
||||
|
||||
This trick will help you to scale your video files to smaller display devices such as tablets and mobiles.
|
||||
|
||||
##### **5\. Compressing video files**
|
||||
|
||||
It is always an good idea to reduce the media files size to lower size to save the harddrive’s space.
|
||||
|
||||
The following command will compress and reduce the output file’s size.
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 output.mp4
|
||||
```
|
||||
|
||||
Please note that you will lose the quality if you try to reduce the video file size. You can lower that **crf** value to **23** or lower if **24** is too aggressive.
|
||||
|
||||
You could also transcode the audio down a bit and make it stereo to reduce the size by including the following options.
|
||||
|
||||
```
|
||||
-ac 2 -c:a aac -strict -2 -b:a 128k
|
||||
```
|
||||
|
||||
** **Recommended Download** – [**Free Guide: “PLEX, a Manual: Your Media, With Style”**][5]
|
||||
|
||||
##### **6\. Compressing Audio files**
|
||||
|
||||
Just like compressing video files, you can also compress audio files using **-ab** flag in order to save some disk space.
|
||||
|
||||
Let us say you have an audio file of 320 kbps bitrate. You want to compress it by changing the bitrate to any lower value like below.
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp3 -ab 128 output.mp3
|
||||
```
|
||||
|
||||
The list of various available audio bitrates are:
|
||||
|
||||
1. 96kbps
|
||||
2. 112kbps
|
||||
3. 128kbps
|
||||
4. 160kbps
|
||||
5. 192kbps
|
||||
6. 256kbps
|
||||
7. 320kbps
|
||||
|
||||
|
||||
|
||||
##### **7. Removing audio stream from a video file
|
||||
|
||||
**
|
||||
|
||||
If you don’t want to a audio from a video file, use **-an** flag.
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -an output.mp4
|
||||
```
|
||||
|
||||
Here, ‘an’ indicates no audio recording.
|
||||
|
||||
The above command will undo all audio related flags, because we don’t audio from the input.mp4.
|
||||
|
||||
##### **8\. Removing video stream from a media file**
|
||||
|
||||
Similarly, if you don’t want video stream, you could easily remove it from the media file using ‘vn’ flag. vn stands for no video recording. In other words, this command converts the given media file into audio file.
|
||||
|
||||
The following command will remove the video from the given media file.
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -vn output.mp3
|
||||
```
|
||||
|
||||
You can also mention the output file’s bitrate using ‘-ab’ flag as shown in the following example.
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -vn -ab 320 output.mp3
|
||||
```
|
||||
|
||||
##### **9. Extracting images from the video **
|
||||
|
||||
Another useful feature of FFmpeg is we can easily extract images from a video file. This could be very useful, if you want to create a photo album from a video file.
|
||||
|
||||
To extract images from a video file, use the following command:
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -r 1 -f image2 image-%2d.png
|
||||
```
|
||||
|
||||
Here,
|
||||
|
||||
* **-r** – Set the frame rate. I.e the number of frames to be extracted into images per second. The default value is **25**.
|
||||
* **-f** – Indicates the output format i.e image format in our case.
|
||||
* **image-%2d.png** – Indicates how we want to name the extracted images. In this case, the names should start like image-01.png, image-02.png, image-03.png and so on. If you use %3d, then the name of images will start like image-001.png, image-002.png and so on.
|
||||
|
||||
|
||||
|
||||
##### **10\. Cropping videos**
|
||||
|
||||
FFMpeg allows to crop a given media file in any dimension of our choice.
|
||||
|
||||
The syntax to crop a vide ofile is given below:
|
||||
|
||||
```
|
||||
ffmpeg -i input.mp4 -filter:v "crop=w:h:x:y" output.mp4
|
||||
```
|
||||
|
||||
Here,
|
||||
|
||||
* **input.mp4** – source video file.
|
||||
* **-filter:v** – Indicates the video filter.
|
||||
* **crop** – Indicates crop filter.
|
||||
* **w** – **Width** of the rectangle that we want to crop from the source video.
|
||||
* **h** – Height of the rectangle.
|
||||
* **x** – **x coordinate** of the rectangle that we want to crop from the source video.
|
||||
* **y** – y coordinate of the rectangle.
|
||||
|
||||
|
||||
|
||||
Let us say you want to a video with a **width of 640 pixels** and a **height of 480 pixels** , from the **position (200,150)** , the command would be:
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -filter:v "crop=640:480:200:150" output.mp4
|
||||
```
|
||||
|
||||
Please note that cropping videos will affect the quality. Do not do this unless it is necessary.
|
||||
|
||||
##### **11\. Convert a specific portion of a video**
|
||||
|
||||
Sometimes, you might want to convert only a specific portion of the video file to different format. Say for example, the following command will convert the **first 50 seconds** of given video.mp4 file to video.avi format.
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -t 10 output.avi
|
||||
```
|
||||
|
||||
Here, we specify the the time in seconds. Also, it is possible to specify the time in **hh.mm.ss** format.
|
||||
|
||||
##### **12\. Set the aspect ratio to video**
|
||||
|
||||
You can set the aspect ration to a video file using **-aspect** flag like below.
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -aspect 16:9 output.mp4
|
||||
```
|
||||
|
||||
The commonly used aspect ratios are:
|
||||
|
||||
* 16:9
|
||||
* 4:3
|
||||
* 16:10
|
||||
* 5:4
|
||||
* 2:21:1
|
||||
* 2:35:1
|
||||
* 2:39:1
|
||||
|
||||
|
||||
|
||||
##### **13\. Adding poster image to audio files**
|
||||
|
||||
You can add the poster images to your files, so that the images will be displayed while playing the audio files. This could be useful to host audio files in Video hosting or sharing websites.
|
||||
|
||||
```
|
||||
$ ffmpeg -loop 1 -i inputimage.jpg -i inputaudio.mp3 -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest output.mp4
|
||||
```
|
||||
|
||||
##### **14. Trim a media file using start and stop times
|
||||
|
||||
**
|
||||
|
||||
To trim down a video to smaller clip using start and stop times, we can use the following command.
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -ss 00:00:50 -codec copy -t 50 output.mp4
|
||||
```
|
||||
|
||||
Here,
|
||||
|
||||
* –s – Indicates the starting time of the video clip. In our example, starting time is the 50th second.
|
||||
* -t – Indicates the total time duration.
|
||||
|
||||
|
||||
|
||||
This is very helpful when you want to cut a part from an audio or video file using starting and ending time.
|
||||
|
||||
Similarly, we can trim down the audio file like below.
|
||||
|
||||
```
|
||||
$ ffmpeg -i audio.mp3 -ss 00:01:54 -to 00:06:53 -c copy output.mp3
|
||||
```
|
||||
|
||||
##### **15\. Split video files into multiple parts**
|
||||
|
||||
Some websites will allow you to upload only a specific size of video. In such cases, you can split the large video files into multiple smaller parts like below.
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -t 00:00:30 -c copy part1.mp4 -ss 00:00:30 -codec copy part2.mp4
|
||||
```
|
||||
|
||||
Here, **-t 00:00:30** indicates a part that is created from the start of the video to the 30th second of video. **-ss 00:00:30** shows the starting time stamp for the next part of video. It means that the 2nd part will start from the 30th second and will continue up to the end of the original video file.
|
||||
|
||||
** **Recommended Download** – [**Free Guide: “How to Start Your Own Successful Podcast”**][6]
|
||||
|
||||
##### **16\. Joining or merging multiple video parts into one**
|
||||
|
||||
FFmpeg will also join the multiple video parts and create a single video file.
|
||||
|
||||
Create **join.txt** file that contains the exact paths of the files that you want to join. All files should be same format (same codec). The path name of all files should be mentioned one by one like below.
|
||||
|
||||
```
|
||||
file /home/sk/myvideos/part1.mp4
|
||||
file /home/sk/myvideos/part2.mp4
|
||||
file /home/sk/myvideos/part3.mp4
|
||||
file /home/sk/myvideos/part4.mp4
|
||||
```
|
||||
|
||||
Now, join all files using command:
|
||||
|
||||
```
|
||||
$ ffmpeg -f concat -i join.txt -c copy output.mp4
|
||||
```
|
||||
|
||||
If you get an error something like below;
|
||||
|
||||
```
|
||||
[concat @ 0x555fed174cc0] Unsafe file name '/path/to/mp4'
|
||||
join.txt: Operation not permitted
|
||||
```
|
||||
|
||||
Add **“-safe 0”** :
|
||||
|
||||
```
|
||||
$ ffmpeg -f concat -safe 0 -i join.txt -c copy output.mp4
|
||||
```
|
||||
|
||||
The above command will join part1.mp4, part2.mp4, part3.mp4, and part4.mp4 files into a single file called “output.mp4”.
|
||||
|
||||
##### **17\. Add subtitles to a video file**
|
||||
|
||||
We can also add subtitles to a video file using FFmpeg. Download the correct subtitle for your video and add it your video as shown below.
|
||||
|
||||
```
|
||||
$ fmpeg -i input.mp4 -i subtitle.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast output.mp4
|
||||
```
|
||||
|
||||
##### **18\. Preview or test video or audio files**
|
||||
|
||||
You might want to preview to verify or test whether the output file has been properly transcoded or not. To do so, you can play it from your Terminal with command:
|
||||
|
||||
```
|
||||
$ ffplay video.mp4
|
||||
```
|
||||
|
||||
[![][1]][7]
|
||||
|
||||
Similarly, you can test the audio files as shown below.
|
||||
|
||||
```
|
||||
$ ffplay audio.mp3
|
||||
```
|
||||
|
||||
[![][1]][8]
|
||||
|
||||
##### **19\. Increase/decrease video playback speed**
|
||||
|
||||
FFmpeg allows you to adjust the video playback speed.
|
||||
|
||||
To increase the video playback speed, run:
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" output.mp4
|
||||
```
|
||||
|
||||
The command will double the speed of the video.
|
||||
|
||||
To slow down your video, you need to use a multiplier **greater than 1**. To decrease playback speed, run:
|
||||
|
||||
```
|
||||
$ ffmpeg -i input.mp4 -vf "setpts=4.0*PTS" output.mp4
|
||||
```
|
||||
|
||||
##### **20. Create Animated GIF
|
||||
|
||||
**
|
||||
|
||||
We use GIF images on almost all social and professional networks for various purposes. Using FFmpeg, we can easily and quickly create animated video files. The following guide explains how to create an animated GIF file using FFmpeg and ImageMagick in Unix-like systems.
|
||||
|
||||
* [**How To Create Animated GIF In Linux**][9]
|
||||
|
||||
|
||||
|
||||
##### **21.** Create videos from PDF files
|
||||
|
||||
I collected many PDF files, mostly Linux tutorials, over the years and saved in my Tablet PC. Sometimes I feel too lazy to read them from the tablet. So, I decided to create a video from PDF files and watch it in a big screen devices like a TV or a Computer. If you ever wondered how to make a movie file from a collection of PDF files, the following guide will help.
|
||||
|
||||
* [**How To Create A Video From PDF Files In Linux**][10]
|
||||
|
||||
|
||||
|
||||
##### **22\. Getting help**
|
||||
|
||||
In this guide, I have covered the most commonly used FFmpeg commands. It has a lot more different options to do various advanced functions. To learn more about it, refer the man page.
|
||||
|
||||
```
|
||||
$ man ffmpeg
|
||||
```
|
||||
|
||||
And, that’s all. I hope this guide will help you to getting started with FFmpeg. If you find this guide useful, please share it on your social, and professional networks. More good stuffs to come. Stay tuned!
|
||||
|
||||
Cheers!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/20-ffmpeg-commands-beginners/
|
||||
|
||||
作者:[sk][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.ostechnix.com/author/sk/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.ostechnix.com/wp-content/uploads/2017/05/FFmpeg-Commands-720x340.png
|
||||
[2]: https://www.ostechnix.com/install-ffmpeg-linux/
|
||||
[3]: http://www.ostechnix.com/wp-content/uploads/2017/05/sk@sk_001.png
|
||||
[4]: https://ostechnix.tradepub.com/free/w_make141/prgm.cgi
|
||||
[5]: https://ostechnix.tradepub.com/free/w_make75/prgm.cgi
|
||||
[6]: https://ostechnix.tradepub.com/free/w_make235/prgm.cgi
|
||||
[7]: http://www.ostechnix.com/wp-content/uploads/2017/05/Menu_004.png
|
||||
[8]: http://www.ostechnix.com/wp-content/uploads/2017/05/Menu_005-3.png
|
||||
[9]: https://www.ostechnix.com/create-animated-gif-ubuntu-16-04/
|
||||
[10]: https://www.ostechnix.com/create-video-pdf-files-linux/
|
@ -0,0 +1,103 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Blockchain 2.0 – Introduction To Hyperledger Sawtooth [Part 12])
|
||||
[#]: via: (https://www.ostechnix.com/blockchain-2-0-introduction-to-hyperledger-sawtooth/)
|
||||
[#]: author: (editor https://www.ostechnix.com/author/editor/)
|
||||
|
||||
Blockchain 2.0 – Introduction To Hyperledger Sawtooth [Part 12]
|
||||
======
|
||||
|
||||
![Introduction To Hyperledger Sawtooth][1]
|
||||
|
||||
After having discussed the [**Hyperledger Fabric**][2] project in detail on this blog, its time we moved on to the next project of interest at the Hyperledger camp. **Hyperledger Sawtooth** is Intel’s contribution to the [**Blockchain**][3] consortium mission to develop enterprise ready modular distributed ledgers and applications. Sawtooth is another attempt at creating an easy to roll out blockchain ledger for businesses keeping their resource constraints and security requirements in mind. While platforms such as [**Ethereum**][4] will in theory offer similar functionality when placed in capable hands, Sawtooth readily provides a lot of customizability and is built from the ground up for specific enterprise level use cases.
|
||||
|
||||
The Hyperledger project page has an introductory video detailing the Sawtooth architecture and platform. We’re attaching it here for readers to get a quick round-up about the product.
|
||||
|
||||
Moving to the intricacies of the Sawtooth project, there are **five primary and significant differences** between Sawtooth and its alternatives. The post from now and on will explore these differences and at the end will mention an example real world use case for Hyperledger Sawtooth in managing supply chains.
|
||||
|
||||
### Distinction 1: The consensus algorithm – PoET
|
||||
|
||||
This is perhaps amongst the most notable and significant changes that Sawtooth brings to the fore. While exploring all the different consensus algorithms that exist for blockchain platforms these days is out of the scope of this post, what is to be noted is that Sawtooth uses a **Proof Of Elapsed Time** (POET) based consensus algorithm. Such a system for validating transactions and blocks on the blockchain is considered to be resources efficient unlike other computation heavy systems which use the likes of **Proof of work** or **Proof of stake** algorithms.
|
||||
|
||||
POET is designed to utilize the security and tamper proof features of modern processors with reference implementations utilizing **Intel’s trusted execution environment** (TEE) architecture on its modern CPUs. The fact that the execution of the validating program takes use of a TEE along with a **“lottery”** system that is implemented to choose the **validator** or **node** to fulfill the request makes the process of creating blocks on the Sawtooth architecture secure and resource efficient at the same time.
|
||||
|
||||
The POET algorithm basically elects a validator randomly based on a stochastic process. The probability of a particular node being selected depends on a host of pointers one of which depends on the amount of computing resources the said node has contributed to the ledger so far. The chosen validator then proceeds to timestamp the said block of data and shares it with the permissioned nodes in the network so that there remains a reliable record of the blockchains immutability. This method of electing the “validator” node was developed by **Intel** and so far, has been shown to exhibit zero bias and or error in executing its function.
|
||||
|
||||
### Distinction 2: A fully separated level of abstraction between the application level and core system
|
||||
|
||||
As mentioned, the Sawtooth platform takes modularity to the next level. Here in the reference implementation that is shared by the [**Hyperledger project**][5] foundation, the core system that enables users to create a distributed ledger, and, the application run-time environment (the virtual environment where applications developed to run on the blockchain otherwise known as [**smart contracts**][6] or **chaincode** ) are separated by a full level of abstraction. This essentially means that developers can separately code applications in any programming language of their choice instead of having to conform to and follow platform specific languages. The Sawtooth platform provides support for the following contract languages out of the box: **Java** , **Python** , **C++** , **Go** , **JavaScript** and **Rust**. This distinction between the core system and application levels are obtained by defining a custom transaction family for each application that is developed on the platform.
|
||||
|
||||
A transaction family contains the following:
|
||||
|
||||
* **A transaction processor** : basically, your applications logic or business logic.
|
||||
* **Data model** : a system that defines and handles data storage and processing at the system level.
|
||||
* **Client-side handler** to handle the end user side of your application.
|
||||
|
||||
|
||||
|
||||
Multiple low-level transaction families such as this may be defined in a permissioned blockchain and used in a modular fashion throughout the network. For instance, if a consortium of banks chose to implement it, they could come together and define common functionalities or rules for their applications and then plug and play the transaction families they need in their respective systems without having to develop everything on their own.
|
||||
|
||||
### Distinction 3: SETH
|
||||
|
||||
It is without doubt that a blockchain future would for sure have Ethereum as one of the key players. People at the Hyperledger foundation know this well. The **Hyperledger Burrow project** is in fact meant to address the existence of entities working on multiple platforms by providing a way for developers to use Ethereum blockchain specifications to build custom distributed applications using the **EVM** (Ethereum virtual machine).
|
||||
|
||||
Basically speaking, Burrow lets you customize and deploy Ethereum based [**DApps**][7] (written in **solidity** ) in non-public blockchains (the kind developed for use at the Hyperledger foundation). The Burrow and Sawtooth projects teamed up and created **SETH**. **Sawtooth-Ethereum Integration project** (SETH) is meant to add Ethereum (solidity) smart contract functionality and compatibility to Sawtooth based distributed ledger networks. A much-less known agenda to SETH is the fact that applications (DApps) and smart contracts written for EVM can now be easily ported to Sawtooth.
|
||||
|
||||
### Distinction 4: ACID principle and ability to batch process
|
||||
|
||||
A rather path breaking feature of Sawtooth is its ability to batch transactions together and then package them into a block. The blocks and transactions will still be subject to the **ACID** principle ( **A** tomicity, **C** onsistency, **I** solation and **D** urability). The implication of these two facts are highlighted using an example as follows.
|
||||
|
||||
Let’s say you have **6 transactions** to be packaged into **two blocks (4+2)**. Block A has 4 transactions which individually needs to succeed in order for the next block of 2 transactions to be timestamped and validated. Assuming they succeed, the next block of 2 transactions is processed and assuming even they are successful the entire package of 6 transactions are deemed successful and the overall business logic is deemed successful. For instance, assume you’re selling a car. Different transactions at the ends of the buyer (block A) and the seller (block B) will need be completed in order for the trade to be deemed valid. Ownership is transferred only if both the sides are successful in carrying out their individual transactions.
|
||||
|
||||
Such a feature will improve accountability on individual ends by separating responsibilities and improve the recognizability of faults and errors by the same principle. The ACID principle is implemented by coding for a custom transaction processor and defining a transaction family that will store data in the said block structure.
|
||||
|
||||
### Distinction 5: Parallel transaction execution
|
||||
|
||||
Blockchain platforms usually follow a serial **first come first serve route** to executing transactions and follow a queueing system for the same. Sawtooth provides support for both **serial** and **parallel execution** of transactions. Parallel transaction processing offers significant performance gains for even faster transactions by reducing overall transaction latencies. More faster transactions will be processed along with slower and bigger transactions at the same time on the platform instead of transactions of all types to be kept waiting.
|
||||
|
||||
The methodology followed to implement the parallel transaction paradigm efficiently takes care of the double spending problems and errors due to multiple changes being made to the same state by defining a custom scheduler for the network which can identity processes and their predecessors.
|
||||
|
||||
Real world use case: Supply Chain Management using Sawtooth applied with IoT
|
||||
|
||||
The Sawtooth **official website** lists seafood traceability as an example use case for the Sawtooth platform. The basic template is applicable for almost all supply chain related use cases.
|
||||
|
||||
![][8]
|
||||
|
||||
Figure 1 From the Hyperledger Sawtooth Official Website
|
||||
|
||||
Traditional supply chain management solutions in this space work majorly through manual record keeping which leaves room for massive frauds, errors, and significant quality control issues. IoT has been cited as a solution to overcome such issues with supply chains in day to day use. Inexpensive GPS enabled RFID-tags can be attached to fresh catch or produce as the case may be and can be scanned for updating at the individual processing centres automatically. Buyers or middle men can verify and or track the information easily using a client on their mobile device to know the route their dinner has taken before arriving on their plates.
|
||||
|
||||
While tracking seafood seems to be a first world problem in countries like India, the change an IoT enabled system can bring to public delivery systems in developing countries can be a welcome change. The application is available for demo at this **[link][9]** and users are encouraged to fiddle with it and adopt it to suit their needs.
|
||||
|
||||
**Reference:**
|
||||
|
||||
* [**The Official Hyperledger Sawtooth Docs**][10]
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/blockchain-2-0-introduction-to-hyperledger-sawtooth/
|
||||
|
||||
作者:[editor][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.ostechnix.com/author/editor/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.ostechnix.com/wp-content/uploads/2019/05/Hyperledger-Sawtooth-720x340.png
|
||||
[2]: https://www.ostechnix.com/blockchain-2-0-introduction-to-hyperledger-fabric/
|
||||
[3]: https://www.ostechnix.com/blockchain-2-0-an-introduction/
|
||||
[4]: https://www.ostechnix.com/blockchain-2-0-what-is-ethereum/
|
||||
[5]: https://www.ostechnix.com/blockchain-2-0-an-introduction-to-hyperledger-project-hlp/
|
||||
[6]: https://www.ostechnix.com/blockchain-2-0-explaining-smart-contracts-and-its-types/
|
||||
[7]: https://www.ostechnix.com/blockchain-2-0-explaining-distributed-computing-and-distributed-applications/
|
||||
[8]: http://www.ostechnix.com/wp-content/uploads/2019/05/Sawtooth.png
|
||||
[9]: https://sawtooth.hyperledger.org/examples/seafood.html
|
||||
[10]: https://sawtooth.hyperledger.org/docs/core/releases/1.0/contents.html
|
@ -0,0 +1,162 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Dockly – Manage Docker Containers From Terminal)
|
||||
[#]: via: (https://www.ostechnix.com/dockly-manage-docker-containers-from-terminal/)
|
||||
[#]: author: (sk https://www.ostechnix.com/author/sk/)
|
||||
|
||||
Dockly – Manage Docker Containers From Terminal
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
A few days ago, we published a guide which covered almost all details you ever need to know to [**getting started with Docker**][2]. In that guide, we have shown you how to create and manage Docker containers in detail. There are also some non-official tools available for managing Docker containers. If you’ve looked at our old archives, you might have stumbled upon two web-based tools namely [**“Portainer”**][3] and [**“PiCluster”**][4]. Both of them makes the Docker management task much easier and simpler from a web browser. Today, I came across yet another Docker management tool named **“Dockly”**.
|
||||
|
||||
Unlike the aforementioned tools, Dockly is a TUI (text user interface) utility to manage Docker containers and services from the Terminal in Unix-like systems. It is free, open source tool built with **NodeJS**. In this brief guide, we will see how to install Dockly and how to manage Docker containers from command line.
|
||||
|
||||
### Installing Dockly
|
||||
|
||||
Make sure you have installed NodeJS on your Linux box. If you haven’t installed it yet, refer the following guide.
|
||||
|
||||
* [**How To Install NodeJS On Linux**][5]
|
||||
|
||||
|
||||
|
||||
Once NodeJS is installed, run the following command to install Dockly:
|
||||
|
||||
```
|
||||
# npm install -g dockly
|
||||
```
|
||||
|
||||
### Manage Docker Containers With Dockly From Terminal
|
||||
|
||||
Managing Docker containers with Dockly is easy! All you have to do is to open the terminal and run the following command:
|
||||
|
||||
```
|
||||
# dockly
|
||||
```
|
||||
|
||||
Dockly will will automatically connect to your localhost docker daemon through the unix socket and display the list of running containers in the Terminal as shown below.
|
||||
|
||||
![][6]
|
||||
|
||||
Manage Docker Containers Using Dockly
|
||||
|
||||
As you can see in the above screenshot, Dockly displays the following information of running containers on the top:
|
||||
|
||||
* Container ID,
|
||||
* Name of the container(s),
|
||||
* Docker image,
|
||||
* Command,
|
||||
* State of the running container(s),
|
||||
* Status.
|
||||
|
||||
|
||||
|
||||
On the top right side, you will see the CPU an Memory utilization of containers. Use UP/DOWN arrow keys to move between Containers.
|
||||
|
||||
At the bottom, there are few keyboard shortcut keys to do various docker management tasks. Here are the list of currently available keyboard shortcuts:
|
||||
|
||||
* **=** – Refresh the Dockly interface,
|
||||
* **/** – Search the containers list view,
|
||||
* **i** – Display the information about the currently selected container or service,
|
||||
* **< RETURN>** – Show logs of the current container or service,
|
||||
* **v** – Toggle between Containers and Services view,
|
||||
* **l** – Launch a /bin/bash session on the selected Container,
|
||||
* **r** – Restart the selected Container,
|
||||
* **s** – Stop the selected Container,
|
||||
* **h** – Show HELP window,
|
||||
* **q** – Quit Dockly.
|
||||
|
||||
|
||||
|
||||
##### **Viewing information of a container**
|
||||
|
||||
Choose a Container using UP/DOWN arrow and press **“i”** to display the information of the selected Container.
|
||||
|
||||
![][7]
|
||||
|
||||
View container’s information
|
||||
|
||||
##### Restart Containers
|
||||
|
||||
If you want to restart your Containers at any time, just choose it and press **“r”** to restart.
|
||||
|
||||
![][8]
|
||||
|
||||
Restart Docker containers
|
||||
|
||||
##### Stop/Remove Containers and Images
|
||||
|
||||
We can stop and/or remove one or all containers at once if they are no longer required. To do so, press **“m”** to open **Menu**.
|
||||
|
||||
![][9]
|
||||
|
||||
Stop, remove Docker containers and images
|
||||
|
||||
From here, you can do the following operations.
|
||||
|
||||
* Stop all Docker containers,
|
||||
* Remove selected container,
|
||||
* Remove all containers,
|
||||
* Remove all Docker images etc.
|
||||
|
||||
|
||||
|
||||
##### Display Dockly help section
|
||||
|
||||
If you have any questions, just press **“h”** to open the help section.
|
||||
|
||||
![][10]
|
||||
|
||||
Dockly Help
|
||||
|
||||
For more details, refer the official GitHub page given at the end.
|
||||
|
||||
And, that’s all for now. Hope this was useful. If you spend a lot of time working with Docker containers, give Dockly a try and see if it helps.
|
||||
|
||||
* * *
|
||||
|
||||
**Suggested read:**
|
||||
|
||||
* **[How To Automatically Update Running Docker Containers][11]**
|
||||
* [**ctop – A Commandline Monitoring Tool For Linux Containers**][12]
|
||||
|
||||
|
||||
|
||||
* * *
|
||||
|
||||
**Resource:**
|
||||
|
||||
* [**Dockly GitHub Repository**][13]
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/dockly-manage-docker-containers-from-terminal/
|
||||
|
||||
作者:[sk][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.ostechnix.com/author/sk/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.ostechnix.com/wp-content/uploads/2019/05/Dockly-720x340.png
|
||||
[2]: https://www.ostechnix.com/getting-started-with-docker/
|
||||
[3]: https://www.ostechnix.com/portainer-an-easiest-way-to-manage-docker/
|
||||
[4]: https://www.ostechnix.com/picluster-simple-web-based-docker-management-application/
|
||||
[5]: https://www.ostechnix.com/install-node-js-linux/
|
||||
[6]: http://www.ostechnix.com/wp-content/uploads/2019/05/Manage-Docker-Containers-Using-Dockly.png
|
||||
[7]: http://www.ostechnix.com/wp-content/uploads/2019/05/View-containers-information.png
|
||||
[8]: http://www.ostechnix.com/wp-content/uploads/2019/05/Restart-containers.png
|
||||
[9]: http://www.ostechnix.com/wp-content/uploads/2019/05/stop-remove-containers-and-images.png
|
||||
[10]: http://www.ostechnix.com/wp-content/uploads/2019/05/Dockly-Help.png
|
||||
[11]: https://www.ostechnix.com/automatically-update-running-docker-containers/
|
||||
[12]: https://www.ostechnix.com/ctop-commandline-monitoring-tool-linux-containers/
|
||||
[13]: https://github.com/lirantal/dockly
|
@ -0,0 +1,320 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How To Check Available Security Updates On Red Hat (RHEL) And CentOS System?)
|
||||
[#]: via: (https://www.2daygeek.com/check-list-view-find-available-security-updates-on-redhat-rhel-centos-system/)
|
||||
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
|
||||
|
||||
How To Check Available Security Updates On Red Hat (RHEL) And CentOS System?
|
||||
======
|
||||
|
||||
As per your organization policy you may need to push only security updates due to varies reasons.
|
||||
|
||||
In most cases, it could be an application compatibility issues.
|
||||
|
||||
How to do that? Is it possible to limit yum to perform only security updates?
|
||||
|
||||
Yes, it’s possible and can be done easily through yum package manager.
|
||||
|
||||
In this article, we are not giving only the required information.
|
||||
|
||||
Instead, we have added lot more commands that help you to gather many information about a given security package.
|
||||
|
||||
This may give you an idea or opportunity to understand and fix the list of vulnerabilities, which you have it.
|
||||
|
||||
If security vulnerabilities are discovered, the affected software must be updated in order to limit any potential security risks on system.
|
||||
|
||||
For RHEL/CentOS 6 systems, run the following **[Yum Command][1]** to install yum security plugin.
|
||||
|
||||
```
|
||||
# yum -y install yum-plugin-security
|
||||
```
|
||||
|
||||
The plugin is already a part of yum itself so, no need to install this on RHEL 7&8/CentOS 7&8.
|
||||
|
||||
To list all available erratas (it includes Security, Bug Fix and Product Enhancement) without installing them.
|
||||
|
||||
```
|
||||
# yum updateinfo list available
|
||||
Loaded plugins: changelog, package_upload, product-id, search-disabled-repos,
|
||||
: subscription-manager, verify, versionlock
|
||||
RHSA-2014:1031 Important/Sec. 389-ds-base-1.3.1.6-26.el7_0.x86_64
|
||||
RHSA-2015:0416 Important/Sec. 389-ds-base-1.3.3.1-13.el7.x86_64
|
||||
RHBA-2015:0626 bugfix 389-ds-base-1.3.3.1-15.el7_1.x86_64
|
||||
RHSA-2015:0895 Important/Sec. 389-ds-base-1.3.3.1-16.el7_1.x86_64
|
||||
RHBA-2015:1554 bugfix 389-ds-base-1.3.3.1-20.el7_1.x86_64
|
||||
RHBA-2015:1960 bugfix 389-ds-base-1.3.3.1-23.el7_1.x86_64
|
||||
RHBA-2015:2351 bugfix 389-ds-base-1.3.4.0-19.el7.x86_64
|
||||
RHBA-2015:2572 bugfix 389-ds-base-1.3.4.0-21.el7_2.x86_64
|
||||
RHSA-2016:0204 Important/Sec. 389-ds-base-1.3.4.0-26.el7_2.x86_64
|
||||
RHBA-2016:0550 bugfix 389-ds-base-1.3.4.0-29.el7_2.x86_64
|
||||
RHBA-2016:1048 bugfix 389-ds-base-1.3.4.0-30.el7_2.x86_64
|
||||
RHBA-2016:1298 bugfix 389-ds-base-1.3.4.0-32.el7_2.x86_64
|
||||
```
|
||||
|
||||
To count the number of erratas, run the following command.
|
||||
|
||||
```
|
||||
# yum updateinfo list available | wc -l
|
||||
11269
|
||||
```
|
||||
|
||||
To list all available security updates without installing them.
|
||||
|
||||
It used to display information about both installed and available advisories on your system.
|
||||
|
||||
```
|
||||
# yum updateinfo list security all
|
||||
Loaded plugins: changelog, package_upload, product-id, search-disabled-repos,
|
||||
: subscription-manager, verify, versionlock
|
||||
RHSA-2014:1031 Important/Sec. 389-ds-base-1.3.1.6-26.el7_0.x86_64
|
||||
RHSA-2015:0416 Important/Sec. 389-ds-base-1.3.3.1-13.el7.x86_64
|
||||
RHSA-2015:0895 Important/Sec. 389-ds-base-1.3.3.1-16.el7_1.x86_64
|
||||
RHSA-2016:0204 Important/Sec. 389-ds-base-1.3.4.0-26.el7_2.x86_64
|
||||
RHSA-2016:2594 Moderate/Sec. 389-ds-base-1.3.5.10-11.el7.x86_64
|
||||
RHSA-2017:0920 Important/Sec. 389-ds-base-1.3.5.10-20.el7_3.x86_64
|
||||
RHSA-2017:2569 Moderate/Sec. 389-ds-base-1.3.6.1-19.el7_4.x86_64
|
||||
RHSA-2018:0163 Important/Sec. 389-ds-base-1.3.6.1-26.el7_4.x86_64
|
||||
RHSA-2018:0414 Important/Sec. 389-ds-base-1.3.6.1-28.el7_4.x86_64
|
||||
RHSA-2018:1380 Important/Sec. 389-ds-base-1.3.7.5-21.el7_5.x86_64
|
||||
RHSA-2018:2757 Moderate/Sec. 389-ds-base-1.3.7.5-28.el7_5.x86_64
|
||||
RHSA-2018:3127 Moderate/Sec. 389-ds-base-1.3.8.4-15.el7.x86_64
|
||||
RHSA-2014:1031 Important/Sec. 389-ds-base-libs-1.3.1.6-26.el7_0.x86_64
|
||||
```
|
||||
|
||||
To print all available advisories security packages (It prints all kind of packages like installed and not-installed).
|
||||
|
||||
```
|
||||
# yum updateinfo list security all | grep -v "i"
|
||||
|
||||
RHSA-2014:1031 Important/Sec. 389-ds-base-1.3.1.6-26.el7_0.x86_64
|
||||
RHSA-2015:0416 Important/Sec. 389-ds-base-1.3.3.1-13.el7.x86_64
|
||||
RHSA-2015:0895 Important/Sec. 389-ds-base-1.3.3.1-16.el7_1.x86_64
|
||||
RHSA-2016:0204 Important/Sec. 389-ds-base-1.3.4.0-26.el7_2.x86_64
|
||||
RHSA-2016:2594 Moderate/Sec. 389-ds-base-1.3.5.10-11.el7.x86_64
|
||||
RHSA-2017:0920 Important/Sec. 389-ds-base-1.3.5.10-20.el7_3.x86_64
|
||||
RHSA-2017:2569 Moderate/Sec. 389-ds-base-1.3.6.1-19.el7_4.x86_64
|
||||
RHSA-2018:0163 Important/Sec. 389-ds-base-1.3.6.1-26.el7_4.x86_64
|
||||
RHSA-2018:0414 Important/Sec. 389-ds-base-1.3.6.1-28.el7_4.x86_64
|
||||
RHSA-2018:1380 Important/Sec. 389-ds-base-1.3.7.5-21.el7_5.x86_64
|
||||
RHSA-2018:2757 Moderate/Sec. 389-ds-base-1.3.7.5-28.el7_5.x86_64
|
||||
```
|
||||
|
||||
To count the number of available security package, run the following command.
|
||||
|
||||
```
|
||||
# yum updateinfo list security all | wc -l
|
||||
3522
|
||||
```
|
||||
|
||||
It’s used to list all of the relevant errata notice information, from the updateinfo.xml data in yum. This includes bugzillas, CVEs, security updates and new.
|
||||
|
||||
```
|
||||
# yum updateinfo list security
|
||||
|
||||
or
|
||||
|
||||
# yum updateinfo list sec
|
||||
|
||||
Loaded plugins: changelog, package_upload, product-id, search-disabled-repos,
|
||||
: subscription-manager, verify, versionlock
|
||||
|
||||
RHSA-2018:3665 Important/Sec. NetworkManager-1:1.12.0-8.el7_6.x86_64
|
||||
RHSA-2018:3665 Important/Sec. NetworkManager-adsl-1:1.12.0-8.el7_6.x86_64
|
||||
RHSA-2018:3665 Important/Sec. NetworkManager-bluetooth-1:1.12.0-8.el7_6.x86_64
|
||||
RHSA-2018:3665 Important/Sec. NetworkManager-config-server-1:1.12.0-8.el7_6.noarch
|
||||
RHSA-2018:3665 Important/Sec. NetworkManager-glib-1:1.12.0-8.el7_6.x86_64
|
||||
RHSA-2018:3665 Important/Sec. NetworkManager-libnm-1:1.12.0-8.el7_6.x86_64
|
||||
RHSA-2018:3665 Important/Sec. NetworkManager-ppp-1:1.12.0-8.el7_6.x86_64
|
||||
RHSA-2018:3665 Important/Sec. NetworkManager-team-1:1.12.0-8.el7_6.x86_64
|
||||
RHSA-2018:3665 Important/Sec. NetworkManager-tui-1:1.12.0-8.el7_6.x86_64
|
||||
RHSA-2018:3665 Important/Sec. NetworkManager-wifi-1:1.12.0-8.el7_6.x86_64
|
||||
RHSA-2018:3665 Important/Sec. NetworkManager-wwan-1:1.12.0-8.el7_6.x86_64
|
||||
```
|
||||
|
||||
To display all updates that are security relevant, and get a return code on whether there are security updates.
|
||||
|
||||
```
|
||||
# yum --security check-update
|
||||
Loaded plugins: changelog, package_upload, product-id, search-disabled-repos, subscription-manager, verify, versionlock
|
||||
rhel-7-server-rpms | 2.0 kB 00:00:00
|
||||
--> policycoreutils-devel-2.2.5-20.el7.x86_64 from rhel-7-server-rpms excluded (updateinfo)
|
||||
--> smc-raghumalayalam-fonts-6.0-7.el7.noarch from rhel-7-server-rpms excluded (updateinfo)
|
||||
--> amanda-server-3.3.3-17.el7.x86_64 from rhel-7-server-rpms excluded (updateinfo)
|
||||
--> 389-ds-base-libs-1.3.4.0-26.el7_2.x86_64 from rhel-7-server-rpms excluded (updateinfo)
|
||||
--> 1:cups-devel-1.6.3-26.el7.i686 from rhel-7-server-rpms excluded (updateinfo)
|
||||
--> openwsman-client-2.6.3-3.git4391e5c.el7.i686 from rhel-7-server-rpms excluded (updateinfo)
|
||||
--> 1:emacs-24.3-18.el7.x86_64 from rhel-7-server-rpms excluded (updateinfo)
|
||||
--> augeas-libs-1.4.0-2.el7_4.2.i686 from rhel-7-server-rpms excluded (updateinfo)
|
||||
--> samba-winbind-modules-4.2.3-10.el7.i686 from rhel-7-server-rpms excluded (updateinfo)
|
||||
--> tftp-5.2-11.el7.x86_64 from rhel-7-server-rpms excluded (updateinfo)
|
||||
.
|
||||
.
|
||||
35 package(s) needed for security, out of 115 available
|
||||
NetworkManager.x86_64 1:1.12.0-10.el7_6 rhel-7-server-rpms
|
||||
NetworkManager-adsl.x86_64 1:1.12.0-10.el7_6 rhel-7-server-rpms
|
||||
NetworkManager-bluetooth.x86_64 1:1.12.0-10.el7_6 rhel-7-server-rpms
|
||||
NetworkManager-config-server.noarch 1:1.12.0-10.el7_6 rhel-7-server-rpms
|
||||
NetworkManager-glib.x86_64 1:1.12.0-10.el7_6 rhel-7-server-rpms
|
||||
NetworkManager-libnm.x86_64 1:1.12.0-10.el7_6 rhel-7-server-rpms
|
||||
NetworkManager-ppp.x86_64 1:1.12.0-10.el7_6 rhel-7-server-rpms
|
||||
```
|
||||
|
||||
To list all available security updates with verbose descriptions of the issues.
|
||||
|
||||
```
|
||||
# yum info-sec
|
||||
.
|
||||
.
|
||||
===============================================================================
|
||||
tzdata bug fix and enhancement update
|
||||
===============================================================================
|
||||
Update ID : RHBA-2019:0689
|
||||
Release : 0
|
||||
Type : bugfix
|
||||
Status : final
|
||||
Issued : 2019-03-28 19:27:44 UTC
|
||||
Description : The tzdata packages contain data files with rules for various
|
||||
: time zones.
|
||||
:
|
||||
: The tzdata packages have been updated to version
|
||||
: 2019a, which addresses recent time zone changes.
|
||||
: Notably:
|
||||
:
|
||||
: * The Asia/Hebron and Asia/Gaza zones will start
|
||||
: DST on 2019-03-30, rather than 2019-03-23 as
|
||||
: previously predicted.
|
||||
: * Metlakatla rejoined Alaska time on 2019-01-20,
|
||||
: ending its observances of Pacific standard time.
|
||||
:
|
||||
: (BZ#1692616, BZ#1692615, BZ#1692816)
|
||||
:
|
||||
: Users of tzdata are advised to upgrade to these
|
||||
: updated packages.
|
||||
Severity : None
|
||||
```
|
||||
|
||||
If you would like to know more information about the given advisory, run the following command.
|
||||
|
||||
```
|
||||
# yum updateinfo RHSA-2019:0163
|
||||
|
||||
Loaded plugins: changelog, package_upload, product-id, search-disabled-repos, subscription-manager, verify, versionlock
|
||||
rhel-7-server-rpms | 2.0 kB 00:00:00
|
||||
===============================================================================
|
||||
Important: kernel security, bug fix, and enhancement update
|
||||
===============================================================================
|
||||
Update ID : RHSA-2019:0163
|
||||
Release : 0
|
||||
Type : security
|
||||
Status : final
|
||||
Issued : 2019-01-29 15:21:23 UTC
|
||||
Updated : 2019-01-29 15:23:47 UTC Bugs : 1641548 - CVE-2018-18397 kernel: userfaultfd bypasses tmpfs file permissions
|
||||
: 1641878 - CVE-2018-18559 kernel: Use-after-free due to race condition in AF_PACKET implementation
|
||||
CVEs : CVE-2018-18397
|
||||
: CVE-2018-18559
|
||||
Description : The kernel packages contain the Linux kernel, the core of any
|
||||
: Linux operating system.
|
||||
:
|
||||
: Security Fix(es):
|
||||
:
|
||||
: * kernel: Use-after-free due to race condition in
|
||||
: AF_PACKET implementation (CVE-2018-18559)
|
||||
:
|
||||
: * kernel: userfaultfd bypasses tmpfs file
|
||||
: permissions (CVE-2018-18397)
|
||||
:
|
||||
: For more details about the security issue(s),
|
||||
: including the impact, a CVSS score, and other
|
||||
: related information, refer to the CVE page(s)
|
||||
: listed in the References section.
|
||||
:
|
||||
: Bug Fix(es):
|
||||
:
|
||||
: These updated kernel packages include also
|
||||
: numerous bug fixes and enhancements. Space
|
||||
: precludes documenting all of the bug fixes in this
|
||||
: advisory. See the descriptions in the related
|
||||
: Knowledge Article:
|
||||
: https://access.redhat.com/articles/3827321
|
||||
Severity : Important
|
||||
updateinfo info done
|
||||
```
|
||||
|
||||
Similarly, you can view CVEs which affect the system using the following command.
|
||||
|
||||
```
|
||||
# yum updateinfo list cves
|
||||
|
||||
Loaded plugins: changelog, package_upload, product-id, search-disabled-repos,
|
||||
: subscription-manager, verify, versionlock
|
||||
CVE-2018-15688 Important/Sec. NetworkManager-1:1.12.0-8.el7_6.x86_64
|
||||
CVE-2018-15688 Important/Sec. NetworkManager-adsl-1:1.12.0-8.el7_6.x86_64
|
||||
CVE-2018-15688 Important/Sec. NetworkManager-bluetooth-1:1.12.0-8.el7_6.x86_64
|
||||
CVE-2018-15688 Important/Sec. NetworkManager-config-server-1:1.12.0-8.el7_6.noarch
|
||||
CVE-2018-15688 Important/Sec. NetworkManager-glib-1:1.12.0-8.el7_6.x86_64
|
||||
CVE-2018-15688 Important/Sec. NetworkManager-libnm-1:1.12.0-8.el7_6.x86_64
|
||||
CVE-2018-15688 Important/Sec. NetworkManager-ppp-1:1.12.0-8.el7_6.x86_64
|
||||
CVE-2018-15688 Important/Sec. NetworkManager-team-1:1.12.0-8.el7_6.x86_64
|
||||
```
|
||||
|
||||
Similarly, you can view the packages which is belongs to bugfixs by running the following command.
|
||||
|
||||
```
|
||||
# yum updateinfo list bugfix | less
|
||||
|
||||
Loaded plugins: changelog, package_upload, product-id, search-disabled-repos,
|
||||
: subscription-manager, verify, versionlock
|
||||
RHBA-2018:3349 bugfix NetworkManager-1:1.12.0-7.el7_6.x86_64
|
||||
RHBA-2019:0519 bugfix NetworkManager-1:1.12.0-10.el7_6.x86_64
|
||||
RHBA-2018:3349 bugfix NetworkManager-adsl-1:1.12.0-7.el7_6.x86_64
|
||||
RHBA-2019:0519 bugfix NetworkManager-adsl-1:1.12.0-10.el7_6.x86_64
|
||||
RHBA-2018:3349 bugfix NetworkManager-bluetooth-1:1.12.0-7.el7_6.x86_64
|
||||
RHBA-2019:0519 bugfix NetworkManager-bluetooth-1:1.12.0-10.el7_6.x86_64
|
||||
RHBA-2018:3349 bugfix NetworkManager-config-server-1:1.12.0-7.el7_6.noarch
|
||||
RHBA-2019:0519 bugfix NetworkManager-config-server-1:1.12.0-10.el7_6.noarch
|
||||
```
|
||||
|
||||
To get a summary of advisories, which needs to be installed on your system.
|
||||
|
||||
```
|
||||
# yum updateinfo summary
|
||||
Loaded plugins: changelog, package_upload, product-id, search-disabled-repos, subscription-manager, verify, versionlock
|
||||
rhel-7-server-rpms | 2.0 kB 00:00:00
|
||||
Updates Information Summary: updates
|
||||
13 Security notice(s)
|
||||
9 Important Security notice(s)
|
||||
3 Moderate Security notice(s)
|
||||
1 Low Security notice(s)
|
||||
35 Bugfix notice(s)
|
||||
1 Enhancement notice(s)
|
||||
updateinfo summary done
|
||||
```
|
||||
|
||||
To print only specific pattern of security advisories, run the following command. Similarly, you can check Important or Moderate security advisories info alone.
|
||||
|
||||
```
|
||||
# yum updateinfo list sec | grep -i "Low"
|
||||
|
||||
RHSA-2019:0201 Low/Sec. libgudev1-219-62.el7_6.3.x86_64
|
||||
RHSA-2019:0201 Low/Sec. systemd-219-62.el7_6.3.x86_64
|
||||
RHSA-2019:0201 Low/Sec. systemd-libs-219-62.el7_6.3.x86_64
|
||||
RHSA-2019:0201 Low/Sec. systemd-sysv-219-62.el7_6.3.x86_64
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/check-list-view-find-available-security-updates-on-redhat-rhel-centos-system/
|
||||
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.2daygeek.com/author/magesh/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/
|
490
sources/tech/20190527 How to write a good C main function.md
Normal file
490
sources/tech/20190527 How to write a good C main function.md
Normal file
@ -0,0 +1,490 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to write a good C main function)
|
||||
[#]: via: (https://opensource.com/article/19/5/how-write-good-c-main-function)
|
||||
[#]: author: (Erik O'Shaughnessy https://opensource.com/users/jnyjny)
|
||||
|
||||
How to write a good C main function
|
||||
======
|
||||
Learn how to structure a C file and write a C main function that handles
|
||||
command line arguments like a champ.
|
||||
![Hand drawing out the word "code"][1]
|
||||
|
||||
I know, Python and JavaScript are what the kids are writing all their crazy "apps" with these days. But don't be so quick to dismiss C—it's a capable and concise language that has a lot to offer. If you need speed, writing in C could be your answer. If you are looking for job security and the opportunity to learn how to hunt down [null pointer dereferences][2], C could also be your answer! In this article, I'll explain how to structure a C file and write a C main function that handles command line arguments like a champ.
|
||||
|
||||
**Me** : a crusty Unix system programmer.
|
||||
**You** : someone with an editor, a C compiler, and some time to kill.
|
||||
|
||||
_Let's do this._
|
||||
|
||||
### A boring but correct C program
|
||||
|
||||
![Parody O'Reilly book cover, "Hating Other People's Code"][3]
|
||||
|
||||
A C program starts with a **main()** function, usually kept in a file named **main.c**.
|
||||
|
||||
|
||||
```
|
||||
/* main.c */
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
This program _compiles_ but doesn't _do_ anything.
|
||||
|
||||
|
||||
```
|
||||
$ gcc main.c
|
||||
$ ./a.out -o foo -vv
|
||||
$
|
||||
```
|
||||
|
||||
Correct and boring.
|
||||
|
||||
### Main functions are unique
|
||||
|
||||
The **main()** function is the first function in your program that is executed when it begins executing, but it's not the first function executed. The _first_ function is **_start()** , which is typically provided by the C runtime library, linked in automatically when your program is compiled. The details are highly dependent on the operating system and compiler toolchain, so I'm going to pretend I didn't mention it.
|
||||
|
||||
The **main()** function has two arguments that traditionally are called **argc** and **argv** and return a signed integer. Most Unix environments expect programs to return **0** (zero) on success and **-1** (negative one) on failure.
|
||||
|
||||
Argument | Name | Description
|
||||
---|---|---
|
||||
argc | Argument count | Length of the argument vector
|
||||
argv | Argument vector | Array of character pointers
|
||||
|
||||
The argument vector, **argv** , is a tokenized representation of the command line that invoked your program. In the example above, **argv** would be a list of the following strings:
|
||||
|
||||
|
||||
```
|
||||
`argv = [ "/path/to/a.out", "-o", "foo", "-vv" ];`
|
||||
```
|
||||
|
||||
The argument vector is guaranteed to always have at least one string in the first index, **argv[0]** , which is the full path to the program executed.
|
||||
|
||||
### Anatomy of a main.c file
|
||||
|
||||
When I write a **main.c** from scratch, it's usually structured like this:
|
||||
|
||||
|
||||
```
|
||||
/* main.c */
|
||||
/* 0 copyright/licensing */
|
||||
/* 1 includes */
|
||||
/* 2 defines */
|
||||
/* 3 external declarations */
|
||||
/* 4 typedefs */
|
||||
/* 5 global variable declarations */
|
||||
/* 6 function prototypes */
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
/* 7 command-line parsing */
|
||||
}
|
||||
|
||||
/* 8 function declarations */
|
||||
```
|
||||
|
||||
I'll talk about each of these numbered sections, except for zero, below. If you have to put copyright or licensing text in your source, put it there.
|
||||
|
||||
Another thing I won't talk about adding to your program is comments.
|
||||
|
||||
|
||||
```
|
||||
"Comments lie."
|
||||
\- A cynical but smart and good looking programmer.
|
||||
```
|
||||
|
||||
Instead of comments, use meaningful function and variable names.
|
||||
|
||||
Appealing to the inherent laziness of programmers, once you add comments, you've doubled your maintenance load. If you change or refactor the code, you need to update or expand the comments. Over time, the code mutates away from anything resembling what the comments describe.
|
||||
|
||||
If you have to write comments, do not write about _what_ the code is doing. Instead, write about _why_ the code is doing what it's doing. Write comments that you would want to read five years from now when you've forgotten everything about this code. And the fate of the world is depending on you. _No pressure_.
|
||||
|
||||
#### 1\. Includes
|
||||
|
||||
The first things I add to a **main.c** file are includes to make a multitude of standard C library functions and variables available to my program. The standard C library does lots of things; explore header files in **/usr/include** to find out what it can do for you.
|
||||
|
||||
The **#include** string is a [C preprocessor][4] (cpp) directive that causes the inclusion of the referenced file, in its entirety, in the current file. Header files in C are usually named with a **.h** extension and should not contain any executable code; only macros, defines, typedefs, and external variable and function prototypes. The string **< header.h>** tells cpp to look for a file called **header.h** in the system-defined header path, usually **/usr/include**.
|
||||
|
||||
|
||||
```
|
||||
/* main.c */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/types.h>
|
||||
```
|
||||
|
||||
This is the minimum set of global includes that I'll include by default for the following stuff:
|
||||
|
||||
#include File | Stuff It Provides
|
||||
---|---
|
||||
stdio | Supplies FILE, stdin, stdout, stderr, and the fprint() family of functions
|
||||
stdlib | Supplies malloc(), calloc(), and realloc()
|
||||
unistd | Supplies EXIT_FAILURE, EXIT_SUCCESS
|
||||
libgen | Supplies the basename() function
|
||||
errno | Defines the external errno variable and all the values it can take on
|
||||
string | Supplies memcpy(), memset(), and the strlen() family of functions
|
||||
getopt | Supplies external optarg, opterr, optind, and getopt() function
|
||||
sys/types | Typedef shortcuts like uint32_t and uint64_t
|
||||
|
||||
#### 2\. Defines
|
||||
|
||||
|
||||
```
|
||||
/* main.c */
|
||||
<...>
|
||||
|
||||
#define OPTSTR "vi⭕f:h"
|
||||
#define USAGE_FMT "%s [-v] [-f hexflag] [-i inputfile] [-o outputfile] [-h]"
|
||||
#define ERR_FOPEN_INPUT "fopen(input, r)"
|
||||
#define ERR_FOPEN_OUTPUT "fopen(output, w)"
|
||||
#define ERR_DO_THE_NEEDFUL "do_the_needful blew up"
|
||||
#define DEFAULT_PROGNAME "george"
|
||||
```
|
||||
|
||||
This doesn't make a lot of sense right now, but the **OPTSTR** define is where I will state what command line switches the program will recommend. Consult the [**getopt(3)**][5] man page to learn how **OPTSTR** will affect **getopt()** 's behavior.
|
||||
|
||||
The **USAGE_FMT** define is a **printf()** -style format string that is referenced in the **usage()** function.
|
||||
|
||||
I also like to gather string constants as **#defines** in this part of the file. Collecting them makes it easier to fix spelling, reuse messages, and internationalize messages, if required.
|
||||
|
||||
Finally, use all capital letters when naming a **#define** to distinguish it from variable and function names. You can run the words together if you want or separate words with an underscore; just make sure they're all upper case.
|
||||
|
||||
#### 3\. External declarations
|
||||
|
||||
|
||||
```
|
||||
/* main.c */
|
||||
<...>
|
||||
|
||||
extern int errno;
|
||||
extern char *optarg;
|
||||
extern int opterr, optind;
|
||||
```
|
||||
|
||||
An **extern** declaration brings that name into the namespace of the current compilation unit (aka "file") and allows the program to access that variable. Here we've brought in the definitions for three integer variables and a character pointer. The **opt** prefaced variables are used by the **getopt()** function, and **errno** is used as an out-of-band communication channel by the standard C library to communicate why a function might have failed.
|
||||
|
||||
#### 4\. Typedefs
|
||||
|
||||
|
||||
```
|
||||
/* main.c */
|
||||
<...>
|
||||
|
||||
typedef struct {
|
||||
int verbose;
|
||||
uint32_t flags;
|
||||
FILE *input;
|
||||
FILE *output;
|
||||
} options_t;
|
||||
```
|
||||
|
||||
After external declarations, I like to declare **typedefs** for structures, unions, and enumerations. Naming a **typedef** is a religion all to itself; I strongly prefer a **_t** suffix to indicate that the name is a type. In this example, I've declared **options_t** as a **struct** with four members. C is a whitespace-neutral programming language, so I use whitespace to line up field names in the same column. I just like the way it looks. For the pointer declarations, I prepend the asterisk to the name to make it clear that it's a pointer.
|
||||
|
||||
#### 5\. Global variable declarations
|
||||
|
||||
|
||||
```
|
||||
/* main.c */
|
||||
<...>
|
||||
|
||||
int dumb_global_variable = -11;
|
||||
```
|
||||
|
||||
Global variables are a bad idea and you should never use them. But if you have to use a global variable, declare them here and be sure to give them a default value. Seriously, _don't use global variables_.
|
||||
|
||||
#### 6\. Function prototypes
|
||||
|
||||
|
||||
```
|
||||
/* main.c */
|
||||
<...>
|
||||
|
||||
void usage(char *progname, int opt);
|
||||
int do_the_needful(options_t *options);
|
||||
```
|
||||
|
||||
As you write functions, adding them after the **main()** function and not before, include the function prototypes here. Early C compilers used a single-pass strategy, which meant that every symbol (variable or function name) you used in your program had to be declared before you used it. Modern compilers are nearly all multi-pass compilers that build a complete symbol table before generating code, so using function prototypes is not strictly required. However, you sometimes don't get to choose what compiler is used on your code, so write the function prototypes and drive on.
|
||||
|
||||
As a matter of course, I always include a **usage()** function that **main()** calls when it doesn't understand something you passed in from the command line.
|
||||
|
||||
#### 7\. Command line parsing
|
||||
|
||||
|
||||
```
|
||||
/* main.c */
|
||||
<...>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int opt;
|
||||
options_t options = { 0, 0x0, stdin, stdout };
|
||||
|
||||
opterr = 0;
|
||||
|
||||
while ((opt = getopt(argc, argv, OPTSTR)) != EOF)
|
||||
switch(opt) {
|
||||
case 'i':
|
||||
if (!(options.input = [fopen][6](optarg, "r")) ){
|
||||
[perror][7](ERR_FOPEN_INPUT);
|
||||
[exit][8](EXIT_FAILURE);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
if (!(options.output = [fopen][6](optarg, "w")) ){
|
||||
[perror][7](ERR_FOPEN_OUTPUT);
|
||||
[exit][8](EXIT_FAILURE);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
options.flags = (uint32_t )[strtoul][9](optarg, NULL, 16);
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
options.verbose += 1;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
default:
|
||||
usage(basename(argv[0]), opt);
|
||||
/* NOTREACHED */
|
||||
break;
|
||||
}
|
||||
|
||||
if (do_the_needful(&options) != EXIT_SUCCESS) {
|
||||
[perror][7](ERR_DO_THE_NEEDFUL);
|
||||
[exit][8](EXIT_FAILURE);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
OK, that's a lot. The purpose of the **main()** function is to collect the arguments that the user provides, perform minimal input validation, and then pass the collected arguments to functions that will use them. This example declares an **options** variable initialized with default values and parse the command line, updating **options** as necessary.
|
||||
|
||||
The guts of this **main()** function is a **while** loop that uses **getopt()** to step through **argv** looking for command line options and their arguments (if any). The **OPTSTR** **#define** earlier in the file is the template that drives **getopt()** 's behavior. The **opt** variable takes on the character value of any command line options found by **getopt()** , and the program's response to the detection of the command line option happens in the **switch** statement.
|
||||
|
||||
Those of you paying attention will now be questioning why **opt** is declared as a 32-bit **int** but is expected to take on an 8-bit **char**? It turns out that **getopt()** returns an **int** that takes on a negative value when it gets to the end of **argv** , which I check against **EOF** (the _End of File_ marker). A **char** is a signed quantity, but I like matching variables to their function return values.
|
||||
|
||||
When a known command line option is detected, option-specific behavior happens. Some options have an argument, specified in **OPTSTR** with a trailing colon. When an option has an argument, the next string in **argv** is available to the program via the externally defined variable **optarg**. I use **optarg** to open files for reading and writing or converting a command line argument from a string to an integer value.
|
||||
|
||||
There are a couple of points for style here:
|
||||
|
||||
* Initialize **opterr** to 0, which disables **getopt** from emiting a **?**.
|
||||
* Use **exit(EXIT_FAILURE);** or **exit(EXIT_SUCCESS);** in the middle of **main()**.
|
||||
* **/* NOTREACHED */** is a lint directive that I like.
|
||||
* Use **return EXIT_SUCCESS;** at the end of functions that return **int**.
|
||||
* Explicitly cast implicit type conversions.
|
||||
|
||||
|
||||
|
||||
The command line signature for this program, if it were compiled, would look something like this:
|
||||
|
||||
|
||||
```
|
||||
$ ./a.out -h
|
||||
a.out [-v] [-f hexflag] [-i inputfile] [-o outputfile] [-h]
|
||||
```
|
||||
|
||||
In fact, that's what **usage()** will emit to **stderr** once compiled.
|
||||
|
||||
#### 8\. Function declarations
|
||||
|
||||
|
||||
```
|
||||
/* main.c */
|
||||
<...>
|
||||
|
||||
void usage(char *progname, int opt) {
|
||||
[fprintf][10](stderr, USAGE_FMT, progname?progname:DEFAULT_PROGNAME);
|
||||
[exit][8](EXIT_FAILURE);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
int do_the_needful(options_t *options) {
|
||||
|
||||
if (!options) {
|
||||
errno = EINVAL;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!options->input || !options->output) {
|
||||
errno = ENOENT;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* XXX do needful stuff */
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
Finally, I write functions that aren't boilerplate. In this example, function **do_the_needful()** accepts a pointer to an **options_t** structure. I validate that the **options** pointer is not **NULL** and then go on to validate the **input** and **output** structure members. **EXIT_FAILURE** returns if either test fails and, by setting the external global variable **errno** to a conventional error code, I signal to the caller a general reason. The convenience function **perror()** can be used by the caller to emit human-readable-ish error messages based on the value of **errno**.
|
||||
|
||||
Functions should almost always validate their input in some way. If full validation is expensive, try to do it once and treat the validated data as immutable. The **usage()** function validates the **progname** argument using a conditional assignment in the **fprintf()** call. The **usage()** function is going to exit anyway, so I don't bother setting **errno** or making a big stink about using a correct program name.
|
||||
|
||||
The big class of errors I am trying to avoid here is de-referencing a **NULL** pointer. This will cause the operating system to send a special signal to my process called **SYSSEGV** , which results in unavoidable death. The last thing users want to see is a crash due to **SYSSEGV**. It's much better to catch a **NULL** pointer in order to emit better error messages and shut down the program gracefully.
|
||||
|
||||
Some people complain about having multiple **return** statements in a function body. They make arguments about "continuity of control flow" and other stuff. Honestly, if something goes wrong in the middle of a function, it's a good time to return an error condition. Writing a ton of nested **if** statements to just have one return is never a "good idea."™
|
||||
|
||||
Finally, if you write a function that takes four or more arguments, consider bundling them in a structure and passing a pointer to the structure. This makes the function signatures simpler, making them easier to remember and not screw up when they're called later. It also makes calling the function slightly faster, since fewer things need to be copied into the function's stack frame. In practice, this will only become a consideration if the function is called millions or billions of times. Don't worry about it if that doesn't make sense.
|
||||
|
||||
### Wait, you said no comments!?!!
|
||||
|
||||
In the **do_the_needful()** function, I wrote a specific type of comment that is designed to be a placeholder rather than documenting the code:
|
||||
|
||||
|
||||
```
|
||||
`/* XXX do needful stuff */`
|
||||
```
|
||||
|
||||
When you are in the zone, sometimes you don't want to stop and write some particularly gnarly bit of code. You'll come back and do it later, just not now. That's where I'll leave myself a little breadcrumb. I insert a comment with a **XXX** prefix and a short remark describing what needs to be done. Later on, when I have more time, I'll grep through source looking for **XXX**. It doesn't matter what you use, just make sure it's not likely to show up in your codebase in another context, as a function name or variable, for instance.
|
||||
|
||||
### Putting it all together
|
||||
|
||||
OK, this program _still_ does almost nothing when you compile and run it. But now you have a solid skeleton to build your own command line parsing C programs.
|
||||
|
||||
|
||||
```
|
||||
/* main.c - the complete listing */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#define OPTSTR "vi⭕f:h"
|
||||
#define USAGE_FMT "%s [-v] [-f hexflag] [-i inputfile] [-o outputfile] [-h]"
|
||||
#define ERR_FOPEN_INPUT "fopen(input, r)"
|
||||
#define ERR_FOPEN_OUTPUT "fopen(output, w)"
|
||||
#define ERR_DO_THE_NEEDFUL "do_the_needful blew up"
|
||||
#define DEFAULT_PROGNAME "george"
|
||||
|
||||
extern int errno;
|
||||
extern char *optarg;
|
||||
extern int opterr, optind;
|
||||
|
||||
typedef struct {
|
||||
int verbose;
|
||||
uint32_t flags;
|
||||
FILE *input;
|
||||
FILE *output;
|
||||
} options_t;
|
||||
|
||||
int dumb_global_variable = -11;
|
||||
|
||||
void usage(char *progname, int opt);
|
||||
int do_the_needful(options_t *options);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int opt;
|
||||
options_t options = { 0, 0x0, stdin, stdout };
|
||||
|
||||
opterr = 0;
|
||||
|
||||
while ((opt = getopt(argc, argv, OPTSTR)) != EOF)
|
||||
switch(opt) {
|
||||
case 'i':
|
||||
if (!(options.input = [fopen][6](optarg, "r")) ){
|
||||
[perror][7](ERR_FOPEN_INPUT);
|
||||
[exit][8](EXIT_FAILURE);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
if (!(options.output = [fopen][6](optarg, "w")) ){
|
||||
[perror][7](ERR_FOPEN_OUTPUT);
|
||||
[exit][8](EXIT_FAILURE);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
options.flags = (uint32_t )[strtoul][9](optarg, NULL, 16);
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
options.verbose += 1;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
default:
|
||||
usage(basename(argv[0]), opt);
|
||||
/* NOTREACHED */
|
||||
break;
|
||||
}
|
||||
|
||||
if (do_the_needful(&options) != EXIT_SUCCESS) {
|
||||
[perror][7](ERR_DO_THE_NEEDFUL);
|
||||
[exit][8](EXIT_FAILURE);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void usage(char *progname, int opt) {
|
||||
[fprintf][10](stderr, USAGE_FMT, progname?progname:DEFAULT_PROGNAME);
|
||||
[exit][8](EXIT_FAILURE);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
int do_the_needful(options_t *options) {
|
||||
|
||||
if (!options) {
|
||||
errno = EINVAL;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!options->input || !options->output) {
|
||||
errno = ENOENT;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* XXX do needful stuff */
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
Now you're ready to write C that will be easier to maintain. If you have any questions or feedback, please share them in the comments.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/5/how-write-good-c-main-function
|
||||
|
||||
作者:[Erik O'Shaughnessy][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/jnyjny
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_hand_draw.png?itok=dpAf--Db (Hand drawing out the word "code")
|
||||
[2]: https://www.owasp.org/index.php/Null_Dereference
|
||||
[3]: https://opensource.com/sites/default/files/uploads/hatingotherpeoplescode-big.png (Parody O'Reilly book cover, "Hating Other People's Code")
|
||||
[4]: https://en.wikipedia.org/wiki/C_preprocessor
|
||||
[5]: https://linux.die.net/man/3/getopt
|
||||
[6]: http://www.opengroup.org/onlinepubs/009695399/functions/fopen.html
|
||||
[7]: http://www.opengroup.org/onlinepubs/009695399/functions/perror.html
|
||||
[8]: http://www.opengroup.org/onlinepubs/009695399/functions/exit.html
|
||||
[9]: http://www.opengroup.org/onlinepubs/009695399/functions/strtoul.html
|
||||
[10]: http://www.opengroup.org/onlinepubs/009695399/functions/fprintf.html
|
@ -0,0 +1,228 @@
|
||||
ddgr - 一个从终端搜索 DuckDuckGo 的命令行工具
|
||||
======
|
||||
在 Linux 中,Bash 技巧非常棒,它使 Linux 中的一切成为可能。
|
||||
|
||||
对于开发人员或系统管理员来说,它真的很管用,因为他们大部分时间都在使用终端。你知道他们为什么喜欢这种技巧吗?
|
||||
|
||||
因为这些技巧可以提高他们的工作效率,也能使他们工作更快。
|
||||
|
||||
### 什么是 ddgr
|
||||
|
||||
[ddgr][1] 是一个命令行实用程序,用于从终端搜索 DuckDuckGo。如果设置了 BROWSER 环境变量,ddgr 可以在几个基于文本的浏览器中开箱即用。
|
||||
|
||||
确保你的系统安装了任何基于文本的浏览器。你可能知道 [googler][2],它允许用户从 Linux 命令行进行 Google 搜索。
|
||||
|
||||
它在命令行用户中非常受欢迎,他们期望对隐私敏感的 DuckDuckGo 也有类似的实用程序,这就是 ddgr 出现的原因。
|
||||
|
||||
与 Web 界面不同,你可以指定每页要查看的搜索结果数。
|
||||
|
||||
**建议阅读:**
|
||||
**(#)** [Googler – 从 Linux 命令行搜索 Google][2]
|
||||
**(#)** [Buku – Linux 中一个强大的命令行书签管理器][3]
|
||||
**(#)** [SoCLI – 从终端搜索和浏览堆栈溢出的简单方法][4]
|
||||
**(#)** [RTV(Reddit 终端查看器)- 一个简单的 Reddit 终端查看器][5]
|
||||
|
||||
### 什么是 DuckDuckGo
|
||||
|
||||
DDG 即 DuckDuckGo。DuckDuckGo(DDG)是一个真正保护用户搜索和隐私的互联网搜索引擎。
|
||||
|
||||
它们没有过滤用户的个性化搜索结果,对于给定的搜索词,它会向所有用户显示相同的搜索结果。
|
||||
|
||||
大多数用户更喜欢谷歌搜索引擎,但是如果你真的担心隐私,那么你可以放心地使用 DuckDuckGo。
|
||||
|
||||
### ddgr 特性
|
||||
|
||||
* 快速且干净(没有广告,多余的 URL 或杂物),自定义颜色
|
||||
* 旨在以最小的空间提供最高的可读性
|
||||
* 指定每页显示的搜索结果数
|
||||
* 从浏览器中打开的 omniprompt URL 导航结果页面
|
||||
* Bash、Zsh 和 Fish 的搜索和配置脚本
|
||||
* DuckDuckGo Bang 支持(自动完成)
|
||||
* 直接在浏览器中打开第一个结果(就像我感觉 Ducky)
|
||||
* 不间断搜索:无需退出即可在 omniprompt 中触发新搜索
|
||||
* 关键字支持(例如:filetype:mime、site:somesite.com)
|
||||
* 按时间、指定区域、禁用安全搜索
|
||||
* HTTPS 代理支持,无跟踪,可选择禁用用户代理
|
||||
* 支持自定义 URL 处理程序脚本或命令行实用程序
|
||||
* 全面的文档,man 页面有方便的使用示例
|
||||
* 最小的依赖关系
|
||||
|
||||
|
||||
### 需要条件
|
||||
|
||||
ddgr 需要 Python 3.4 或更高版本。因此,确保你的系统应具有 Python 3.4 或更高版本。
|
||||
```
|
||||
$ python3 --version
|
||||
Python 3.6.3
|
||||
|
||||
```
|
||||
|
||||
### 如何在 Linux 中安装 ddgr
|
||||
|
||||
我们可以根据发行版使用以下命令轻松安装 ddgr。
|
||||
|
||||
对于 **`Fedora`** ,使用 [DNF 命令][6]来安装 ddgr。
|
||||
```
|
||||
# dnf install ddgr
|
||||
|
||||
```
|
||||
|
||||
或者我们可以使用 [SNAP 命令][7]来安装 ddgr。
|
||||
```
|
||||
# snap install ddgr
|
||||
|
||||
```
|
||||
|
||||
对于 **`LinuxMint/Ubuntu`**,使用 [APT-GET 命令][8] 或 [APT 命令][9]来安装 ddgr。
|
||||
```
|
||||
$ sudo add-apt-repository ppa:twodopeshaggy/jarun
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get install ddgr
|
||||
|
||||
```
|
||||
|
||||
对于基于 **`Arch Linux`** 的系统,使用 [Yaourt 命令][10]或 [Packer 命令][11]从 AUR 仓库安装 ddgr。
|
||||
```
|
||||
$ yaourt -S ddgr
|
||||
or
|
||||
$ packer -S ddgr
|
||||
|
||||
```
|
||||
|
||||
对于 **`Debian`**,使用 [DPKG 命令][12] 安装 ddgr。
|
||||
```
|
||||
# wget https://github.com/jarun/ddgr/releases/download/v1.2/ddgr_1.2-1_debian9.amd64.deb
|
||||
# dpkg -i ddgr_1.2-1_debian9.amd64.deb
|
||||
|
||||
```
|
||||
|
||||
对于 **`CentOS 7`**,使用 [YUM 命令][13]来安装 ddgr。
|
||||
```
|
||||
# yum install https://github.com/jarun/ddgr/releases/download/v1.2/ddgr-1.2-1.el7.3.centos.x86_64.rpm
|
||||
|
||||
```
|
||||
|
||||
对于 **`opensuse`**,使用 [zypper 命令][14]来安装 ddgr。
|
||||
```
|
||||
# zypper install https://github.com/jarun/ddgr/releases/download/v1.2/ddgr-1.2-1.opensuse42.3.x86_64.rpm
|
||||
|
||||
```
|
||||
|
||||
### 如何启动 ddgr
|
||||
|
||||
在终端上输入 `ddgr` 命令,不带任何选项来进行 DuckDuckGo 搜索。你将获得类似于下面的输出。
|
||||
```
|
||||
$ ddgr
|
||||
|
||||
```
|
||||
|
||||
![][16]
|
||||
|
||||
### 如何使用 ddgr 进行搜索
|
||||
|
||||
我们可以通过两种方式启动搜索。从omniprompt 或者直接从终端开始。你可以搜索任何你想要的短语。
|
||||
|
||||
直接从终端:
|
||||
```
|
||||
$ ddgr 2daygeek
|
||||
|
||||
```
|
||||
|
||||
![][17]
|
||||
|
||||
从 `omniprompt`:
|
||||
![][18]
|
||||
|
||||
### Omniprompt 快捷方式
|
||||
|
||||
输入 `?` 以获得 `omniprompt`,它将显示关键字列表和进一步使用 ddgr 的快捷方式。
|
||||
![][19]
|
||||
|
||||
### 如何移动下一页、上一页和第一页
|
||||
|
||||
它允许用户移动下一页、上一页或第一页。
|
||||
|
||||
* `n:` 移动到下一组搜索结果
|
||||
* `p:` 移动到上一组搜索结果
|
||||
* `f:` 跳转到第一页
|
||||
|
||||
![][20]
|
||||
|
||||
### 如何启动新搜索
|
||||
|
||||
“**d**” 选项允许用户从 omniprompt 发起新的搜索。例如,我搜索了 `2daygeek 网站`,现在我将搜索 **Magesh Maruthamuthu** 这个新短语。
|
||||
|
||||
从 `omniprompt`.
|
||||
```
|
||||
ddgr (? for help) d magesh maruthmuthu
|
||||
|
||||
```
|
||||
|
||||
![][21]
|
||||
|
||||
### 在搜索结果中显示完整的 URL
|
||||
|
||||
默认情况下,它仅显示文章标题,在搜索中添加 **x** 选项以在搜索结果中显示完整的文章网址。
|
||||
```
|
||||
$ ddgr -n 5 -x 2daygeek
|
||||
|
||||
```
|
||||
|
||||
![][22]
|
||||
|
||||
### 限制搜索结果
|
||||
|
||||
默认情况下,搜索结果每页显示 10 个结果。如果你想为方便起见限制页面结果,可以使用 ddgr 带有 `--num` 或 ` -n` 参数。
|
||||
```
|
||||
$ ddgr -n 5 2daygeek
|
||||
|
||||
```
|
||||
|
||||
![][23]
|
||||
|
||||
### 网站特定搜索
|
||||
|
||||
要搜索特定网站的特定页面,使用以下格式。这将从网站获取给定关键字的结果。例如,我们在 2daygeek 网站搜索 **Package Manager**,查看结果。
|
||||
```
|
||||
$ ddgr -n 5 --site 2daygeek "package manager"
|
||||
|
||||
```
|
||||
|
||||
![][24]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/ddgr-duckduckgo-search-from-the-command-line-in-linux/
|
||||
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.2daygeek.com/author/magesh/
|
||||
[1]:https://github.com/jarun/ddgr
|
||||
[2]:https://www.2daygeek.com/googler-google-search-from-the-command-line-on-linux/
|
||||
[3]:https://www.2daygeek.com/buku-command-line-bookmark-manager-linux/
|
||||
[4]:https://www.2daygeek.com/socli-search-and-browse-stack-overflow-from-linux-terminal/
|
||||
[5]:https://www.2daygeek.com/rtv-reddit-terminal-viewer-a-simple-terminal-viewer-for-reddit/
|
||||
[6]:https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/
|
||||
[7]:https://www.2daygeek.com/snap-command-examples/
|
||||
[8]:https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[9]:https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[10]:https://www.2daygeek.com/install-yaourt-aur-helper-on-arch-linux/
|
||||
[11]:https://www.2daygeek.com/install-packer-aur-helper-on-arch-linux/
|
||||
[12]:https://www.2daygeek.com/dpkg-command-to-manage-packages-on-debian-ubuntu-linux-mint-systems/
|
||||
[13]:https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/
|
||||
[14]:https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/
|
||||
[15]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[16]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux1.png
|
||||
[17]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-3.png
|
||||
[18]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-2.png
|
||||
[19]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-4.png
|
||||
[20]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-5a.png
|
||||
[21]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-6a.png
|
||||
[22]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-7a.png
|
||||
[23]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-8.png
|
||||
[24]:https://www.2daygeek.com/wp-content/uploads/2018/03/ddgr-duckduckgo-command-line-search-for-linux-9a.png
|
@ -0,0 +1,67 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (4 open source apps for plant-based diets)
|
||||
[#]: via: (https://opensource.com/article/19/4/apps-plant-based-diets)
|
||||
[#]: author: (Joshua Allen Holm https://opensource.com/users/holmja)
|
||||
|
||||
4 款基于植物饮食的开源应用
|
||||
======
|
||||
这些应用使素食者、纯素食主义者和那些想吃得更健康的杂食者找到可以吃的食物。
|
||||
![][1]
|
||||
|
||||
减少对肉类、乳制品和加工食品的消费对地球来说更好,也对你的健康更有益。改变你的饮食习惯可能很困难,但是一些开源的 Android 应用可以帮助你切换成基于植物的饮食。无论你是参加[无肉星期一][2],参加 Mark Bittman 的 [6:00 前的素食][3]指南,还是完全切换到[全植物性饮食][4],这些应用能帮助你找出要吃什么,发现素食和素食友好的餐馆,并轻松地将你的饮食偏好传达给他人,来助你更好地走这条路。所有这些应用都是开源的,可从 [F-Droid 仓库][5]下载。
|
||||
|
||||
### Daily Dozen
|
||||
|
||||
![Daily Dozen app][6]
|
||||
|
||||
[Daily Dozen][7] 提供了医学博士、美国法律医学院院士 Michael Greger 推荐的项目清单,作为健康饮食和生活方式的一部分。Greger 博士建议食用全食,由多种食物组成的基于植物的饮食,并坚持日常锻炼。该应用可以让你跟踪你吃的每种食物的份数,你喝了多少份水(或其他获准的饮料,如茶),以及你是否每天锻炼。每类食物都提供食物分量和属于该类别的食物清单。例如,十字花科蔬菜类包括白菜、花椰菜、芽甘蓝等许多其他建议。
|
||||
|
||||
### Food Restrictions
|
||||
|
||||
![Food Restrictions app][8]
|
||||
|
||||
[Food Restrictions][9] 是一个简单的应用,它可以帮助你将饮食限制传达给他人,即使这些人不会说你的语言。用户可以输入七种不同类别的食物限制:鸡肉、牛肉、猪肉、鱼、奶酪、牛奶和辣椒。每种类别都有“我不吃”和“我过敏”选项。“不吃”选项会显示带有红色 X 的图标。“过敏” 选项显示 X 和小骷髅图标。可以使用文本而不是图标显示相同的信息,但文本仅提供英语和葡萄牙语。还有一个选项可以显示一条文字信息,说明用户是素食主义者或纯素食主义者,它比选择更简洁、更准确地总结了这些饮食限制。纯素食主义者的文本清楚地提到不吃鸡蛋和蜂蜜,这在挑选中是没有的。但是,就像挑选方式的文字版本一样,这些句子仅提供英语和葡萄牙语。
|
||||
|
||||
### OpenFoodFacts
|
||||
|
||||
![Open Food Facts app][10]
|
||||
|
||||
购买杂货时避免不必要的成分可能令人沮丧,但 [OpenFoodFacts][11] 可以帮助简化流程。该应用可让你扫描产品上的条形码,以获得有关产品成分和是否健康的报告。即使产品符合纯素产品的标准,产品仍然可能非常不健康。拥有成分列表和营养成分可让你在购物时做出明智的选择。此应用的唯一缺点是数据是用户贡献的,因此并非每个产品都可有数据,但如果你想回馈项目,你可以贡献新数据。
|
||||
|
||||
### OpenVegeMap
|
||||
|
||||
![OpenVegeMap app][12]
|
||||
|
||||
使用 [OpenVegeMap][13] 查找你附近的纯素食或素食主义餐厅。此应用可以通过手机的当前位置或者输入地址来搜索。餐厅分类为仅限纯素食者、纯素友好,仅限素食主义者,素食友好者,非素食和未知。该应用使用来自 [OpenStreetMap][14] 的数据和用户提供的有关餐馆的信息,因此请务必仔细检查以确保所提供的信息是最新且准确的。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/4/apps-plant-based-diets
|
||||
|
||||
作者:[Joshua Allen Holm ][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/holmja
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003588_01_rd3os.combacktoschoolserieshe_rh_041x_0.png?itok=tfg6_I78
|
||||
[2]: https://www.meatlessmonday.com/
|
||||
[3]: https://www.amazon.com/dp/0385344740/
|
||||
[4]: https://nutritionstudies.org/whole-food-plant-based-diet-guide/
|
||||
[5]: https://f-droid.org/
|
||||
[6]: https://opensource.com/sites/default/files/uploads/daily_dozen.png (Daily Dozen app)
|
||||
[7]: https://f-droid.org/en/packages/org.nutritionfacts.dailydozen/
|
||||
[8]: https://opensource.com/sites/default/files/uploads/food_restrictions.png (Food Restrictions app)
|
||||
[9]: https://f-droid.org/en/packages/br.com.frs.foodrestrictions/
|
||||
[10]: https://opensource.com/sites/default/files/uploads/openfoodfacts.png (Open Food Facts app)
|
||||
[11]: https://f-droid.org/en/packages/openfoodfacts.github.scrachx.openfood/
|
||||
[12]: https://opensource.com/sites/default/files/uploads/openvegmap.png (OpenVegeMap app)
|
||||
[13]: https://f-droid.org/en/packages/pro.rudloff.openvegemap/
|
||||
[14]: https://www.openstreetmap.org/
|
Loading…
Reference in New Issue
Block a user