A few words of thanks would be greatly appreciated.

Unable to delete file: Argument list too long

Linux users encounter a typical error message of 'argument list too long'when they try to delete a file. This issue arises due to the problem in command rm which is one of the most commonly used shell commands in Linux. This error occurs due to the reason that the system commands show limitations when a large number of arguments are fed into a single command. There are four solutions that can effectively deal with the operating system's problem. Through Xargs, Command Find, Perl Program and running loop in shell script, the error 'Argument list too long' is solved.


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 (it is developed by the shell in a series of arguments).



Send each rm argument using the command xargs as below:
ls *.toto | xargs rm          
find . -type f -name *.toto | xargs rm

Command find

The second solution consists of using the command find together with exec:
find . -name "*.toto" -exec rm {} ;

loop for (bash)

Another solution consists of performing a loop in shell script:

for i in 'seq 0-9'[ALPHABET] ; do rm $i*.toto ; done          

Perl program

Another solution using Perl :
perl -e 'for(</home/lami20j/*.toto>){unlink}'

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.


This document, titled « Unable to delete file: Argument list too long », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).