Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy one file into every subdirectory

I'm trying to cp one file: index.php into all subdirectories, and subdirectories of those subdirectories, and so on, so that every child directory of the root has index.php

I started with this:

for d in */; do cp index.php "$d"; done; 

Which only worked for the top subdirectories. I tried to nest it in itself a few times like this:

for d in */; do cp index.php "$d"; for e in */; do cp index.php "$e";for f in */; do cp index.php "$f"; done; done; done

But that didn't seem to do anything

like image 256
Chris Avatar asked Dec 26 '22 07:12

Chris


1 Answers

Try this :

find . -type d -exec cp index.php {} \;

Note

  • -type d find all dirs and sub-dirs
like image 192
Gilles Quenot Avatar answered Jan 03 '23 10:01

Gilles Quenot