Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Symbolic Link

Status
Not open for further replies.

ranjank

IS-IT--Management
May 9, 2003
176
IN
Hi,

I have some 100 files in abc directory.And i want to create sybolic link for these files from xyz directory.Can anyone tell me a scriptwhich can do this.

Regards,
RK.
 
man ln (the -s option)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
And I bet you a dollar that if you read the man page on your shell it will give an example of a for loop iterating over a list of files and performing an action on each one.
 
Also, try
Code:
cp -s abc/* xyz
.

That will "copy" the files, but instead of making real copies, make symbolic links to the originals.

That may be an extension specific to GNU [tt]cp[/tt], by the way.
 
Hi,

Thanks for the reply.Actually i want to create symbolic link in different path and not in the same directory.

Rgds,
RK
 
Basically i'm getting input-output error.
here wht i'm doing...

foreach i ( `ls` )
foreach? ln -s $i /net/abc/blah/xyz
foreach?end

My shell is tcsh.
 
ranjank said:
Actually i want to create symbolic link in different path and not in the same directory.

And how are [tt]ln -s[/tt] and [tt]cp -s[/tt] insufficient for that task?

Both methods described do exactly what you're asking for.
 
The directory which i want to create is nfs mounted....
 
ranjank said:
foreach i ( `ls` )
foreach? ln -s $i /net/abc/blah/xyz
foreach?end

[tt]ls[/tt] only lists filenames, not complete paths.

Therefore, when you say
Code:
ln -s $i /net/abc/blah/xyz
you're creating a link to a filename only, so the current directory is assumed to be the path.

Since by default, the link gets named after what you tell it to point to, you end up with a symbolic link that points to itself. That would probably account for any input-output errors you get.


You need to give the path of the file as the second argument, not just its name.
 
By the way, you don't need a foreach loop to do that.

Just go into the destination directory and use [tt]ln -s[/tt].
Pass the source pathnames (which you could get with a shell glob) as the first arguments, then [tt].[/tt] (a dot, representing the current (destination) directory) as the last argument.
 
I'm bit confused.can u tell me with example

-rgds
RK
 
I thought I just did.


chipperMDW said:
Just go into the destination directory...
Code:
cd /destination/directory


chipperMDW said:
...and use ln -s.
Code:
ln -s ...

chipperMDW said:
Pass the source pathnames (which you could get with a shell glob) as the first arguments...
Code:
ln -s /source/files/* ...

chipperMDW said:
...then . (a dot, representing the current (destination) directory) as the last argument.
Code:
ln -s /source/files/* .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top