LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 11-09-2014, 12:40 AM   #1
Alexkeinjas4
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, 08:14 AM   #2
RobertP
Member
 
Registered: Jan 2004
Location: Manitoba, Canada
Distribution: Debian
Posts: 454

Rep: Reputation: 32
Smile

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 a.sh $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/myscript.sh $f/myscript.sh ;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
/home/pogson/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
export PATH=/home/pogson/z:$PATH
echo $PATH
/home/pogson/z:/home/pogson/bin:/usr/local/bin:/usr/bin:/bin:/usr/games

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 08:21 AM.
 
  


Reply



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 10:23 PM
[SOLVED] How to copy a file to all subfolders in a directory using a single command? SirTristan Linux - Newbie 7 07-18-2010 11:19 PM
Copy files from various locations to a single destination folder deostroll Linux - Newbie 5 05-13-2009 06:52 AM
Copying single file to multiple locations Ashiro Linux - Server 4 12-05-2008 05:50 AM
Copy single file to multiple locations - What am I doing wrong decartes Linux - Newbie 7 04-26-2008 04:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:58 PM.

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