【问题标题】:Move files that are 30 minutes old移动 30 分钟前的文件
【发布时间】:2016-09-21 13:45:47
【问题描述】:

我使用的服务器系统不允许我存储超过 50 GB 的文件。我的应用程序需要 20 分钟才能生成一个文件。有什么方法可以将所有超过 30 分钟的文件从源移动到目标?我试过rsync

rsync -avP source/folder/ user@destiantionIp:dest/folder

但这不会从我的服务器中删除文件,因此存储限制失败。

其次,如果我使用mv 命令,仍在生成的文件也会移动到目标文件夹并且程序会失败。

【问题讨论】:

  • 据我所知,rsync 不会从发件人端删除文件,它甚至可能无法挑选出超过 30 分钟的文件。文件的 mtime 应在创建文件时更新,以便您选择过去 30 分钟内未修改的文件。

标签: linux bash shell ubuntu csh


【解决方案1】:

您可以使用 find-exec 来实现:-

根据需要将/sourcedirectory/destination/directory/ 替换为源路径和目标路径。

find /sourcedirectory -maxdepth 1 -mmin -30 -type f -exec mv "{}" /destination/directory/ \;

该命令的基本作用是,它尝试在当前文件夹 -maxdepth 1 中查找 30 分钟前最后一次修改的文件 -mmin -30 并将它们移动到指定的目标目录。如果您想使用上次访问文件的时间,请使用-amin -30

或者,如果您想查找某个范围内修改的文件,您可以使用 -mmin 30 -mmin -35 之类的名称,它会为您找到修改时间超过 30 分钟但不到 35 分钟的文件。

来自man 页面的引用:-

   -amin n
          File was last accessed n minutes ago.

   -atime n
          File was last accessed n*24 hours ago.  When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so  to  match  -atime
          +1, a file has to have been accessed at least two days ago.

   -mmin n
          File's data was last modified n minutes ago.

   -mtime n
          File's data was last modified n*24 hours ago.  See the comments for -atime to understand how rounding affects the interpretation of file modification times.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2014-01-20
    相关资源
    最近更新 更多