Открыть url в linux

Equivalent of .URL file on Ubuntu

An URL link has been saved in *.url file via Windows. If you double click the file in Windows, it will open your default browser to the indicated URL. Here is an example of *.url file content:

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

When the same file is copied on Ubuntu OS, Ubuntu handles it such as a text file. Hence, the browser does not open the URL when double-clicking the file. My question is: what is the equivalent of *.url file in Linux to make shortcut file for URLs?

Here is a small workaround saidulhassan.com/open-url-files-in-linux-mint-ubuntu-1029 but I hope this will be eventually supported by linix distros out of the box

I tried to set Firefox to open .url files, and associating the file type inside Firefox as well, but a bizarre bug made it aggressively open tabs ad infinitum. That both scared me and made me laugh for a second.

@mchid URL files aren’t an app or an executable or a platform-specific «Windows shortcut». They’re a generic file format for storing a URL. There’s no reason to expect it to work on only one operating system. Should .txt files only open in Windows?

4 Answers 4

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"; >> 

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.

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= Icon=

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.

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.

You can make your Linux file manager open .URL file in your default browser. This is particularly useful for people who share files between Windows and *nix machines. To do this create a script file let’s call it mswin-urlfile (or what ever you like) in /usr/local/bin (or your preferred folder). Change permission: chmod +x /usr/local/bin/mswin-urlfile

#!/usr/bin/bash if [ "$1" == "" ] || [ "$1" == "--help" ] ; then echo "$(basename "$0") URLFILE - opens a .url file in the default browser" else sed 's/^BASEURL=/URL=/' "$1" | grep -m 1 '^URL=' | sed 's/^URL=//' | sed 's/\r//' | xargs xdg-open fi 

To test use it manually from a shell prompt using:

Next you will need to configure file manager to call mswin-urlfile when opening a .URL file type. This works across all *nix and shells allowing you to open your .URL files from within your file manager. Exactly how to do this depends on the file manager you use. Lookup «file association» for the specific file manager you use.

For example Nautilus file manager is mentioned at 369967 and create a mimetype for the .url extension

Open Applications > System Tools > File Types Editor, and click the New button. Enter the following information in the corresponding tabs:

► General: Category: Text and source code

Name: x-url

Description: Microsoft Internet Explorer Shortcut

You can choose an icon for the .url file-type via the browse button […] – if you don’t have any, there are some at the bottom of this post that you can save to a folder like /home/yourusername/Settings/Icons.

► Filenames:

Filename pattern: *.url

► File contents:

When you click +Add, you’ll see more than one data entry field, but all you need to worry about is the Value: one.

Value: [InternetShortcut]

Now your system knows what .url files are, but it still doesn’t know what to do with them. You now have to associate the .url extension with the executable script fx-url, so right-click any .url file and go to Properties > Open With. Click the Add button, and at the bottom of the “Add Application“ window you’ll see the “Use a custom command“ option; click this, then either browse to /user/bin and select the symlink you created, or enter /usr/bin/Web Shortcut Browser (or the appropriate name if you changed it). Click the Add button to save your changes (but leave the “Properties“ window open as you’ll need it in the next step).

Now you need to make the associated action the default option for double-clicking, otherwise you’ll have to right-click .url files and choose the required option from the context menu. To make opening in Firefox the default action, in the Open With tab of the “Properties“ window, click the dot to the left of the entry you just added (eg: “Web Shortcut Browser“), then click Close.

open any Nautilus (file manager) window and go to Edit > Preferences > Behaviour. In the “Executable Text Files“ section, make sure that “View executable text files when they are opened“ is selected. Click Close, and it is done (you may need to log out or reboot for the changes to take effect). Now when you right-click any .url file, you should see “Open with Web Shortcut Browser“ as the top entry of the context menu, and it will be the default action for double-clicks.

I use a different file manager so I have not tested the above Nautilus instructions.

Читайте также:  Установка видеокодеков linux mint

I prefer to keep using URL files as I use a mixed environment Android + app to open or create URL files; Linux + script (above) to open URL files; Windows (built in URL file support). Alternatively, you could convert every system to just use bookmark files and sync them, but builtin browser syncing has messed up my bookmarks more than once. If you use different browsers (eg Chrome, Firefox, Brave) on different system syncing is not simple.

Источник

