- In the "A" directory:
find . -type f > a.txt
- In the "B" directory:
cat a.txt | while read FILENAMES; do touch "$FILENAMES"; done
Result: Step 2 "creates the files" (I mean only with the same filename, but with 0 Byte size) but if there are subdirs in the "A" directory, then step 2 can't create the files in the subdir, because there are no directories in it.
Question: Is there a way, that "touch" can create directories?
quick shot:
Be aware of special chars (whitespaces, ...) in file-/pathnames and so on ...
I'm on quite a GNU parallel kick lately. Here's a way to do this in one line using that tool:
Note that this is inefficient because it runs a lot of extra unneeded
mkdir -p
for intermediary directories. That should be optimized if you are dealing with really huge directory structures.in the original, "A" directory:
"B" directory:
This works even if A contains the file:
A/My brother's 12" records dir/My brother's 12" records
Having dealt with users creating "creative" filenames I always test script like these on
If it works for that, then chances are good it will not fail.
Thanks to Phil H for giving the basic building blocks.
Before doing:
do:
As already pointed out, be careful about special char in dirnames/filenames, especially slashes (I would hate to have a file named "aaa/ccc", but it is always possible).