LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-07-2009, 01:18 PM   #1
homer_3
Member
 
Registered: May 2008
Posts: 99

Rep: Reputation: 15
Mass relink symlinks?


I have 100+ symlinks that are all linked relatively like
foo -> ../a/b/c. I want to change them all so they are foo -> /path/a/b/c. Is there a simple way to do this?
 
Old 07-07-2009, 02:31 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Are the links all in one place, or scattered around the directory tree?

If you can create a list of the links somehow, it should be pretty simple to write a script to change them. A simple for loop using readlink and ln should do.

Code:
#!/bin/bash

for link in *.link; do

target=$(readlink $link)

ln -sf "/new/path/${target#../}" "$link"

done

exit 0
readlink outputs the current target path of the link. "${target#../}" should strip the first ../ directory section off the old target name, so you can tack on the new one. See parameter substitution for other variable manipulation options.

Last edited by David the H.; 07-07-2009 at 02:33 PM.
 
Old 07-07-2009, 02:52 PM   #3
homer_3
Member
 
Registered: May 2008
Posts: 99

Original Poster
Rep: Reputation: 15
They are all in one directory. Thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
An question about tethereal.【relink】 operand Linux - Newbie 0 12-21-2005 07:10 PM
Symlinks and .. smidgie82 Linux - General 2 12-21-2005 04:13 PM
How to relink a file ForumKid Linux - General 9 11-09-2002 12:52 PM
Symlinks b0b0 Linux - General 2 11-08-2001 08:43 AM
symlinks tstuhr Linux - General 3 10-05-2001 10:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration