Professional Documents
Culture Documents
How To Copy A File To Multiple Directories in Linux
How To Copy A File To Multiple Directories in Linux
How To Copy A File To Multiple Directories in Linux
com/)
Monitoring/)
Installations (Https://Net2.Com/Category/Installations/)
Troubleshooting (Https://Net2.Com/Category/Troubleshooting/)
SEARCH
How to copy a file to
Search
multiple directories in
Linux RECENT POSTS
As mentioned above, the cp command cannot be used to copy one file cpufreq/) December 30,
2019
to multiple folders. The solution would be to use the xargs or GNU
parallel commands. How to run Windows
applications on Linux
Using xargs (https://net2.com/how-to-
run-windows-applications-
To copy for instance file_1 into the folders directory_1, directory_2, we on-linux/) December 27,
could proceed as follows: 2019
next directory path fed to it from the previous echo command to the error-in-ubuntu/)
How to Google search
end of the standard cp command.
from Linux terminal –
So instead of executing two separate cp commands, we can now use
Build your own search
one single command to perform the same task. If the file to be copied
engine
exists already in one of the destination folders, the old file will be
(https://net2.com/how-to-
replaced without prompting the user. In other words, the -i option
google-search-from-linux-
(interactive) of the cp command cannot be used in conjunction with terminal-build-your-own-
xargs. search-engine/)
If the file to be copied has a large size and you do not want the How to fix high memory
destination file (if it exists) to be replaced, you might want to add the -n usage in Linux
switch to the cp command in the single line above. This will prevent (https://net2.com/how-to-
Read: Linux directories explained (https://net2.com/linux-
directories-explained/)
xfAnother solution would be to use a for loop within a one line shell as //www
follows :
.faceb
for dir in *; do [ -d “$dir” ] && cp
/full_path/file.txt “$dir” ; done
(https: ook.co
This will copy the file /full_path/file.txt to all directories in your current
path or location. //twitt m/ami
This however will copy the folder /full_path/folder to every sub-folder /Amin y.net2
or sub-directory in your current location.
_net2) /)
Read: How to find the largest files on Linux
(https://net2.com/how-to-find-the-largest-files-on-linux/)
GNU parallel is a shell utility used for executing tasks or jobs in parallel
//www
over one or multiple machines. The basic syntax is as follows:
Using tee
2/)
The tee command allows you to copy one file to multiple destinations.
Here is an example on how to perform this: STAY INFORMED BY
JOINING OUR
NEWSLETTER!
tee ~/directory1/file1 ~/directory2/file1 < ~/file1
Note that the input that is written by tee will be forwarded to the
Email
standard output (stdout). If you don’t like this behavior, you have the
possibility to prevent it by rerouting standard output to /dev/null as SUBSC R I B E
shown below:
Conclusion
As you have seen, there are many ways to copy a file to multiple
directories. Most of these solutions make use of the cp command
which cannot perform this feat on its own.
4 Leave a Reply
2 2 0 3
Subscribe newest oldest most voted
Deryk Barker
0 Reply
1 day ago | View Replies (1)
Major
cp -r
Guest
Directories won’t be copied without the recursive
option
0 Reply
1 day ago | View Replies (1)
Join net2@Reddit
(https://reddit.com/r/net
2)
Copyright net2.com all rights reserved 2019 contact
about convert pdf to
| word policy/)
us (https://net2.com/contact-us/)
(https://net2.com/about/) for| free
(https://net2.com/convert-pdf-to-word/) |
privacy policy (https://net2.com/privacy-