Linux equivalent to QNX's ws (walk directory structure) command?

D. Hugh Redelmeier hugh-pmF8o41NoarQT0dZR+AlfA at public.gmane.org
Thu Jan 5 22:47:47 UTC 2006


| From: G. Matthew Rice <matt-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org>

|        find <somedir or 2> -type d (maybe -depth) 
| 
| and then pipe that to xargs(1) or use the -exec option with find.  I usually
| prefer xargs(1).  Especially if there are a lot of matches.

xargs is very useful.  Too bad there isn't an xargs built into find.
It would have the advantage of being more concise and it would avoid
the following problem.

xargs has a weakness: in-band signalling.  The characters used to
separate file names in the output are perfectly legal within
filenames.  xargs actually makes this worse because it allows more
characters to separate filenames than find actually uses.

Where does this come up?  For example, when filenames have whitespace
in them.  Historically, this has been rare in UNIX filenames because
it makes dealing with them in the shell a bit awkward.  But MS Windows
users often put spaces in because space is just an ordinary character
in a GUI.  So files originating on MS Windows make this problem more
common in UNIX.  I got two such files today in (non SPAM) email.

To compensate, Gnu versions of find(1) and xargs(1) have -print0 and
--null flags.  -print0 tells find(1) to terminate each filename with
a NUL character (not legal in a file name) instead of a NewLine
(which is legal).  --null tells xargs to take each character in a
filename as-is and to accept NUL as the end of a name.  It is a good
idea to use these features.

I also think that xargs' --no-run-if-empty flag ought to be the
default.  I bet that a number of scripts have bugs because they don't
use this.
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list