Solved

Creating a bunch of symbolic links at once

Posted on 2004-10-20
13
306 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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 …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

776 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