

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Copy a File to Multiple Directories in Linux?
Did you get to take one file on a Linux or Unix approach and replicate it to a whole bunch of alternative directories? Then, this article is for you to copy a file to multiple directories in Linux/Ubuntu.
Using with cp
and xargs
To copy a file to multiple directories in Linux/Ubuntu, use the following in command –
$ echo dir1 dir2 dir3 | xargs -n 1 cp file1
In the above command, we are copying file1 to dir1,dir2, and dir3 directories.The sample example of the above command is as shown below −
$ echo Music Videos Desktop | xargs -n 1 cp httpstat.py
In the above command, we are copying httpstat.py file to Music, Videos, and Desktop directories. To verify the above command, use the following command –
$ cd Music ~/Music$ ls
The sample output should be like this –
httpstat.py
Another sample to verify the above command is as shown below –
$ cd Desktop ~/Desktop$ ls
The sample output should be like this –
httpstat.py
Using with cp
and find
To copy a file to multiple directories in Linux/Ubuntu, use the following in command –
find dir1 dir2 dir3 -type d -exec cp file1 {} \;
The above command finds dir1,dir2, and dir3 directories and copy file1 to those directories.The sample example is as shown below –
$ find Music Desktop -type d -exec cp httpstat.py {} \;
In the above command, we are copying httpstat.py file to Music and Desktop directories. To verify the above command, use the following command –
$ cd Desktop ~/Desktop$ ls
The sample output should be like this –
httpstat.py
Another sample to verify the above command is as shown below –
$ cd Music ~/Music$ ls
The sample output should be like this –
httpstat.py
In the above article, we have learnt – How to Copy a File to multiple directories in Linux. In our next articles, we will come up with more Linux based tricks and tips. Keep reading!
- Related Questions & Answers
- How to move a file, group of files, and directories in Linux?
- How to Copy File Permissions and Ownership to Another File in Linux?
- How to copy a file, group of files, or directory in Linux?
- How to Search and Remove Directories Recursively on Linux?
- How to Protect Files and Directories from Deleting in Linux
- How to copy multiple files in PowerShell using Copy-Item?
- How to Find a Specific String or Word in Files and Directories in Linux
- How to sort a file in-place in Linux?
- How to Save Command Output to a File in Linux?
- How to create Directories using the File utility methods in Java?
- How to Create Multiple User Accounts in Linux?
- How to Create a New Ext4 File System in Linux?
- How to Create a New File in Linux from Bash?
- How to compare the files available in two directories using diff command in Linux?
- How do I copy a file in python?