September 16, 2010
On Sep 16, 10 04:35, "Jérôme M. Berger" wrote:
> Nick Sabalausky wrote:
>> "Jonathan M Davis"<jmdavisProg@gmx.com>  wrote in message
>> news:mailman.225.1284568096.858.digitalmars-d@puremagic.com...
>>> If you're on a non-Windows system, the mime-type becomes far more
>>> important than
>>> the extension. Most programs in Linux (and I believe MacOS X as well)
>>> don't care
>>> about the extension. They just look at the mime type. Extensions become
>>> almost
>>> entirely a thing for the user. So, whether your file is useable becomes
>>> more of
>>> an issue of known mime type than known extension. Still, you don't
>>> generally
>>> want to just be making up extensions.
>>>
>>
>> I didn't think unix file systems had a concept of mime type.
>>
> 	It doesn't, but Unix tools use the file contents to determine the
> mime type and then choose the app associated to the mime type.
>
> 		Jerome

Please don't confuse Unix with a distro.
September 16, 2010
Nick Sabalausky wrote:

> "Jonathan M Davis" <jmdavisProg@gmx.com> wrote in message news:mailman.227.1284590189.858.digitalmars-d@puremagic.com...
>> On Wednesday, September 15, 2010 12:48:32 Nick Sabalausky wrote:
>>> "Jonathan M Davis" <jmdavisProg@gmx.com> wrote in message news:mailman.225.1284568096.858.digitalmars-d@puremagic.com...
>>>
>>> > If you're on a non-Windows system, the mime-type becomes far more
>>> > important than
>>> > the extension. Most programs in Linux (and I believe MacOS X as well)
>>> > don't care
>>> > about the extension. They just look at the mime type. Extensions become
>>> > almost
>>> > entirely a thing for the user. So, whether your file is useable becomes
>>> > more of
>>> > an issue of known mime type than known extension. Still, you don't
>>> > generally
>>> > want to just be making up extensions.
>>>
>>> I didn't think unix file systems had a concept of mime type.
>>
>> They don't have a concept of file extension either. Mime types has to do
>> with the
>> contents of the file and file extensions has to do with the name of the
>> file. It's
>> programs which interpret those, not the file system. Typically, on
>> Windows, the
>> extension is used by the OS to determine which program to use to open a
>> file. In
>> unix, it's the mime type that's used to determine that.
>>
>> The one bit of overlap there is the fact that Windows treats the exe
>> extension
>> essentially the way that unix treats the executable file attribute.
>>
>> Now, I wouldn't advise ditching file extensions in unix, since it not only
>> can
>> help the human using them but there are occasionally programs which check
>> the
>> extension rather the mime type (so, ultimately, you may end up using both
>> the
>> extension and the mime type), but it's primarily the mime type which is
>> used,
>> and it's definitely the mime type which is used to determine which program
>> to use
>> to open a file in the desktop environments.
>>
> 
> Yea, but my question was more "how in the hell would it know the mime type of a file in the first place?" It's obviously not stored in the filename, and 99.9% is the time it's not stored in the file's data either.
> 
> Since then, someone mentioned it typically analyses the content of the file and infers the mime type based on that. That's news to me. It would seem limited and error-prone though, so I have a hard time believing it doesn't suppliment that content-analysis with extension-checking in many cases.

Such a combination is sometimes used. Dolphin for example gives precedence to some extensions. But you'd be surprised how good content analysis alone works, for 99% of files I open from the desktop there is no extension required - it just works. Mostly you have either plain text or a well defined binary format.
September 16, 2010
On Thu, 16 Sep 2010 01:16:20 -0400, Nick Sabalausky <a@a.a> wrote:

