16

I know this question sounds too generic but I am unable to find an answer for it.

How can I create a link (soft/hard) file which when opened, redirect me to a website with http protocol?

One possible way I can think of is creating a lame shell script and making it executable which can make use of a browser to open a website. But isn't there a concept of a "hyperlink file"?

2
  • You could create an HTML file with a <meta> redirection in it.
    – slhck
    Commented Oct 14, 2015 at 11:45
  • 1
    A link (hard/soft) opened how? Only from a graphical environment or from command-line too?
    – Hastur
    Commented Oct 14, 2015 at 16:48

6 Answers 6

17

Add this to target.html:

<html>
<head>
<meta http-equiv="refresh" content="0; url=http://example.com/" />
</head>
</html>

Now if you run firefox target.html it will open example.com.


To clarify, there is no such thing as a "hyperlink file". You may have heard of symbolic and hard links, but those are simply a way to refer to a file on disk - they are not URLs. From man ln:

Symbolic links can hold arbitrary text; if later resolved, a relative link is interpreted in relation to its parent directory.

10

There are .desktop files:

$ cat ~/Desktop/Link.desktop
[Desktop Entry]
Encoding=UTF-8
Name=Link to your site
URL=http://your-site-url.com
Icon=text-html

This is a possible answer when your solution needn't be command-line-based, but supposed to gain much comfort.

Of course the .desktop files don't have to be stored in ~/Desktop/. I just used this location since they might be used in that location mostly.

1
  • 7
    This is missing Type=Link; the key is unconditionally required, and the value is required in order to use it as a web link file. Commented Dec 17, 2016 at 6:52
6

xdbg-open is default application for open anything, so you can create bash script like this:

#!/bin/bash
if which xdg-open > /dev/null
then
  xdg-open YOUR_URL
elif which gnome-open > /dev/null
then
  gnome-open YOUR_URL
fi

Replace YOUR_URL accordingly, save file and make it executable (chmod +x filename.sh)

1
  • 1
    +1 pragmatic solution to an impossible problem :)
    – l0b0
    Commented Oct 14, 2015 at 16:32
3

One answer that has not come up yet, is using Linux’s binfmt_misc capabilities, to create a native executable link format that works on the kernel level!

To automatically open any .link files in xdg-open, put this inside an executable file at /etc/local.d/binfmt_misc.start, or any file your OS runs on startup:

#! /bin/sh
echo ':open-hyperlink:E::link::/usr/local/bin/open-hyperlink:' > /proc/sys/fs/binfmt_misc/register

and put the following into the /usr/local/bin/open-hyperlink executable:

#! /bin/sh
xdg-open "`cat "$1"`"

After that, you can just “run” .link files that are marked as executable via any means, and it will open the link in the browser. Command line, GUI double click, whatever you like.

$ echo 'http://superuser.com/questions/986527/how-to-create-a-hyperlink-file' > this-page.link
$ chmod +x this-page.link
$ ./this-page.link
[Browser opens…]

You can of course change the extension and file format how you like, provided you change the open-hyperlink script accordingly. Even Windows .lnk files!

Of course your kernel has to have that module available and enabled, for it to work. (I have it compiled in.)

Check out the documentation on binfmt_misc, as there are a lot more possibilities, e.g. with matching on a pattern instead of a file extension.

1

There are a lot of answers assuming you want to do this programmatically, but if not then open the page in a browser, and drag from the address bar to the desktop or file explorer window and it should make a link.

3
  • 1
    This is dismissed, but this actually works!
    – anon
    Commented Oct 12, 2016 at 15:21
  • Which versions of Linux does this work on? It seems more like a Windows answer than a Linux answer. Certainly on Red Hat 6, dragging a URL from Firefox ESR 52.5.1 just saved a copy of the page to disk rather than creating a link.
    – Mark Booth
    Commented Mar 16, 2018 at 10:41
  • @Mark Booth It was a long time ago but I think I didn't notice this question was tagged Linux. Also, back then I would have been using Chrome and I assume I also tested on IE. However this should work on Linux although it may be a chrome/chromium thing.
    – SilentVoid
    Commented Mar 17, 2018 at 11:35
1

If you use Firefox you could install FoxyTab addon and it has an option when you right click on the website's tab that's called: "Create Desktop Shortcut". It lets you save a .desktop file anywhere on your computer. On double click it will ask you how to open the file, just select Firefox and it will open the website.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .