Unable to delete file: Argument list too long
When trying to delete a file , you receive the following error message :
bash: /bin/rm: Argument list too long
This is due to a limitation of the command rm which cannot manage a large number of arguments (The joker ‘*’ is developed by the shell in a series of arguments).
Solutions
Xargs
Send each rm argument using the command xargs as below:
ls *.filename | xargs rm
find . -type f -name \*.filename | xargs rm
Command find
The second solution consists of using the command find together with
–exec:
find . -name "*.filename" -exec rm {} \;
loop for (bash)
Another solution consists of performing a loop in shell script:
for i in `seq 0-9`a b c d e f g h i j k l m n o p q r s t u v w x y z ; do rm $i*.toto ; done
Program Perl
using the command Perl :
perl -e 'for(</home/lami20j/*.toto>){unlink}'