FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo User

 
 
LinkBack Thread Tools
 
Old 05-22-2010, 01:49 AM
Daniel D Jones
 
Default xargs and rm funkiness

Running the command:

find -name *.ext | xargs -0 rm

I get the result:

rm: cannot remove `Long File Name One.ext
Long File Name Two.ext
Long File
Name Three.ext
': File name too long.

(The actual list is much longer than this, of course, or I wouldn't be using
xargs.) For some reason, the
isn't being recognized as a separator but
rather as a part of a single long file name. Don't think $IFS would affect a
command like rm but it doesn't appear to be the issue:

ddjones@merlin ~ $ set | grep IFS
IFS=$'
'

I don't see any other ser variable which looks like a likely candidate to
cause the behavior. Anyone have a clue what's going on?

--
"Why assume so glibly that the God who created the universe is still running
it? It is certainly conceivable that He may have finished it and then turned it
over to lesser gods to operate." - H.L. Mencken
 
Old 05-22-2010, 02:11 AM
 
Default xargs and rm funkiness

Daniel D Jones <ddjones@riddlemaster.org> wrote:

> Running the command:
>
> find -name *.ext | xargs -0 rm
>
> I get the result:
>
> rm: cannot remove `Long File Name One.ext
Long File Name Two.ext
Long File
> Name Three.ext
': File name too long.
>
> (The actual list is much longer than this, of course, or I wouldn't be using
> xargs.) For some reason, the
isn't being recognized as a separator but
> rather as a part of a single long file name. Don't think $IFS would affect a
> command like rm but it doesn't appear to be the issue:
>
> ddjones@merlin ~ $ set | grep IFS
> IFS=$'
'
>
> I don't see any other ser variable which looks like a likely candidate to
> cause the behavior. Anyone have a clue what's going on?
Why do you have -0 -- this replaces the
's with a null character -- is
that what you want?

--
Your life is like a penny. You're going to lose it. The question is:
How do
you spend it?

John Covici
covici@ccs.covici.com
 
Old 05-22-2010, 07:46 AM
Neil Bothwick
 
Default xargs and rm funkiness

On Fri, 21 May 2010 21:49:49 -0400, Daniel D Jones wrote:

> find -name *.ext | xargs -0 rm
>
> I get the result:
>
> rm: cannot remove `Long File Name One.ext
Long File Name Two.ext
Long
> File Name Three.ext
': File name too long.

xargs can suck with anything but plain ASCII-without-spaces filenames.,
and it quite unnecessary here.

find -name *.ext -exe rm "{}" ;

or maybe even

find -name *.ext -exe rm "{}" +


--
Neil Bothwick

He who asks a question is a fool for a minute,
He who doesn't ask is a fool for a lifetime.
 
Old 05-22-2010, 07:49 AM
Patrick Holthaus
 
Default xargs and rm funkiness

Hey!

On Saturday 22 May 2010 03:49:49 Daniel D Jones wrote:
> Running the command:
>
> find -name *.ext | xargs -0 rm

You might try:

find -name *.ext -print0 | xargs -0 rm

Cheers
Patrick
 
Old 05-22-2010, 11:35 AM
David W Noon
 
Default xargs and rm funkiness

On Sat, 22 May 2010 10:10:02 +0200, Neil Bothwick wrote about Re:
[gentoo-user] xargs and rm funkiness:

>On Fri, 21 May 2010 21:49:49 -0400, Daniel D Jones wrote:
>
>> find -name *.ext | xargs -0 rm
>>
>> I get the result:
>>
>> rm: cannot remove `Long File Name One.ext
Long File Name
>> Two.ext
Long File Name Three.ext
': File name too long.
>
>xargs can suck with anything but plain ASCII-without-spaces filenames.,
>and it quite unnecessary here.
>
>find -name *.ext -exe rm "{}" ;
>
>or maybe even
>
>find -name *.ext -exe rm "{}" +

Or simpler still:

find -name *.ext -delete

--
Regards,