> "Jonathan M Davis" <jmdavisProg@gmx.com> wrote in message
> news:mailman.227.1284590189.858.digitalmars-d@puremagic.com...
>> On Wednesday, September 15, 2010 12:48:32 Nick Sabalausky wrote:
>>> "Jonathan M Davis" <jmdavisProg@gmx.com> wrote in message
>>> news:mailman.225.1284568096.858.digitalmars-d@puremagic.com...
>>>
>>> > If you're on a non-Windows system, the mime-type becomes far more
>>> > important than
>>> > the extension. Most programs in Linux (and I believe MacOS X as well)
>>> > don't care
>>> > about the extension. They just look at the mime type. Extensions  
>>> become
>>> > almost
>>> > entirely a thing for the user. So, whether your file is useable  
>>> becomes
>>> > more of
>>> > an issue of known mime type than known extension. Still, you don't
>>> > generally
>>> > want to just be making up extensions.
>>>
>>> I didn't think unix file systems had a concept of mime type.
>>
>> They don't have a concept of file extension either. Mime types has to do
>> with the
>> contents of the file and file extensions has to do with the name of the
>> file. It's
>> programs which interpret those, not the file system. Typically, on
>> Windows, the
>> extension is used by the OS to determine which program to use to open a
>> file. In
>> unix, it's the mime type that's used to determine that.
>>
>> The one bit of overlap there is the fact that Windows treats the exe
>> extension
>> essentially the way that unix treats the executable file attribute.
>>
>> Now, I wouldn't advise ditching file extensions in unix, since it not only
>> can
>> help the human using them but there are occasionally programs which check
>> the
>> extension rather the mime type (so, ultimately, you may end up using both
>> the
>> extension and the mime type), but it's primarily the mime type which is
>> used,
>> and it's definitely the mime type which is used to determine which program
>> to use
>> to open a file in the desktop environments.
>>
>
> Yea, but my question was more "how in the hell would it know the mime type
> of a file in the first place?" It's obviously not stored in the filename,
> and 99.9% is the time it's not stored in the file's data either.

Most binary file formats are designed to be detectable using a "magic number" that's found at the front of the file.  This magic number allows programs to easily determine the file type.

So yeah, it is stored in the file's data :)

> Since then, someone mentioned it typically analyses the content of the file
> and infers the mime type based on that. That's news to me. It would seem
> limited and error-prone though, so I have a hard time believing it doesn't
> suppliment that content-analysis with extension-checking in many cases.

I think it's a combination of many things.  Try the Linux 'file' command to see how it detects all different types of files.

-Steve
September 16, 2010
KennyTM~ wrote:
> On Sep 16, 10 04:35, "Jérôme M. Berger" wrote:
>> Nick Sabalausky wrote:
>>> I didn't think unix file systems had a concept of mime type.
>>>
>>     It doesn't, but Unix tools use the file contents to determine the
>> mime type and then choose the app associated to the mime type.
>>
>>         Jerome
> 
> Please don't confuse Unix with a distro.

	Which distro? I used the terms "Unix tools" because it transcends
distributions and Unices. It is as true on Ubuntu as on *BSD or
Solaris...

		Jerome
-- 
mailto:jeberger@free.fr
http://jeberger.free.fr
Jabber: jeberger@jabber.fr



September 16, 2010
Jérôme M. Berger wrote:
> KennyTM~ wrote:
>> On Sep 16, 10 04:35, "Jérôme M. Berger" wrote:
>>> Nick Sabalausky wrote:
>>>> I didn't think unix file systems had a concept of mime type.
>>>>
>>>     It doesn't, but Unix tools use the file contents to determine the
>>> mime type and then choose the app associated to the mime type.
>>>
>>>         Jerome
>> Please don't confuse Unix with a distro.
> 
> 	Which distro? I used the terms "Unix tools" because it transcends
> distributions and Unices. It is as true on Ubuntu as on *BSD or
> Solaris...
> 
> 		Jerome
BTW: http://www.darwinsys.com/file/
<quote>
Unlike most GUI systems, command-line UNIX systems - with this
program leading the charge - don't rely on filename extentions to
tell you the type of a file, but look at the file's actual contents.
</quote>

	They say "UNIX systems", they don't say "Ubuntu" (which I don't use
anyway).

		Jerome
-- 
mailto:jeberger@free.fr
http://jeberger.free.fr
Jabber: jeberger@jabber.fr



September 16, 2010
On 2010-09-15 21:48, Nick Sabalausky wrote:
> "Jonathan M Davis"<jmdavisProg@gmx.com>  wrote in message
> news:mailman.225.1284568096.858.digitalmars-d@puremagic.com...
>>
>> If you're on a non-Windows system, the mime-type becomes far more
>> important than
>> the extension. Most programs in Linux (and I believe MacOS X as well)
>> don't care
>> about the extension. They just look at the mime type. Extensions become
>> almost
>> entirely a thing for the user. So, whether your file is useable becomes
>> more of
>> an issue of known mime type than known extension. Still, you don't
>> generally
>> want to just be making up extensions.
>>
>
> I didn't think unix file systems had a concept of mime type.

