So I want to recursively search a directory with thousands of folders for a specific file extension and get the date it was added then filter by a specific year. The code below works but is there a way it can be converted to a one-liner?
get all files ending with xml & write to tmp.txt
find . -name "*xml" >> tmp.txt
get permission info & timestamp info for all those files in tmp.txt
foreach i ( ` cat tmp.txt ` ) ls -ltrh $i >> tmp2.txt end
column 8 contains dates as years, so get all files with years greater than a specific 2014...
awk '$8 >=2014' tmp2.txt >> tmp3.txt
Try this one:
find . -type f -name '*xml' -newermt "2014-01-01" -ls
From man find
:
-newerXY reference
Succeeds if timestamp X of the file being considered is newer
than timestamp Y of the file reference. The letters X and Y
can be any of the following letters:
a The access time of the file reference
B The birth time of the file reference
c The inode status change time of reference
m The modification time of the file reference
t reference is interpreted directly as a time
What I would do in a bash shell :
find . -mtime -$((365*4)) -name "*xml" >> tmp.txt
This is just an example, adapt the math to your needs...
Another solution :
find . -name '*xml' -printf '%TY %p\n' | awk '$1 >= 2014 {$1=""; print}'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.