# Finding an icon for a file in Linux

**URL:** <https://www.ruby-forum.com/t/finding-an-icon-for-a-file-in-linux/186702>\
**Category:** Ruby\
**Created:** [April 11, 2010, 9:10pm UTC](https://www.ruby-forum.com/t/finding-an-icon-for-a-file-in-linux/186702 "2010-04-11T21:10:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [April 11, 2010, 9:10pm UTC](https://www.ruby-forum.com/t/finding-an-icon-for-a-file-in-linux/186702/1 "2010-04-11T21:10:01Z")

</div>

Hi,

I am writing a file manager and am looking for the best way to get the  
icon for a file type. I am assuming it uses mimetypes, but I haven’t  
found a good solution yet. If anyone could point me in the right  
direction I’d appreciate it.

Thanks.

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [April 12, 2010, 2:49am UTC](https://www.ruby-forum.com/t/finding-an-icon-for-a-file-in-linux/186702/2 "2010-04-12T02:49:30Z")

</div>

Riccardo Cecolin wrote:

> John B. wrote:
> 
> > Hi,
> > 
> > I am writing a file manager and am looking for the best way to get the  
> > icon for a file type. I am assuming it uses mimetypes, but I haven’t  
> > found a good solution yet. If anyone could point me in the right  
> > direction I’d appreciate it.
> > 
> > Thanks.
> 
> You could parse output of “file” command:  
> [file (command) - Wikipedia](http://en.wikipedia.org/wiki/File_(command))  
> [http://en.wikipedia.org/wiki/File\_(command)](http://en.wikipedia.org/wiki/File_%28command%29)

As far as I can tell, that will only tell me the mimetype. My main  
problem really is that I can’t take the mimetype and use it to find the  
icon file. I already found the gem that will determine the mimetype.  
([http://mime-types.rubyforge.org/](http://mime-types.rubyforge.org/))

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [April 12, 2010, 1:20am UTC](https://www.ruby-forum.com/t/finding-an-icon-for-a-file-in-linux/186702/3 "2010-04-12T01:20:03Z")

</div>

John B. wrote:

> Hi,
> 
> I am writing a file manager and am looking for the best way to get the  
> icon for a file type. I am assuming it uses mimetypes, but I haven’t  
> found a good solution yet. If anyone could point me in the right  
> direction I’d appreciate it.
> 
> Thanks.

You could parse output of “file” command:

> **[file (command)](https://en.wikipedia.org/wiki/File_(command))**
>
> The file command is a standard program of Unix and Unix-like operating systems for recognizing the type of data contained in a computer file.
> The original version of file originated in Unix Research Version 4 in 1973. System V brought a major update with several important changes, most notably moving the file type information into an external text file rather than compiling it into the binary itself.
> Most major BSD and Linux distributions use a free, open-source reimplementation which was writt...

[http://en.wikipedia.org/wiki/File\_(command)](http://en.wikipedia.org/wiki/File_%28command%29)
