I set up the following folders with empty text files:
1/a.txt
2/b.txt
I want to copy only txt files to another directory while maintaining their directory structure. So I tried the following commands:
mkdir -p temp/s;
find ./ -name '*txt' -exec cp --parents '{}' ./temp/s \;
Now I see the following files from my current directory:
1/a.txt
2/b.txt
temp/s/1/a.txt
temp/s/2/b.txt
temp/s/temp/s/2/b.txt
I don't understand why the final line temp/s/temp/s/2/b.txt
occurred. Can someone explain to me why that happened and how I can fix my command such that temp
is not nested within another temp
?
This is the final result that I was expecting:
1/a.txt
2/b.txt
temp/s/1/a.txt
temp/s/2/b.txt