3

Knowing file extensions really helps to understand what a program is doing or using. What are some common one's and how do I extract them?

wojox
  • 11,362
  • 2
    Newbie questions spree tonite, @wojox ? In an OS where file extentions play little role, its quite "weird" to ask about the common ones, specially since most are inherited from Windows. – MestreLion Jun 10 '11 at 14:46
  • Is this what you are looking for? – Steven Jun 10 '11 at 09:25

3 Answers3

10

File extension are up to the creator of the file. In Linux you can name something music.mp3 but if it is a text file it will open with gedit if that is your texteditor because it will look at the 1st bit/byte(?) where it says what kind of file it is.

When it comes to bash script it is considered best practise to not include .sh at the end. By omitting it you basically create a command so those do not tend to even have an extension. And those commands could be made in bash but also in perl or python.

So looking at the actual name of the file might be misleading!

Linux has a command file to find out what a file is. Syntax file *
Some random samples:

xxxx.sql:    UTF-8 Unicode text, with very long lines
xxxx.sql.gz: gzip compressed data, was "xxxx.sql", from Unix, last modified: 
             Wed May 18 10:21:34 2011
yyyyy:       ASCII text
iffffff:     directory
ghgggg.tar:  POSIX tar archive (GNU)
fhhfhf.pl:   perl script text executable

For a list of extensions Fuddledumpy's post can be used and files ending on .pl will more than likely be perl scripts but to make sure use file.

Rinzwind
  • 299,756
  • So why does screenshot.png.odf: PNG image data, 601 x 317, 8-bit/color RGB, non-interlaced open in LibreOffice when I double-click it? – ændrük Jun 10 '11 at 13:35
  • That is a nautilus configuration, not using file output information. – enzotib Jun 10 '11 at 14:03
  • 1
    Because (of nautilus usage) of mimetypes: there are more than 1 images filetypes that can be openend by more than 1 program. He asked for a way in command line to identify files. screenshot.png.odf is an image from your example. screenshot.png.odf could also have shown you "Microsoft Office Document" if it was created in word ;) – Rinzwind Jun 10 '11 at 14:03
4

Be aware that Linux doesn't care too much about file name extensions. It determines the file type based on the file's contents/MIME type, so knowing a file extension doesn't give too much insight into a program's usage pattern.

See What is the relationship between MIME types and File .extensions? and How are file-extensions/mime-types/icons/default applications associated? for more info.

Christoph
  • 3,108
  • Linux may not care too much, whatever that means, but GNOME certainly does. Try gnome-opening a file with a misleading extension and you'll see what I mean. – ændrük Jun 10 '11 at 13:37
  • yeah, you're right, and I think gnome-open is messed up in that regard. – Christoph Jun 10 '11 at 14:10
  • @ændrük: Doesnt gnome-open follow MIME/type ? If so, file extension is only a part of the puzzle... not even the most important one – MestreLion Jun 10 '11 at 14:48
2

Technically, the list of known file extensions is stored in /usr/share/mime/globs. Here's a copy with nicer formatting.

I'm not sure how to decide which file extensions are "common". This list claims to be "common" but I think I've only ever run across about five percent of it.

ændrük
  • 76,794