移动30分钟的文件

sau*_*abh 6 linux bash shell ubuntu csh

我在一个服务器系统上工作,不允许我存储超过50千兆字节的文件.我的应用程序需要20分钟才能生成文件.有什么方法可以将所有超过30分钟的文件从源移动到目的地吗?我试过了rsync:

rsync -avP source/folder/ user@destiantionIp:dest/folder
Run Code Online (Sandbox Code Playgroud)

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

其次,如果我使用该mv命令,仍然生成的文件也会移动到目标文件夹,程序将失败.

Ini*_*ian 13

您可以使用find沿-exec此: -

更换/sourcedirectory/destination/directory/与源和目标路径,因为你需要.

find /sourcedirectory -maxdepth 1 -mmin -30 -type f -exec mv "{}" /destination/directory/ \;
Run Code Online (Sandbox Code Playgroud)

基本上该命令的作用是,它尝试查找当前文件夹-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.
Run Code Online (Sandbox Code Playgroud)