1.awk Array
Awk is handy for data processing. An array of awk, an associative array (associative Arrays), which can be a number and a string. You do not need to specify the number of elements because you do not need to declare the array names and elements in advance. Array elements are initialized with 0 or empty strings, depending on the context.
<1> set up array Array[index] = value: Array name array, subscript index, and corresponding value values. Copy code <2> read array value {for (item in array) print Array[item]} # The order of output is random
{for (i=1;i<=len;i++) print Array[i]} # len is the length of the array copy code awk array Example:
Total count (sum) (used in this job) awk ' {name[$0]+=$1}; End{for (i in name) print I, Name[i]} ' #注意空格
Another example:
echo "AAA 1
AAA 1
CCC 1
AAA 1
BBB 1
CCC 1 "|awk ' {a[$1]+=$2}end{for (i in a) print i,a[i]} '
AAA 3
BBB 1
CCC 2 Copy Code
In addition, see the school Linux version of the post: http://bbs.byr.cn/#!article/Linux/119000
2. RM Command Pipe operation problem (ll|grep "AB" |RM problem resolution)
Since only the output of LS is redirected, we can think of a temporary file (not actually) to the grep to do parameters, the content of this file is: 2.log, 3.log. And then take this as a temporary file and pass it on to RM. That is, RM removes a redirect, and RM cannot do it because RM cannot take redirection as a parameter
RM ' Ls|grep AB ' is the right approach.
(Also, note that the quotation marks here are the symbols below the ESC key.) )
3,Linux Statistics folder number of files
The first method:
Ls-l|grep "^-" |wc-l
Ls-l
The long list prints the file information in the directory (note that the file here, different from the general file, may be directories, links, device files, etc.). If the Ls-lr|grep "^-" |wc-l can be counted together with the files in the subdirectory. grep ^-here will be a long list of output information filter part, only the general file, if only keep the directory is ^d
Wc-l statistics output The number of rows, because has been filtered only general file, so the statistical result is the number of general file information, and because a line of information corresponding to a file, so that is the number of files.
The second method:
Find./-type F|wc-l (for example, I used this time is: found./-name "*". Log-empty,-->man know what's going on)
Because the default find will go to the subdirectory lookup, if you only want to find the files in the current directory, use finding./-maxdepth 1-type f|wc-l.
It should be explained that the second method is much faster than the first method, especially when subdirectories are counted.
4.crontab (from the ancient Greek word "chronos", "Time" means.)
Use See the following figure:
* * * * *
Time-sharing day and Moon
Example
0 2 1 * * Root rm-f/tmp/* #每月1号凌晨2点, clean/tmp files
0 8 6 5 * Root mail Robin