Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-09-2014, 01:40 AM   #1
LQ Newbie
Registered: Nov 2014
Posts: 1

Rep: Reputation: Disabled
How do you copy a single file or directory into a multiple locations?

Hi, i am a new user to Linux/Unix and the forums. I was wondering what the script would look like to copy a file or directory and have it go into multiple locations such as /tmp /bin /usr /local/ or the home directory? Anything will help
Old 11-09-2014, 09:14 AM   #2
Registered: Jan 2004
Location: Manitoba, Canada
Distribution: Debian
Posts: 454

Rep: Reputation: 32

for f in /bin /usr/bin /home/fred;do echo $f;ls $f|head;done

will loop through the list of directories to do operations on each item of the list referenced by $f. Replace the ls |head part with some copy operation like cp $f

That will do the operations sequentially. If you have a lot of files and file-systems, it may be faster to do the operations in parallel. In that case replace the ;done with &done.

For information read man bash

It is unusual to do copies like this. Usually, there is one copy made and in the other locations there is a link to the first copy, like this:
for f in a b c;do ln -s /usr/bin/ $f/ ;done

Further, for executables, one's PATH variable lists likely locations of executables so an executable or link need be found in only one of several directories. One can add some new directory to one's PATH.
echo $PATH
export PATH=/home/pogson/z:$PATH
echo $PATH

This can be done in one's ~/.bashrc file to set the PATH variable on each login.

Last edited by RobertP; 11-09-2014 at 09:21 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
copy multiple directories into another one directory with single cp command zeusys Linux - Newbie 2 08-17-2011 11:23 PM
[SOLVED] How to copy a file to all subfolders in a directory using a single command? SirTristan Linux - Newbie 7 07-19-2010 12:19 AM
Copy files from various locations to a single destination folder deostroll Linux - Newbie 5 05-13-2009 07:52 AM
Copying single file to multiple locations Ashiro Linux - Server 4 12-05-2008 06:50 AM
Copy single file to multiple locations - What am I doing wrong decartes Linux - Newbie 7 04-26-2008 05:09 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:50 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration