0

There are multiple ways to open files or folders such as

gnome-open
see
xdg-open
gvfs-open

so... which should I use ?!

Zanna
  • 70,465
Saver
  • 9
  • 2
    I personally made a little Bash function for myself that uses xdg-open internally: xo () { xdg-open ${1:-.} &> /dev/null } - My modifications silence any possible output to the terminal and set the first argument to . (current directory) if none is given. However, I can't tell whether xdg-open is the recommended approach for every version and desktop environment. I have 16.04 and Unity, where it works well. Did not try the others. – Byte Commander Jun 16 '18 at 14:59
  • 1
    xdg-open is a wrapper script that calls whichever of gio open, gvfs-open, gnome-open, kde-open, etc. is available. – muru Jun 16 '18 at 15:58
  • @muru The question had some specifics that are different from the marked duplicate. His question showed his familiarity with the information included in the question you marked as duplicate, so that doesn't appear to address his question. – L. D. James Jun 16 '18 at 16:03
  • @L.D.James as for the specifics, there is no standard on the topic, and as for the "best", most upvoted is as good a measure of "best" as any. – muru Jun 16 '18 at 16:05
  • By the way, I don't think my answer would be as appropriate for the "duplicated" question as for this question, which is different. I'll complete the answer and provide it to you in a chat message. There is a chance that you might notice the difference in the two question in seeing the appropriate answer to this specific question. It may take about 10 minutes. – L. D. James Jun 16 '18 at 16:07
  • I would have to change the answer to make it fit the other question. – L. D. James Jun 16 '18 at 16:08

1 Answers1

2

It would depend on how you want to open the file. The commands you mentioned in your question and specifics for handing the target in a specific way.

First, the gnome-open command isn't available by default in the Ubuntu repository. So it wouldn't be standard for the Ubuntu environment. If you had a very specific reason for using something non-standard for Ubuntu, that would be your special occasion to change from the standard.

xdg-open is a generic method for opening files from the commandline, as if it was being opening by a click from the file browser. The application or context of the file being opened would depend on what you have set as a default method for the file to be handled.

gvfs-open Is no longer a standard method in Ubuntu. It has been replaced with gio open (an argument of the gio app). It will have a limited number of methods for opening the destination. If the destination file is an execution file you would have to specify the program to execute it (which can also be done via the shebang file header).

While clicking on helloworld.sh or helloworld.pl will open the file as a program, opening it with gio open helloworld.sh will open it as a text file, not as an executional file.

The latter is a an example that it would depend on how you want the file to be opened, or how you want to use the file.

In this case, if you want to execute the file you would open it with one of these options:

$ bash helloworld.sh
$ ./helloworld.sh

The quick answer is that way to open a file would depend on how you want to open it.

L. D. James
  • 25,036