I'm pretty sure HFS+ (Mac OS X) has some type of metadata in the file system.

-- 
/Jacob Carlborg
September 16, 2010
"Steven Schveighoffer" <schveiguy@yahoo.com> wrote in message news:op.vi4kyub1eav7ka@localhost.localdomain...
> On Thu, 16 Sep 2010 01:16:20 -0400, Nick Sabalausky <a@a.a> wrote:
>>
>> Yea, but my question was more "how in the hell would it know the mime
>> type
>> of a file in the first place?" It's obviously not stored in the filename,
>> and 99.9% is the time it's not stored in the file's data either.
>
> Most binary file formats are designed to be detectable using a "magic number" that's found at the front of the file.  This magic number allows programs to easily determine the file type.
>
> So yeah, it is stored in the file's data :)
>

Yea, I know, but I was thinking more about text formats (and the rare binary formats that don't have that). A lot of text-based formats out there don't use shebang syntax. And a lot of them are just small variations on each other (at least from a type-detection standpoint).

>> Since then, someone mentioned it typically analyses the content of the
>> file
>> and infers the mime type based on that. That's news to me. It would seem
>> limited and error-prone though, so I have a hard time believing it
>> doesn't
>> suppliment that content-analysis with extension-checking in many cases.
>
> I think it's a combination of many things.  Try the Linux 'file' command to see how it detects all different types of files.
>

Yea, that makes sence. Never knew that before though, I just assumed it was just extensions and shebang syntax.


September 16, 2010
On Sep 17, 10 02:26, "Jérôme M. Berger" wrote:
> Jérôme M. Berger wrote:
>> KennyTM~ wrote:
>>> On Sep 16, 10 04:35, "Jérôme M. Berger" wrote:
>>>> Nick Sabalausky wrote:
>>>>> I didn't think unix file systems had a concept of mime type.
>>>>>
>>>>      It doesn't, but Unix tools use the file contents to determine the
>>>> mime type and then choose the app associated to the mime type.
>>>>
>>>>          Jerome
>>> Please don't confuse Unix with a distro.
>>
>> 	Which distro? I used the terms "Unix tools" because it transcends
>> distributions and Unices. It is as true on Ubuntu as on *BSD or
>> Solaris...
>>
>> 		Jerome
> BTW: http://www.darwinsys.com/file/
> <quote>
> Unlike most GUI systems, command-line UNIX systems - with this
> program leading the charge - don't rely on filename extentions to
> tell you the type of a file, but look at the file's actual contents.
> </quote>
>
> 	They say "UNIX systems", they don't say "Ubuntu" (which I don't use
> anyway).
>
> 		Jerome

This describes the file(1) command, which the job is to inspect the file content and conclude what kind of file it actually is.

But this is just one particular UNIX command. The command line interface in general does not care about the type of a regular file. This is needed in the GUI, but it is outside of the common parts of UNIX. There is no rule saying that a file manager must use file(1) or MIME type or extensions to determine the file type.

September 17, 2010
KennyTM~ wrote:
> On Sep 17, 10 02:26, "Jérôme M. Berger" wrote:
>> Jérôme M. Berger wrote:
>>> KennyTM~ wrote:
>>>> On Sep 16, 10 04:35, "Jérôme M. Berger" wrote:
>>>>> Nick Sabalausky wrote:
>>>>>> I didn't think unix file systems had a concept of mime type.
>>>>>>
>>>>>      It doesn't, but Unix tools use the file contents to determine the
>>>>> mime type and then choose the app associated to the mime type.
>>>>>
>>>>>          Jerome
>>>> Please don't confuse Unix with a distro.
>>>
>>>     Which distro? I used the terms "Unix tools" because it transcends
>>> distributions and Unices. It is as true on Ubuntu as on *BSD or
>>> Solaris...
>>>
>>>         Jerome
>> BTW: http://www.darwinsys.com/file/
>> <quote>
>> Unlike most GUI systems, command-line UNIX systems - with this
>> program leading the charge - don't rely on filename extentions to
>> tell you the type of a file, but look at the file's actual contents.
>> </quote>
>>
>>     They say "UNIX systems", they don't say "Ubuntu" (which I don't use
>> anyway).
>>
>>         Jerome
> 
> This describes the file(1) command, which the job is to inspect the file content and conclude what kind of file it actually is.
> 
	I suggest you re-read the paragraph I posted. Although it was taken
