[Quick Tip] Universal Linux Command to Open Media, Document, Other Files, URLs

Working on Linux terminal or command console regularly? There’s an universal command to open a file or URL via the preferred application.

xdg-open is the handy command line tool that will automatically use user’s preferred application to open a video, audio, tarball, document, folder directory, and http / https url.

xdg-open command is part of xdg-utils package which is installed by default in most Linux desktops. It’s a desktop-independent tool for configuring the default applications of a user.

Inside a desktop environment (like GNOME, KDE, or Xfce), xdg-open simply passes the arguments to those desktop environment’s file-opener application (eg. gvfs-open, kde-open, or exo-open). which means that the associations are left up to the desktop environment. When no desktop environment is detected (for example when one runs a standalone window manager like eg. Openbox), xdg-open will use its own configuration files.

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

Command Usage:

xdg-open /PATH/TO/FILE

Tips for typing path/to/file section, you can just type a few letters at the beginning and hit Tab key to auto-complete.

Examples:

Here are some examples show you how to use the command:

1. universal command to open user’s Downloads folder:

xdg-open ~/Downloads

2. universal command to open a mp3 file:

xdg-open ~/Music/Love_Me_Not.mp3

3. It can even open .deb, .tar packages:

xdg-open xsnow_3.1.9-1_amd64.deb

4. And open a website / URL via your favorite web browser. It will open in new tab if a browser window already exist.

Merilyn Ne
Hi, I'm Merilyn Ne, a geek who has been working on Ubuntu Linux for many years and would like to write useful tips for beginners. Forgive me for language mistakes. I'm not a native speaker of English.