Solved

Creating a bunch of symbolic links at once

Posted on 2004-10-20
13
305 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sendmail STARTTLS error 37 84
Access_log 17 101
Python variable _ manually assigned 9 65
Setting up static IP - Ubuntu server 16.04 12 32
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

867 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

21 Experts available now in Live!

Get 1:1 Help Now