Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I was just looking for a little insight on a quick clean up script I'm writing. The directory I'm cleaning up is basically temp directories that get created on almost a daily basis. Currently there are over 200 temp directories in the parent directory I'm looking to clean up.
Each of the temp directories is named via a number, ex : 1153456537603.
I want to keep a few of the most recent ones just in case they are needed but my shell script is currently this:
#!/bin/ksh
cd <parent dir>
find . -name "11*" -type d -mtime +10|xargs rm -rThe parent directory is about 120MB in size and when I tested this script with -print instead of xargs it prints out the directories I want to delete so I'm confident that this will run and work fine.
My questions are this:
1.) The script seems to take a while to execute. Is that purely due to the amount of dirs it's trying to remove?2.) Would using -exec rm -r {} \; make it execute quicker?
3.) I put -type d in the code even though there are no files in the parent directory, is it needed? or is it redundent?
Thank in advance.
Regards
~Verta

1.) The script seems to take a while to execute. Is that purely due to the amount of dirs it's trying to remove?
The script is rather simple so its probably the amount of dirs.
2.) Would using -exec rm -r {} \; make it execute quicker? xargs is the preferred method. It's a lot faster than -exec. Also, with a large number of files, it's possible to overflow the command line buffer. See this link:
http://www.unixreview.com/documents/s=8274/sam0306g/0306g.htm
3.) I put -type d in the code even though there are no files in the parent directory, is it needed? or is it redundent?If your algorithm is to only check directories I would use the type directory check.

Nails,
Thanks for the read. It had a lot of good pointers and information. And thanks for your quick response as always :)
Regards
~Verta

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |