Does the command line have a way to get a recommended list of programs used to open a particular file, based on the file type? For example, a .pdf
file would have an open with...
recommendation using the programs Evince
and Document Viewer
.
I use the command line for most things, but sometimes I forget the name of a program that I want to use to open a particular type of file.
BTW I am using Ubuntu 13.10.
pro-tip
Thanks to @slm 's selected answer below, I made the following bash script in a file called openwith.sh
:
xdg-mime query default $(xdg-mime query filetype $1)
Add as an alias or execute directly as an openwith
command.
Best Answer
There isn't a command that I've ever seen that will act as "open with..." but you can use the command
xdg-open <file>
to open a given<file>
in the application that's associated with that particular type of file.Examples
Opening a text file:
Resulting in the file
tstfile.txt
being opened ingedit
:Opening a LibreOffice Writer document:
Resulting in the file
tstfile.odt
being opened in Writer:What apps get used?
You can use
xdg-mime
to query the system to find out what applications are associated to a given file type.This is a 2 step operation. First I'm querying for the mime-type of a given file,
xdg-mime query filetype tstfile.txt
, which will returntext/plain
. This is then used to perform another lookup to find out the list of applications that are associated with this mime-type. As you can see above I have 2 apps associated,gedit
andcalibre
, for.txt
files.You can use
xdg-mime
to change the associations too. Seeman xdg-mime
for more details.