0

The manpage for find says:

   -prune True;  if  the file is a directory, do not descend into it. If -depth is 
          given, false; no effect.  Because -delete implies -depth, you cannot 
          usefully use -prune and -delete together.

What is the meaning of the last sentence? Can't one usefully run the below command...

find /path/ -prune -type f -ctime +15 -delete

... to find and delete all files last changed more than 15 days ago in /path/ but not in the subdirectories under /path/? I think it's a perfectly valid use case.

2

Looks like the problem is that -prune is ineffective if -depth is also used and -delete implies -depth.

As for the use case you're asking about, I've always used -maxdepth X.

For example

find /path/ -maxdepth 1 -type f -ctime +15 -delete

will do.

| improve this answer | |
  • You're right. Use of -delete automatically turns on the `-depth' option., says the manpage just a few lines before. Guess I completely missed out that bit. – dr_ Sep 18 '18 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.