Introduction to Linux Shell

Before you start

Objectives: Learn what is shell in Linux, why it is used, what is the syntax for commands and how can we compare it with CMD in Windows.

Prerequisites: no prerequisites.

Key terms: shell, command, linux, file, switch, case, cp, dash, interface, system


Shell as User Interface

The shell is the interface between us as users and the Linux operating system itself. By using the shell we or programs can send commands to the Linux kernel. In Linux, commands sent through a GUI (Graphical User Interface) or through applications, are actually send by using the shell. We can compare the shell with the DOS command interpreter. Like in DOS, in shell we can open a terminal session or a command prompt window to type commands and receive responses back. This is also similar to a Command Prompt (CMD.exe) in Windows).

In general, there are two shells that we will probably use in Linux. The first one is Bourne shell. This shell uses syntax similar to a UNIX shell. Steve Bourne created the original shell which is called “sh”. The derivation of sh is the bash shell which includes many improvements. Bash is the default shell for many new distributions. The second type of shells are C-shells. C-shells use syntax similar to the C programming language. The original C-shell is called csh, and there are also improved derivations liketcsh, zsh, and ksh.

Shell is just a component in Linux distribution. That means that we can choose which shell we want to use. We can also have multiple shells installed. A list of available shells on our system is stored in the/etc/shells file. Every user has a default shell saved in the user account database. Users can customize every shell by using commands. Shells can be run by users or by the system. Shells can be run within one another. This can be done by users or by the system when running scripts or programs. To establish their environments shells use configuration file. Environment variables can be passed to child processes.

When entering commands in shell we first enter the command, then switches, and then options. So, switches come immediately after the command, not at the end (like in MS-DOS). So, in Linux we put switches before the things we operate on (but after the command). For example, in the command: “cp -i file10 file20“, the “-i” switch comes after the command cp (for copy), and before the “file10 file20” part, which are source and destination files.

Switches also come in two modes. We can have a single dash or double dash with the switch. If we use a single dash (like in -i), the switch is a single letter. That letter can be in upper case or in lower case (Linux is case sensitive). So, lower case and upper case single and same letter switch are two different things (for example, -i and -I are different switches). In contrast, command line in Windows is not case sensitive. If we use a double dash in the switch, we will use a full word switch. For example, the copy command that we mentioned earlier would look like this with double dash switch: “cp –interactive file10 file20“. To find all switches that can be used with the command we can use the “–help” switch. For example, to see all switches associated with the “cp” command, we would use the: “cp –help”.

CP --help Command

cp –help Command