[英]How can I combine this into a one-liner — bash
因此,我想递归搜索具有数千个文件夹的目录以查找特定的文件扩展名,并获取添加日期,然后按特定年份进行过滤。 下面的代码有效,但是有没有办法将其转换为单行代码?
获取所有以xml结尾的文件并写入tmp.txt
find . -name "*xml" >> tmp.txt
在tmp.txt中获取所有这些文件的权限信息和时间戳信息
foreach i ( ` cat tmp.txt ` ) ls -ltrh $i >> tmp2.txt end
第8列包含以年为单位的日期,因此请获取所有年份大于特定2014年的文件...
awk '$8 >=2014' tmp2.txt >> tmp3.txt
试试这个:
find . -type f -name '*xml' -newermt "2014-01-01" -ls
从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
我会在bash shell中做什么:
find . -mtime -$((365*4)) -name "*xml" >> tmp.txt
这只是一个例子,根据您的需要调整数学...
另一个解决方案:
find . -name '*xml' -printf '%TY %p\n' | awk '$1 >= 2014 {$1=""; print}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.