2

How can I work around the bash shell limitation of 'Argument list too long' when using filename wildcards that match a ton of files in /tmp/?

[my-centos4 tmp] rm -rf /tmp/myLocalFiles*
bash: /bin/rm: Argument list too long

5 Answers 5

3

for i in myLocalFiles*; do rm -f $i; done

3

This is a little simpler than jáquer suggested:

find /tmp -name "myLocalFiles*" -delete
2
  • My 'find' on centos4 does not support the -delete option.
    – WilliamKF
    Feb 1, 2011 at 1:06
  • 2
    @WilliamKF: Then your find probably also does not support find ... -exec rm {} + Feb 1, 2011 at 1:31
2
find /tmp -name "myLocalFiles*" -exec rm -rf {} +
2

For those who can't use -delete to find command, this also works:

find /tmp -name "myLocalFiles*" -print0 | xargs -0 rm -rf
1
  • 1
    from #bash channel: "xargs(1) is dangerous (broken, exploitable, etc.) when reading non-NUL-delimited input. If you're working with filenames, use find's -exec [command] {} + instead or -print0 | xargs -0 provided you don't care about portability and like doing unnecessary extra work. Othwerwise a nice for loop." Sep 5, 2013 at 23:25
0

You can use Wines cmd

wine cmd
del "Z:\tmp\myLocalFiles*"
exit

Shell expansion works great but it has some caveats. The Windows convention never suffers from these problems, but places the duty on the programmer. This is probably better, since the writer of the shell cannot know how any program expects its input data.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .