Skip to main content
added 32 characters in body
Source Link
terdon
  • 252.2k
  • 69
  • 480
  • 718

Assuming that, as you said in the comments, the names in the text file are unique, that there will only be one subdirectory with that name in the entire directory tree, then you can simply do (in bash):

while read -r dirName; do
    cp -r dir0/*/"$dirName"/ /path/to/newTargetDir
done < listOfDirs.txt
while read -r dirName; do
    cp -r dir0/*/"$dirName"/ /path/to/newTargetDir
done < listOfDirs.txt

Assuming that, as you said in the comments, the names in the text file are unique, that there will only be one subdirectory with that name in the entire directory tree, then you can simply do (in bash):

while read -r dirName; do
    cp -r dir0/*/"$dirName"/ /path/to/newTargetDir
done < listOfDirs.txt

Assuming that, as you said in the comments, the names in the text file are unique, that there will only be one subdirectory with that name in the entire directory tree, then you can simply do (in bash):

while read -r dirName; do
    cp -r dir0/*/"$dirName"/ /path/to/newTargetDir
done < listOfDirs.txt
Source Link
terdon
  • 252.2k
  • 69
  • 480
  • 718

Assuming that, as you said in the comments, the names in the text file are unique, that there will only be one subdirectory with that name in the entire directory tree, then you can simply do (in bash):

while read -r dirName; do
    cp -r dir0/*/"$dirName"/ /path/to/newTargetDir
done < listOfDirs.txt