xdg-open — opens a file or URL in the user’s preferred application

Sponsored Link
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 a file is provided the file will be opened in the preferred application for files of that type. xdg-open supports file, ftp, http and https URLs.

xdg-open is for use inside a desktop session only. It is not recommended to use xdg-open as root.

Using xdg-open


xdg-open { file | URL }

xdg-open Examples

xdg-open ‘http://www.ubuntugeek.com/'

Opens the ubuntugeek.com website in the user's default browser

xdg-open /photos/1.png

Opens the PNG image file /photos/1.png in the user's default image viewing application.

Exit Codes

An exit code of 0 indicates success while a non-zero exit code indicates failure. The following failure codes can be returned:

1    Error in command line syntax.
2    One of the files passed on the command line did not exist.
3    A required tool could not be found.
4    The action failed.

Available options

--help  Show command synopsis.

--manual Show this manualpage.

--version Show the xdg-utils version information.

Sponsored Link

Related posts

7 thoughts on “xdg-open — opens a file or URL in the user’s preferred application

  1. Any significant difference between xdg-open and gnome-open? Other than “gnome-open” is much easier to remember? (Though it is longer.)

  2. @Victor, the difference may be that a user doesn’t have (or want) GNOME apps. ‘kde-open’ does this same thing and it is shorter, why not use that? Oh because maybe you don’t want KDE apps.

  3. @Victor – xdg-open is a shell script which attempts to call the appropriate ‘open’ utility given the current environment (so if you are using gnome it will call gnome-open).

  4. Hi,
    When i use xdg-open ,
    it open the file in the default browser say Firefox rather than then Default viewer.

    Any help

Leave a comment

Your email address will not be published. Required fields are marked *