将文件复制到多个目录 - Unix

Copy file into multiple directories - Unix

我想将一个文件复制到多个目录中。我的路径结构如上。

folder1-> anotherfolder -> **here I want to copy my file**
folder2-> anotherfolder -> **here I want to copy my file**
folder3-> anotherfolder -> **here I want to copy my file**
folder4-> anotherfolder -> **here I want to copy my file**

folder1,2,3,4 在同一个目录下。但是名称是文件夹不是顺序的。

我可以使用此代码获取文件夹的名称,但之后我不知道如何进入文件夹并复制我的文件。

    for d in */ ; do
     echo "$d"
    done

此代码为我提供了目录中的文件夹名称。完成此步骤后,如何进入文件夹并复制我的文件?

你似乎想做这样的事情:

for d in */; do
    cp file "$d"/anotherfolder
done

第一次尝试(有限制)

for d in $(find . -maxdepth 2 -type d | grep "/.*/"); do
    cp file "$d"
done

LIMITATIONS:

  • No spaces/slashes/glob characters in the dir-names

第二次尝试(更干净,感谢gniourf_gniourf)

find . -maxdepth 2 -path './*/*' -type d -exec cp file {} \;