mv a file without breaking a symlink to that file












21















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:




  1. get the target of the link

  2. mv the target

  3. recreate the link to the new target

  4. 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:




  1. 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.










share|improve this question




















  • 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
















21















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:




  1. get the target of the link

  2. mv the target

  3. recreate the link to the new target

  4. 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:




  1. 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.










share|improve this question




















  • 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














21












21








21


4






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:




  1. get the target of the link

  2. mv the target

  3. recreate the link to the new target

  4. 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:




  1. 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.










share|improve this question
















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:




  1. get the target of the link

  2. mv the target

  3. recreate the link to the new target

  4. 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:




  1. 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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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










3 Answers
3






active

oldest

votes


















7














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.






share|improve this answer



















  • 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 requires ln -s -f.. (I've made the adjustment)

    – Peter.O
    Aug 23 '11 at 17:12





















4














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





share|improve this answer


























  • Note: it will be more complicated if a chain of links is involved.

    – Peter.O
    Aug 23 '11 at 18:09





















0














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:



extensions svg inside symbolic links that I want to change to png



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





share








New contributor




Indacochea Wachín is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    7














    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.






    share|improve this answer



















    • 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 requires ln -s -f.. (I've made the adjustment)

      – Peter.O
      Aug 23 '11 at 17:12


















    7














    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.






    share|improve this answer



















    • 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 requires ln -s -f.. (I've made the adjustment)

      – Peter.O
      Aug 23 '11 at 17:12
















    7












    7








    7







    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.






    share|improve this answer













    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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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 requires ln -s -f.. (I've made the adjustment)

      – Peter.O
      Aug 23 '11 at 17:12
















    • 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 requires ln -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















    4














    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





    share|improve this answer


























    • Note: it will be more complicated if a chain of links is involved.

      – Peter.O
      Aug 23 '11 at 18:09


















    4














    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





    share|improve this answer


























    • Note: it will be more complicated if a chain of links is involved.

      – Peter.O
      Aug 23 '11 at 18:09
















    4












    4








    4







    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





    share|improve this answer















    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






    share|improve this answer














    share|improve this answer



    share|improve this answer








    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





















    • 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













    0














    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:



    extensions svg inside symbolic links that I want to change to png



    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





    share








    New contributor




    Indacochea Wachín is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.

























      0














      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:



      extensions svg inside symbolic links that I want to change to png



      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





      share








      New contributor




      Indacochea Wachín is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.























        0












        0








        0







        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:



        extensions svg inside symbolic links that I want to change to png



        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





        share








        New contributor




        Indacochea Wachín is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.










        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:



        extensions svg inside symbolic links that I want to change to png



        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






        share








        New contributor




        Indacochea Wachín is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.








        share


        share






        New contributor




        Indacochea Wachín is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered 2 mins ago









        Indacochea WachínIndacochea Wachín

        1012




        1012




        New contributor




        Indacochea Wachín is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        Indacochea Wachín is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        Indacochea Wachín is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Loup dans la culture

            How to solve the problem of ntp “Unable to contact time server” from KDE?

            ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux