mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-25 00:50:15 +08:00
20131216-2 选题
This commit is contained in:
parent
d8e0242d7e
commit
5de10ff1ad
@ -0,0 +1,158 @@
|
||||
10 Useful Chaining Operators in Linux with Practical Examples
|
||||
================================================================================
|
||||
Chaining of Linux commands means, combining several commands and make them execute based upon the behaviour of operator used in between them. Chaining of commands in Linux, is something like you are writing [short shell scripts][1] at the shell itself, and executing them from the terminal directly. Chaining makes it possible to automate the process. Moreover, an unattended machine can function in a much systematic way with the help of chaining operators.
|
||||
|
||||

|
||||
*10 Chaining Operators in Linux*
|
||||
|
||||
This Article aims at throwing light on frequently used **command-chaining operators**, with short descriptions and corresponding examples which surely will increase your productivity and lets you write short and meaningful codes beside reducing system load, at times.
|
||||
|
||||
### 1. Ampersand Operator (&) ###
|
||||
|
||||
The function of ‘**&**‘ is to make the command run in background. Just type the command followed with a white space and ‘**&**‘. You can execute more than one command in the background, in a single go.
|
||||
|
||||
Run one command in the background:
|
||||
|
||||
tecmint@localhost:~$ ping c5 www.tecmint.com &
|
||||
|
||||
Run two command in background, simultaneously:
|
||||
|
||||
root@localhost:/home/tecmint# apt-get update & apt-get upgrade &
|
||||
|
||||
### 2. semi-colon Operator (;) ###
|
||||
|
||||
The semi-colon operator makes it possible to run, several commands in a single go and the execution of command occurs sequentially.
|
||||
|
||||
root@localhost:/home/tecmint# apt-get update ; apt-get upgrade ; mkdir test
|
||||
|
||||
The above command combination will first execute **update** instruction, then **upgrade** instruction and finally will create a ‘**test**‘ directory under the current working directory.
|
||||
|
||||
### 3. AND Operator (&&) ###
|
||||
|
||||
The **AND Operator (&&)** would execute the second command only, if the execution of first command fails, i.e., the exit status of the first command is **1**. This command is very useful in checking the execution status of last command.
|
||||
|
||||
For example, I want to visit website **tecmint.com** using **[links command][2]**, in terminal but before that I need to check if the host is **live** or **not**.
|
||||
|
||||
root@localhost:/home/tecmint# ping -c3 www.tecmint.com && links www.tecmint.com
|
||||
|
||||
### 4. OR Operator (||) ###
|
||||
|
||||
The **OR Operator (||)** is much like an ‘**else**‘ statement in programming. The above operator allow you to execute second command only if the execution of first command fails, i.e., the exit status of first command is ‘**1**‘.
|
||||
|
||||
For example, I want to execute ‘**apt-get update**‘ from non-root account and if the first command fails, then the second ‘**links www.tecmint.com**‘ command will execute.
|
||||
|
||||
tecmint@localhost:~$ apt-get update || links tecmint.com
|
||||
|
||||
In the above command, since the **user** was not allowed to **update** system, it means that the exit status of first command is ’**1**′ and hence the last command ‘**links tecmint.com**‘ gets executed.
|
||||
|
||||
What if the first command is executed successfully, with an exit status ‘**0**‘? Obviously! Second command won’t execute.
|
||||
|
||||
tecmint@localhost:~$ mkdir test || links tecmint.com
|
||||
|
||||
Here, the user creates a folder ‘**test**‘ in his home directory, for which user is permitted. The command executed successfully giving an exit status ‘**0**‘ and hence the last part of the command is not executed.
|
||||
|
||||
### 5. NOT Operator (!) ###
|
||||
|
||||
The **NOT Operator (!)** is much like an ‘**except**‘ statement. This command will execute all except the condition provided. To understand this, create a directory ‘**tecmint**‘ in your home directory and ‘**cd**‘ to it.
|
||||
|
||||
tecmint@localhost:~$ mkdir tecmint
|
||||
tecmint@localhost:~$ cd tecmint
|
||||
|
||||
Next, create several types of files in the folder ‘**tecmint**‘.
|
||||
|
||||
tecmint@localhost:~/tecmint$ touch a.doc b.doc a.pdf b.pdf a.xml b.xml a.html b.html
|
||||
|
||||
See we’ve created all the new files within the folder ‘**tecmint**‘.
|
||||
|
||||
tecmint@localhost:~/tecmint$ ls
|
||||
|
||||
a.doc a.html a.pdf a.xml b.doc b.html b.pdf b.xml
|
||||
|
||||
Now delete all the files except ‘**html**‘ file all at once, in a smart way.
|
||||
|
||||
tecmint@localhost:~/tecmint$ rm -r !(*.html)
|
||||
|
||||
Just to verify, last execution. List all of the available files using [ls command][3].
|
||||
|
||||
tecmint@localhost:~/tecmint$ ls
|
||||
|
||||
a.html b.html
|
||||
|
||||
### 6. AND – OR operator (&& – ||) ###
|
||||
|
||||
The above operator is actually a combination of ‘**AND**‘ and ‘**OR**‘ Operator. It is much like an ‘**if-else**‘ statement.
|
||||
|
||||
For example, let’s do ping to **tecmint.com**, if success echo ‘**Verified**‘ else echo ‘**Host Down**‘.
|
||||
|
||||
tecmint@localhost:~/tecmint$ ping -c3 www.tecmint.com && echo "Verified" || echo "Host Down"
|
||||
|
||||
#### Sample Output ####
|
||||
|
||||
PING www.tecmint.com (212.71.234.61) 56(84) bytes of data.
|
||||
64 bytes from www.tecmint.com (212.71.234.61): icmp_req=1 ttl=55 time=216 ms
|
||||
64 bytes from www.tecmint.com (212.71.234.61): icmp_req=2 ttl=55 time=224 ms
|
||||
64 bytes from www.tecmint.com (212.71.234.61): icmp_req=3 ttl=55 time=226 ms
|
||||
|
||||
--- www.tecmint.com ping statistics ---
|
||||
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
|
||||
rtt min/avg/max/mdev = 216.960/222.789/226.423/4.199 ms
|
||||
Verified
|
||||
|
||||
Now, disconnect your internet connection, and try same command again.
|
||||
|
||||
tecmint@localhost:~/tecmint$ ping -c3 www.tecmint.com && echo "verified" || echo "Host Down"
|
||||
|
||||
#### Sample Output ####
|
||||
|
||||
ping: unknown host www.tecmint.com
|
||||
Host Down
|
||||
|
||||
### 7. PIPE Operator (|) ###
|
||||
|
||||
This **PIPE** operator is very useful where the output of first command acts as an input to the second command. For example, pipeline the output of ‘**ls -l**‘ to ‘**less**‘ and see the output of the command.
|
||||
|
||||
tecmint@localhost:~$ ls -l | less
|
||||
|
||||
### 8. Command Combination Operator {} ###
|
||||
|
||||
Combine two or more commands, the second command depends upon the execution of the first command.
|
||||
|
||||
For example, check if a file ‘**xyz.txt**‘ and ‘**xyz1.txt**‘ is available under my **Downloads** directory or not, and output corresponding output.
|
||||
|
||||
tecmint@localhost:~$ [ -f /home/tecmint/Downloads/xyz.txt ] || echo “The file does not exist”
|
||||
|
||||
tecmint@localhost:~$ [ -f /home/tecmint/Downloads/xyz1.txt ] || echo “The file does not exist”
|
||||
|
||||
“The file does not exist”
|
||||
|
||||
### 9. Precedence Operator () ###
|
||||
|
||||
The Operator makes it possible to execute command in precedence order.
|
||||
|
||||
Command_x1 &&Command_x2 || Command_x3 && Command_x4.
|
||||
|
||||
In the above pseudo command, what if the **Command_x1** fails? Neither of the **Command_x2**, **Command_x3**, **Command_x4** would executed, for this we use **Precedence Operator**, as:
|
||||
|
||||
(Command_x1 &&Command_x2) || (Command_x3 && Command_x4)
|
||||
|
||||
In the above pseudo command, if **Command_x1** fails, **Command_x2** also fails but Still **Command_x3** and **Command_x4** executes depends upon exit status of **Command_x3**.
|
||||
|
||||
### 10. Concatenation Operator (\) ###
|
||||
|
||||
The **Concatenation Operator (\)** as the name specifies, is used to concatenate large commands over several lines in the shell. For example, The below command will open text file **test(1).txt**.
|
||||
|
||||
tecmint@localhost:~/Downloads$ nano test\(1\).txt
|
||||
|
||||
That’s all for now. I am coming up with another interesting article very soon. Till then Stay tuned, healthy and connected to **Tecmint**. Don’t forget to give your Valuable feedback in our comment section.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/chaining-operators-in-linux-with-practical-examples/
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[1]:http://www.tecmint.com/category/bash-shell/
|
||||
[2]:http://www.tecmint.com/command-line-web-browsers/
|
||||
[3]:http://www.tecmint.com/15-basic-ls-command-examples-in-linux/
|
@ -0,0 +1,41 @@
|
||||
Daily Ubuntu Tips – Take Screenshots Of your Desktop
|
||||
================================================================================
|
||||
Ubuntu, a powerful and modern operating system allows you to perform many tasks. From creating and editing documents using LibreOffice Productivity Suite to enhancing an image with GIMP, Ubuntu is super!
|
||||
|
||||
If you need a super operating system to carry out your tasks, you may want to choose Ubuntu.
|
||||
|
||||
Another thing you can do when using Ubuntu is to take screenshots of your desktop and/or active application windows. There are many third-party tools you can install to perform such tasks, but you don’t have to, because Ubuntu comes with one already installed.
|
||||
|
||||
This program is useful if you want to show someone how do something in Ubuntu. Screenshots are just normal image files that can stored and send via email programs to others.
|
||||
|
||||
To use the screenshots program, go to Dash or press the Windows key on your keyboard to bring up Dash. The Windows key is the key left of the spacebar with Windows logo.
|
||||
|
||||
When Dash opens, search for Screenshot, select Screenshot to open it.
|
||||
|
||||
Here are some of the screen you can capture:
|
||||
|
||||
- You can grab the whole screen
|
||||
- You can grab the current program windows
|
||||
- You can select a particular area and grab it
|
||||
|
||||
If you wan to include the mouse pointer, check the box next to it and enable it.
|
||||
|
||||

|
||||
|
||||
When you want to capture a screen, click ‘**Take Screenshot**’. The program will disappear and automatically take a screenshot.
|
||||
|
||||
If you want to capture a particular area, choose that option and when you click ‘**Take Screenshot**’, the mouse pointer will change into a crosshair. You can then be drag the curser to desired size. When you stop, the image is captured automatically.
|
||||
|
||||
This is how you do it when you’re using Ubuntu
|
||||
|
||||
Hope this helps and please come back again.
|
||||
|
||||
Enjoy!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.liberiangeek.net/2013/12/daily-ubuntu-tips-take-screenshots-of-your-desktop/
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
@ -0,0 +1,76 @@
|
||||
Software May Be Eating The World, But Open Source Software Is Eating Itself
|
||||
================================================================================
|
||||
**Nothing sits still for long in the world of open source.**
|
||||
|
||||
Software may be eating the world, as [Marc Andreessen posits][1], but open-source software seems to be eating itself. And at a far faster clip. While the software world has grown used to products and their vendors dominating for long stretches (think: Microsoft in operating systems and Oracle in databases), the new world of open source is moving at an accelerated, Darwinian pace, leaving no project to rest on its laurels.
|
||||
|
||||
In this fast-changing open source world, how should enterprises decide where to invest?
|
||||
|
||||
### Open Source Picks Up The Pace ###
|
||||
|
||||
Though [Dirk Riehle's analysis][2] of the total growth in open source projects is a few years old, if anything the trend he plots has [accelerated][3]:
|
||||
|
||||

|
||||
|
||||
Today much of the interesting code in technology’s most important markets—Big Data, cloud, mobile—is open source. With more activity focused on areas like Hadoop or OpenStack, we should expect the pace and volume of open code creation to increase.
|
||||
|
||||
Which may be good or bad.
|
||||
|
||||
### No Rest For The Open Source Developer ###
|
||||
|
||||
Take, for example, the configuration management market. Redmonk’s Stephen O’Grady sifts a number of data sources that measure the popularity of Chef, Puppet, Ansible and Salt, the latter two being very new to the market, yet demonstrating considerable community enthusiasm and adoption.
|
||||
|
||||
This prompts O’Grady to [speculate][4] that “Where it once was reasonable to conclude that the configuration management space would evolve in similar fashion to the open source relational database market—i.e. with two dominant projects—that future is now in question.”
|
||||
|
||||
O’Grady goes on to suggest:
|
||||
|
||||
> The most interesting conclusion to be taken from this brief look at a variety of community data sources, however, may well be the relevance of both Ansible and Salt. That these projects appear to have viable prospects in front of them speaks to the demand for solutions in the area, as well as the strong influence of personal preferences—e.g. the affinity for Salt amongst Python developers.
|
||||
|
||||
Actually, I’d argue that the most interesting conclusion is that no open-source project has guaranteed longevity. Puppet came out in 2005 and is still making headway against entrenched proprietary incumbents, yet now it has to fight off Chef (which came out four years later), Ansible (last two years) and Salt (last two years).
|
||||
|
||||
Yes, incumbents in any important market, proprietary or otherwise, will always have new market entrants nibbling at their heels. But in open source, the competition doesn’t wait for billion-dollar markets to form before it launches attacks. The rise of Salt and Ansible in a market already well-served by Chef and Puppet is a testament to this.
|
||||
|
||||
### The Community Giveth, And The Community Taketh Away ###
|
||||
|
||||
You will find this same dynamic in content management (Drupal vs. Joomla vs. Alfresco vs. Wordpress vs. countless other CMSes), cloud (Eucalyptus vs. OpenStack vs. CloudStack vs. CloudFoundry vs. OpenShift vs. many others), [web servers][5] and databases, both relational and NoSQL.
|
||||
|
||||
The ranks of open-source databases swell with new entrants almost daily, as can be seen on the [DB-Engines database tracking service][6]. Perhaps most interesting is the open-source relational database market. Up until recently, MySQL dominated that market. Postgres was a viable runner up to MySQL, but it was a very distant second.
|
||||
|
||||
Today things are in motion. Or commotion. Largely due to Oracle’s alleged fumbling of the MySQL community, Postgres is on a tear, booming even with the hipster crowd that welcomed MySQL. But so is MariaDB. Though still a comparative gnat, leading [Linux distributions like Red Hat’s Fedora and Ubuntu have embraced MariaDB][7], as has Google, replacing MySQL.
|
||||
|
||||
Perhaps, as O’Grady implies, this comes down to developer preferences. If developers rule, then little impedes them from switching to new projects that may fit their needs better, throwing a given market into disarray. If this is correct, it would explain why open source resists long term monopolies:
|
||||
|
||||
It’s hard to keep developers happy.
|
||||
|
||||
### Building A Community-Friendly Business ###
|
||||
|
||||
What does this mean for enterprises that are looking to make long-term investments on a given open-source project? An easy, if unsatisfying, answer is that enterprises should contribute to the projects they care about, ensuring their sustainability as well as giving the enterprise the ability to support themselves should the project dwindle.
|
||||
|
||||
But most enterprises don’t want to have to code the winner themselves.
|
||||
|
||||
Instead they should look for popular projects that are good technical fits for their enterprise requirements and that have strong communities. Popularity can be fleeting if a project grows callous to its community. One of the primary reasons Linux has endured so long at the top of the operating system heap is that it has been so accommodating to community influence and requirements.
|
||||
|
||||
Unfortunately, there’s no One True Way to measure vitality in an open source community. Some successful projects, like OpenStack, lean on a strong foundation. Others, like Linux, depend upon a strong individual and her lieutenants.
|
||||
|
||||
But all successful open-source projects that maintain their lead innovate quickly, with regular releases every few months. While a fast-moving project may be more difficult for enterprises to support, it may also be a key indication that the project will remain relevant.
|
||||
|
||||
How else should enterprises hedge against the risk of obsolescence of an open-source project?
|
||||
|
||||
Lede image courtesy of [Shutterstock][8].
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://readwrite.com/2013/12/12/open-source-innovation
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[1]:http://online.wsj.com/news/articles/SB10001424053111903480904576512250915629460
|
||||
[2]:http://dirkriehle.com/publications/2008-2/the-total-growth-of-open-source/
|
||||
[3]:http://www.techrepublic.com/blog/linux-and-open-source/driving-forces-behind-linux-and-open-source-growth/
|
||||
[4]:http://redmonk.com/sogrady/2013/12/06/configuration-management-2013/
|
||||
[5]:http://www.theregister.co.uk/2013/02/06/open_and_shut/
|
||||
[6]:http://db-engines.com/en/ranking
|
||||
[7]:http://www.zdnet.com/oracle-who-fedora-and-opensuse-will-replace-mysql-with-mariadb-7000010640/
|
||||
[8]:http://www.shutterstock.com/
|
Loading…
Reference in New Issue
Block a user