LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-17-2006, 10:34 AM   #1
Luvz2Fly
LQ Newbie
 
Registered: Aug 2005
Location: Florida
Distribution: Fedora, CentOS
Posts: 15

Rep: Reputation: 0
Recursive Copy / Create


Greetings all...
I have over 300 directories in one place and I must create 4 symlinks in each dir. Is there a quick way to copy 4 symlinks recursively or do I need to create a script that will traverse the directories, make the symlinks and then move to the next dir? Any ideas on how I should do that?

Thanks so much!
 
Old 11-17-2006, 11:12 AM   #2
ygloo
Member
 
Registered: Aug 2006
Distribution: slack
Posts: 323

Rep: Reputation: 30
post more info...
u want to create the same symlinks in every dir??
 
Old 11-17-2006, 12:12 PM   #3
Luvz2Fly
LQ Newbie
 
Registered: Aug 2005
Location: Florida
Distribution: Fedora, CentOS
Posts: 15

Original Poster
Rep: Reputation: 0
Yep - I need the same exact symlink in every dir:
/dir/1
/dir/2
/dir/3
...
/dir/x

for /dir/1->x I must place 4 exact symlinks - for example:
dir/1/index.html --> links to /dir/master/index.html
dir/2/index.html --> links to /dir/master/index.html
 
Old 11-17-2006, 12:15 PM   #4
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
Code:
#!/bin/bash

create_symlinks()
{
  [ $# -eq 1 ] || return false

  orig_dir="`pwd`"

  cd $1 || return false

  for i in *; do
    [ -d $i ] && create_symlinks $i
  done

  # Run your symlink commands here
  # eg.
  # ln -s /blah/blah/blah some_link1

  cd $orig_dir
}

( [ $# -eq 0 ] && start_dir="." ) || ( ( [ -d $1 ] && start_dir="$1" ) || ( echo "$1 is not a directory" && exit ) )

create_symlinks $start_dir
Edit: Forgot to add. Save it as whatever you want (ex. create_links), then run it w/ sh create_links some_dir where some_dir is your starting dir.

Last edited by 95se; 11-17-2006 at 12:18 PM.
 
Old 11-17-2006, 01:51 PM   #5
Luvz2Fly
LQ Newbie
 
Registered: Aug 2005
Location: Florida
Distribution: Fedora, CentOS
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks for the fast reply ...

I ran the script as instructed and it did make the links in the current directory but did not traverse the other directories:

FROM:
/var/www/vhosts/my-domain.com/httpdocs/Info-A

I ran

./make-sym /var/www/vhosts/my-domain.com/httpdocs/Info-A

It DID make the 4 sym links in Info-A dir but NONE in

Info-A/1
Info-A/2
Info-A/3
...
Info-A/x

Thanks again!
 
Old 11-18-2006, 04:52 PM   #6
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hello.

Try this one-liner:
Code:
export to=`pwd`/index.html;
find dir/ -type d -exec bash -c "cd {}; ln -s $to `basename $to`" \;
Instead of basename it's better to define a variable, which holds base name of your file (i.e. without path).
 
  


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
Create new user and copy the privilages Relja Linux - Security 6 10-10-2006 03:43 AM
Recursive Copy of certain files Whiskerz Linux - Newbie 5 12-18-2005 07:06 PM
Linux live-cd to create HD copy over the LAN ? hq4ever Linux - Software 9 12-10-2005 06:34 AM
Recursive Copy fizgig10 Linux - Newbie 1 07-16-2005 11:58 PM
How to do recursive file copy of directory for specific files? Arodef Linux - Newbie 4 06-29-2004 05:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:20 AM.

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