Help Yourself With xdg-open

I am a keyboard junkie, and I encourage others to use it more than the average use and experience the change, whether it is in the console or one of the modern keyboard-driven launchers.

One of the complaints I keep hearing is that with the command line, people have to type in name of the executable to open a document. Whereas in the GUI world, you just double-click on a document, or on the application icon. And I realized it was not so much about typing the application name, it was more about having to remember application executable name along with the file name.

So here is a solution for those of you on Linux and possibly other Unix systems. What we need is an application which can identify the application for a specific file type and open it for us. And we already have something for this – xdg-open. It is part of the XdgUtils toolkit which aims at better desktop integration across various desktop environments. And most of the popular DEs qualify to be XDG compliant.

xdg-open opens a file, including URLs, using the preferred applications. In short, you can type xdg-open resume.odt and it opens up OpenOffice, or your preferred application, for you to edit the document. If you find xdg-open to be cumbersome to type, create a symbolic link with your favourite command. For example, if I want to open files using the command o, I do

ln -s /usr/bin/xdg-open /usr/local/bin/o

Now I type o resume.odt or o blog.py or o http://ifacethoughts.net to open any of the corresponding applications and work on those files.

We can perhaps take this one step further by using command_not_found extension for bash to invoke the application by just typing in the file name, without having to worry about the application name at all.

Discussion [Participate or Link]

  1. johnson said:

    You could put this in your .bashrc instead of creating symlinks. That way when you migrate to another computer/account your settings persist.

    alias o=xdg-open

Say your thought!

If you want to use HTML you can use these tags: <a>, <em>, <strong>, <abbr>, <code>, <blockquote>. Closing the tags will be appreciated as this site uses valid XHTML.



Abhijit Nadgouda
iface Consulting
+91 9819820312
My bookmarks


This is the weblog of Abhijit Nadgouda where he writes down his thoughts on software development and related topics. You are invited to subscribe to the feed to stay updated or check out more subscription options. Or you can choose to browse by one of the topics.