from the "file" web site, it states clearly that other apps look at
the file contents instead of the extension. Of course, some apps
don't care about the file type but some do. And most of those that
do care don't use the extension.

> But this is just one particular UNIX command. The command line interface in general does not care about the type of a regular file. This is needed in the GUI, but it is outside of the common parts of UNIX. There is no rule saying that a file manager must use file(1) or MIME type or extensions to determine the file type.
> 
	True, but then, there is no rule that says that on windows a file
manager must use the extension. However, on Windows, all the file
managers I've tried have used the extension (actually, most of the
time they don't use the extension themselves, they simply ask
Windows to open the file and Windows uses the extension), whereas on
UNIX most file managers use the file contents (usually, they don't
use the file command, but instead rely on libmagic directly) and
most applications will ignore the extension when asked to open a
file (OK, some Windows applications do that too but on *NIX most of
them do).

		Jerome
-- 
mailto:jeberger@free.fr
http://jeberger.free.fr
Jabber: jeberger@jabber.fr



September 17, 2010
On Friday 17 September 2010 13:24:36 Jérôme M. Berger wrote:
> KennyTM~ wrote:
> > On Sep 17, 10 02:26, "Jérôme M. Berger" wrote:
> >> Jérôme M. Berger wrote:
> >>> KennyTM~ wrote:
> >>>> On Sep 16, 10 04:35, "Jérôme M. Berger" wrote:
> >>>>> Nick Sabalausky wrote:
> >>>>>> I didn't think unix file systems had a concept of mime type.
> >>>>>> 
> >>>>>      It doesn't, but Unix tools use the file contents to determine
> >>>>>      the
> >>>>> 
> >>>>> mime type and then choose the app associated to the mime type.
> >>>>> 
> >>>>>          Jerome
> >>>> 
> >>>> Please don't confuse Unix with a distro.
> >>>> 
> >>>     Which distro? I used the terms "Unix tools" because it transcends
> >>> 
> >>> distributions and Unices. It is as true on Ubuntu as on *BSD or Solaris...
> >>> 
> >>>         Jerome
> >> 
> >> BTW: http://www.darwinsys.com/file/
> >> <quote>
> >> Unlike most GUI systems, command-line UNIX systems - with this
> >> program leading the charge - don't rely on filename extentions to
> >> tell you the type of a file, but look at the file's actual contents.
> >> </quote>
> >> 
> >>     They say "UNIX systems", they don't say "Ubuntu" (which I don't use
> >> 
> >> anyway).
> >> 
> >>         Jerome
> > 
> > This describes the file(1) command, which the job is to inspect the file content and conclude what kind of file it actually is.
> 
> 	I suggest you re-read the paragraph I posted. Although it was taken
> from the "file" web site, it states clearly that other apps look at
> the file contents instead of the extension. Of course, some apps
> don't care about the file type but some do. And most of those that
> do care don't use the extension.
> 
> > But this is just one particular UNIX command. The command line interface in general does not care about the type of a regular file. This is needed in the GUI, but it is outside of the common parts of UNIX. There is no rule saying that a file manager must use file(1) or MIME type or extensions to determine the file type.
> 
> 	True, but then, there is no rule that says that on windows a file
> manager must use the extension. However, on Windows, all the file
> managers I've tried have used the extension (actually, most of the
> time they don't use the extension themselves, they simply ask
> Windows to open the file and Windows uses the extension), whereas on
> UNIX most file managers use the file contents (usually, they don't
> use the file command, but instead rely on libmagic directly) and
> most applications will ignore the extension when asked to open a
> file (OK, some Windows applications do that too but on *NIX most of
> them do).
> 
> 		Jerome

It's so ingrained in Unix  that extension isn't what matters that it totally threw me of at one point when I couldn't get my flac files to play in audacious. The file browser clearly indicated that they were flac files, but audacious wouldn't put them in its playlist. It turns out that audacious _does_ use the extension, and I had screwed up with the settings on my CD ripper such that there was no extension on the files, so audacious didn't think that it could read them. That's the only time that I've ever seen that sort of problem in Linux. Pretty much everything uses mime type.

- Jonathan M Davis