0

I'm a Mac user trying to make the switch to Ubuntu Linux (with the Gnome DE). But as I've always relied heavily on the "open" and "edit" commands in Terminal on the Mac, I'm trying to find (or create) similar functionality in Linux. Today I'm wrestling with "edit", which should open the given document(s) in a new gedit window if they weren't already open, but if they were already open, just bring that window to the front.

Unfortunately, that's not what the gedit command does. It works great if the file isn't already open, but if it is, it opens it in a new window (without bringing it to the front), and gives me a scary warning that the file "is already open in another window" with "Edit Anyway" and "Don't Edit" buttons.

But if I right-click on a file in Files (or whatever the Gnome equivalent of the Finder is called), and select the "Open With gedit" command, it does exactly what I want: brings the existing editor to the front, or opens a new one.

How can I do that exact same operation from the command line?

1 Answer 1

0

I'm reading there that you can use xdg-open for that.

Not sure it will actually do exactly what you want as I just found it myself, but at least it will open a file of any type with the appropriate application!

Edit: I tried it yesterday after having walked away from the WiFi: it does what you are asking for! So either opens a new window or brings an already open window to the front.

3
  • Hmm, not for me. I get the same "This file is already open in another window. Do you want to edit it anyway?" warning.
    – Joe Strout
    Commented Jul 28, 2017 at 14:00
  • Makes me wonder if the gedit command would also work as it should on your machine... clearly your version of something or other is different from mine; perhaps it was fixed at that level?
    – Joe Strout
    Commented Jul 28, 2017 at 14:01
  • @JoeStrout I've just tried re-opening a file with gedit, works fine on my computer indeed... Doesn't bring it to the front strangely, but makes the gedit icon jiggle and doesn't open a new gedit. I'm running Ubuntu 17.04 with Nautilus for file navigation (the default for Ubuntu since some time now). If you're using Gnome, did you try gnome-open maybe? Commented Jul 29, 2017 at 0:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .