How to work around shell limitation of 'Argument list too long'?
5,317
Solution 1
for i in myLocalFiles*; do rm -f $i; done
Solution 2
This is a little simpler than jáquer suggested:
find /tmp -name "myLocalFiles*" -delete
Solution 3
For those who can't use -delete to find command, this also works:
find /tmp -name "myLocalFiles*" -print0 | xargs -0 rm -rf
Solution 4
find /tmp -name "myLocalFiles*" -exec rm -rf {} +
Related videos on Youtube
![WilliamKF](https://i.stack.imgur.com/FkIiK.png?s=256&g=1)
Author by
WilliamKF
Updated on September 17, 2022Comments
-
WilliamKF almost 2 years
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
-
WilliamKF over 13 yearsMy 'find' on centos4 does not support the -delete option.
-
Dennis Williamson over 13 years@WilliamKF: Then your
find
probably also does not supportfind ... -exec rm {} +
-
Édouard Lopez almost 11 yearsfrom #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 nicefor
loop."