xdg-open - Linux


xdg-open is a utility command found in Linux environments which is used to open a file or URL in the user’s preferred application. It is part of the XDG Utils package and serves as a method of environment-independent file opening in applications. The command is useful for integrating with scripts or other commands within a system that requires opening a document or connecting to a URL directly from the command line.


The basic syntax for xdg-open is as follows:

xdg-open [file|URL]
  • file: Path to the file you want to open.
  • URL: Web URL that you wish to open through the default web browser.

xdg-open does not have extensive parameters; it simply takes a file name or URL as an argument.


xdg-open has no specific options or flags. It is designed to be straightforward to use: pass the file or URL to the command, and it will utilize the default application set by the user’s environment to open it.


  1. Opening a PDF File:

    xdg-open example.pdf

    This command opens example.pdf using the system’s default PDF viewer.

  2. Opening a URL:

    xdg-open https://www.example.com

    This will open the specified URL in the user’s default web browser.

Common Issues

  • Permission Errors: If xdg-open fails to open a file, check if you have the necessary permissions to view the file.
  • Default Application Not Configured: If xdg-open does nothing, it might be because there isn’t a default application configured for the file type or URL. Consult your desktop environment’s documentation on how to set default applications.


xdg-open can be combined with other commands to perform more complex tasks. For example, in a script to download a file and open it:

curl -o example.pdf https://www.example.com/example.pdf && xdg-open example.pdf

This script downloads a PDF and then opens it immediately after.

  • curl or wget: Use these tools to download files from the internet which can be subsequently opened with xdg-open.
  • mimeopen: Another utility for opening files in their associated applications, similar in functionality but with additional options like specifying the MIME type manually.

For further reading and more detailed information, consult the XDG Utils official documentation available on most Linux distributions or the specific documentation provided by your distribution.