[sf-lug] how to copy all but dot files

Rick Moen rick at linuxmafia.com
Wed Nov 21 19:48:11 PST 2018


Quoting Alex Kleider (akleider at sonic.net):
> On 2018-11-19 09:04, Michael Paoli wrote:
> 
> >Anyway, I might do something roughly like:
> >$ find . \( -type d ! -name . -prune \)  -o \( ! -name '.*' \) -print0
> > | pax -rw -0d -p p target_directory
> 
> I'm not versed enough in bash and shell scripting to follow what's
> going on above.

Well, you are -- but you just need to deconstruct it piece by piece.
Doing so amounts to unwinding how Michael (probably) built it.

The first line (as quoted above) is a slightly opaque 'find' command
with an 'or' clause in the what-to-find specifier.  That's the '-o'
widget between two distinct 'find thing A' and 'find thing B' specs.

The 'find' command includes on either side of the 'or' operator various
other switches that you can look up and understand pretty easily if you
delve into the (horribly long) man page for 'find', e.g., '-type d'
means limit what is found in this expression to directory-type files as
opposed to regular-type files.  '!' means 'not' (inverting the specifier
that follows).  And so on.

All of those '\' characters are just for escaping purposes, to make sure
they're passed along to where they're intended to be processed.  So, 
to figure out what Michael is doing, you would ponder, and also test on
a real shell, first the 'find thing A' statement, then the 'find thing
B' one.  Then last, after guesstimating what Michael is trying to find
and why, you would consider what is being done on the _second_ line with
that generated (found) list of filenames.

The 'find thing A' statement:
  find . \( -type d ! -name . -prune \) -print0

The 'find thing B' statement:
  find . \( ! -name '.*' \) -print0

The full list of filenames generated by both haves of this pair then
gets fed via pipe to:
  pax -rw -0d -p p target_directory

pax is a relatively new-ish archive-management utility.  Looking at the
man page will clarify what Michael's doing with it.





More information about the sf-lug mailing list