India Broadband Forum


Linux Workaround for ‘Argument list too long’ error message while removing all files

This is a discussion on Linux Workaround for ‘Argument list too long’ error message while removing all files within the Computer hardware and software tips and tricks forums, part of the News and views category; Linux Workaround for ‘Argument list too long’ error message while removing all files from a directory While someone deleting the ...

Go Back   India Broadband Forum > General > General offtopic discussions > News discussions > News and views > Computer hardware and software tips and tricks

India Broadband Forum


Computer hardware and software tips and tricks Tips, tricks, and how-to's that help you get the most from your computer gear.Visit our Computer Tips And Tricks section

                      

Reply

 

LinkBack Thread Tools Display Modes
Old 03-26-06, 01:15 PM   #1
 
Admin's Avatar
 
Join Date: Jan 2006
Location: New Delhi
Age: 32
Posts: 4,699
Rep Power: 12
Admin is just really niceAdmin is just really niceAdmin is just really niceAdmin is just really niceAdmin is just really nice
Default Linux Workaround for ‘Argument list too long’ error message while removing all files

Linux Workaround for ‘Argument list too long’ error message while removing all files from a directory
While someone deleting the files by using rm on the linux server, he might face this problem. There is a maximum number of files that can be passed as arguments to rm. So it does not allow you remove the files with ‘rm’ command.
Using rm to delete files is the easiest way adopted by linux users. Well, I see that if this does not work, there is a solution provided for this problem. As mentioned, there were around 72K files were generated in a folder which needed to be deleted. In the example, there are all the files starting with “Count”, so can be chosen using “Count*”.
Here is the output on command prompt.
root # rm Count*
/bin/rm: Argument list too long.

The workaround as given is: Use find to pipe all the matching files to rm, one at a time.
root # find . -name ‘Count*’ | xargs rm
And this can remove as many files as you want. Perfect!! Not yet…
The “find | xargs” solution doesn’t work on files with spaces.Now what to do? The only reliable way I could find is to use
find . -name ‘Count*’ -exec rm {} \;
but there’s a caveat: it will look for Count* in subdirectories as well, which may be undesireable. So in that case, -maxdepth 0 does the trick.
root # find . -maxdepth 0 -name ‘Count*’ -exec rm {} \;
I hope you got your trick now!!
Admin is offline   Reply With Quote
Reply

Tags
linux, list, long’, workaround, ‘argument

Thread Tools
Display Modes

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +5.5. The time now is 04:56 PM.


India Broadband Forum