Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Nautilus, when you double click a file, it will open it with the default application associated with the file's extension. For instance, .html files will open in a web browser and .pdf will be opened with Document Viewer. Is there a way to reproduce the same behavior from within the command line (i.e. open path/filename)? I'm asking because I like to browse my file-system from the command line but sometimes don't remember which app. opens what.

share|improve this question
    
There is a similar question regarding launching default browser from the command line: askubuntu.com/questions/8252/… – kounryusui Nov 29 '10 at 13:42
up vote 81 down vote accepted

I think xdg-open is the command you are looking for.

NAME
       xdg-open - opens a file or URL in the user's preferred application

SYNOPSIS
       xdg-open {file | URL}

       xdg-open {--help | --manual | --version}

DESCRIPTION
       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.

eg: xdg-open index.php

This will open index.php in gedit(if you are using gnome).

If you want to open a url in browser

xdg-open http://google.com

this will open google.com in your default browser.

share|improve this answer
1  
wish I searched on google for this earlier – JohnMerlino Sep 25 '13 at 23:55
2  
On Gnome: gnome-open and on KDE: kde-open works. – Farahmand Feb 21 '14 at 16:01

xdg-open and gnome-open

xdg-open is the most universal way (work also on KDE)

share|improve this answer
1  
This answer was posted earlier. – Kadir Jan 15 '15 at 11:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.