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

标签 linux bash shell

所以我想递归地搜索一个包含数千个文件夹的目录以查找特定的文件扩展名,并获取它的添加日期,然后按特定年份进行过滤。下面的代码有效,但有没有办法将其转换为单行代码?

  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
    

最佳答案

试试这个:

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

关于linux - 我怎样才能将它组合成一个单行 - bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47871688/

相关文章:

linux - 是否有可能/如何创建实时远程日志文件的本地副本以供观看/拖尾?

python - Behave 测试运行程序在 Jenkins 上没有彩色输出

bash - -bash : !“:未找到事件

json - 如何读取并解析json文件并将其添加到shell脚本变量中?

linux - 用两条新线替换一条线

linux - 排序文件夹大小不起作用 - RedHat Linux

Linux:如何检查驱动器是否挂载到 nfs

c - 编写程序以处理导致 Linux 上丢失写入的 I/O 错误

bash - 如果连接中断,ffmpeg 从实时流中录制视频将关闭

shell - 从日志中排序唯一的 url