How Linux commands are executed

Working with the shell, is where the user interfaces with the system to execute command syntax into instructions for the linux kernel.

The kernel being the system’s core manages the system’s hardware and software resources receives the instruction from the shell to perform the desired action.

Command Line Syntax – In 3 parts:

  1. Command – instructs the kernel to perform a task
  2. Options – modifies the behavior of a command
  3. Arguement – can: modify the behavior of a command as well as specify where the command should do its work (target).

Example:

  1. Command: ls instructs to list directory contents.
  2. Option: – l instructs to use the long listing format
  3. Arguement: /etc instucts to go to this target to obtain the long listing format list.

The shell makes distinctions between 3 different types of commands such as:

1. Alias – a type of shortcut command that a user can define as needed for instance using the example above, if you find yourself typing the command ls -l alot. An alias of ll could be created with the following command.

2. Internal command – this type of command is a part of the shell itself, which doesn’t have to be loaded separately making it faster to load.

Let’s try another command such as pwd (present working directory)

A shell builtin – is an internal command.

3. External command – a command that exist in an executable file on the disk of the computer, its slower than an internal command because it has to be read from the disk of the computer.

To determine the command type…

When a command is entered the shell looks for an intenal command first, if its not found it then searches for an executable file (external) with the name that matches the command on the disk.

For instance:

$PATH is an environment variable that stores colon-separated list of directories. When a command is entered in the terminal without specifying its full path, the shell searches these directories, in the order they appear in $PATH, to find the executable file for that command.

$PATH ls can be executed without needing to know the command name or absolute path.

Linux searches through the directories listed in the $PATH environment variable to find the first executable file that matches the command name provided as an argument.

If found, which outputs the absolute path to that executable.
In the above example, which ls would output /usr/bin/ls…. indicating where the ls executable is located on the system.

In closing $PATH defines where the shell looks for executable files, and which is a tool that uses $PATH to tell you which executable will be run for a specific command.

Similar Posts

  • Linux Login Methods

    Text Mode vs Graphical In Linux you are able to login using a graphical user interface (gui) or text mode with the command line interface. One would login to a Console a terminal or a graphical emulator, these word are used interchangeably nowdays. The way you login to Linux is determined on the way the…

Leave a Reply

Your email address will not be published. Required fields are marked *