Bash - How to loop through sub directories and copy in a file Bash - How to loop through sub directories and copy in a file unix unix

Bash - How to loop through sub directories and copy in a file


for i in dir1, dir2, dir3, .., dirN    do        cp /home/user1068470/fileToCopy.txt $i    done

Alternatively, you can use the following code.

for i in *    do                 # Line breaks are important        if [ -d $i ]   # Spaces are important            then                cp fileToCopy.txt $i        fi    done


Finds all directory under the current directory (.) and copies the file into them:

find . -type d -exec cp fileToCopy.txt '{}' \;