Symlink to a URL

14

8

Is there any way to create a symbolic link to a URL?

Update: I need to symlink it to an HTTP URL.

Update: The reason I want to do this is so that I can move this symlink to another computer without having to copy the file itself (it's big), and instead, the other computer will just use the online copy from the URL.

SZH

Posted 2011-04-29T20:22:46.687

Reputation: 243

2URL's have little to do with HTTP (assuming that's what's implied). That's why it's explicitly http:// at the beginning. You need to be more specific. Wouldn't just mounting WebDAV do, using davfs, again assuming you're on Linux? – Daniel Beck – 2011-04-29T20:26:06.733

What do you want to do? Should a browser open if you click it? Or why you need such a link? – binfalse – 2011-04-29T20:27:46.490

1You still haven't told us the protocol this is about. It could as well be file://, indicating a path on the local file system, http://, https://, ftp://, svn://, etc. – Daniel Beck – 2011-04-29T20:34:07.650

2It is an http:// url – SZH – 2011-04-29T20:37:38.470

Consider using WebDAV. Otherwise, most systems allow the storing of URL references, e.g. .url files on Windows or .webloc files on Mac OS X. – Daniel Beck – 2011-04-29T20:44:38.033

Is there a way to have a file on my hard drive automatically kept up-to-date with a version that's on the web? (But not deleted or overwritten with garbage if the online version disappears or changes, of course.) Should that be a different question? – endolith – 2012-04-06T14:28:13.847

@NotMe If you just want to create a cross-platform internet shortcut (using an HTML page that automatically redirects to another page), then see here: http://superuser.com/questions/538089/cross-platform-internet-shortcut-files

– Anderson Green – 2013-01-19T04:12:02.097

Answers

13

It's not possible to create a symlink to an URL. If you can make executables and the target OS is Linux-alike, you can create a file which opens the URL as in:

#!/bin/sh
x-www-browser 'http://example.com/your/link'

Lekensteyn

Posted 2011-04-29T20:22:46.687

Reputation: 5 236

If your default browser is Firefox and your also have Chrome installed, Chrome might open the URL due to a Firefox bug with "alternatives" system in dpkg. https://bugzilla.mozilla.org/show_bug.cgi?id=1218174

– dotnetCarpenter – 2015-10-25T13:33:46.350

10

If you are using a GUI desktop in Linux, like Gnome or Unity, you can drag and drop a URL from Firefox and other browsers either onto the desktop or into a folder in the Nautilus file manager. This will create a .desktop file with several lines in it like this one:

[Desktop Entry]
Encoding=UTF-8
Name=Link to Google Calendar
Type=Link
URL=https://www.google.com/calendar/render?pli=1
Icon=text-html

As long as you are in the GUI, you can just double-click on the file to open it into the default Web browser. I do this in Ubuntu to store links to documents in my private Drupal wiki on my machine.

This may work for KDE, xfce, and other desktop managers, but I haven't tried it.

Tim Ingalls

Posted 2011-04-29T20:22:46.687

Reputation: 101

6

You want an automatic URL link, stored in a file in your file system, to open.

The way to do this is with a minimalist .HTML file. For example, to take you to the Google home page, place the following code in a file named Google.HTML:

<!DOCTYPE HTML>
<html>
  <head>
    <title>Google automatic redirect</title>
    <meta http-equiv="refresh" content="0; url=http://www.google.com/" />
  </head>
  <body>
    <h1>For older browsers, click Redirect</h1>
    <p><a href="http://www.google.com/">Redirect</a></p>
  </body>
</html>

When you open (i.e double click) on this file, the OS will open your default browser (e.g. Firefox) and render this little HTML file, which has a URL redirect in the header, which in turn will automatically open the URL in the redirect.

This can be adapted to take you to the online file as per your question.

The URL contains the protocol (e.g. HTTP), so just make sure that it's in there. To be more minimalist, you can omit the <title> and <h1> lines.

I tried the other answers on this page with Ubuntu 16.04 without success, but this solution works.

wwmbes

Posted 2011-04-29T20:22:46.687

Reputation: 81

3

It's not possible to link to a HTTP location. You might be able to mount the location of this file via WebDAV to your system and link to the local mount, but this only works if it's configured to get exported via WebDAV..
But if you want to read the file (I think you are trying to do so), you anyhow have to download the content (even if it would be possible to create such a link). So I recommend to simply download it.

binfalse

Posted 2011-04-29T20:22:46.687

Reputation: 1 426

But if you download it and it changes, your downloaded copy is out of date. – endolith – 2012-04-06T14:29:25.217

0

For ease of use, I wrote a script to generate bash-link like Lekensteyn suggested. Making it runnable makes things even more handy. Run it like $ linkscript.sh http://example.com/your/link YourLinkFile.sh.

#!/bin/sh
echo '#!/bin/sh' >> $2
echo "x-www-browser '$1'" >> $2
chmod +x $2 #Makes the generated script executeable

Cadoiz

Posted 2011-04-29T20:22:46.687

Reputation: 40