如何将index.php复制到每个子文件夹的所有子文件夹和所有子目录中?

时间:2015-09-04 04:20:56

标签: linux macos

我有以下Mac命令可以将index.php复制到/Library/WebServer/Documents内的所有子目录中:

for i in /Library/WebServer/Documents/*
do
    if [ -d "$i" ] # if it's a directory
    then
        sudo cp /Library/WebServer/Documents/index.php "$i" 
    fi
done

如何复制index.php子文件夹的所有子文件夹(and their subfolders too)内的/Library/WebServer/Documents

例如,

/Library/WebServer/Documents/folder1/folder2/Library/WebServer/Documents/folder1/folder2/folder3/,...

1 个答案:

答案 0 :(得分:1)

find /Library/WebServer/Documents/ -type d -exec cp /Library/WebServer/Documents/index.php {} \;

应该成功。您可能会收到有关/Library/WebServer/Documents/index.php与自身相同的警告。忽略它,只是find尝试将/Library/WebServer/Documents/index.php复制到/Library/WebServer/Documents/index.phpcp发现它们是同一个文件。