rm argument list too long find and xargs
Colin McGregor
colin.mc151-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Mon Apr 12 18:58:48 UTC 2010
On Mon, Apr 12, 2010 at 12:29 PM, teddymills <teddy-5sHjOODPK7E at public.gmane.org> wrote:
>
> I was trying to rm more than 1024 files at one time (old logs)
> and rm returned a strange error. "Argument list too long"
>
> so find and xargs to the rescue..
> find . -name 'myDEBUG*.log' | xargs rm
>
> http://en.wikipedia.org/wiki/Xargs
> uname -a shows a kernel less than 2.6.23
Chris Johnson and Chris Browne have offered nice, neat, even elegant
solutions that should be great... Let me offer the sledgehammer
solution... Ugly, but it works :-) . Create a little script called say
script :
-------------------------------------------
#! /bin/bash
echo "# /bin/bash" > script2
find . -name 'myDEBUG*.log' | awk '{ print("rm " $1) }' >> script2
chmod 700 script2
./script2
--------------------------------------------
Okay, so I am a sucker for programs that write other programs, even in
this trivial example :-) . Removing a bunch of old log files is a
problem that may need doing, but is normally something that needs
doing so infrequently that it doesn't need to be done well. In other
words, better to do a quick, easy to come up with, ugly solution
rather than spend a lot of time finding the most elegant solution :-)
.
Colin.
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list