Solved

Creating a bunch of symbolic links at once

Posted on 2004-10-20
13
304 Views
Last Modified: 2013-12-16
Hi, I've got a directory each with many files.  I need to create individual symbolic links for each of the files.  I'd rather not do 'ln -s' for every single file.  Is there a one liner I could use to automate this?  I've created a Perl script to do this for me but I'm thinking there must be an easier way.
0
Comment
Question by:nysus1
  • 5
  • 2
  • 2
  • +1
13 Comments
 
LVL 38

Accepted Solution

by:
yuzh earned 500 total points
ID: 12355899
Why not simply create a symbolic link for the dir?

ln -s /path-to/srcdir /path-to/target-dir

if you still want to create ln for each file, have a look at my comment in:
http:Q_21160690.html#12273566
0
 

Author Comment

by:nysus1
ID: 12357212
Because some of the individual symbolic link files will eventually be replaced with real files.

Is this your solution?

for f in `find /home/myusername/project/data  -type f -print`
do
     linkf=`basename $f`
     ln -s $f /dir1/${linkf}
done

I'm pretty weak on shell scripting.
0
 
LVL 13

Expert Comment

by:Caseybea
ID: 12359299
The "for" loop shown above would have been my recommended solution.
0
 
LVL 38

Expert Comment

by:yuzh
ID: 12359413
just remember to replace the source dir and target dir with the real
names!
0
 

Author Comment

by:nysus1
ID: 12359489
OK, thanks.  That a little easier than my Perl script.  Can you recommend any good links for learning shell scripting?  By the way, is it more common to use shell scripts or perl scripts for such kinds of tasks?  Does it really matter?  What do you see out in the field?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 13

Expert Comment

by:Caseybea
ID: 12360110
There are several books published by O'Reiley (available in most good bookstores) that are GREAT for learning various things in *nix land---  Perl, C, and other goodies like sendmail, etc!
0
 

Author Comment

by:nysus1
ID: 12360214
Yeah, I got to pick one up.  Site admin is a weak area of mine.  Thanks.
0
 
LVL 6

Expert Comment

by:de2Zotjes
ID: 12361081
Sorry to intrude but why not do:

ln -s /src/dir/* /target/dir

The last argument in the list you supply to ln can be a directory. This functions exactly the same as the cp command: no matter how many arguments you supply the whole list gets copied (or linked) to the last argument, if that last argument is a directory then the files are created...
0
 

Author Comment

by:nysus1
ID: 12361135
Very neat.  It works.  I need to give you some credit for that answer but I already accepted one.  Sorry.
0
 
LVL 6

Expert Comment

by:de2Zotjes
ID: 12362743
nysus1, you failed to notice a subtle difference between the solution of yush
( ln -s /src/dir /target/dir )

and the solution I provided

( lns -s /src/dir/* /target/dir )

I don't mind the points, who needs them, but give credit to whom credit is due...
0
 

Author Comment

by:nysus1
ID: 12367983
de2Zotjes,

Sorry, I wasn't very clear.  I did give you credit and did notice the difference between the solutions when I said "I need to give you some credit for that answer but I already accepted one."  The answer I accepted was for the link to the other solution. Thanks.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now