Solved

Creating a bunch of symbolic links at once

Posted on 2004-10-20
13
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
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
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

691 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