Dave [RLU #314465]
================================================== ====================
dwnoon@ntlworld.com (David W Noon)
================================================== ====================
 
Old 05-22-2010, 12:25 PM
Neil Bothwick
 
Default xargs and rm funkiness

On Sat, 22 May 2010 12:35:10 +0100, David W Noon wrote:

> >find -name *.ext -exe rm "{}" +
>
> Or simpler still:
>
> find -name *.ext -delete

Neat - I hadn't noticed that option.

Anyone for find / -delete ?


--
Neil Bothwick

Top Oxymorons Number 31: Small crowd
 
Old 05-22-2010, 04:04 PM
Daniel D Jones
 
Default xargs and rm funkiness

On Friday 21 May 2010 22:11:49 covici@ccs.covici.com wrote:
> Daniel D Jones <ddjones@riddlemaster.org> wrote:
> > Running the command:
> >
> > find -name *.ext | xargs -0 rm
> >
> > I get the result:
> >
> > rm: cannot remove `Long File Name One.ext
Long File Name Two.ext
Long
> > File Name Three.ext
': File name too long.
> >
> > (The actual list is much longer than this, of course, or I wouldn't be
> > using xargs.) For some reason, the
isn't being recognized as a
> > separator but rather as a part of a single long file name. Don't think
> > $IFS would affect a command like rm but it doesn't appear to be the
> > issue:
> >
> > ddjones@merlin ~ $ set | grep IFS
> > IFS=$'
'
> >
> > I don't see any other ser variable which looks like a likely candidate to
> > cause the behavior. Anyone have a clue what's going on?
>
> Why do you have -0 -- this replaces the
's with a null character -- is
> that what you want?

Not exactly. It doesn't replace anything. It tells xargs to look for a null
to separate fields and to ignore the normal field separation characters. This
is required if you have spaces in the field name, otherwise xargs sees the
spaces as a field separator.

xargs was doing exactly what I told it to do. Unfortunately, I didn't read
the man pages and was relying on some poorly written web pages which indicated
that -0 told xargs to skip spaces but didn't mention that it also told it to
ignore
.

The solution, as Patrick Holthaus pointed out, was to use the -print0 argument
with find, which instructs find to use the null character as a field separator in
its output.

--
"The road of excess leads to the palace of wisdom." - William Blake
 
Old 05-22-2010, 06:38 PM
Jan Engelhardt
 
Default xargs and rm funkiness

On Saturday 2010-05-22 09:46, Neil Bothwick wrote:

>On Fri, 21 May 2010 21:49:49 -0400, Daniel D Jones wrote:
>
>> find -name *.ext | xargs -0 rm
>>
>> I get the result:
>>
>> rm: cannot remove `Long File Name One.ext
Long File Name Two.ext
Long
>> File Name Three.ext
': File name too long.
>
>xargs can suck with anything but plain ASCII-without-spaces filenames.,

That's why you use NUL terminators. Simple as that.

Also find's -exe calls rm *for each* file when used with ;.

>find -name *.ext -exe rm "{}" ;
>
>or maybe even
>
>find -name *.ext -exe rm "{}" +
 
Old 05-23-2010, 05:51 PM
Daniel D Jones
 
Default xargs and rm funkiness

On Saturday 22 May 2010 08:25:55 Neil Bothwick wrote:
> On Sat, 22 May 2010 12:35:10 +0100, David W Noon wrote:
> > >find -name *.ext -exe rm "{}" +
> >
> > Or simpler still:
> >
> > find -name *.ext -delete
>
> Neat - I hadn't noticed that option.
>
> Anyone for find / -delete ?

If you use the -delete switch, just be careful. From the man page:

<QUOTE>
Warnings: Don't forget that the find command line is evaluated as an
expression, so putting -delete first will make find try to delete
everything below the starting points you specified.
</QUOTE>

That means that the command

find -name *.tmp -delete

will delete all your temp files while

find -delete -name *.tmp

will delete everything below your current directory. If you're in the root
directory, it's equivalent to running your suggested command above. I just
found this out the hard way, although luckily I wasn't in the root directory
when I ran the command and so didn't trash my system. I did lose the changes
I'd made to the project I was working on but fortunately had a backup of the
original files.

--
"If you give me six lines written by the most honest man, I will find something
in them to hang him." - Cardinal Richelieu
 
Old 05-26-2010, 10:41 AM
 
Default xargs and rm funkiness

Neil Bothwick <neil@digimed.co.uk> wrote:

> xargs can suck with anything but plain ASCII-without-spaces filenames.,
> and it quite unnecessary here.
>
> find -name *.ext -exe rm "{}" ;
>
> or maybe even
>
> find -name *.ext -exe rm "{}" +

Just avoid xargs as it is the source of the proplem.

find -name *.ext -exec some-command "{}" +

Is the preferred method since 1990.

Jörg

--
EMail:joerg@schily.isdn.cs.tu-berlin.de (home) Jörg Schilling D-13353 Berlin
js@cs.tu-berlin.de (uni)
joerg.schilling@fokus.fraunhofer.de (work) Blog: http://schily.blogspot.com/
URL: http://cdrecord.berlios.de/private/ ftp://ftp.berlios.de/pub/schily
 

Thread Tools




All times are GMT. The time now is 01:03 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org