How to Open a URL in the Web Browser from Linux Terminal

Flexibility is an underrated attribute overlooked by many users of the Linux operating system. Being a flexible Linux user implies that you can launch most; if not all, of your user and system applications from the command line interface without having to navigate and search for them from the system GUI applications’ menu.

Also, the flexibility of your Linux OS user experience not only applies to system-based applications like installed apps but also to non-system-based applications like web apps that require a URL for access.

When working with Linux, you don’t necessarily need to open a browser application before you can access targeted URLs associated with specific websites.

This article will walk us through various ways (commands) of opening a URL on a default browser application from the terminal.

1. The xdg-open Command

As per the Linux man page, the xdg-open command opens a file or URL via the user’s preferred/default file application or browser application.

Its usage can be demonstrated via the following command syntax:

For instance, to open the LinuxShellTips home page from the Linux command-line interface, we will execute the following command.

$ xdg-open 'http://ubuntumint.com'

Opens File or URL in Linux Commandline

The execution of the xdg-open command will open the specified URL on your default web browser application.

Opens URL in Web Browser

2. The sensible-browser Command

As per the Linux operating system man pages, the sensible-browser command can be used to execute sensible decisions regarding a default web browser application that can be used to open a targeted web URL.

Its implementation can be referenced from the following command syntax:

$ sensible-browser URL_OF_TARGETED_WEB_PAGE

For instance, we can access a random LinuxShellTips website URL in the following manner:

$ sensible-browser 'http://ubuntumint.com/ssh-passwordless-login-almalinux'

sensible-browser Command Opens URL

The execution of the sensible-browser command should redirect us to the specified URL on the default web browser.

Читайте также:  Arch linux testing linux

Opens Webpage in Browser

The use of the sensible-browser command is fully supported in Debian-based Linux operating system distributions like Linux Mint and Ubuntu.

3. The x-www-browser Command

Even though the x-www-browser command might not exist in the Linux man-pages ($ man x-www-browser) of the Linux operating system distribution you are using, it is equally effective in redirecting a user to a specified web URL on their default web browser.

Its command syntax can be represented in the following manner:

$ x-www-browser URL_OF_TARGETED_WEB_PAGE

For demonstration, let us try to access another random web page on the LinuxShellTips website.

$ x-www-browser 'http://ubuntumint.com/download-files-remote-linux-servers'

x-www-browser Command

The execution of the x-www-browser command should swiftly redirect you to a web browser with a display of the specified web page URL.

Opens Webpage in Browser

4. Alternative Commands to Open URL

You could alternatively use your browser name as part of the Linux command for opening the web page URL you are targeting:

For Firefox web browser:

For Google Chrome web browser:

$ google-chrome http://google.com

Despite the error messages on the terminal on executing these alternative commands, your specified web URL should open without any issues.

Open URL from Linux Commandline

You now know some cool tweaks on opening web URLs on the Linux command-line without directly going to the web browser’s GUI app.

Источник

Command to open a URL

There’s a command that knows about your default browser:

This will also work for every other type of URI (Uniform Resource Identifier), like images — which will automatically open with eog, openoffice documents, and so on, and also on filesystem paths ( xdg-open /tmp/foobar.png ).

xdg-email team@stackexchange.com 
xdg-mime query default text/html 

To find out what application is going to be used.

You can set your preffered application by going to System → Preferences → Preferred Applications:

alt text

These utilities are part of the freedesktop.org specification, so you can use them in your applications — and it’s going to work on all of the desktops that adhere to the spec.

You can use xdg-open like so:

xdg-open opens a file or URL in the user’s preferred application. If a URL is provided the URL will be opened in the user’s preferred web browser.

If you don’t necessarily want to use the default browser, you can call any browser program directly and give the URL as argument, for example:

chromium-browser https://youtube.com 

gnome-open works as well as xdg-open but neither knows what to do with naked domain.

So gnome-open http://askubuntu.com works but not gnome-open askubuntu.com .

Here is a small function to make it easier to type and accept the stripped down domain name.

Paste the above in your command line, hit enter and try it out. If you like it you can save it to your .bash_aliases or .bashrc file, then source ~/.bash_aliases (assuming it is in your home directory) and it will be persistent for that session and all new sessions.

So now we just type go askubuntu.com and wallah!

Источник

Оцените статью
Adblock
detector