Table of Contents
When you start learning Linux commands the first thing that you encounter is Linux shell. Linux shell appear as an interface where you enter your commands. So in this post we will understand about Linux Shell.
The Role of Linux Shell
To understand the Linux Shell and the Kernel, it’s imperative to lay a strong foundation by delving into the intricate world of Linux Architecture. Linux Architecture serves as the fundamental framework that underpins the entire Linux ecosystem, acting as the vital link between the physical hardware, such as your laptop or CPU, and the layers of software that users interact with.
The hardware components, in their raw state, lack the capacity for direct communication with users due to the absence of a shared language. To bridge this gap, the Kernel steps in as an intermediary. It not only interprets user commands and instructions but also ensures their seamless execution by relaying them to the hardware.
The results are promptly presented to users through the Shell, which plays a pivotal role as an intuitive interface, enhancing the user experience within the Linux environment.
Understanding Linux Architecture
In order to gain a comprehensive understanding of the Linux Shell and the Kernel, it’s essential to begin with a solid grasp of Linux Architecture. So, let’s delve into the intricacies of Linux Architecture.
This architectural framework serves as the foundation for the entire Linux ecosystem, bridging the gap between the hardware, such as your laptop or CPU, and the software layers that users interact with.
Essentially, the hardware components alone cannot directly communicate with users due to the absence of a common language. To facilitate this crucial interaction, the Kernel acts as an intermediary.
It interprets user commands and instructions, and then relays them to the hardware, ensuring that the desired operations are performed seamlessly. The result is promptly presented to users through the Shell, serving as a vital interface that enhances the user experience within the Linux environment.”
How Linux Shell Commands Work
Hardware just cannot contact with the users directly. So let’s say we have a motherboard laying on the table. Then we cannot communicate with that motherboard directly because there is no common language between us and that motherboard lying on the table.
So to enable this communication between the user and hardware we have a kernel. This kernel is the middleman which basically contacts the hardware for us. We as users use the utilities or the application. Let’s suppose we are using the calculator application and we want to do arithmetic operations using the calculator.
So when we start a calculator or any other application if we give some command to the application then the first instruction is given to the shell. So if we try to multiply two numbers in a calculator then the shell receives the command or interprets the information that user wants to multiply two numbers and it passes this information to the kernel.
So basically the shell instructs the kernel to do this particular operation. Now the kernel will understand what exactly is the operation that needs to be performed and it will push that to the hardware in a language which the hardware can understand such as the assembly language.
Now the hardware will do the requested operation for us and will send it back to the shell from where users can view it.
User Interaction with Linux Shell
So as a user, we just type in the command and such as copy command or paste command but we do not know what happens inside and how it comes back to us. We just type in the command and we get the result in a fraction of a second.
We only see the monitor value where we type in the command in a shell. The shell acts as an interpreter to the kernel. So the kernel gets the command and it knows what to do. It does those operations with the help of hardware.
The hardware sends the result back to the kernel which is then shown on the shell where we find that the operation has successfully completed. Or if there is an error then we can see the error message too.
Now let’s understand the Linux Shell
A Shell interprets the commands that we have entered using a keyboard and sends it to the OS to perform them. As we just discussed in Linux architecture we have two entities — the shell and the kernel. Now both shell and kernel are programs which are running on the operating system.
So the operating system is what makes the shell and kernel possible. The kernel tries to communicate with the hardware and shell is the interface between the kernel and the user.
So now what shell does is, it interprets the commands which we as user enter into the system using keyboard or the mouse. Shell interprets and understands what these commands are trying to say and it translates and sends it to the operating system or the kernel to be precise.
The kernel now understands what exactly should happen and so it uses the hardware help to complete those operations. And once it is done, kernel sends it back to the shell so that we can view it on our monitor. So this is the basic explanation of Linux shell.
How to use Shell?
Nowadays, we use a lot of GUI-based Linux distributions such as CentOS. There is also a CentOS server which is a command line interface but there is also graphical user interface.
And like CentOS there is Ubuntu, Red Hat, Debian, Kali Linux etc. There are lots of Linux distributions which have GUI. So in the graphical operating system, how can we basically communicate with kernel with the user of a shell?
To emulate the purpose of a command line interface, all the GUI based distributions have a terminal within them. A terminal is basically an emulator or duplicate of command line interface.
If you are familiar with Linux then you would have seen terminal atleast once. To open it you can simply right click on desktop and select terminal. If you open the terminal in your GUI based Linux systems, you will see a terminal like the one shown below.
On this terminal you will see you current logged in username@your system name. And then there will be a $ symbol after which you can enter your commands. You cans ee in figure above the I have entered the command “pwd” which shows my present working directory.
Currently I am on desktop and that’s what the command is showing us on terminal. So this the emulated version of a command line interface.
So terminal in a GUI server emulates a command line interface of Linux server. Terminal emulators are more commonly used now due to GUI operating systems like Mac or Windows or Ubuntu.
In Windows we have command prompt and powershell, in Mac we have terminal and in Ubuntu or CentOS Linux distribution we have terminal which emulates of duplicates the purpose of a command line interface server.
Exploring Top Shells in Linux
We have seen what is a linux Shell and how does an emulator of a shell looks like in a GUI based system. Now let’s look at the top shells in Linux.
I our previous post we discussed that Linux is an open-source operting system. So obviously there are lots of contributors who creates different types of shell. But the most commands or you say the default Linux shell is the bash shell.
Bash shell: The elaboration of bash is Bourne Again Shell. It is the default shell in a lot of Linux distributions be it CentOS, Ubuntu, or any other Linux distributions. We can further install other shells also. It is your wish. But bash is the most portable shell available.
Zsh or Z shell: There is also zsh or Z shell and it is similar to bash or an extended version of bash shell. So basically developers have taken the base Linux operating system and created another operating system which has better features.
So like that, they took bash and added a few features like sharing your command history across multiple terminals. So let’s say there are four different users using the same Linux operating system. They have different user names.
So with Z shell, you can share your command history with other users. This is one of the features but there are so many other useful features in Z shell.
Fish: Fish shell elaboration is a Friendly and interactive shell. It is again an extended version of the common shell which is bash and has great features like auto-completion of commands.
So let’s say you need to type a long command but you do not want to type this long command then you can type first few letters of the command and hit tab button, and the command will get auto-completed.
So it is like an IDE with intellisense. So if you like intellisense feature then you can use Fish Shell.
Tcsh: The Tenex C shell is an extended version of C shell. So basically there is another shell called csh or the C shell which is written mostly in C programming language. This is why it is called as the C shell.
And Tcsh is an extended version of it. Developers have taken C shell and added more capabilities to it. The plus point of Tcsh is that it is a scripting language because it will be similar for the users who already have experience in C programming.
So this is the benefit of Tcsh. If you already have good experience with C programming, then you will find shell scripting pretty easy in Tcsh because it might have the same method of writing programs.
There are so many other linux shells available. You can do a simple google search and you will get information about several different shells. But the ones that we mentioned above are the top and one of the most popular shells.
To interact with a shell we enter commands. So if you type a command in shell such as “pwd” command to return present working directory then the shell understands that you are entering a command and it first validates the command, whether the particular command that we entered is valid in this Linux distribution, then it further pushes it to the kernel. The kernel executes the command with the help of hardware and then it gives back the result to shell. The shell then displays it to us so that we can view it. So this is the basic concept of Linux shell.
In next post we will discuss about Linux Kernel.