Quick question about the command find.

Maxime Alarie malarie at processia.com
Fri Jun 4 14:09:52 UTC 2010


 I definitely want to erase  backups that are older than 15 days using cron.   Maybe I made a typo when  trying rm -rf in  ny test folder.

Thanks for your help 






-----Original Message-----
From: ubuntu-users-bounces at lists.ubuntu.com [mailto:ubuntu-users-bounces at lists.ubuntu.com] On Behalf Of Markus Schönhaber
Sent: 04 June 2010 10:04
To: ubuntu-users at lists.ubuntu.com
Subject: Re: Quick question about the command find.

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.

-- 
Regards
  mks


-- 
ubuntu-users mailing list
ubuntu-users at lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users




More information about the ubuntu-users mailing list