Argument List Too Long Error – Delete lot of files from a folder
In linux/unix, a folder contains lot of file and you may not delete files by using the rm rf * because small amount of buffer memory allocated to storing the list of arguments and if it is filled up, the shell will not execute the program and will throw the exception like Argument List Too Long Error.
The command rm rf * command will work like as rm -rf file1 file2 file3 file4 and so on.
So we have to delete one by one file by executing the following commands.
rm -rf file1 rm -rf file2
But the above command will be very tedious work to delete one by one.
So we can use find command and pass the file to remove command and then delete.
find . -type f -exec rm -v {} \;
Or
The below command will display the deleted file name also and its very faster compare to the above command
find . -type f -print -delete
Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in the IT industry for more than 12 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting, Website Development, and IAM(ForgeRock) Specialist
I am a self-learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.