Linux equivalent command for "open" command on Mac/Windows?

47

22

Coming from Mac OS X, you can type:

$ open yourfilehere.txt

and your file will open just as if you had opened it from Finder.


On Windows, one can type:

> start yourfilehere.txt

and it will open just as if you had opened it from Explorer.


On Ubuntu, I'd like to be able to open files in the same manner in GNOME. What's the command?

jweede

Posted 2009-09-10T12:49:34.803

Reputation: 6 325

I just saw that On Windows, this is the start program. On OS X, this is the open program. On Ubuntu Linux, this is the see program. in book automate-the-boring-stuff-with-python, but I didn't get any info about see command from Google.

– CodyChan – 2017-09-20T08:39:03.570

1In little related I found this little gem to open Finder in a certain path (not current path necessarily): open -a Finder . or open -a Finder /your/path/here – Mikko Ohtamaa – 2012-02-10T19:56:45.650

Answers

41

xdg-open is what you're looking for.

You might like this snippet I put in my .bashrc files so that whether I'm using cygwin on windows, linux, or OSX, I can use either the start or the open commands and they work great:

case "$OSTYPE" in
   cygwin*)
      alias open="cmd /c start"
      ;;
   linux*)
      alias start="xdg-open"
      alias open="xdg-open"
      ;;
   darwin*)
      alias start="open"
      ;;
esac

Good comments, xdg-open is indeed a better option than gnome-open as explained below. I updated my personal scripts a while ago, but forgot to update this answer.

WARNING: This will override the functionality of both openvt (virtual terminal) and start from init.

Jordan

Posted 2009-09-10T12:49:34.803

Reputation: 860

"xdg-open" does not support launching executable programs for safety - use "exec" for them. – eadmaster – 2014-07-26T01:34:20.627

I wonder if this script could be extended to detect when it's an executable program, and use exec for those? – Joe Strout – 2017-07-26T15:21:14.637

1That BASH script is a great idea. – jweede – 2009-09-10T13:00:38.513

9cygwin: try "cygstart" – Doug Harris – 2009-09-10T15:02:36.037

13gnome-open is GNOME-specific. xdg-open is available on all Freedesktop.org compliant distros. – Avdi – 2009-10-25T14:18:26.040

@DougHarris, +1. cygstart may be further preferable, as in Emacs bookmarks, it allows one to continue using Emacs. With start, my Emacs is frozen. – Brady Trainor – 2014-03-23T23:17:38.380

Then, start is nice if you don't want to rely on Cygwin being available. start "" or "start \"\"" just worked for me. (Set of quotes "" prevents Emacs hanging on process.) – Brady Trainor – 2014-03-24T00:24:13.210

34

xdg-open xyz.bar

will open xyz.bar (may be a file or an URL) in any freedesktop compatible environment with the application registered for xyz.bar's type. See also the documentation here (man page of xdg-open).

In practive this should then call kde-open, gnome-open, exo-open or possibly even open, depending on the current desktop environment (KDE, Gnome, XFCE, OS X).

akira

Posted 2009-09-10T12:49:34.803

Reputation: 52 754

It's almost equivalent to Mac's "open" command, but not quite — I'm finding (under Ubuntu 14 at least) that when I use it on a directory, the directory opens in the background. I'd rather it bring the freshly opened window to the front. Any way to make it do that? (Forgive me, I'm a total Linux noob.) – Joe Strout – 2017-07-26T15:22:28.387

3also works. What's the difference between xdg-open and gnome-open ? – jweede – 2009-09-10T13:28:23.510

5well, xdg-open was developed by the freedesktop.org folks which claim to create the "standard", while gnome-open was developed by the gnome folks .. which you only get when you install gnome. i personally like the freedesktop.org stuff more. – akira – 2009-09-10T13:32:52.660

2"xdg-open will be available on any freedesktop-compliant system" means, in practice, that no matter whether you are using GNOME, KDE, Xfce, or any other environment, xdg-open will do the Right Thing, using the file-type-to-program mapping of the running environment. – RavuAlHemio – 2012-01-16T20:26:13.703

2Indeed, xdg-open is the right answer here. gnome-open is specific to desktops that have GNOME installed. xdg-open will be available on any freedesktop-compliant system. – Avdi – 2009-10-25T14:19:32.620

10

You can even write a small wrapper around gnome-open to open multiple files with one command:

for i in $*
do
    gnome-open "$i"
done

Put this into a shell script named open and

open *.c

will open all c files in the current directory.

Kim

Posted 2009-09-10T12:49:34.803

Reputation: 2 238

2Useful script, but you'll want to replace $* with "$@" (including the quotes) to properly handle filenames with spaces. – pimlottc – 2012-01-03T22:44:41.870

1

You can use the gnome-open command in your Terminal. Once in the directory which you want to open an OS window of, type in the Terminal:

gnome-open .

This will open a window showing what is in this folder. Similarly, you can specify a subfolder located in this directory by substituting the . by the name of the subfolder.

Note that if gnome-open doesn't work, it may just need to be installed. You can do so using Synaptic (sudo apt-get update and then sudo apt-get install synaptic in your terminal, very convinient when installing package because it installs all the dependencies properly) or directly install Gnome Shell in your Terminal: sudo apt-get install gnome-shell

LeChat

Posted 2009-09-10T12:49:34.803

Reputation: 111

-1

Enter this into the terminal: ./yourfile

yourfile is the name of the file you want to open or run. You can also use this command to run bash scripts. (Remember to enter the file extension!)

gnome-open is what you're looking for.

Another quote from another poster.

user113907

Posted 2009-09-10T12:49:34.803

Reputation: 162