Skip to content
Advertisement

How to copy a file to all subdirectories?

How can I paste read-me.jpg file into all sub-directories? Here is a command to create a new file in all subdirectories.

for dir in `find . -type d` ; do echo "mywebsite.com" > $dir/downloadedfrom.txt ; done

But I want to copy jpg file into all subdirectories instead.

Directory List:

2011
2012
2009
2019
2021
2000/2001/..../2010
...
...

already tried with this command but no output

for dir in `find . -type d` ; cp read-me.jpg > $dir ; done

Advertisement

Answer

You tried to redirect cp‘s output into $dir but instead we should specify the destination $dir/read-me.jpg as the second argument of cp

for dir in `find . -type d` ; do cp read-me.jpg $dir/read-me.jpg ; done
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement