Internal and External Command-Linux Unix with example
What is difference between internal and external command in linux / Unix ?
Internal commands are the commands that are executed directly by the shell. These commands will not have a separate process running for each.External commands are the commands that are executed by the kernal. These commands will have a process id running for it.
Since ls is a program or file having an independent existence in the /bin directory or /user/bin, it is branded as an external command. Most commands are external in nature, but there are some which are not really found any where, and some which are normally not executed even if they are in one of the directories specified by PATH. Lets see with example-
$ type echo
echo is a shell built in
echo is not an external command in the same that, when you type echo , the system won’t look in its PATH to locate it (even if it is there in /bin). Rather, it will execute it from its own set of built-in commands there are stored as separate files. These built in commands , of which echo is a member , are known as internal commands.
Now see ls commands i .e and external command
$ type ls
ls is /bin/ls
We have been attributing all this hunting work to “system” as , if there is such a thing as a system. The agency that actually does all this work is knows as shell. which starts running for you when you log in , and dies when you log out. The shell , which itself is a command, possesses its own set of commands and even if there’s a command of the same name in /bin or /usr/bin, the shell will accord top priority to its own internal command of the same name.
This is exactly the case with echo, which is also to be found in /bin, but rarely ever executed because the shell builtin almost always makes sure that the internal command echo takes precedence over the external.
The sequence of directories that the system will search to look for a command is specified in its own PATH variable. If you evaluate the value of this variable , you will find a directory list separated by colons (:)
$ echo $PATH
There are six directories in this list, and when you issue a command, the system will search this list in the sequence specified to locate and execute it. Note that this list also includes the current directory indicated by a singular dot at the end