Solved

Creating a bunch of symbolic links at once

Posted on 2004-10-20
13
308 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Fine Tune your automatic Updates for Ubuntu / Debian
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 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.:

734 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