views:

3342

answers:

4

I've found the "open" command in Mac OS X very handy in the command line. From "man open":

The open command opens a file (or a directory or URL), just as if you had
double-clicked the file's icon. If no application name is specified, the
default application as determined via LaunchServices is used to open the
specified files.

That is, if I want to open a PDF file with the default PDF viewer (happens to be Preview), I only need to do:

open my.pdf

In Linux, however, to open a PDF file from the command line, I had to dig around to find the default PDF viewer is, for instance, "eog" (who'd have guessed??), and then

eog my.pdf

So, is there a simple equivalent of the 'open' command in the Linux command line?

Thanks!

+7  A: 

you could try xdg-open, most linux distros have it, it will open default associated app for your file.

FYI http://portland.freedesktop.org/xdg-utils-1.0/xdg-open.html

number5
+2  A: 

gnome-open

Paul Betts
+6  A: 

Indeed, I use gnome-open regularly, and have heard of xdg-open. However, this is really hard to type quickly and accurately. Instead, you should make an alias to gnome-open or xdg-open, which makes the process much quicker.

Personally, I use the right square bracket (]) for my shortcut. To use this, add the following to your .bashrc file:

alias ']'='gnome-open'

Then, to open any resource, use it like any of these examples:

] www.google.com
] file.txt
] /home/jeremy/Pictures
] ssh://myserver.local/home/jeremy

This is very quick and efficient. Obviously, you can bind gnome-open or xdg-open to any alias, but one-letter aliases work best.

Jeremy Visser
I made an alias from 'open' to 'xdg-open' in order to have it consistent on both Linux and Mac.
Adam Byrtek
+1  A: 

Traditionally, you can use the "see" command. Which just uses run-mailcap. This will work without Gnome and X etc.

man see
Ali A