mv a file without breaking a symlink to that file
Is it possible to mv
a file w/out breaking a symbolic link to that file?
My initial response to this is no, and I'm working out a script based solution to change the links immediately following the move, but I was wondering how others have approached this issue. The paths and names of the symlinks are known in advance, so In theory all I need to do is:
- get the target of the link
- mv the target
- recreate the link to the new target
- create a new link to the new target (different than the original link, which I still want to keep for now)
At a later date:
- delete the old link
1-4 will be encapsulated in a bash script, but I'm wondering if anyone has a more elegant approach, or knows of a built-in or command that I'm not aware of.
command-line rename symlink
add a comment |
Is it possible to mv
a file w/out breaking a symbolic link to that file?
My initial response to this is no, and I'm working out a script based solution to change the links immediately following the move, but I was wondering how others have approached this issue. The paths and names of the symlinks are known in advance, so In theory all I need to do is:
- get the target of the link
- mv the target
- recreate the link to the new target
- create a new link to the new target (different than the original link, which I still want to keep for now)
At a later date:
- delete the old link
1-4 will be encapsulated in a bash script, but I'm wondering if anyone has a more elegant approach, or knows of a built-in or command that I'm not aware of.
command-line rename symlink
2
Hard links don't have this problem. They have other drawbacks though. :-)
– Stéphane Gimenez
Aug 23 '11 at 15:30
3
Yeah, can't use hardlinks as the files are across several file systems.
– gabe.
Aug 23 '11 at 16:09
2
Also: can't hardlink to a directory.
– sampablokuper
Apr 23 '18 at 18:01
add a comment |
Is it possible to mv
a file w/out breaking a symbolic link to that file?
My initial response to this is no, and I'm working out a script based solution to change the links immediately following the move, but I was wondering how others have approached this issue. The paths and names of the symlinks are known in advance, so In theory all I need to do is:
- get the target of the link
- mv the target
- recreate the link to the new target
- create a new link to the new target (different than the original link, which I still want to keep for now)
At a later date:
- delete the old link
1-4 will be encapsulated in a bash script, but I'm wondering if anyone has a more elegant approach, or knows of a built-in or command that I'm not aware of.
command-line rename symlink
Is it possible to mv
a file w/out breaking a symbolic link to that file?
My initial response to this is no, and I'm working out a script based solution to change the links immediately following the move, but I was wondering how others have approached this issue. The paths and names of the symlinks are known in advance, so In theory all I need to do is:
- get the target of the link
- mv the target
- recreate the link to the new target
- create a new link to the new target (different than the original link, which I still want to keep for now)
At a later date:
- delete the old link
1-4 will be encapsulated in a bash script, but I'm wondering if anyone has a more elegant approach, or knows of a built-in or command that I'm not aware of.
command-line rename symlink
command-line rename symlink
edited Aug 23 '11 at 16:16
gabe.
asked Aug 23 '11 at 14:33
gabe.gabe.
6,48593554
6,48593554
2
Hard links don't have this problem. They have other drawbacks though. :-)
– Stéphane Gimenez
Aug 23 '11 at 15:30
3
Yeah, can't use hardlinks as the files are across several file systems.
– gabe.
Aug 23 '11 at 16:09
2
Also: can't hardlink to a directory.
– sampablokuper
Apr 23 '18 at 18:01
add a comment |
2
Hard links don't have this problem. They have other drawbacks though. :-)
– Stéphane Gimenez
Aug 23 '11 at 15:30
3
Yeah, can't use hardlinks as the files are across several file systems.
– gabe.
Aug 23 '11 at 16:09
2
Also: can't hardlink to a directory.
– sampablokuper
Apr 23 '18 at 18:01
2
2
Hard links don't have this problem. They have other drawbacks though. :-)
– Stéphane Gimenez
Aug 23 '11 at 15:30
Hard links don't have this problem. They have other drawbacks though. :-)
– Stéphane Gimenez
Aug 23 '11 at 15:30
3
3
Yeah, can't use hardlinks as the files are across several file systems.
– gabe.
Aug 23 '11 at 16:09
Yeah, can't use hardlinks as the files are across several file systems.
– gabe.
Aug 23 '11 at 16:09
2
2
Also: can't hardlink to a directory.
– sampablokuper
Apr 23 '18 at 18:01
Also: can't hardlink to a directory.
– sampablokuper
Apr 23 '18 at 18:01
add a comment |
3 Answers
3
active
oldest
votes
You are on the right track, I don't think there is an easier way than the sequence you describe.
Steps 3 and 4 are a little confusing. If you want to re-target existing links you keeping the same name you can use ln -f
to overwrite existing files. If you want the name of your links to also change to reflect the new target name, your sequence is correct.
1
Heh, yeah, just re-read that part and now I've confused myself as well. I'll tweak it so it makes more sense. Thanks.
– gabe.
Aug 23 '11 at 15:22
I'm a bit confused on the use of ln -f, but I think the script @fred posted may help clarify how it works. The man page wasn't much help, surprisingly.
– gabe.
Aug 23 '11 at 16:17
@gabe. The original version of my answer had the correct-s -f
, but while mofifying it, it "lost" the-s
: wrong! From wikipedia: 'ln' with no options creates a hard link, 'ln -f' forces a hard link ... so thanks for the question, it has really confirmed the syntax for me now.. It certainly made me double-check things... It requiresln -s -f
.. (I've made the adjustment)
– Peter.O
Aug 23 '11 at 17:12
add a comment |
For your situation:
# change target of a symbolic link
# -------------
# ln -s, --symbolic make symbolic links instead of hard links
# ln -f, --force remove existing destination files
#
# Setup: make junk.link to file junk
echo hello > ~/junk
ln -s ~/junk ~/junk.link; cat ~/junk.link
#
# move file and point the link to it.
org="$(readlink ~/junk.link)"
new="$org".moved
mv "$org" "$new"
ln -s -f "$new" "$new".link # '-s' for a soft link
Note: it will be more complicated if a chain of links is involved.
– Peter.O
Aug 23 '11 at 18:09
add a comment |
I have the next problem. I found a icon theme very good called "Suru++"
Suru++ 20 [Officially bug-free and 11 DEs-compatible]
But this icon theme are made in svg all image. Now I want to use it in Fluxbox and generate menu entries but this only is possible with png icon image
I download the master inside that are all icons in svg format, and yes I can convert from command line svg to png all ok generate for each folder size like 16x16, 24x24 px. But in that folders are symbolic links to a svg files:
If there is a way possible to change extension svg to png inside all symbolix links the icon theme would be working fine in Fluxbox menu and File Managers. I made a entrie about this icon theme using in Xubuntu but in spanish
God Bless
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f19267%2fmv-a-file-without-breaking-a-symlink-to-that-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are on the right track, I don't think there is an easier way than the sequence you describe.
Steps 3 and 4 are a little confusing. If you want to re-target existing links you keeping the same name you can use ln -f
to overwrite existing files. If you want the name of your links to also change to reflect the new target name, your sequence is correct.
1
Heh, yeah, just re-read that part and now I've confused myself as well. I'll tweak it so it makes more sense. Thanks.
– gabe.
Aug 23 '11 at 15:22
I'm a bit confused on the use of ln -f, but I think the script @fred posted may help clarify how it works. The man page wasn't much help, surprisingly.
– gabe.
Aug 23 '11 at 16:17
@gabe. The original version of my answer had the correct-s -f
, but while mofifying it, it "lost" the-s
: wrong! From wikipedia: 'ln' with no options creates a hard link, 'ln -f' forces a hard link ... so thanks for the question, it has really confirmed the syntax for me now.. It certainly made me double-check things... It requiresln -s -f
.. (I've made the adjustment)
– Peter.O
Aug 23 '11 at 17:12
add a comment |
You are on the right track, I don't think there is an easier way than the sequence you describe.
Steps 3 and 4 are a little confusing. If you want to re-target existing links you keeping the same name you can use ln -f
to overwrite existing files. If you want the name of your links to also change to reflect the new target name, your sequence is correct.
1
Heh, yeah, just re-read that part and now I've confused myself as well. I'll tweak it so it makes more sense. Thanks.
– gabe.
Aug 23 '11 at 15:22
I'm a bit confused on the use of ln -f, but I think the script @fred posted may help clarify how it works. The man page wasn't much help, surprisingly.
– gabe.
Aug 23 '11 at 16:17
@gabe. The original version of my answer had the correct-s -f
, but while mofifying it, it "lost" the-s
: wrong! From wikipedia: 'ln' with no options creates a hard link, 'ln -f' forces a hard link ... so thanks for the question, it has really confirmed the syntax for me now.. It certainly made me double-check things... It requiresln -s -f
.. (I've made the adjustment)
– Peter.O
Aug 23 '11 at 17:12
add a comment |
You are on the right track, I don't think there is an easier way than the sequence you describe.
Steps 3 and 4 are a little confusing. If you want to re-target existing links you keeping the same name you can use ln -f
to overwrite existing files. If you want the name of your links to also change to reflect the new target name, your sequence is correct.
You are on the right track, I don't think there is an easier way than the sequence you describe.
Steps 3 and 4 are a little confusing. If you want to re-target existing links you keeping the same name you can use ln -f
to overwrite existing files. If you want the name of your links to also change to reflect the new target name, your sequence is correct.
answered Aug 23 '11 at 15:02
CalebCaleb
50.7k9147191
50.7k9147191
1
Heh, yeah, just re-read that part and now I've confused myself as well. I'll tweak it so it makes more sense. Thanks.
– gabe.
Aug 23 '11 at 15:22
I'm a bit confused on the use of ln -f, but I think the script @fred posted may help clarify how it works. The man page wasn't much help, surprisingly.
– gabe.
Aug 23 '11 at 16:17
@gabe. The original version of my answer had the correct-s -f
, but while mofifying it, it "lost" the-s
: wrong! From wikipedia: 'ln' with no options creates a hard link, 'ln -f' forces a hard link ... so thanks for the question, it has really confirmed the syntax for me now.. It certainly made me double-check things... It requiresln -s -f
.. (I've made the adjustment)
– Peter.O
Aug 23 '11 at 17:12
add a comment |
1
Heh, yeah, just re-read that part and now I've confused myself as well. I'll tweak it so it makes more sense. Thanks.
– gabe.
Aug 23 '11 at 15:22
I'm a bit confused on the use of ln -f, but I think the script @fred posted may help clarify how it works. The man page wasn't much help, surprisingly.
– gabe.
Aug 23 '11 at 16:17
@gabe. The original version of my answer had the correct-s -f
, but while mofifying it, it "lost" the-s
: wrong! From wikipedia: 'ln' with no options creates a hard link, 'ln -f' forces a hard link ... so thanks for the question, it has really confirmed the syntax for me now.. It certainly made me double-check things... It requiresln -s -f
.. (I've made the adjustment)
– Peter.O
Aug 23 '11 at 17:12
1
1
Heh, yeah, just re-read that part and now I've confused myself as well. I'll tweak it so it makes more sense. Thanks.
– gabe.
Aug 23 '11 at 15:22
Heh, yeah, just re-read that part and now I've confused myself as well. I'll tweak it so it makes more sense. Thanks.
– gabe.
Aug 23 '11 at 15:22
I'm a bit confused on the use of ln -f, but I think the script @fred posted may help clarify how it works. The man page wasn't much help, surprisingly.
– gabe.
Aug 23 '11 at 16:17
I'm a bit confused on the use of ln -f, but I think the script @fred posted may help clarify how it works. The man page wasn't much help, surprisingly.
– gabe.
Aug 23 '11 at 16:17
@gabe. The original version of my answer had the correct
-s -f
, but while mofifying it, it "lost" the -s
: wrong! From wikipedia: 'ln' with no options creates a hard link, 'ln -f' forces a hard link ... so thanks for the question, it has really confirmed the syntax for me now.. It certainly made me double-check things... It requires ln -s -f
.. (I've made the adjustment)– Peter.O
Aug 23 '11 at 17:12
@gabe. The original version of my answer had the correct
-s -f
, but while mofifying it, it "lost" the -s
: wrong! From wikipedia: 'ln' with no options creates a hard link, 'ln -f' forces a hard link ... so thanks for the question, it has really confirmed the syntax for me now.. It certainly made me double-check things... It requires ln -s -f
.. (I've made the adjustment)– Peter.O
Aug 23 '11 at 17:12
add a comment |
For your situation:
# change target of a symbolic link
# -------------
# ln -s, --symbolic make symbolic links instead of hard links
# ln -f, --force remove existing destination files
#
# Setup: make junk.link to file junk
echo hello > ~/junk
ln -s ~/junk ~/junk.link; cat ~/junk.link
#
# move file and point the link to it.
org="$(readlink ~/junk.link)"
new="$org".moved
mv "$org" "$new"
ln -s -f "$new" "$new".link # '-s' for a soft link
Note: it will be more complicated if a chain of links is involved.
– Peter.O
Aug 23 '11 at 18:09
add a comment |
For your situation:
# change target of a symbolic link
# -------------
# ln -s, --symbolic make symbolic links instead of hard links
# ln -f, --force remove existing destination files
#
# Setup: make junk.link to file junk
echo hello > ~/junk
ln -s ~/junk ~/junk.link; cat ~/junk.link
#
# move file and point the link to it.
org="$(readlink ~/junk.link)"
new="$org".moved
mv "$org" "$new"
ln -s -f "$new" "$new".link # '-s' for a soft link
Note: it will be more complicated if a chain of links is involved.
– Peter.O
Aug 23 '11 at 18:09
add a comment |
For your situation:
# change target of a symbolic link
# -------------
# ln -s, --symbolic make symbolic links instead of hard links
# ln -f, --force remove existing destination files
#
# Setup: make junk.link to file junk
echo hello > ~/junk
ln -s ~/junk ~/junk.link; cat ~/junk.link
#
# move file and point the link to it.
org="$(readlink ~/junk.link)"
new="$org".moved
mv "$org" "$new"
ln -s -f "$new" "$new".link # '-s' for a soft link
For your situation:
# change target of a symbolic link
# -------------
# ln -s, --symbolic make symbolic links instead of hard links
# ln -f, --force remove existing destination files
#
# Setup: make junk.link to file junk
echo hello > ~/junk
ln -s ~/junk ~/junk.link; cat ~/junk.link
#
# move file and point the link to it.
org="$(readlink ~/junk.link)"
new="$org".moved
mv "$org" "$new"
ln -s -f "$new" "$new".link # '-s' for a soft link
edited Aug 23 '11 at 17:06
answered Aug 23 '11 at 14:47
Peter.OPeter.O
18.9k1791144
18.9k1791144
Note: it will be more complicated if a chain of links is involved.
– Peter.O
Aug 23 '11 at 18:09
add a comment |
Note: it will be more complicated if a chain of links is involved.
– Peter.O
Aug 23 '11 at 18:09
Note: it will be more complicated if a chain of links is involved.
– Peter.O
Aug 23 '11 at 18:09
Note: it will be more complicated if a chain of links is involved.
– Peter.O
Aug 23 '11 at 18:09
add a comment |
I have the next problem. I found a icon theme very good called "Suru++"
Suru++ 20 [Officially bug-free and 11 DEs-compatible]
But this icon theme are made in svg all image. Now I want to use it in Fluxbox and generate menu entries but this only is possible with png icon image
I download the master inside that are all icons in svg format, and yes I can convert from command line svg to png all ok generate for each folder size like 16x16, 24x24 px. But in that folders are symbolic links to a svg files:
If there is a way possible to change extension svg to png inside all symbolix links the icon theme would be working fine in Fluxbox menu and File Managers. I made a entrie about this icon theme using in Xubuntu but in spanish
God Bless
New contributor
add a comment |
I have the next problem. I found a icon theme very good called "Suru++"
Suru++ 20 [Officially bug-free and 11 DEs-compatible]
But this icon theme are made in svg all image. Now I want to use it in Fluxbox and generate menu entries but this only is possible with png icon image
I download the master inside that are all icons in svg format, and yes I can convert from command line svg to png all ok generate for each folder size like 16x16, 24x24 px. But in that folders are symbolic links to a svg files:
If there is a way possible to change extension svg to png inside all symbolix links the icon theme would be working fine in Fluxbox menu and File Managers. I made a entrie about this icon theme using in Xubuntu but in spanish
God Bless
New contributor
add a comment |
I have the next problem. I found a icon theme very good called "Suru++"
Suru++ 20 [Officially bug-free and 11 DEs-compatible]
But this icon theme are made in svg all image. Now I want to use it in Fluxbox and generate menu entries but this only is possible with png icon image
I download the master inside that are all icons in svg format, and yes I can convert from command line svg to png all ok generate for each folder size like 16x16, 24x24 px. But in that folders are symbolic links to a svg files:
If there is a way possible to change extension svg to png inside all symbolix links the icon theme would be working fine in Fluxbox menu and File Managers. I made a entrie about this icon theme using in Xubuntu but in spanish
God Bless
New contributor
I have the next problem. I found a icon theme very good called "Suru++"
Suru++ 20 [Officially bug-free and 11 DEs-compatible]
But this icon theme are made in svg all image. Now I want to use it in Fluxbox and generate menu entries but this only is possible with png icon image
I download the master inside that are all icons in svg format, and yes I can convert from command line svg to png all ok generate for each folder size like 16x16, 24x24 px. But in that folders are symbolic links to a svg files:
If there is a way possible to change extension svg to png inside all symbolix links the icon theme would be working fine in Fluxbox menu and File Managers. I made a entrie about this icon theme using in Xubuntu but in spanish
God Bless
New contributor
New contributor
answered 2 mins ago
Indacochea WachínIndacochea Wachín
1012
1012
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f19267%2fmv-a-file-without-breaking-a-symlink-to-that-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Hard links don't have this problem. They have other drawbacks though. :-)
– Stéphane Gimenez
Aug 23 '11 at 15:30
3
Yeah, can't use hardlinks as the files are across several file systems.
– gabe.
Aug 23 '11 at 16:09
2
Also: can't hardlink to a directory.
– sampablokuper
Apr 23 '18 at 18:01