【问题标题】:Unix command for find updated and newly added files/folder用于查找更新和新添加的文件/文件夹的 Unix 命令
【发布时间】:2011-10-28 16:35:15
【问题描述】:

我需要找出在两个不同时间(脚本开始和结束时间)之间在文件系统路径 (/home/user01/myapps/) 中添加/更新的文件或文件夹的列表。

我正在运行一个 Shell 脚本来更新/添加新文件到来自不同来源的资源路径 /home/user01/myapps/。因此,在脚本结束时,我想知道已添加或更新的文件或文件夹的列表。

我有以下命令

找到 /opt/app/tds/tdsbatch -mtime -1

但是,我不确定脚本的运行时间。

确实有帮助!

【问题讨论】:

  • “不确定脚本运行时间”是什么意思。请更新您的问题以包含您需要的示例输出。祝你好运。

标签: unix filesystems find command


【解决方案1】:

在任何需要的时刻记录时间:

# record the current time in seconds on script startup
start_time=$(date +%s)
...
# do whatever you like
...
# to get the runtime in secods - if you like:
runtime=$(($(date +%s) - start_time))
# to get the runtime in minutes (minutes are useful for -mmin find param)
runtime=$((($(date +%s) - start_time) / 60))
...
# to record the finish time in seconds:
end_time=$(date +%s)

现在 find 根据您的需要。像

find /path \( -mmin $((-($(date +%s) - start_time) / 60)) \
  -a $((($(date +%s) - end_time) / 60)) \)
  • 第一个-mmin 参数指定在(当前时间 - 脚本开始时间)分钟后修改
  • 第二个-mmin 参数指定在(当前时间 - 脚本结束时间)分钟之前修改
  • 两者都与-a参数结合并用前缀括号括起来

你也许可以用这些来做。否则,我需要进一步说明您的需求。

【讨论】:

    【解决方案2】:

    在脚本开始时,您可以对任何现有文件使用 touch 命令或创建一个虚拟文件。

    例如

    脚本开始

    touch filename1 - 它会将filename1的时间戳更改为当前时间

    然后在脚本结束时,您可以使用以下命令:

    查找目录名-新文件名1

    它将给出该目录中filename1时间戳之后修改或创建的所有文件

    【讨论】:

      猜你喜欢
      • 2015-06-01
      • 1970-01-01
      • 2010-11-05
      • 2012-05-22
      • 1970-01-01
      • 1970-01-01
      • 2019-07-19
      • 1970-01-01
      相关资源
      最近更新 更多