create empty files with same directory structure as reference directory
With GNU coreutils (e.g.. on non-embedded Linux or Cygwin), it's as simple as
cp -a --attributes-only Dir1 Dir2
Or more complicatedly but with a single filesystem pass (for even more portability ~
should be written as $HOME
)
find . \( -type d -exec mkdir -p "~/elsewhere/{}" \; \
-o -type f -exec touch "~/elsewhere/{}" \; \)
The complexity here is that of Boolean logic (which may be of some benefit to learn) and precedence (also good to know) and how find
implements these concepts with an implicit AND between the -type
and subsequent action, and OR making an appearance as -o
.