How to solve: Delete file argument list too long
Why argument list too long
The “argument list too long” error occurs because there is a limit to the number of arguments that can be passed to a command in Linux. This limit is determined by the value of the ARG_MAX variable. When you try to delete a large number of files at once, the list of arguments passed to the rm
command exceeds the value of ARG_MAX, and the error is raised.
use find
find . -name filename | xargs rm -f
## or
find . -name filename -delete
find . -name "*.txt" -exec rm {} \;
too many files may also cause the argument list too long problem in find
. Could use ls
and grep
instead.
ls |grep YOUR_FILE_PATTERN |xargs rm -f
use xargs
ls | xargs -n 50 rm -rf
xargs
could control the batch size of an output. In this case, 50 elements in a batch/group, and pass to rm to process progressively.