Find the answer to your Linux question:
Results 1 to 5 of 5
Windows depend on the extension of the file to decide its type: .doc > Doccument .bat > Batch File .zip > Compressed File ...etc What does Linux depend on to ...
  1. #1
    Just Joined!
    Join Date
    Aug 2005
    Posts
    54

    File Type In Linux

    Windows depend on the extension of the file to decide its type:
    .doc > Doccument
    .bat > Batch File
    .zip > Compressed File ...etc

    What does Linux depend on to decide the type of the file?

    Another Related Question:

    in Windows u could save a test file as *.bat and it will work as command prompt
    what should I save the text file in Linux so it would work as Terminal Program directly??

  2. #2
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    Nothing so primitive for Linux

    You can use filetype associations, but ultimately the filetype is determined by a 'magic number'. If you look at shell scripts they always start with
    Code:
    #!/bin/bash
    The #! is the file start and it indicates that the file is an executable script. It's the same for most dedicated filetypes. For example, take a jpeg and remove the .jpg extension - it will still be recognised that it is a jpeg because the start of the file already indicates that it is. It is the same for most files, the exception being when a file is just a generic text file; .html, .xml, .txt for example. In this case the file extension is helpful.

  3. #3
    Just Joined!
    Join Date
    Aug 2005
    Posts
    54
    in Windows u could save a test file as *.bat and it will work as command prompt
    what should I save the text file in Linux so it would work as Terminal Program directly??

  4. #4
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Right. You can use the 'file' command to find out what type of file a file is.

    As far as making executable scripts, this is done by setting the executable permission. I have a big explanation on UNIX permissions at:
    http://www.linuxforums.org/forum/lin...y-group-2.html
    (about halfway down the page)

    This allows you to execute the script by giving its absolute path. For instance, if I have a script at /home/user/my_script, I need to type out that entire path. If you want to be able to run the script from anywhere, you need to add it to a location in your $PATH variable. Just run the command:
    Code:
    echo $PATH
    to see all the locations that you could put it.
    DISTRO=Arch
    Registered Linux User #388732

  5. #5
    Linux Guru Juan Pablo's Avatar
    Join Date
    Mar 2006
    Location
    /home/south_america/ecuador/quito
    Posts
    2,064
    Linux uses what is called 'magic' , it identifies the files with the first bytes found in the file. For example #! are two 'magic' characters that define an script.

    You don't need to name a file in a particular manner to make it run as a script, you write the magic, next the interpreter, make it executable and it should just work.
    More info 'man magic'
    For example:

    #!/usr/bin/perl

    will tell the shell that your script needs to be interpreted by the 'perl' binary found on /usr/bin

    EDIT: All you are quick
    Put your hand in an oven for a minute and it will be like an hour, sit beside a beautiful woman for an hour and it will be like a minute, that is relativity. --Albert Einstein
    Linux User #425940

    Don't PM me with questions, instead post in the forums

Posting Permissions

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