Ubuntu – How to Copy one file to many subfolders

clipboardcommand linefilesgui

It sounds like a simple question but if it was I wouldn't be asking it. I can obviously do this by opening all the folders in nautilus and pasting each one individually but the computer is the robot not me (I'm talking about 500 files).

So is there a way of doing this more efficently by gui or command line? either is as good as the other.

If it makes you feel better you will be saving a poor "V" key from severe punishment.

Best Answer

If the folders are in the same folder that the file exists, then use:

for dir in *; do [ -d "$dir" ] && cp YOURFILE.EXT "$dir" ; done

In other scenery, if the file is in a different path, use:

for i in folder1 folder2 folder3 folder4; do cp YOURFILE.EXT $i; done

If you don't know what exactly are the names of the folders where to put the file, try:

There is no need to make a script. Simply drop these commands in a terminal and check the results.

Glossary:

YOURFILE.EXT = The name of your file, may contain the full path.
folder1 folder[...] = the name of the folders where to drop the file,
-- folder names may contain the full path.