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.
I think
xdg-open
is the command you are looking for.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
this will open google.com in your default browser.
xdg-open
is a wrapper script - it will use the desktop environment's tool (gio open
,gvfs-open
,kde-open
,gnome-open
,dde-open
,exo-open
, and a host of other such tools). It is also installed by default, and very likely to work on past, current and future versions (on the other hand,gvfs-open
andgnome-open
have been deprecated, and may be unavailable in future releases).xdg-open
andgnome-open
xdg-open
is the most universal way (work also on KDE)If you want to:
open
)You can use this .bashrc function: