trying to create a scripts that deletes files older than X days. It seemed straight forward enough but all files seem to be getting removed?

find /Volumes/Groups/Projects/530_BFAMI/test/ -ctime +30 -print -exec rm {} \;

any ideas welcome!?

Also would be good to print file information for matches as maybe my dates are misleading in finder?

  • agh apologies. Is working. Can i have multiple parameters? Ie include a size? -ctime +30 AND -size +10000000c – v3nt Jun 13 '11 at 14:16
  • 2
    There's a significant difference between ctime and mtime and in most cases people mean to use mtime (the time the contents of the file last changed) and not ctime (the time the inode-related information for the file changed). Very rare to see ctime used this way, so I mention this as a caution to you OP. – Ian C. Jun 13 '11 at 14:45

Never suggesting -exec rm ....

rm is simply too dangerous command. Always dry-run first. IMHO it is better using this:

find /Volumes/Groups/Projects/530_BFAMI/test/ -ctime +30 -print0 | xargs -0 -n1

this will show the dry-run and only when you satisfied you can add the rm to the end

find /Volumes/Groups/Projects/530_BFAMI/test/ -ctime +30 -print0 | xargs -0 rm

If you start using this piped to xargs version, you can always add more filters, like:

find /some/where -mtime +3d -print0 | grep -ziE '\.(jpg|png|gif)$' | xargs -0 rm

and similar (more) powerful combinations.

  • This answer should have been accepted. Thanks, was looking for just this. – user14492 Aug 10 '15 at 19:33
  • 1
    What is -ctime +30 ? Is it 30 days before? or 30 minutes before files. Please explain. – Naveed Abbas May 2 '17 at 7:18
  • @ToughGuy If no units are specified, this primary evaluates to true if the difference between the time of last change of file status information and the time find was started, rounded up to the next full 24-hour period, is n 24-hour periods. - aka: days – jm666 May 2 '17 at 8:27

To answer the question asked in your comment: You can join separate criteria just by listing them, one after the other. If you prefer, you can use -a or -and in between them, but these are redundant. You can also use -o or -or for the OR operator, and you can use parentheses – which must be quoted to protect them from the shell, as in \( and \) for grouping.

For the full details, run: man find


It is considered dangerous to use -exec rm without first ls. You should probably check that first. Reverse check is also a good hint to tell you if your timing is correct.

find . -maxdepth 1 -type f -mtime -30d -exec ls -latr {} \;


find . -maxdepth 1 -type f -atime -30d -exec ls -latr {} \;
  1. Constrain your find result. Make sure what you explicitly ask for.
  2. Compare to see if the opposite result is what actually has been excluded from your original command.
  3. Probably -mtime or -atime are more appropraite but again compare the result and see if they are actually what you need.

Try this: find . -ctime +30 | xargs rm -r 2> /dev/null

For some reason, this runs rm twice. So I just redirect the errors to the black hole /dev/null


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .