• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Friday, May 9, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

How to Copy a File to Multiple Directories in Linux

How VPS by How VPS
November 2, 2018
in Linux, Operating System
0
0
SHARES
11
VIEWS
Share on FacebookShare on Twitter

While learning Linux, it is always the norm for newbies to keep on typing several commands to accomplish a simple task. This is understandable especially when one is just getting accustomed to using the terminal.

However, as you look forward to becoming a Linux power user, learning what I would refer to as “shortcut commands” can significantly reduce time wasting tendencies.

In this article, we will explain an easy way, using a single command to copy a file into multiple directories in Linux.

In Linux, the cp command is used to copy files from one directory to another, the easiest syntax for using it is as follows:

# cp [options….] source(s) destination

Alternatively, you can also use the advanced-copy command, which shows a progress bar while copying large files/folders in Linux.

Consider the commands below, normally, you would type two different commands to copy the same file into two separate directories as follows:

# cp -v /home/aaronkilik/bin/sys_info.sh /home/aaronkilik/test
# cp -v /home/aaronkilik/bin/sys_info.sh /home/aaronkilik/tmp
How to Copy a File to Multiple Directories in Linux

Copy Files to Multiple Directories

Assuming that you want to copy a particular file into up to five or more directories, this means you would have to type five or more cp commands?

To do away with this problem, you can employ the echo command, a pipe, xargs command together with the cp command in the form below:

# echo /home/aaronkilik/test/ /home/aaronkilik/tmp | xargs -n 1 cp -v /home/aaronkilik/bin/sys_info.sh

In the form above, the paths to the directories (dir1,dir2,dir3…..dirN) are echoed and piped as input to the xargs command where:

  1. -n 1 – tells xargs to use at most one argument per command line and send to the cp command.
  2. cp – used to copying a file.
  3. -v – enables verbose mode to show details of the copy operation.
How to Copy a File to Multiple Directories in Linux

Copy File to Multiple Locations in Linux

Try to read through the man pages of cp, echo and xargs commands to find useful and advanced usage information:

$ man cp
$ man echo
$ man xargs

That’s all, you can send us questions in relation to the topic or any feedback through the comment form below. You may also want to read about the progress command which helps to monitor the progress of (cp, mv, dd, tar, etc.) commands that are presently running in Linux.

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
Previous Post

How to Convert Files to UTF-8 Encoding in Linux

Next Post

3 Ways to Permanently and Securely Delete ‘Files and Directories’ in Linux

Next Post

3 Ways to Permanently and Securely Delete ‘Files and Directories’ in Linux

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet