LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 11-10-2004, 09:48 AM   #1
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Rep: Reputation: 32
Copy one file to multiple directories


I have a mp3 directory tree,
Code:
/mp3/Artist1
/mp3/Artisit2
...
/mp3/ArtistN
I am making it web browseable with the hellp of some PHP scripting. I need to copy a index.php file from /mp3/Artist1 to the subdirectory for every other artist (some 450+).

I know this has to be pretty easy to do. I just haven't been able to crack the nut.

Any thoughts?
 
Old 11-10-2004, 10:04 AM   #2
meblost
Member
 
Registered: May 2004
Location: At Keyboard
Distribution: Mandrake 10.0, SuSE 9.0
Posts: 114

Rep: Reputation: 15
Maybe you could place a symbolic link in each subdir that points to index.php.

try ln -s /path/to/index.php /path/to/desired_link. I have used this several times successfully with image galleries. This way when you want to change index.php, you don't have to recopy the file to each sub dir.

To be more clear, if index.php is in /mp3 try,

$ cd /mp3
$ for foo in $(ls);do ln -s /mp3/index.php /mp3/$foo;done

If their are other subdirs in /mp3 that you do not want to place a link in, you will have to replace for foo in $(ls) with something else that prints only the files you want. The command listed above will place a link to /mp3/index.php in each subdir of /mp3.

Last edited by meblost; 11-10-2004 at 10:26 AM.
 
Old 11-10-2004, 10:10 AM   #3
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Original Poster
Rep: Reputation: 32
I didn't think about using a symlink. That could work. Don't I have the same problem though? I have to create a symlink for each of the 450+ directories. I'm trying to automate that process via a piped command or small bash script.
 
Old 11-10-2004, 10:26 AM   #4
meblost
Member
 
Registered: May 2004
Location: At Keyboard
Distribution: Mandrake 10.0, SuSE 9.0
Posts: 114

Rep: Reputation: 15
Oops, you are too quick for me. Read my edited post above...
 
Old 11-10-2004, 10:38 AM   #5
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
You could try the following:-
Code:
for i in $(ls /mp3); do if [ -d $i ]; then ln -s /path/to/file/index.php $i/index.php; fi; done
 
Old 11-10-2004, 10:40 AM   #6
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
Oops, too quick for me too...
 
Old 11-10-2004, 11:06 AM   #7
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Original Poster
Rep: Reputation: 32
Well. It's a good start. Some of the artist/subdir names have spaces in them. The script chocks on them.

I know I have to escape the spaces somehow.
 
Old 11-10-2004, 11:49 AM   #8
LasseW
Member
 
Registered: Oct 2004
Distribution: Fedora 7, OpenSuse 10.2
Posts: 108

Rep: Reputation: 15
Try putting quotes round the loop variable, ie "$i"
 
Old 11-10-2004, 11:51 AM   #9
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
This is a bit of a cludge, but it should work.
Code:
for i in $(ls /mp3 | tr " " "_"); do j=$(echo $i | tr "_" " "); if [ -d "$j" ]; then ln -s /path/to/index.php  "$j"/index.php; fi; done
 
Old 11-10-2004, 12:57 PM   #10
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Original Poster
Rep: Reputation: 32
Ahh...
That did it.

Cheers mate.

Thanks all.
 
  


Reply


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy files from multiple directories into one directory MadRabbit Linux - Newbie 8 02-07-2014 07:56 PM
Searching multiple directories and sub directories for a file jeep99899 Linux - Newbie 2 10-13-2005 12:23 PM
Copying a single file to multiple directories tgolly Linux - Newbie 3 04-26-2004 03:47 PM
find and copy files into multiple directories avargas22 Linux - Newbie 2 04-01-2004 11:11 AM
How to copy one file in all users directories aizkorri Programming 1 09-02-2002 07:32 AM


All times are GMT -5. The time now is 07:33 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration