Get the catalog file date and compare

Source: Internet
Author: User

---------------------------for directory operations
pocdata_exp_from_172.20.8.23_nscrmdb_20140907.0200

1, according to the modified time and the current time comparison, the directory name to filter, and then directly deleted
Find. -maxdepth 1-follow-type D! -mtime-7-name "pocdata_exp_from_*" | Xargs RM-RF
(1)-maxdepth 1 means only the first layer is found
(2)-type D means directory-type f means file
(3) In addition to Mtime, you can also use the-newer parameter
(4) Delete can also use command-exec RM-RF

2, first filter the directory, and then use awk based on the directory modification Time (timestamp) and target time comparison, and then directly delete--loop to add processing as the Independent property rights
Ls-f | grep '/$ ' |grep pocdata_exp_from | awk ' {cmd= ' date +%s--date=\ "-1 day\" "Cmd|getline a;for (i=1;i<=nf;i++) {cmd=" stat-c%Y "$i" "; Cmd|getline b;if (b< A) {print $i}} '
(1) Delete the catalogue ls-f | grep '/$ ' |grep pocdata_exp_from
(2) Time also with "$ (date-d" 7 days Ago "+%y%m%d") "
(3) Ls|awk ' {for (i=1;i<=nf;i++) {print NF, $i}} '
(4) Ls|awk ' {for (i=1;i<=nf;i++) {cmd= "stat-c%Y" $i ""; cmd|getline b;print b,nf, $i}} '

3, first filter out the directory, and then filter out the time-matching directory (according to the time in the directory name), delete
Find. -maxdepth 1-type d-name "pocdata_exp_from_*" |sed ' s/\ (. *\) \ ([0-9]\{8\}\) \ (. *\)/\2/'

-----to a non-directory operation-----Just a string to get the time-------------
-rw-r--r--. 1 aiweb_s aigrp 13408625 2014-08-06 13:30:30.913401174 +0800 catalina.out
Now you need to extract the time attribute of the file, shown as: 20140806133030

1.
Ls-l--full-time catalina.out |sed-e ' s/\ (. *\) \ ([0-9]\{4\}-[0-9]\{1,2\}-[0-9]\{1,2\} [0-9]\{1,2\}:[0-9]\{1,2\}:[0-9 ]\{1,2\}\) \ (. *\)/\2/'-E ' s/[-:]//g '
(1) "s//" replacement, "//" contains three parts, as a whole replaced by the second part of the
(2) "/[-:]//g", replace all three symbols with an empty
(3)-e executes multiple SED commands and should be available ";" Separated, placed in a "'"

2.
Stat catalina.out |sed-n ' 6 s/[-: \ (modify\)]//gp ' |awk-f. ' {print $} '
(1) Take the sixth line of the stat result, and remove the "-" "Modidfy" "" ":" Symbol
(2) The above results are "." Separate, take the first part

3. Separating the columns directly with awk
awk ' BEGIN {fs= ' [-:.] "; O Fs= ""; Ls-l--full-time catalina.out "|getline;print $13,$14,$15,$16,$17,$18} '
(1) begin{} preset The internal variable fs field delimiter, the above sentence with the regular, OFS for the reverse output delimited (the above statement is actually the merge split field)
(2) Other Rs/ors line separators (rs default "\ n") http://blog.51yip.com/shell/1151.html
(3) Getline is read through the pipe or standard input, if the read is successful, Getline returns 1, if the file Terminator (EOF) is read, Getline returns 0, and if an error occurs, such as opening the file, Getline returns-1, so Getline can be used in a while loop


=================================================
Two functions of the SED command: Match + operation (split substitution, etc.)
Sed '/^\.\/\ ([0-9]\{8\}\) $/!d; S//\1/'
(1) The regular expression used by SED is the pattern enclosed by the slash line "/": ^\.\/\ ([0-9]\{8\}\) $ ("./" after 8 consecutive 0-9 digits)
^ Match beginning, $ match end
"." Matches a single word other than a newline character, preceded by a "\" escape, which means "." Itself
\(.. \) To save the characters that have been matched
[] matches any character within the specified character group
X\{m\} consecutive M x
(2)!d Delete other rows
(3) s//\1/'

