Move files that are 30 minutes

I am working on a server system that does not allow storing files larger than 50 gigabytes. My application takes 20 minutes to generate a file. Is there a way in which I can move all files older than 30 minutes from source to destination? I tried rsync :

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

but this does not delete the files from my server, and therefore the storage limit is not met.

Secondly, if I use the mv command, the files that still appear also move to the destination folder, and the program does not work.

+5
source share
1 answer

You can use find along with -exec to do this: -

Replace /sourcedirectory and /destination/directory/ source and destination paths as needed.

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

What the team basically does, it tries to find the files in the current -maxdepth 1 folder that were last modified 30 minutes ago -mmin -30 and move them to the specified destination directory. 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 give you files modified more than 30, but less than 35 minutes ago.

Links 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 data was last modified n minutes ago. -mtime n File data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times. 
+10
source

All Articles