
- Kali Linux Tutorial
- Kali Linux - Home
- Installation & Configuration
- Information Gathering Tools
- Vulnerability Analyses Tools
- Kali Linux - Wireless Attacks
- Website Penetration Testing
- Kali Linux - Exploitation Tools
- Kali Linux - Forensics Tools
- Kali Linux - Social Engineering
- Kali Linux - Stressing Tools
- Kali Linux - Sniffing & Spoofing
- Kali Linux - Password Cracking Tools
- Kali Linux - Maintaining Access
- Kali Linux - Reverse Engineering
- Kali Linux - Reporting Tools
- Kali Linux Useful Resources
- Kali Linux - Quick Guide
- Kali Linux - Useful Resources
- Kali Linux - Discussion
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 Articles
- 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 Protect Files and Directories from Deleting in Linux
- How to Search and Remove Directories Recursively on Linux?
- How to Append Contents of Multiple Files Into One File on Linux?
- How to copy multiple files in PowerShell using Copy-Item?
- Compare two directories in Linux?
- How to Find a Specific String or Word in Files and Directories in Linux
- How to create Directories using the File utility methods in Java?
- How to sort a file in-place in Linux?
- How to Save Command Output to a File in Linux?
- How to Run a Command Multiple Times in Linux?
- How to compare the files available in two directories using diff command in Linux?
- Append Lines to a File in Linux
