Argument List Too Long Error – Delete lot of files from a folder

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

 

 

Leave a Reply