What is `xdg-open`?
`xdg-open` is a command line utility used to open graphical applications with their default preferred application engine as configured by the XDG_VTUNE environment variable and desktop settings. It simplifies opening files using any available application in an operating system that follows the freedesktop.org specifications, such as GNOME or KDE on Linux systems.
The purpose of this command is to provide a consistent way for users to open graphical applications across different desktop environments without having to know which engine (e.g., gnome-terminal, Konsole) was chosen as their default application for certain file types and protocols by the system configuration files (`~/.config/mimeapps.list` on most systems).
To use this command:
```sh
$ xdg-open somefile.txt
```
$ xdg-open somefile.txt
```
```sh
$ xdg-open --info mydocument.pdf
```
$ xdg-open --info mydocument.pdf
```
```sh
$ xdg-open # No arguments required here - opens the graphical selector interface now.
```
$ xdg-open # No arguments required here - opens the graphical selector interface now.
```
```sh
$ myapplication file:///path/to/file1.txt # Opens with 'myapplication' now and remember your choice for future files of same type, as configured system-wide in ~/.config/mimeapps.list or per user setting under `~/.local/share`.
```
$ myapplication file:///path/to/file1.txt # Opens with 'myapplication' now and remember your choice for future files of same type, as configured system-wide in ~/.config/mimeapps.list or per user setting under `~/.local/share`.
```
```sh
$ xdg-open http://www.example.com # Opens www.example.com with default web browser as configured in settings and available engines on system (e.g., Firefox, Chrome).
```
$ xdg-open http://www.example.com # Opens www.example.com with default web browser as configured in settings and available engines on system (e.g., Firefox, Chrome).
```
```sh
$ xdg-open --application=gedit mydocument.txt # Opens 'mydocument.txt' with gedit, ignoring all other configured and detected engines on your system for this particular file type (in general `.txt` files). Note the use of `--application`.
```
$ xdg-open --application=gedit mydocument.txt # Opens 'mydocument.txt' with gedit, ignoring all other configured and detected engines on your system for this particular file type (in general `.txt` files). Note the use of `--application`.
```
```sh
$ xdg-open --browser https://www.example.com # Opens 'https://www.example.com' in your configured and detected web browsers (e.g., Firefox, Chrome). Note the use of `--browser`.
```
$ xdg-open --browser https://www.example.com # Opens 'https://www.example.com' in your configured and detected web browsers (e.g., Firefox, Chrome). Note the use of `--browser`.
```
```sh
$ xdg-open /path/to/directory # Opens specified directory using system default file manager as configured under ~/.config/mimeapps.list and by desktop settings (e.g., Nautilus, Dolphin). Note the use of `--dir`.
```
$ xdg-open /path/to/directory # Opens specified directory using system default file manager as configured under ~/.config/mimeapps.list and by desktop settings (e.g., Nautilus, Dolphin). Note the use of `--dir`.
```
```sh
$ xdg-open ssh://user@remotehost # Opens an SSH connection to 'remotehost' using user credentials and default settings from ~/.ssh/config file if configured (or system defaults otherwise). Note the use of `--protocol`.
```
$ xdg-open ssh://user@remotehost # Opens an SSH connection to 'remotehost' using user credentials and default settings from ~/.ssh/config file if configured (or system defaults otherwise). Note the use of `--protocol`.
```
```sh
$ xdg-open runvtui # Opens your preferred Termux version Terminal Emulator with custom command and arguments predefined as per user settings in ~/.config/termux/vtiu file if configured (or system defaults otherwise). Note the use of `--exec`.
```
$ xdg-open runvtui # Opens your preferred Termux version Terminal Emulator with custom command and arguments predefined as per user settings in ~/.config/termux/vtiu file if configured (or system defaults otherwise). Note the use of `--exec`.
```
```sh
$ xdg-open vnc://remote_desktop 'localhost' --display=default # Opens your configured display ('default', etc.) over the default SSH port to connect with specified user on target host and opening Remmina/Remi session as predefined under ~/.remmina or ~/.xmonad.conf (for XMonad) files if configured, alongwith custom command line arguments for terminal window size (if defined). Note: The usage of `--display` here is crucial to specifying the display you intend to connect with when using desktop sharing protocols like VNC/NX or similar setups on systems supporting Wayland.
```
$ xdg-open vnc://remote_desktop 'localhost' --display=default # Opens your configured display ('default', etc.) over the default SSH port to connect with specified user on target host and opening Remmina/Remi session as predefined under ~/.remmina or ~/.xmonad.conf (for XMonad) files if configured, alongwith custom command line arguments for terminal window size (if defined). Note: The usage of `--display` here is crucial to specifying the display you intend to connect with when using desktop sharing protocols like VNC/NX or similar setups on systems supporting Wayland.
```
```sh
$ myapplication --terminal # Opens 'myapplication' but also opens the system default terminal inside of it (e.g., Nautilus with Firefox tabs enabled). Note the use of `--terminal`.
```
$ myapplication --terminal # Opens 'myapplication' but also opens the system default terminal inside of it (e.g., Nautilus with Firefox tabs enabled). Note the use of `--terminal`.
```
```sh
$ xdg-open rdp://myremotehost # Opens your configured display ('default', etc.) over default SSH port to connect with specified user on target host and opening Remmina/Remi session as predefined under ~/.remmina or ~/.xmonad.conf (for XMonad) files if configured, alongwith custom command line arguments for terminal window size (if defined). Note: The usage of `--display` here is crucial to specifying the display you intend to connect with when using desktop sharing protocols like RDP/VNC or similar setups on systems supporting Wayland.
```
$ xdg-open rdp://myremotehost # Opens your configured display ('default', etc.) over default SSH port to connect with specified user on target host and opening Remmina/Remi session as predefined under ~/.remmina or ~/.xmonad.conf (for XMonad) files if configured, alongwith custom command line arguments for terminal window size (if defined). Note: The usage of `--display` here is crucial to specifying the display you intend to connect with when using desktop sharing protocols like RDP/VNC or similar setups on systems supporting Wayland.
```
```sh
$ xdg-open ssh://remotehost 'bash' # Opens an interactive shell (e.g., bash) within the default terminal emulator or another preconfigured one at target host with given user credentials and custom command line arguments defined for it in ~/.bashrc, .zshrc files etc if configured under them as per requirements. Note: The use of `--shell` here is crucial to specifying what shell you want inside the connection (e.g., bash) on a target host instead opening an interactive login session using default configuration settings from system or user-specific configs/environment variables like .bashrc, .zshrc files etc if configured under them as per requirements - and custom commands line arguments for it when defined therein to execute upon starting remote terminal.
```
$ xdg-open ssh://remotehost 'bash' # Opens an interactive shell (e.g., bash) within the default terminal emulator or another preconfigured one at target host with given user credentials and custom command line arguments defined for it in ~/.bashrc, .zshrc files etc if configured under them as per requirements. Note: The use of `--shell` here is crucial to specifying what shell you want inside the connection (e.g., bash) on a target host instead opening an interactive login session using default configuration settings from system or user-specific configs/environment variables like .bashrc, .zshrc files etc if configured under them as per requirements - and custom commands line arguments for it when defined therein to execute upon starting remote terminal.
```
```sh
$ xdg-open gnome-terminal # Opens 'gnome-terminal' as configured under ~/.config/gtk-3.0 (or similar for other terminal emulators like Konsole, Guake or Termux etc) by system and user settings with custom command line arguments if defined in their respective config files therein - including prompting to remember your choice using 'xdg-userie' as per preferences specified under ~/.config/gtk.conf file (if available on the machine). Note: The use of `--shell` here is crucial, although not strictly required for opening terminals itself but can be used together with `--exec`.
```
$ xdg-open gnome-terminal # Opens 'gnome-terminal' as configured under ~/.config/gtk-3.0 (or similar for other terminal emulators like Konsole, Guake or Termux etc) by system and user settings with custom command line arguments if defined in their respective config files therein - including prompting to remember your choice using 'xdg-userie' as per preferences specified under ~/.config/gtk.conf file (if available on the machine). Note: The use of `--shell` here is crucial, although not strictly required for opening terminals itself but can be used together with `--exec`.
```