Find the answer to your Linux question:
Results 1 to 4 of 4
hey i have question !! i want to know how linux recognize file type without extensions ? in windows every file has its own extension but in linux some file ...
  1. #1
    Just Joined!
    Join Date
    Dec 2008
    Posts
    3

    Extensions

    hey
    i have question !! i want to know how linux recognize file type without extensions ?
    in windows every file has its own extension but in linux some file hasn't any extension but linux can open it with suitable app!!
    thanks for answers.

  2. #2
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    Most filetypes have a header in the file describing what they are. Windows is no different but sticks with the DOS way of doing things, the file extension.

    If you open a terminal you can use the file command to see what properties a particular file has. Have a look at this example, I'm running file againsta CD ISO image.
    Code:
    tom@btrprime:~/iso$ file osol-0811.iso 
    osol-0811.iso: ISO 9660 CD-ROM filesystem data 'OpenSolaris                    ' (bootable)
    tom@btrprime:~/iso$

  3. #3
    Just Joined!
    Join Date
    Dec 2008
    Posts
    3
    so...i think windows is a bit faster because windows don't open a file to recognize it's type.(only for showing the filetype not executing the file i mean)

  4. #4
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    No not really, Linux (and all Unix-like systems) achieve this by reading only the first few bytes of a file to retrieve this information. In many cases it'd be less information than even reading the file name!

    For example, you may have seen in Linux bash scripts the first line is always
    Code:
    #!/bin/bash
    The most important thing there is !#. Those two characters combined represent the information to tell Linux that it is an executable.

    Have a read about magic numbers and the shebang:

    File format - Wikipedia, the free encyclopedia
    Shebang (Unix) - Wikipedia, the free encyclopedia
    File format - Wikipedia, the free encyclopedia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...