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

Syntax

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

You may also like...

7 Responses

  1. DAY says:

    Hmm, how to set the user’s applied app when using non-main-stream DEs, but WMs?

  2. DAY says:

    Typo, I meant `the user’s preferred app’.

  3. Victor says:

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

  4. lefty.crupps says:

    @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.

  5. What happens if I type:
    xdg-open http://myserver/webdavstuff/nicedoc.odt

    Ideally I would open OpenOffice (or whatever is configured for ODT) and hand over the URL. If the http source/destination is webdav it would be read/write

  6. Bradley Dean says:

    @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).

  7. hardik says:

    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 Reply

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