Quick question about the command find.

Markus Schönhaber ubuntu-users at list-post.mks-mail.de
Fri Jun 4 14:04:20 UTC 2010

04.06.2010 15:21, Maxime Alarie:

> I  want to erase files and directories that are older than 15 days..
> the command I use is :   find $MyPath -type d -exec rm {} \;
> Obviously rm wont erase  a non empty directory..

Without -r rm won't erase any directory, empty or not. rmdir will delete
directories iff they are empty.

> I tried using  rm -r but I got errors..  

And these errors were exactly...?

> My question is, How can I recursively delete  directories using find
> -exec rm  without having to  use 2 commands:  find  . -type f -mtime +15
> -exec rm  THEN  find . -type d -exec rmdir

By default, find ANDs multiple tests. Therfore,
find $MyPath -type d -mtime +15
should print all directories below $MyPath which were not modified for
more than 15 days.
>From your description it's not entirely clear to me, whether you really
want to recursively delete those directories regardless whether or not
they contain files or directories with a more recent mtime. If not, rm
-r is obviously not what you want to use.


More information about the ubuntu-users mailing list