I am working at an OS independent file manager (mostly Windows and Linux), and I am wondering if there is a Linux way to open a file in its default viewer. For example, open a html file with Firefox, an .avi with vlc, and so on. On Windows, there is a function ShellExecute() that does that, but my understanding is that on Linux it is not that simple, and each desktop environment has a specific way. I would appreciate any help with this.
If you want to open any file with a specific application, just enter: open -a "Application" /Path/to/file .
Files (nautilus) >> select a file >> right click & Properties >> "Open With" tab >> select a program you fancy >> "Select as default". Done.
Cat. The simplest way to view text files in Linux is the cat command. It displays the complete contents in the command line without using inputs to scroll through it. Here is an example of using the cat command to view the Linux version by displaying the contents of the /proc/version file.
You could use xdg-open(1)
. It works on all freedesktop compliant desktops.
The default programs for different mime-types are defined in /etc/mailcap and $HOME/.mailcap, indexed by file type and action (display, edit, print). The command line interface is run-mailcap. See also the manpages run-mailcap(1) and mailcap(5).
It depends what desktop environment you're using in Linux. Gnome for example has a MIME database you can use to find out what to launch for a given file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With