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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove files 2

Status
Not open for further replies.

razalas

Programmer
Apr 23, 2002
237
0
0
US
On our system we generate a large number of temporary files every day, and at the end of the day, we remove them. Except lately, the number of files has grown to be quite long, so the remove command we are executing is failing, as shown below:
Code:
$ rm RECPT-ZONE*
-bash: /bin/rm: Argument list too long

I am planning to change to the following method of removing these files:
Code:
find . -name "RECPT-ZONE*" -exec rm -f {} \;

I have tested this and it works fine, but my question is, is there a better way to do this? I don't have any reason to suspect otherwise, but just thought I'd check with this community to make sure I am not going to run into any unforeseen issues.


Code what you mean,
and mean what you code!
But by all means post your code!

Razalas
 
I recommend using something like this:

Code:
# UNTESTED!
find . -name "RECPT-ZONE*" |xargs rm -f

-exec rm ... generates a Unix process for each file removed where xargs generates only one and xargs guarantees not to overflow the command line.
 
Great point! I knew there was a good a reason for checking here.

thanks, Olded. Have a star!

Code what you mean,
and mean what you code!
But by all means post your code!

Razalas
 
You may also try this:
for f in RECPT-ZONE*; do rm $f; done

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

another excellent suggestion!

Thanks!

Code what you mean,
and mean what you code!
But by all means post your code!

Razalas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top