[CentOS] This "find" command

Wed Dec 28 18:45:06 UTC 2005
Bryan J. Smith <thebs413 at earthlink.net>

Les Mikesell <lesmikesell at gmail.com> wrote:
> However, if you have filenames with embedded spaces, shell
> metacharacters or newlines, you can have problems as xargs
> presents them on a command line to the program.

With various editions of BASH 2.0x, 3.x, etc..., the behavior
of how parameters with newlines versus other whitespace seems
to be very inconsistent.  Furthermore, changing the reserved
IFS variable can lead to some rather interesting and
unpredictable functionality which, again, seems to vary from
BASH version to BASH version.

As much as I prefer the Bourne shell approach, when I know
spaces are going to be reality, I use either Perl or, if it
must be shell, TCSH.  All versions of TCSH I've ever thrown
at spaces seems to handle them properly, assuming that
newline is the delimiter when the parameter list is enclosed
in double quotes.

Although the Advanced Bash Scripting Guide (ABSG) says BASH
acts the same, it is not true at all -- and the way it acts
seems to vary between versions in some cases.

> On GNU based systems you can use the -print0 argument to
find
> and -0 to xargs to make them pass the filenames
null-terminated 
> and quote them correctly on the command line.

Yes, this is about the only way I can use FIND in a BASH
script, to take BASH's variable delimiter handling completely
out of the equation -- such as with xargs.

> One way is to use the -mount argument and make separate
> runs for each filesystem.  That also avoids the problem of
> wandering into isos/dvd's/nfs mounts, etc.

Yep.  Use the "-mount" argument and accomodate
correspondingly.  A lot of people will tell you to use
"-xdev" instead, but "-mount" is more universal across BSD,
SysV, etc... than "-xdev".

> You can also redirect the find output to a file and look at
> or edit the results before feeding it to xargs.

That's another way I deal with BASH's delimiting -- I output
to a temporary file and then do readln's into variables.


-- 
Bryan J. Smith     Professional, Technical Annoyance                      b.j.smith at ieee.org      http://thebs413.blogspot.com
----------------------------------------------------
*** Speed doesn't kill, difference in speed does ***