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

Beginning vi

The default editor that comes with the UNIX operating system is called vi (visual editor). vi is case sensitive.

start vi
vi

quit vi
# quit and save
:x

# quit and save
:wq

# quit vi
:q

# quit without saving
:q!

start insert mode
press i key

turn off insert mode
press (Escape) key