Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»How to Copy a File to Multiple Directories in Linux

    How to Copy a File to Multiple Directories in Linux

    By RahulDecember 21, 20221 Min Read

    To copy a file to multiple directories in Linux, you can use the `cp` command with the `xargs` command. Here all the destination directories will be piped as standard input to the `xargs` command. and specify a list of directories separated by space. For example:

    Advertisement
    echo dir1 dir2 dir3 | xargs -n 1 cp -v file.txt 
    

    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:

    for dir in dir1 dir2 dir3; do
        cp file.txt $dir
    done
    

    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:

    find dir1 dir2 dir3 -type d -exec cp file.txt {} \; 
    

    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.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9

    How to Install MySQL 8.0 on RHEL & CentOS Stream 9

    How to Split Large Archives in Linux using the Command Line

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • What is the /etc/mtab File in Linux
    • The “Hello World” Challenge: Printing in 20 Different Programming Languages
    • How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9
    • How to Install MySQL 8.0 on RHEL & CentOS Stream 9
    • How to Split Large Archives in Linux using the Command Line
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.