Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

thread822-305749

Status
Not open for further replies.

Neelimaix

Technical User
Jun 29, 2005
23
US
How to delete dir of 2 months old .

in the solution where did she add the * ?..

Regards,


find /starting/directory/ -type d -mtime +60 -exec rm -r {} \;

 
I have found a solution for this question in archives ..

find /starting/directory/ -type d -mtime +60 -exec rm -r {} \;

-exec rm -r {} results in :

[root@sfadadm02 scripts]# find /root/scripts -type d -mtime +92 -exec rm -r {} \;
find: /root/scripts/sfqaapp14/2005/10/02: No such file or directory


How to correct this error ?..
 
I think you get that error because the directory listed has been removed, but the "find" command still wants to look down there for sub-directories. If you just want to hide the error, re-direct it to /dev/null:

find /root/scripts -type d -mtime +92 -exec rm -r {} \; 2>/dev/null

Personally, this type of command can be unnerving, and I'd much rather see the errors (even if I know to ignore most of them).
 
[tt]-depth Process each directory’s contents before the directory itself.[/tt]
Make find start at the leaves of the tree first, and work it's way back to the root.

A problem you might find is that if you have
[tt]dir1
dir1/dir2[/tt]
Removing dir2 will change the date of dir1, which might have been old enough to delete.

--
 
This will also perform the same work without creating the error. It allows "find" to complete before the matching results are removed:

$ find /root/scripts -type d -mtime +60|xargs rm -r

To be safe, I'd always run it first without the "rm":

$ find /root/scripts -type d -mtime +60|xargs ls
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top