1. Extract "James" or "Curry" from the AAA.log file without "Kobe" line, then extract ":" To split the fifth field.
Cat aaa.log|grep-e "James|curry" |grep-v "Kobe" |awk-f ":" ' {print $} '
"Comment" search "A or B" method is Grep-e "a| B "method,-E must be written. The method that does not contain XXX is grep-v. There are two ways to split, one is cut and one is awk. Note the difference between the cut and the awk command parameters.
The above command is written with cut to be cat aaa.log|grep-e "James|curry" |grep-v "Kobe" |cut-d:-F 2
2, please use the Shell to query the file AAA.log inside the space to start the line number
Grep-n ^$ AAA.log |cut-d:-F 1
"Comment" Why Cat-n aaa.log|grep ^$ not get this effect? Think about it.
3. How Linux learns how long a remote computer is running in the shell environment
The way to compare the forcing is this:
cat/proc/uptime| Awk-f. ' {run_days=$1/86400;run_hour= ($ 86400)/3600;run_minute= ($ 3600)/60;run_second=$1% 60;printf ("system has been running:%d days% D at%d seconds ", Run_days,run_hour,run_minute,run_second)} '
In fact, there are many ways that Linux can see how long a remote computer is running, #uptime也可以, #top也可以, #w也可以. And these three methods directly display hours, unlike/proc/uptime, in seconds to display, but also to convert a bit.
4, how to view the current Linux system status, such as CPU, memory, load, version
The top three is directly viewed with the top, version with #uname-a
"Comment" If you want to know more about the hardware of the server. Using Cat/proc/cpuinfo
5, use a command to see the current system has started the service listening to the port
Netstat-antp|grep LISTEN
"Comment" Netstat-antl results and the above is not the same, diff-y a bit, found-ANTL will have established items.
6. Sed changes "Haiwao" in the 50th line of the file test to "Haiwai"
Sed-i ' 50s/haiwao/haiwai/g ' test
Not to be continued
This article is from "Life is waiting for Gordo" blog, please make sure to keep this source http://chenx1242.blog.51cto.com/10430133/1745136
Linux operations engineer face test eighth set