1) in the "A" directory:
find . -type f > a.txt
2) in the "B" directory:
cat a.txt | while read FILENAMES; do touch "$FILENAMES"; done
3) Result: the 2) "creates the files" [i mean only with the same filename, but with 0 Byte size] ok. But if there are subdirs in the "A" directory, then the 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?
Since find
outputs one file per line:
cat a.txt | while read file; do
if [[ "$file" = */* ]]; then
mkdir -p "${file%/*}";
fi;
touch "$file";
done
EDIT:
This would be slightly more efficient if the directories where created in a separate step:
cat a.txt | grep / | sed 's|/[^/]*$||' | sort -u | xargs -d $'\n' mkdir -p
cat a.txt | while read file; do
touch "$file";
done
And, no, touch
cannot create directories on its own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With