HOW TO SET FILE ASSOCIATIONS OF FILE WITH COMMAND LINE IN LINUX

QUES: Why would one choose to use command line for changing file associaiton……..?
ANS: Several times you come across a situation when you have to setup file associations from the command line. Like sometimes, file managers just won’t work, other times you may have a corrupted file or bad line in your file.It involves just 3 steps as follows :

STEP 1) Then query the file to figure out the mimetype syntax

[user@linux:~]$xdg-mime query filetype /home/linux/Desktop/vid.flv
[user@linux:~]$video/x-flv

STEP 2) Check what the default program is of that mimetype.

[user@linux:~]$xdg-mime query default video/x-flv

STEP 3) Set the file association

[user@linux:~]$xdg-mime default vlc.desktop

NOTE :– Here I knew the programme name to be associated with the new filetype, so I jumped to the step 3 after the step 2. If you dont know the programme names and there association then follow these steps.

ADDITIONAL STEP :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.

[user@linux:~]$vi /home/linux/.local/share/applications/mimeapps.list

If that doesn’t work try searching for the file with a similar command.

[user@linux:~]$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.Here I will use the vlc media player.

[user@linux:~]$grep -ri "vlc media player" /usr/share/applications/* 2>/dev/null
[user@linux:~]$/usr/share/applications/vlc.desktop:Name=VLC media player

For Centos/Fedora/Rhel users if they find this error while changing the file types —

[user@linux:~]$/usr/bin/xdg-mime: line 532: kde-config: command not found

follow this link(https://bugs.freedesktop.org/show_bug.cgi?id=25563#c2)

[user@linux:~]$find / -iname '*vlc.desktop*' 2>/dev/null
About

learn and share the happening in world of linux

Tagged with: , , ,
Posted in Linux

Leave a comment

  • An error has occurred; the feed is probably down. Try again later.
  • An error has occurred; the feed is probably down. Try again later.
  • An error has occurred; the feed is probably down. Try again later.