I have many folders, for instance let's consider two folders(folder1, folder2) and inside each folder there are sub folders of same name(a1,b1).
For example:
folder1
a1
b1
folder2
a1
b1
I just want to copy the content of sub folder(a1) of folder1 to sub folder(a1) of folder2, similarly sub folder(b1) of folder1 to sub folder(b1) of folder2.
I tried the script
cp -a ./folder1/. ./folder2/a1
But it doesnot do the work...
for path in folder1/*/*; do
echo cp -a "$path" "folder2/${path#folder1/}"
done
echo
once you are satisfied with the “suggestions”.--reflink
to cp
.rsync
that you’re looking for, depending on how exactly this replication should work and what the initial state is. (Are the targets initially empty? If not, what should happen to the old content?).
reasonably (i.e., without ..
and .
), you can use e.g. ?(.@([^.]|.?))*
instead of *
(with shopt -s extglob
switched on).