What is Shell in Linux.

We all know that computers understand binary language, a language which is in the form of zeros and ones. This language is not in human readable form and can only be accepted by computers.

In the initial days of computing, these numbers were manually translated and then fed to the computer for its understanding and execution. But this method was not convenient enough to solve big problems as it was making the computer an mechanical device rather than an electronic one.

This is where the work of shells comes into play.

A shell in Linux is a special program whose work is to convert human readable code and instructions into machine language i.e in the binary language. These instructions are then passed on to Linux kernel for execution.

It accepts input commands from most of the Input devices and converts these command instructions to fit into machine language so that it can be executed properly.

A shell in Linux is not a part of Kernel. It is a separate utility. Though it uses utilities provided by the Linux kernel for execution of instructions and programs.

There can be more than one shell in a system. To see which all the shells your system has, open the terminal and write the following command:

cat /etc/shells

It will show you all the shells that are currently available on your system.

Many people get confused by referring terminal and the shell as the same thing.

Instead, they are completely different. Linux terminal provides a way to access the shell. A terminal only provides a medium to access the shell. A shell, on the other hand, is an independent program. 

A single terminal can support many types of shell too.

Types of Shells in Linux

There are 4 types of shell in Linux:

BASH (Bourne Again Shell)

It is the most common type of shell. Open-source and is most widely used. People often write bash scripts to execute a series of command.

CSH (C Shell)

It is a shell written in C language. Its syntax is very similar to that of C language.

KSH (Korn Shell)

Developed in AT & T Bell Labs, it is backward compatible with the Bourne Again Shell and includes many features of C shell.

TCSH

It is an advanced and compatible version of CSH used in Unix.

 

Any shell can accept instructions via various input devices such as a keyboard and tells the kernel what to do with the command. An instruction can include sending signals to processes, taking input etc.

It is just a medium between the user and the machine.

How to open a shell in Linux

There are many ways to open a shell in Linux:

  1. Via terminal: One can gain access to a shell by running X Terminal (XTerm), Gnome Terminal (GTerm), or KDE Terminal (KTerm) application.
  2. Via SSH: You can access a shell by login into a remote server via ssh.

Shell Scripts

Shell scripts are a series of shell commands written in a sequence to be executed automatically. It is similar to a batch file in Windows OS. There can be different shell scripts depending upon the type of shell which is being used.

Shell scripts can take user inputs and perform other common tasks that can be performed much more efficiently by Linux kernel. It is a good and an easy way to do multiple things easily and regularly.

Command line interface

A shell provides a command line interface in Linux where you can run and execute the commands. There are many short cuts which are generic to almost most of the shells. Bourne Again Shell being most user-friendly has a set of shortcuts which can be used perform specific tasks. The list goes like this:

  • CTRL + L: Clear the screen.
  • CTRL + W: Delete the word starting at the cursor.
  • CTRL + U: Clear the line i.e. Delete all words from the command line.
  • Up and Down arrow keys: Recall commands
  • Tab: Auto-complete files, directory, command names and much more.
  • CTRL + R: Search through previously used commands.
  • CTRL + C: Cancel currently running commands.
  • CTRL + T: Swap the last two characters before the cursor.
  • ESC + T: Swap the last two words before the cursor.
  • CTRL + H: Delete the letter starting at the cursor.

Apart from these commands, there are many utilities such as date.

Just type date in the CLI and it will print the date. 

  • Add Your Comment