This will copy the file file.txt to the directories dir1, dir2, and dir3. Alternatively, you can use the for loop to copy the file to multiple directories. For example: This will loop through the list of directories and copy the file to each of them. You can also use the find command to copy the file to multiple directories. For example: This will find all directories named dir1, dir2, and dir3 and copy the file to each of them. Note: Make sure you have the necessary permissions to copy the file to the target directories.


title: “How To Copy A File To Multiple Directories In Linux Tecadmin” ShowToc: true date: “2022-12-24” author: “Thomas Batson”


This tutorial will explain you to how to copy a file to multiple directories in a single command. By default we can copy a file to single destination directory in one command. For example, copy a file tecadmin.txt from home directory to two different directories, uses commands like:

Now, use the following command to copy the same file to both destination directories in a single command. Here we use echo command followed by the the destination directory names. Then pipe the results to the xargs commands, which will take directory names as input and pass it to the cp command.

Next, verify that the source file is copied to both destination directories. Just use ls command to list file at both locations. You will find that the same file is copied to both destinations in single command. While copying file to 2-3 directories, you can do it easily with multiple commands. But think, if you have to copy this to large number of directories at a time. For example, I have a WHM/cPanel server with large number of account and want to place a file to each accounts public_html directory. We can do this in single command as: Hope this tutorial help you understand to copy file to multiple directories in a single command.

How to Copy a File to Multiple Directories in Linux   TecAdmin - 62How to Copy a File to Multiple Directories in Linux   TecAdmin - 87