1832576 Members
3336 Online
110043 Solutions
New Discussion

rm Too many arguments

 
SOLVED
Go to solution
Neil Harris
Regular Advisor

rm Too many arguments

I am trying to delete over 500000 small files which have accumulated over time and now are no longer needed. rm returns too many arguments. Is there a work round for this as I seem only to be able to delete them 5000 or so at a time.
An inveterate hacker
6 REPLIES 6
Pete Randall
Outstanding Contributor
Solution

Re: rm Too many arguments

Try using find:

find /dirname -name *whatever* -exec rm {} \;

that should do it.

Pete

Pete
Justo Exposito
Esteemed Contributor

Re: rm Too many arguments

hi,

Yes, there are. You must go to the directory and then execute this:
for i in *
do
rm $i
done

Regards,

Justo.
Help is a Beatiful word
RAC_1
Honored Contributor

Re: rm Too many arguments

ll|awk '{print $9}'|xargs rm -fr

You are getting this because
check
getconf ARG_MAX is 2048000

xargs is just for such things
There is no substitute to HARDWORK
Patrick Wallek
Honored Contributor

Re: rm Too many arguments

You could also take a look at 'xargs'. Do a 'man xargs' for more info.
James R. Ferguson
Acclaimed Contributor

Re: rm Too many arguments

Hi:

A 'find' piped to 'xargs' is kinder to your system then a 'find ... -exec'. With '-exec' a new task is spawned for every file to remove. With 'xargs', a large group of files names can be buffered and a single task for that group spawned. For example:

# cd
# find . -type f -print|xargs -n500 rm {}

Regards!

...JRF...
MANOJ SRIVASTAVA
Honored Contributor

Re: rm Too many arguments

there is also a laymans way


ls > abc

rm `cat abc`



Manoj Srivastava