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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
03-08-2011, 06:44 PM
|
#1
|
Member
Registered: Nov 2005
Location: Deerfield MA
Distribution: OpenSuSE, Kubuntu
Posts: 293
Rep:
|
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.
|
|
|
03-08-2011, 07:10 PM
|
#2
|
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141
Rep:
|
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...
|
|
|
03-08-2011, 07:22 PM
|
#3
|
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Rep:
|
@pwabrahams: dumb question - must it be a symlink? (i.e. Would a hard link do? Is the link across filesystems?)
|
|
|
03-08-2011, 08:04 PM
|
#4
|
Member
Registered: Nov 2005
Location: Deerfield MA
Distribution: OpenSuSE, Kubuntu
Posts: 293
Original Poster
Rep:
|
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?
|
|
|
All times are GMT -5. The time now is 09:39 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|