Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora Resources > Guides & Solutions (Not For Questions)
FedoraForum Search

Forgot Password? Join Us!

Guides & Solutions (Not For Questions) Post your guides here (No links to Blogs accepted). You can also append your comments/questions to a guide, but don't start a new thread to ask a question. Use another forum for that.

Thread Tools Search this Thread Display Modes
Old 17th January 2012, 12:52 PM
Registered User
Join Date: Jan 2011
Posts: 353
linux set file associations from the command line

At various times it is helpful to know how to setup file associations from the command line. Sometimes file managers just won't work, other times you may have a corrupted file or bad line in your file. I will give 3 examples.

Pick out out a file of the type of file you want to set.
I picked an avi, m4a, and jpg.
Then query the file to figure out the mimetype syntax.
xdg-mime query filetype /home/bob/Downloads/vid1.avi
Check what the default program is of that mimetype.
Figure out what the programname.desktop of the program you want to use is. The simplest way to do this is by checking your mimeapps.list file located here. Obviously change your username.
vi /home/bob/.local/share/applications/mimeapps.list
If that doesn't work try searching for the file with a similar command.
find / -iname '*vlc.desktop*' 2>/dev/null
If the programname.desktop file has a weird name then you will need to grep for that file. Handbrake has the weirdest file name I have seen so I will use that as my example.
sudo grep -riI "handbrake" /usr/share/applications/* 2>/dev/null
Check what the default program is of that mimetype.
xdg-mime query default video/x-msvideo
Set the file association.
xdg-mime default vlc.desktop video/x-msvideo
The examples.
xdg-mime query filetype /home/bob/Downloads/vid1.avi
xdg-mime query default video/x-msvideo
xdg-mime default vlc.desktop video/x-msvideo
xdg-mime query filetype /media/3CACE1E0ACE194A4/Anthem.m4a
xdg-mime query default audio/mp4
xdg-mime default vlc.desktop audio/mp4
xdg-mime query filetype /home/bob/Downloads/shellr.jpg
xdg-mime query default image/jpeg
xdg-mime default gwenview.desktop image/jpeg
Verify that what you were trying to set worked. First check the mimeapps.list. Then use your favorite file manager to verify your work or use xdg-open.
vi /home/bob/.local/share/applications/mimeapps.list
xdg-open /home/bob/Downloads/vid1.avi
Reply With Quote

associations, command, file, line, linux, set

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Video file properties on the command line? scruffy72 Using Fedora 10 21st September 2012 08:39 AM
Get video file attributes from command line szilagyic Using Fedora 2 17th October 2009 03:29 AM
Command line to get output on a file satimis Programming & Packaging 4 26th June 2005 02:21 PM
How do I edit a file in the command line? BoomerFZ1 Using Fedora 3 5th April 2005 08:28 PM

Current GMT-time: 15:04 (Friday, 22-09-2017)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat