Move files that are 30 minutes old
Asked Answered
A

1

7

I work on a server system that does not allow me to store files more than 50 gigabytes. My application takes 20 minutes to generate a file. Is there any way whereby I can move all the files that are more than 30 minutes old from source to destination? I tried rsync:

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

but this does not remove the files from my server and hence the storage limit fails.

Secondly, if I use the mv command, the files that are still getting generated also move to the destination folder and the program fails.

Aquamarine answered 24/5, 2016 at 11:16 Comment(1)
As far as I know rsync will not remove files from sender end and it might not even be able to pick out files older then 30 minutes. File's mtime should get updated as the file is being created so that allow you to pick files that have not been modified in the last 30 minutes.Arlyne
E
15

You can use find along with -exec for this:-

Replace /sourcedirectory and /destination/directory/ with the source and target paths as you need.

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

What basically the command does is, it tries to find files in the current folder -maxdepth 1 that were last modified 30 mins ago -mmin -30 and move them to the target directory specified. If you want to use the time the file was last accessed use -amin -30.

Or if you want to find files modified within a range you can use something like -mmin 30 -mmin -35 which will get you the files modified more than 30 but less than 35 minutes ago.

References from the man page:-

   -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.
Espalier answered 24/5, 2016 at 11:22 Comment(1)
For me , the directive +MIN works fine, but -MIN not... -rw-r--r-- 1 apache apache 588870234 Dec 11 17:26 midia-3c7e1d70ff59655e189db0107a5824bc.mp4 -rw-r--r-- 1 apache apache 588870234 Dec 11 16:36 midia-84b6a746a5115561b99a44636911d54d.mp4 [root@video storage]# find /storage -maxdepth 1 -mmin -5 -type f [root@video storage]# find /storage -maxdepth 1 -mmin +5 -type f /storage/midia-84b6a746a5115561b99a44636911d54d.mp4 /storage/midia-3c7e1d70ff59655e189db0107a5824bc.mp4Bonnette

© 2022 - 2024 — McMap. All rights reserved.