Sometimes I want to open a file in a specific application from the terminal. Using Linux, there are two easy options.
application-name filename
The first option is to type the application name followed by the filename. For example, to open a JavaScript file in Sublime Text or an HTML file in Google Chrome I type the following:
subl script.js
google-chrome index.html
However, sometimes you don’t know the exact name of the application. In these situations, xdg-open is useful.
xdg-open filename
A second options is to type xdg-open followed by the filename which opens a file in the preferred application for files of that type. For example, if I want to open a JavaScript file or an HTML file in my preferred application, I type the following:
xdg-open script.js
xdg-open index.html