我怎样才能将它组合成一个单行 - bash

问题描述 投票:1回答:2

因此,我希望以递归方式搜索具有数千个文件夹的目录以获取特定文件扩展名,并获取添加日期,然后按特定年份过滤。下面的代码有效但有没有办法可以转换为单行代码?

  1. 获取所有以xml结尾的文件并写入tmp.txt find . -name "*xml" >> tmp.txt
  2. 获取tmp.txt中所有这些文件的权限信息和时间戳信息 foreach i ( ` cat tmp.txt ` ) ls -ltrh $i >> tmp2.txt end
  3. 第8列包含日期作为年份,因此获取年份大于特定2014年的所有文件... awk '$8 >=2014' tmp2.txt >> tmp3.txt
linux bash shell
2个回答
5
投票

试试这个:

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

1
投票

我会在 shell中做什么:

find . -mtime -$((365*4)) -name "*xml" >> tmp.txt  

这只是一个例子,根据您的需求调整数学...

另一种方案:

find . -name '*xml' -printf '%TY %p\n' | awk '$1 >= 2014 {$1=""; print}'
© www.soinside.com 2019 - 2024. All rights reserved.