Internal and External Linux commands

Linux commands can be classified into two categories :

  1. External
  2. Internal

Let’s look into what External Linux commands are.

External commands programs with files in /bin directory (In Linux, everything is represented in the form of files). If the files are not present in the path specified by the $PATH variable, they do not get executed. Similarly, if the files are available but are not present int the path specified by $PATH, the commands cannot be executed. Another point worth noting is that every time an external command gets executed, a new process gets spawned.

Internal commands are those which are directly executed by the shell. These are built-ins in the shell. They do not depend on paths since they are not coded in files. Unlike external commands no process is created when an internal command is executed.

How to distinguish between internal and external commands ?

There is a Linux command type, which (quoting the Wikipedia) specifies how its arguments would be interpreted if they were used as a command name. This command could be used to identify between the two types of commands. Execute the command : type <command>

If the output states that the command is shell built-in, it is an internal command. Instead, if the output states that the command is present in /bin, then it is an external command.

For example, cd and pwd are examples of internal commands.


savita@Amrita:~$ type cd
cd is a shell builtin
savita@Amrita:~$ type pwd
pwd is a shell builtin
savita@Amrita:~$

cp and mv are examples of external commands.


savita@Amrita:~$ type cp
cp is /bin/cp
savita@Amrita:~$ type mv
mv is /bin/mv
savita@Amrita:~$

However, there might be certain commands which have files in /bin directory and at the same time, are also built-ins in the shell. In such cases, the first preference would always be given to the internal command, meaning that, even if the corresponding file did not exist, it would be executed by the shell as a built-in. One example is the Linux command echo.

Differences between the two types of commands :

Summarizing the above two paragraphs, some of the differences between internal and external commands (from what I understood about them) are :

External Linux Commands

Internal Linux Commands

These are executed by the kernel. These are executed by the shell.
A separate process is spawned every time a new external command is executed. No new process is created.
These are separate files in /bin directory. The execution of these commands happens through the execution of their corresponding files in /bin directory. These are built-ins in the shell. The execution of these commands happens through the execution of their corresponding files in /bin directory.
A few examples are cp, mv, etc. Some examples are cd, pwd, etc.

References : 1   2

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s