Open File in Application From the Terminal

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

Share and Enjoy
  • Facebook
  • Twitter
  • LinkedIn
  • del.icio.us
  • StumbleUpon
  • RSS
  • email
  • PDF

Published by

Samuel

Ph.D. Student in the Department of Computer and Systems Sciences, Stockholm University.

Leave a Reply

Your email address will not be published. Required fields are marked *