Often you may want to copy one file to multiple directories using Bash.
You can use the following syntax to do so:
find $dir1 $dir2 -type d -exec cp teams1.txt {} \;
This particular example will copy the file from the current directory named teams1.txt into the directories specified by the variables named $dir1 and $dir2.
Here is what the various commands do:
- find $dir1 $dir2 -type d: Match only the directories specified by the $dir1 and $dir2 variables.
- -exec cp teams1.txt {}: Copy the teams1.txt file to each matched directory
The following example shows how to use this syntax in practice.
Example: How to Copy a File to Multiple Directories in Bash
Suppose that we have a file named teams1.txt in our current directory that we would like to copy to the following two directories:
- c:/users/bobbi/data1
- c:/users/bobbi/data2
For simplicity, both of these two destination directories are currently empty.
We can use the following syntax to copy the team1.txt file into both of these directories:
dir1="c:/users/bobbi/data1"
dir2="c:/users/bobbi/data2"
find $dir1 $dir2 -type d -exec cp teams1.txt {} \;
The following screenshot shows how to use this syntax in practice:

Notice that when we use the ls command to view the files in both destination directories we can see that the teams1.txt file has been copied into both directories successfully.
Note: In this example we copied a single file into two directories, but you can specify as many directory paths as you’d like if you would like to copy the file into even more directories.
Related Tutorials
The following tutorials explain how to perform other common tasks in Bash:
Bash: How to List All Files in Folder by Date
Bash: How to List All Files in Folder by Size
Bash: How to Delete All Files in Directory
