LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-08-2011, 05:44 PM   #1
pwabrahams
Member
 
Registered: Nov 2005
Location: Deerfield MA
Distribution: OpenSuSE, Kubuntu
Posts: 293

Rep: Reputation: 41
Making a symlink follow its target when the target moves


Suppose I have a symlink S pointing to a file F in a directory A, and I want to move F from A to another directory B. That move, by itself, will invalidate the symlink. What would be the best way to update S, other than explicitly rewriting it? If it would help, I could arrange for A to be a subdirectory of B or B to be a subdirectory of A. I'd prefer to do it within Dolphin, but I'll resort to the shell if necessary.

The old symlink S might be a full pathname rather than a path using ".." for navigation, which makes the problem harder. I want to do a bunch of these in a single action if possible. I expect it could be done using a shell procedure and iterating over the files to be moved, but that doesn't seem very simple.

The directory B has hundreds of entries, so I want to be sure not to lose track of F during the modification.
 
Old 03-08-2011, 06:10 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
You can use find to identify the broken links in A with this:
Code:
find -L /path/to/A -type l -exec ls -ld {} \;
You could also change the exec statement to run a script that creates a link in the new location each time it finds a broken link. I haven't tried writing the script myself - I'm about to go into a meeting here...
 
Old 03-08-2011, 06:22 PM   #3
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
@pwabrahams: dumb question - must it be a symlink? (i.e. Would a hard link do? Is the link across filesystems?)
 
Old 03-08-2011, 07:04 PM   #4
pwabrahams
Member
 
Registered: Nov 2005
Location: Deerfield MA
Distribution: OpenSuSE, Kubuntu
Posts: 293

Original Poster
Rep: Reputation: 41
Broken links, hard links

I'm not so concerned about inadvertent broken links because the only broken links would be those I know about.

Hard links are a possibility I need to think about. Originally the directories were on different filesystems but for reasons unrelated to this question, I've relocated one of them so they now are on the same filesystem. I need to look at the behavior of hard links when I'm doing mv, rm, cp, or even other ln operations, both hard and soft. I've been using soft links so regularly that I never really thought about hard links, though I certainly know about them. Is it possible to create them in Dolphin?
 
  


Reply

Tags
symlink



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find symlink target name in script germanyzulu Linux - Software 4 08-14-2015 10:23 AM
Question How to get stat() of symlink and not of target of symlink ? ronbarak Programming 3 11-08-2010 12:14 PM
Maxtor Onetouch II: symlink points to wrong target Robert S Linux - Hardware 2 12-23-2007 03:26 PM
Copy the target from a symlink? menator Linux - Newbie 1 01-25-2007 07:04 AM
Tip: How to copy a symlink and its target file in a script fotoguy Programming 4 08-05-2006 03:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:30 AM.

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