How to open a specific application like macOS `open -a`?

On macOS in the default Terminal running bash, I can type:

open -a Firefox http://www.wikipedia.org

to open a URL with Firefox, or another browser. It also works to launch a program, e.g. open -a maps, and to open a file in the default program, e.g. open file.pdf.

How can I do the same on Ubuntu in the default GNOME Terminal also running bash? I know that I can open a file or URL with xdg-open /path/to/file, and I can open the default browser with sensible-browser. Does Ubuntu have a general command to open files, applications, or files in specific applications?

I am running bash on both machines, 3.2.57(1)-release on macOS and 4.4.19(1)-release on Ubuntu.


Solution 1:

You can specifically use your desired program's name (if it's able to be used as a command line tool).

For example, urls:

firefox duckduckgo.com
chromium-browser askubuntu.com

PDF:

evince foo.pdf
okular bar.pdf

Images:

gpicview foo.png
feh bar.jpeg

Texts:

gedit foo.txt
mousepad /etc/config
leafpad bar.xml

Video/Music:

mpv  foo.mp3
vlc  bar.mp4

If you want the program to be run detached from the terminal then this is the way that I prefer doing it:

nohup program args &

For example:

nohup firefox askubuntu.com &

Remember that you can always redirect the outputs as usual, e.g. :

nohup firefox duckduckgo.com &> /dev/null &

Solution 2:

As indicated in a response to the accepted anwser, the equivalent to the open command from macOS in Linux is xdg-open:

xdg-open opens a file or URL in the user's preferred application. If a URL is provided the URL will be opened in the user's preferred web browser. If a file is provided the file will be opened in the preferred application for files of that type. xdg-open supports file, ftp, http and https URLs.

When compared to the macOS open, the main difference is that here you can't specify an specific application to use from the command line. For that, you can refer to the accepted answer, as the problem is kind of pointless in Linux because applications are normally available in your PATH already.