Sami
Sami

Reputation: 1491

How to copy index.php into all Subfolders and all Subdirectories of every Subfolder?

I have the below Mac command which can copy index.php into all subdirectories inside the /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

How to copy the index.php inside all subfolders (and their subfolders too) of the subfolders of /Library/WebServer/Documents?

For example,

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

Upvotes: 1

Views: 174

Answers (1)

Renaud Pacalet
Renaud Pacalet

Reputation: 29280

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

should make it. You will probably get a warning about /Library/WebServer/Documents/index.php being identical to itself. Ignore it, it's just that find tried to copy /Library/WebServer/Documents/index.php to /Library/WebServer/Documents/index.php and cp found that they are the same file.

Upvotes: 1

Related Questions