Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find files that are older than 15 minutes

Tags:

linux

find

unix

I have a chache directory setup on Amazon EBS. I'm using it as a cache for an S3FS mounted file system that holds virtual backup tapes. The tapes are being used with Bacula.

The backup to the S3 mounted directory would be way to slow to be usable without some form of local cache. The storage on S3 is of course virtually limitless. So I need to clear out the /cache directory every so often.

I want to be able to delete tape files in that directory that are older than 15 minutes.

So I tried this command:

[root@ops:~] #find /cache/jf-backup/ -type f -daystart -mmin +15
/cache/jf-backup/jf-backup-tape-0073
/cache/jf-backup/jf-backup-tape-0074

And it does find the files. Howewver they are not older than 15 minutes:

[root@ops:~] #ls -l /cache/jf-backup/
total 6199968
-rw-------. 1 root root 5368688607 Feb 25 14:39 jf-backup-tape-0073
-rw-------. 1 root root  980074496 Feb 25 14:42 jf-backup-tape-0074
[root@ops:~] #date
Thu Feb 25 14:46:59 EST 2016

How can I get the find command to only find files that are older than 15 minutes? Once I do I want to delete those files with a command like this:

find /cache/jf-backup/ -type f -daystart -mmin +15 -exec rm -rf {} \;
like image 546
bluethundr Avatar asked Feb 25 '16 19:02

bluethundr


People also ask

How do you find all files which are modified 10 minutes before?

Syntax of find command with “-mmin n” option -n : find command will look for files modified in last n minutes. +n : find command will look for files modified in before the last n minutes i.e. which are not modified in last n mins. n : find command will look for files which are modified exactly n minutes ago.

How do I find files older than 30 minutes in Linux?

-mmin +<minutes> : The mmin option is used to find files/directories with last modified in minutes (replace minutes with the amount of minutes as an integer). In our case, we want to search files older than 10 minutes. If you need to search for files older than 20 minutes, you would simply use -mmin +20 .

How do I find out what files have been modified more than 1 day?

/directory/path/ is the directory path where to look for files that have been modified. Replace it with the path of the directory where you want to look for files that have been modified in the last N days. -mtime -N is used to match files that had their data modified in the last N days.


1 Answers

From @Jan at https://unix.stackexchange.com/questions/155184/how-to-find-and-delete-files-older-than-specific-days-in-unix, try

find /PATH/TO/FILES -type f -mmin +15 -exec rm -f {} +

like image 55
neallred Avatar answered Oct 21 '22 14:10

neallred