Computing.Net > Forums > Unix > XARGS vs -exec

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

XARGS vs -exec

Reply to Message Icon

Name: Vertabreaker
Date: July 21, 2006 at 05:30:18 Pacific
OS: AIX
CPU/Ram: 2CPUS/4GB RAM
Product: IBM
Comment:

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 -r

The 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



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: July 21, 2006 at 08:20:51 Pacific
Reply:

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.


0

Response Number 2
Name: Vertabreaker
Date: July 21, 2006 at 11:43:31 Pacific
Reply:

Nails,

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

Regards

~Verta


0

Response Number 3
Name: nails
Date: July 21, 2006 at 14:29:59 Pacific
Reply:

You're welcome. Anytime..


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: XARGS vs -exec

rm files > 30 days to another dir www.computing.net/answers/unix/rm-files-30-days-to-another-dir/7255.html

Script to scan files for a string www.computing.net/answers/unix/script-to-scan-files-for-a-string/7532.html

Check for new file, exec sql*plus www.computing.net/answers/unix/check-for-new-file-exec-sqlplus/6714.html