Search code examples
fileubuntupathshortcut

Ubuntu - how to create relative file path shortcuts


I have a problem with file shortcuts on Ubuntu (in particular, on the 16.04 release).

I have folder containing my project (let's call it MyProject), and that folder has a subfolder inside, called html (generated with Doxygen, if that matters), that contains a very large amount of files. One of them, "index.html", is the only thing I have to manually open as all the other ones are mostly elements used by it. What I have done is thus to create a file shortcut and cut-paste it into the parent folder (i.e. MyProject folder), so that I can avoid browsing through all those files every time (or having to search for it through the file explorer).

My problem is that I need my project to be independent from my machine, since I am working at it with other people. If one of them downloads the MyProject folder, everything works fine apart from the index.html file shortcut, because after double-clicking it, it tries to locate the file by looking for the same file path as the one on my computer, which is of course different. Is there a smart way to solve this issue? I would prefer to avoid scripts if possible, since I assume there is actually a way to make a "more flexible" file shortcut.


Solution

  • You can specify the path of the symbolic link as relative, as explained in this question. I've tried it in my machine (SO: Linux Mint Sylvia) and works just fine.

    Example:

    1. I have two folders /Projects/ProjectA and /Projects/ProjectB, both of which contain a relative html/index.html (generated by Doxygen, as in your case).
    2. I create a relative symlink in ProjectA
    cd /Projects/ProjectA
    ln -s ./html/index.html my_link # Note the './' in the source path
    
    1. If I use xdg-open my_link my browser opens /Projects/ProjectA/html/index.html correctly.
    2. Then I move that same link to the other directory.
    cd /Projects/ProjectB
    mv /Projects/ProjectA/my_link .
    
    1. And if I run xdg-open my_link it opens /Projects/ProjectB/html/index.html
    2. I've not tested it in different machines, but as the moved link doesn't try to open /Projects/ProjectA/html/index.html I'm pretty shure this should do.

    The link is relative to its own directory, so even if you open it from other location, it will open the same file always (until the link itself is moved or copied).