Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

an URL link has been saved in *.url file via Windows and when you open this file . If you double click on the newly created internet shortcut, a simple URL file, it will open your default browser to the indicated URL. Example f URL file cntent :

[InternetShortcut]
URL=http:abdennour-insat.blogspot.com

When the same file (.url) is copied on Ubuntu OS , Ubuntu handles it such as a text file . Hence , browser does not openend when trigging double click on file

My Question is : What is the equivalent of .url file in Linux to make shortcut file for URLs ?

share|improve this question
add comment

3 Answers

up vote 11 down vote accepted

In Ubuntu an URL shortcut is stored in a .desktop file as follow (for example):

[Desktop Entry]
Encoding=UTF-8
Name=Link to Best Practices Software engineering
Type=Link
URL=http://abdennour-insat.blogspot.com/
Icon=text-html

If you still want to open your Windows URL files in Ubuntu, here is described how you can do it:

The Perl script given in that article appears to be broken, but the following code should do the same thing correctly:

#!/usr/bin/perl
# Script to make Microsoft Windows Internet Shortcuts (*.url) work on Linux.

my $browser = 'sensible-browser';  # use the system default browser

while (<>) {
    # match any line of the form "URL = something-without-spaces"
    if (/^\s*URL\s*=\s*(\S+)\s*$/) {
        exec $browser, $1;         # successful exec never returns
        die "$0: could not launch $browser: $!\n";
    }
}
share|improve this answer
3  
That Perl script looks broken in several ways: the "filter out carriage return" regexp won't work because it's missing a backslash, and indeed, the earlier regexp in the if clause will never match unless the URL contains the number 1, for the same reason. Also, if it does somehow manage to match, the URL will be passed unescaped to the shell, which is not only a security flaw, but will also break any URLs containing e.g. parameters separated with &. I've submitted an edit suggestion to your answer fixing these issues. –  Ilmari Karonen Oct 5 '13 at 11:40
    
@IlmariKaronen Thank you for correcting it! –  Radu Rădeanu Oct 5 '13 at 11:51
add comment

In Unity we have .desktop files for defining items on the launcher, desktop, or other locations. To create these see the following question:

A link to an internet file may have an entry as simple as the following

[Desktop Entry]
Encoding=UTF-8
Name=Internet Link
Type=Link
URL=<url>
Icon=<icon to display>

You can create such a file with a text editor, or much easier by simply dragging and dropping a bookmark from your browser to the desktop.

However keep in mind that such a simple .desktop file will not automatically open the given URL in a browser if the target is e.g a text document, or image. To overcome this see the following question:

In case we do need to open .URL files more often (e.g. from a shared drive) we may also run a bash script similar to this to open them:

#! /bin/bash

# opens Windows URL file submitted as command line argument in browser

source $1
xdg-open $URL

The command not found error from this script can be ignored or sent to /dev/null. If we must then we could associate this script to a Mime type for the extension URL to double click open an URL file.

share|improve this answer
    
An amazingly simple script when compared to the other answer. Put that into a .desktop file and associate .url files with it then you are done. –  minerz029 Oct 10 '13 at 10:06
add comment

If you want to keep .URL files (this is common for people who share files between Windows and *nix machines) then create a script file let's call it win-urlfile.sh (or what ever you like) in /usr/local/bin (or your preferred folder). Change permission: chmod +x win-urlfile.sh

#!/usr/bin/bash
sed 's/^BASEURL=/URL=/' "$1" | grep -m 1 '^URL=' | sed 's/^URL=//' | sed 's/\r//' | xargs xdg-open

This works across all *nix and shells allowing you to open your .URL files from within you file manager. You will need to configure Unity to call win-urlfile.sh when opening a .URL file type. Just ensure your file manager passes a single file name argument to the script when you open a .URL file type. Test with a simple name like test.url when you first setup.

Although the "source" (bash specific) solution works executing .desktop files as a script code could lead to unexpected code execution. Personally I consider that bad coding.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.