20151012-3 选题

This commit is contained in:
DeadFire 2015-10-12 15:35:59 +08:00
parent b9aa6be17c
commit 097f331da2
2 changed files with 150 additions and 0 deletions

View File

@ -0,0 +1,90 @@
How to Monitor Stock Prices from Ubuntu Command Line Using Mop
================================================================================
Having a side income is always good, especially when you can easily manage the work along with your full time job. If your regular work involves working on an Internet-connected computer, trading stocks is a popular option to earn a few extra bucks.
While there are quite a few stock-monitoring applications available for Linux, most of them are GUI-based. What if youre a Linux professional who spends a lot (or all) of your time working on machines that do not have any GUI installed? Are you out of luck? Well, no, there are some command line stock-tracking tools, including Mop, which well be discussing in this article.
### Mop ###
Mop, as already mentioned in the introduction above, is a command line tool that displays continuous and updated information about the US stock markets and individual stocks. Implemented in the GO programming language, the project is the brain child of Michael Dvorkin.
### Download and Install ###
Since the project is implemented in GO, before installing the tool, youll first have to make sure that the programming language is installed on your machine. Following are the steps required to install GO on a Debian-based system like Ubuntu:
sudo apt-get install golang
mkdir ~/workspace
echo 'export GOPATH="$HOME/workspace"' >> ~/.bashrc
source ~/.bashrc
Once GO is installed, the next step is to install the Mop tool and set the environment, something which you can do by running the following commands:
sudo apt-get install git
go get github.com/michaeldv/mop
cd $GOPATH/src/github.com/michaeldv/mop
make install
export PATH="$PATH:$GOPATH/bin"
Once done, just run the following command to execute Mop:
cmd
### Features ###
When you run the Mop command for the first time, youll see an output similar to the following.
![](https://www.maketecheasier.com/assets/uploads/2015/09/mop-first-run.jpg)
As you can see in the image above, the output which auto-refreshes frequently contains information related to various popular stock exchanges around the world as well as individual stocks.
### Add/remove stocks ###
Mop allows you to easily add/remove individual stocks to and from the output list. To add a stock, all you have to do is to press “+” and mention the stock listing name when prompted. For example, the following screenshot was taken while adding Facebook (FB) to the list.
![](https://www.maketecheasier.com/assets/uploads/2015/09/mop-add-stock.png)
As I pressed the “+” key, a row containing text “Add tickers:” appeared, prompting me to add the stock listing name I added FB for Facebook and pressed Enter. The output refreshed, and the new stock was added to the list:
![](https://www.maketecheasier.com/assets/uploads/2015/09/mop-stock-added.png)
Similarly, you can delete a stock listing by pressing “-” and mentioning its name.
#### Group stocks based on value ####
There is a way to group stocks based on whether their value is going up or down all you have to do is to press the “g” key. Following this, the stocks which are advancing will be grouped together and shown in green, while those whose value is going down will be represented in black.
Here is an example screenshot.
![](https://www.maketecheasier.com/assets/uploads/2015/09/mop-group-stocks-profit-loss.png)
#### Column sort ####
Mop also allows you to change the sort order of individual columns. For this you first need to press “o” (this will select the first column by default), and then use the left and right arrow keys to select the column you want to sort. Once done, press enter to sort the column contents.
For example, the following screenshot shows the output after the contents of the first column were sorted in descending alphabetical order.
![](https://www.maketecheasier.com/assets/uploads/2015/09/mop-change-order.png)
**Note**: to better understand, compare it with the previous screenshot.
#### Other options ####
Other available options include “p” for pausing market data and stock updates, “q” or “esc” for quitting the command line application, and “?” for displaying the help page.
![](https://www.maketecheasier.com/assets/uploads/2015/09/mop-help.png)
### Conclusion ###
Mop is a basic stock monitoring tool that doesnt offer a plethora of features, but does what it promises. Its quite obvious that the tool is not for stock trading professionals but is still a decent choice if all you want to do is some basic stock tracking on a command line-only machine.
--------------------------------------------------------------------------------
via: https://www.maketecheasier.com/monitor-stock-prices-ubuntu-command-line/
作者:[Himanshu Arora][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.maketecheasier.com/author/himanshu/

View File

@ -0,0 +1,60 @@
Remember sed and awk? All Linux admins should
================================================================================
![](http://images.techhive.com/images/article/2015/03/linux-100573790-primary.idge.jpg)
Credit: Shutterstock
**We arent doing the next generation of Linux and Unix admins any favors by forgetting init scripts and fundamental tools**
I happened across a post on Reddit by chance, [asking about textfile manipulation][1]. It was a fairly simple request, similar to those that folks in Unix see nearly every day. In this case, it was how to remove all duplicate lines in a file, keeping one instance of each. This sounds relatively easy, but can get a bit complicated if the source file is sufficiently large and random.
There are countless answers to this problem. You could write a script in nearly any language to do this, with varying levels of complexity and time investment, which I suspect is what most would do. It might take 20 or 60 minutes depending on skill level, but armed with Perl, Python, or Ruby, you could make quick work of it.
Or you could use the answer stated in that thread, which warmed my heart: Just use awk.
That answer is the most concise and simplest solution to the problem by far. Its one line:
awk '!seen[$0]++' <filename>.
Lets take a look at this.
In this command, theres a lot of hidden code. Awk is a text processing language, and as such it makes a lot of assumptions. For starters, what you see here is actually the meat of a for loop. Awk assumes you want to loop through every line of the input file, so you dont need to explicitly state it. Awk also assumes you want to print the postprocessed output, so you dont need to state that either. Finally, Awk then assumes the loop ends when the last statement finishes, so no need to state it.
The string seen in this example is the name given to an associative array. $0 is a variable that represents the entirety of the current line of the file. Thus, this command translates to “Evaluate every line in this file, and if you havent seen this line before, print it.” Awk does this by adding $0 to the seen array if it doesnt already exist and incrementing the value so that it will not match the pattern the next time around and, thus, not print.
Some will see this as elegant, while others may see this as obfuscation. Anyone who uses awk on a daily basis will be in the first group. Awk is designed to do this. You can write multiline programs in awk. You can even write [disturbingly complex functions in awk][2]. But at the end of the day, awk is designed to do text processing, generally within a pipe. Eliminating the extraneous cruft of loop definition is simply a shortcut for a very common use case. If you like, you could write the same thing as the following:
awk '{ if (!seen[$0]) print $0; seen[$0]++ }
It would lead to the same result.
Awk is the perfect tool for this job. Nevertheless, I believe many admins -- especially newer admins -- would jump into [Bash][3] or Python to try to accomplish this task, because knowledge of awk and what it can do seems to be fading as time goes on. I think it may be an indicator of things to come, where problems that have been solved for decades suddenly emerge again, based on lack of exposure to the previous solutions.
The shell, grep, sed, and awk are fundaments of Unix computing. If youre not completely comfortable with their use, youre artificially hamstrung because they form the basis of interaction with Unix systems via the CLI and shell scripting. One of the best ways to learn how these tools work is by observing and working with live examples, which every Unix flavor has in spades with their init systems -- or had, in the case of Linux distros that have adopted [systemd][4].
Millions of Unix admins learned how shell scripting and Unix tools worked by reading, writing, modifying, and working with init scripts. Init scripts differ greatly from OS to OS, even from distribution to distribution in the case of Linux, but they are all rooted in sh, and they all use core CLI tools like sed, awk, and grep.
Ive heard many complaints that init scripts are “ancient” and “difficult,” but in fact, init scripts use the same tools that Unix admins work with every day, and thus provide an excellent way to become more familiar and comfortable with those tools. Saying that init scripts are hard to read or difficult to work with is to admit that you lack fundamental familiarity with the Unix toolset.
Speaking of things found on Reddit, I also came across this question from a budding Linux sys admin, [asking whether he should bother to learn sysvinit][5]. Most of the answers in the thread are good -- yes, definitely learn sysvinit and systemd. One commenter even notes that init scripts are a great way to learn Bash, and another states that the Fortune 50 company he works for has no plans to move to a systemd-based release.
But it concerns me that this is a question at all. If we continue down the path of eliminating scripts and roping off core system elements within our operating systems, we will inadvertently make it harder for new admins to learn the fundamental Unix toolset due to the lack of exposure.
Im not sure why some want to cover up Unix internals with abstraction after abstraction, but such a path may reduce a generation of Unix admins to hapless button pushers dependent on support contracts. Im pretty sure that would not be a good development.
--------------------------------------------------------------------------------
via: http://www.infoworld.com/article/2985804/linux/remember-sed-awk-linux-admins-should.html
作者:[Paul Venezia][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://www.infoworld.com/author/Paul-Venezia/
[1]:https://www.reddit.com/r/linuxadmin/comments/3lwyko/how_do_i_remove_every_occurence_of_duplicate_line/
[2]:http://intro-to-awk.blogspot.com/2008/08/awk-more-complex-examples.html
[3]:http://www.infoworld.com/article/2613338/linux/linux-how-to-script-a-bash-crash-course.html
[4]:http://www.infoworld.com/article/2608798/data-center/systemd--harbinger-of-the-linux-apocalypse.html
[5]:https://www.reddit.com/r/linuxadmin/comments/3ltq2y/when_i_start_learning_about_linux_administration/