1 |
On Friday 21 May 2010 22:11:49 covici@××××××××××.com wrote: |
2 |
> Daniel D Jones <ddjones@××××××××××××.org> wrote: |
3 |
> > Running the command: |
4 |
> > |
5 |
> > find -name *.ext | xargs -0 rm |
6 |
> > |
7 |
> > I get the result: |
8 |
> > |
9 |
> > rm: cannot remove `Long File Name One.ext\nLong File Name Two.ext\nLong |
10 |
> > File Name Three.ext\n': File name too long. |
11 |
> > |
12 |
> > (The actual list is much longer than this, of course, or I wouldn't be |
13 |
> > using xargs.) For some reason, the \n isn't being recognized as a |
14 |
> > separator but rather as a part of a single long file name. Don't think |
15 |
> > $IFS would affect a command like rm but it doesn't appear to be the |
16 |
> > issue: |
17 |
> > |
18 |
> > ddjones@merlin ~ $ set | grep IFS |
19 |
> > IFS=$' \t\n' |
20 |
> > |
21 |
> > I don't see any other ser variable which looks like a likely candidate to |
22 |
> > cause the behavior. Anyone have a clue what's going on? |
23 |
> |
24 |
> Why do you have -0 -- this replaces the \n's with a null character -- is |
25 |
> that what you want? |
26 |
|
27 |
Not exactly. It doesn't replace anything. It tells xargs to look for a null |
28 |
to separate fields and to ignore the normal field separation characters. This |
29 |
is required if you have spaces in the field name, otherwise xargs sees the |
30 |
spaces as a field separator. |
31 |
|
32 |
xargs was doing exactly what I told it to do. Unfortunately, I didn't read |
33 |
the man pages and was relying on some poorly written web pages which indicated |
34 |
that -0 told xargs to skip spaces but didn't mention that it also told it to |
35 |
ignore \n. |
36 |
|
37 |
The solution, as Patrick Holthaus pointed out, was to use the -print0 argument |
38 |
with find, which instructs find to use the null character as a field separator in |
39 |
its output. |
40 |
|
41 |
-- |
42 |
"The road of excess leads to the palace of wisdom." - William Blake |