Wednesday, November 2, 2011

Internal and External Commands

Unix commands are grouped into two categories-Internal and External. There is a set of commands which are part of the shell and to execute them the shell does not need to search the given path in the PATH  variable. These are also called  shell builtins or Internal Commands. The shell does not fork a new process for these commands.

Commands that are available as independently compiled C programs usually located in the /bin or the /usr/bin directory are called  External Commands.  The shell searches the path for these command files. An example is the 'ls ' command which is used for directory listing.

To find out whether a particular command is Internal or External  and to find out the location of  an External Command, the 'type' command is used.

Example:

$ type ls
       ls is /bin/ls
the above command returns the location or the path of the ls command .Therefore ls is an external command.

$ type echo
          echo is a shell builtin
the 'echo' command is an Internal Command or a shell builtin.

$ type LS
         LS: not found

As unix is case sensitive the shell cannot locate the ls command when typed in upper case(capitals).

In the next post I shall list out some  unix utilities.

1 comment: