contador web Skip to content

Shell Introduction

But after all, what the shell? O shell It is a part that makes up the operating system, responsible for interacting or popularly speaking (talking), with the user. In addition he is the command interpreter of GNU / Linux, also known as a command prompt, which reads commands entered by us, interprets and executes what was typed.

The shell is easier, as if it were an interpreter between the user and the computer and vice versa. Below is an image that explains the shell context and the software layers.

Linux: GNU / Linux Shell This image represents the software layers that integrate or make up an operating system. At the bottom we have the hardware, and higher up the kernel, which is responsible for interacting with the hardware. Going up a little more, we have another software layer, the shell, which, as already said, interprets everything you type and makes requests to the kernel, which consults the hardware.

And then the hardware loads what was requested into a memory address, sends it to the kernel, which returns it to the shell, which brings the response of what was requested to the user.

See this other image.

Shell prompt: The prompt represented by the "$" symbol, where you can vary some information contained in it, such as the user, computer name, current directory. This symbology gives us information that is very important to know, it shows which user is currently using the system, which in this case is a common user where using the machine, see the symbol "$". Already if the symbol is a "#" (pound), it says that it is the superuser, better known as user (root). Superuser: He is very special GNU / Linux system administrator as he can do everything on the system, change any file, delete users, make settings etc.

Shell types: Within the shell layer, which was shown in the first image of the article, it is important to mention that for GNU / Linux this layer is like a program, which runs as soon as the system is loaded. There are several types of shell, the first was:

  • C-shell: Which was a shell derived from the C language, we also had:
  • P-shell, K-shell, but the most commonly used today is:
  • bash: The name comes from Bourne Again Shell, and currently the most complete and robust interpreter of coma.

More shell features: It is important to know that the shell, in addition to being a command interpreter, also provides us with a programming environment (shell script programming), where we can automate various tasks, reducing the work of the GNU / Linux administrator. Environmental variables: The shell and its operation can be configured or customized through environmental variables, which are memory locations that hold certain values ​​read by the command interpreter so that we can configure or customize the shell.

There are several types of environmental variables, each with different functions, we have the PS1 (Prompt String 1) variable, this variable stores the bash command prompt, and is represented by the $ (cipher) symbol that appears on the GNU / Linux terminal. We also have the PS2 (Prompt String 2, or Prompt String Extended), which is widely used. When we need to type at the command prompt and need more than one line, we use this variable.

Keep in mind that variables do not affect shell operation, they only provide useful information for the user, such as the current directory, logged in user, and so on. To view any environmental variable, simply enter the command:

$ echo $ PS

Note that before listing the environmental variable PS1 with the echo $ PS1 command, I am showing some other variables, which we can also list its contents with the echo $ (variable name) command.

Special characters: The "" (backslash) character is a metacharacter that shows the command interpreter that the next character after the backslash must be interpreted as it. And not processed, as if it were a shell script program.

Prompt example: Usually the GNU / Linux command prompt comes as follows:

u @ h: w $

This format gives you important information, since u shows the username, h used to represent the hostname, and last but not least w, which shows the current directory. See the example below, which we are in the / home directory.

It is important to remember that the shell is case sensitive, so be very careful when entering commands.

PATH variable: This variable is very important, as it stores a list of directories to be accessed by the operating system for program execution, if it does not find the desired program location in the PATH variable, it gives an error. To view the PATH variable, just give the command:

$ echo $ PATH

HOME Directory: A special directory where each user has their home directory, it is like the user's home, having all permissions to create, change and delete any file within their home directory. See my home directory and how to view the content inside it:

$ ls -l / home / elviseliton /

Execution order: It is important to know that the shell follows an order to find and execute the commands entered, see the image in that order: Explanation: In the first step the shell checks if what was entered is an internal instruction. An internal statement is a command or some request that is part of the shell, and it does not need to call any other external programs to execute what was requested by the user.

If what you enter is not an internal instruction, it means a command or program that needs to be loaded into memory before it can be executed. If it is a program, the shell checks if it is in any directory within the PATH variable I mentioned earlier, if it is not in the PATH path, the shell checks whether this program path has been passed, otherwise it will generate a error for user. If so, it will execute the requested program.

View all variables: So that we can view all environmental variables that are supported and loaded by our command interpreter, use the following command:

$ set

This image is a summary, but as you type in the terminal more information will appear. I didn't put the full image as it would get too big.

Some commands we can use in the shell: There are many commands that we can use in the GNU / Linux shell, I will only show a few, if you want to dig deeper. We have our dear internet and just search, so what will be shown here, just the basics.

Command:

$ ls

Description: Lists information about files in the current directory by default. We have several options for this command.

Command:

$ cat

Description: Shows the contents of a file, but we can also use it to create files:

$ cat> filename

Then type the contents of the file and then press enter to go to another empty line, then Ctrl + D to save. The image below only shows the contents of the file.

Command:

$ mkdir

Description: Create directories so we can organize our files.

Command:

$ aptitude show (program_name)

Description: Shows a description of the desired program, if it is installed, version, and even program dependencies.

Note: Only on Debian based distributions.

The GNU / Linux shell, as shown in this article, is a very powerful tool where we know very well how to configure and customize our GNU / Linux system. It does not require the graphical mode setup wizard and through it we can configure everything right in the root, more clearly and transparently (in my opinion).

I am open to constructive comments on the article published here, soon I will write articles on configuring GNU / Linux servers.

In this article I used the following tools:

  • Operating System: Debian 6.0 "Squeeze"
  • Text Editor: LibreOffice 3.4.6
  • Image Editing: Shotwell Photo Viewer

Founder of blog and channel Diolinux, passionate about technology and games.