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
05-22-2010, 02:11 AM
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
05-22-2010, 07:46 AM
Neil Bothwick
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.
05-22-2010, 07:49 AM
Patrick Holthaus
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
05-22-2010, 11:35 AM
David W Noon
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)
================================================== ====================
05-22-2010, 12:25 PM
Neil Bothwick
xargs and rm funkiness
On Sat, 22 May 2010 12:35:10 +0100, David W Noon wrote:
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
05-22-2010, 06:38 PM
Jan Engelhardt
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 ;.
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
05-26-2010, 10:41 AM
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.