There are two ways a MIME type and a .desktop
file are associated.
Method 1
The first way is through *.list
MIME config files (many exist on the system, see below). For example, a typical entry in ~/.local/share/applications/mimeapps.list
might be:
[Default Applications]
application/x-bittorrent=transmission.desktop;deluge.desktop
This means that the preferred application is transmission
, if it cannot be found, then the second choice is deluge
.
Method 2
The second way is through the .desktop
file itself. The application advertises which MIME types it can open. For example, in transmission-gtk.desktop
, we have the following line
MimeType=application/x-bittorrent;x-scheme-handler/magnet;
which indicates that this program can handle those two MIME types.
Which Application To Use?
The association between MIME types and Applications is defined by the freedesktop.org
standards. Here are the steps taken when determining which application (i.e. which .desktop
file) to launch for a given MIME type.
Step 1: Look for an association in the MIME config files. The lookup order is as follows:
$XDG_CONFIG_HOME/$desktop-mimeapps.list
$XDG_CONFIG_HOME/mimeapps.list
$XDG_CONFIG_DIRS/$desktop-mimeapps.list
$XDG_CONFIG_DIRS/mimeapps.list
$XDG_DATA_HOME/applications/$desktop-mimeapps.list
$XDG_DATA_HOME/applications/mimeapps.list
$XDG_DATA_DIRS/applications/$desktop-mimeapps.list
$XDG_DATA_DIRS/applications/mimeapps.list
Step 2: Once all levels have been checked, if no entry could be found, the implementations can pick any of the .desktop
files associated with the MIME type, taking into account added and removed associations (which exist in the MIME config files).
Although you do not have any MIME config files, the reason that transmission
is being used is because of Step 2 as defined by the standard. Check your transmission-gtk.desktop
file to see whether it advertises its ability to open torrents.
I suggest reading the linked document for a full understanding.
From this answer in What makes grep consider a file to be binary?
If there is a NUL character anywhere in the file, grep will consider it as a binary file.
There might a workaround like this cat file | tr -d '\000' | yourgrep
to eliminate all null first, and then to search through file.
I first tried it with one file in a test directory:
parto@subroot:~/Desktop/test$ ls
info_pdslpostpaid.log-20160518
parto@subroot:~/Desktop/test$ cat info_pdslpostpaid.log-20160518 | tr -d '\000' > info_pdslpostpaid.log-20160518_edited
parto@subroot:~/Desktop/test$ ls
info_pdslpostpaid.log-20160518 info_pdslpostpaid.log-20160518_edited
parto@subroot:~/Desktop/test$
And the result, a plain text document (text/plain)
text mime file.
Then since I am working with multiple files, I tried running the same command for multiple files in a directory:
parto@subroot:~/Desktop/test$ ls
info_pdslpostpaid.log-20160518 info_pdslpostpaid.log-20160520 info_pdslpostpaid.log-20160523 info_pdslpostpaid.log-20160525
parto@subroot:~/Desktop/test$ for i in * ; do cat "$i" | tr -d '\000' > "${i}_edited" ; done
parto@subroot:~/Desktop/test$ ls
info_pdslpostpaid.log-20160518 info_pdslpostpaid.log-20160520_edited info_pdslpostpaid.log-20160525
info_pdslpostpaid.log-20160518_edited info_pdslpostpaid.log-20160523 info_pdslpostpaid.log-20160525_edited
info_pdslpostpaid.log-20160520 info_pdslpostpaid.log-20160523_edited
parto@subroot:~/Desktop/test$
And awesome, all my log files are now in a readable format!! :)
Best Answer
Save the following as e.g.
less.xml
:Then open a Terminal and run
Now all files with the extension
.less
should have the MIME typetext/x-less
.See Shared MIME-info Database if you want to learn more about how MIME types are defined.