=================================================

Occasionally in a shell script to see a similar sed ' s/(\ (. *\))/\1\1/' Such statement, in fact, this sed replacement is for the case of containing parentheses

No1=100 (AAA) no2=100 (BBB) no3=100 (CCC) no4= (DDD)
Where aaabbbcccddd are changing, we want to extract the AAA or BBB situation

First understand the situation of a ()
As an example:
[[email protected] root]# echo "111 (222) 333" | Sed ' s/(\ (. *\))/\1\1/'
111222222333

Because (\ (. *\)) There is only one part, so \1 means that this part is extracted two times (if \2 should not be mentioned).

[[email protected] root]# echo "111 (222) 333" | Sed ' s/(\ (. *\))/\1\2/'
Sed:-e expression #1, character 16:invalid reference \2 on ' s ' Command ' RHS

Because "(" is not a meta-character, so write directly "(" means "(" This symbol, and "\" means that it contains nothing.

And because it's (), it extracts 222 two times.

If you remove (), for example
[[email protected] root]# echo "111 (222) 333" | Sed ' s/\ (. *\)/\1\1/'
111 (222) 333111 (222) 333
So the extraction match is the part.

-------------------------------------
[[email protected] root]# echo "111 (222) 333" | Sed ' s/\ (. *\) (\ (. *\))/\1\1\1/'
111111111333
Because//inside is composed of \ (. *\) and (\ (. *\)) two parts, and \1 is still extracting the first part, that is, all the content before (222) and (222) This whole part is replaced by (222) all the content is extracted three times, followed by 333 unchanged

[[email protected] root]# echo "111 (222) 333" | Sed ' s/\ (. *\) (\ (. *\))/\2\2\2/'
222222222333
All parts before (222) and (222) are treated as a whole, replaced by the part within (), that is, 222.

The meaning of this understanding of \2\2\2,2 should be to extract the second \ (. *\), namely: "The second contains" means: (change () to YY is also the same meaning)
[Email protected] root]# echo "111y222y333" | Sed ' s/\ (. *\) y\ (. *\) y/\2\2\2/'
222222222333

-------------------------------------
Two brackets and above:

[Email protected] root]# echo "no1=100 (AAA) no2=100 (BBB) no3=100 (CCC) no4= (DDD)" | Sed ' s/\ (. *\) (\ (. *\)). */\2/'
Ddd
[Email protected] root]# echo "no1=100 (AAA) no2=100 (BBB) no3=100 (CCC) no4= (DDD)" | Sed ' s/.* (\ (. *\)). */\1/'
Ddd
The above two sentences have the same meaning.
We were going to take AAA, but why did we take DDD?
The regular expression is greedy, it always matches the longest possible length, and the higher the preceding wildcard precedence. According to this principle to get the DDD, then how should we get AAA?

We consider if the ". *" in the first ". *" in the pattern string is told that the sed ". *" Cannot contain "(", while the second ". *" should not contain "" should be OK--[BENMM] should be the second ". *" Can not contain "
Give it a try:
[Email protected] root]# echo "no1=100 (AAA) no2=100 (BBB) no3=100 (CCC) no4= (DDD)" | Sed ' s/[^ (]* (\ ([^)]*\)). */\1/'
Aaa

And so on, you can get
[Email protected] root]# echo "no1=100 (AAA) no2=100 (BBB) no3=100 (CCC) no4= (DDD)" | Sed ' s/[^ (]* ([^)]*\)) [^ (]* (\ ([^)]*\)] [^ (]* ([^)]*\)] [^ (]* (\ ([^)]) [^ ([^)]
]*\))/\2/'
Bbb
Change 2 to 3 is CCC
Change 3 to 4 is DDD

Get the catalog file date and compare

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.