Exploring file types in Linux

Exploring file types in Linux

My setup

I don't actually run a Linux desktop, strictly speaking - I use MobaXTerm on my Windows laptop to ssh in. Moba runs an X server, so I can open windows from the Linux machine as if they were native Windows ... windows.

(I feel that sentence got away from me a little.)

My Linux usage is probably slightly atypical, but I'm willing to bet there's quite a few of us doing that now.

The problem

Recently I had a problem getting Firefox to open a file manager window. Since it was opening a filer window, rather than a specific file type, the usual Firefox settings didn't help me.

Brief tangent... MIME types

If you don't want to know the why, skip to the next section. 😊

MIME is (strictly speaking) an email standard. MIME types are a general/specific pair describing the nature of a resource. For example:

  • text/html
  • image/jpeg
  • application/octet-stream

It turns out that (a) the database of file types that's been built up is quite extensive, and (b) this is useful for helping programs other than email apps to know how to handle something.

The solution

We finally got there.

The MIME type of a directory? inode/directory

(“What's an inode?” is a whole other post... the Wikipedia article will have to do for now!)

So - what I needed was to change the default program used to open that type. Enter xdg-mime:

xdg-mime default nemo.desktop inode/directory 

(Note: the tool takes .desktop files rather than the program path.)

Useful extras

I also found a couple of other useful things:

  1. file -bi will give you file’s best guess at a MIME type
  2. xdg-open should act like open does on macOS, which is great as I find that really useful.
  3. There's a whole ton of stuff in this area if people are curious for more.

(Post image thanks to Alexander Sinn.)

Subscribe to Paul Walker

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.