Answering a title question:
source_dir=/some/dir target_dir=/some/other/dir file_name=myfile.txt cd $target_dir while read path; do mkdir -p $(dirname $path) cp $source_dir/$path $target_dir/$path done < <(cd $source_dir; find . -name $file_name -type f)
this duplicates all $file_name found in $source_dir in $tagert_dir
As for your second question (why is your code not working), maybe you do not have bash 4+, and therefore globstar is not working? Or maybe it returns something else, which is the relative path to the file (I thought, but I canβt check, since I have bash 3.2)
source share