Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to copy a file to all subfolders in a folder. How can I do this with the command line?

share|improve this question
up vote 7 down vote accepted

How to put a file in the current working directory in all subfolders (and maybe their subfolders, depending on what you want to do)

This will put the file in all of the subfolders, but not their subfolders:

for d in */; do cp water.txt "$d"; done

This will put the file water.txt (change all instances of water.txt to the filename you want to copy) in all the subfolders and their subfolders

for i in ./* # iterate over all files in current dir
    if [ -d "$i" ] # if it's a directory
        cp water.txt "$i" # copy water.txt into it

Info from this linuxquestions thread

share|improve this answer

You could use that one-liner:

find <target-dir> -type d -exec cp <the file> {} \;

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.