The Linux Terminal and Shell

Lesson

Terminal, shell, bash and other terminology are often used interchangeably, some definitions of the technical differences are given below. What people are typically referring to is somewhere to enter commands which are executed by the operating system (OS) – a command line interface (CLI) for the system. These commands could execute inbuilt tools which came with the OS or additional programs which have been installed. On some systems (for example a remote web server) a terminal is the only way to interact with the systems, usually accessed by connecting with 'SSH' (Secure Shell). On a desktop Linux machine, you will usually have a 'Graphical User Interface' (GUI), from here you can open a terminal window which presents the command line interface (CLI) to type into.

Using a terminal is daunting at first because we're used to pointing and clicking with a graphical interface. However, it is just a case of typing commands and hitting enter. There is also plenty of help and documentation to get you started. Once you become familiar with the shell, it can be a powerful tool which will enable you to accomplish things much faster than if you'd used a GUI.

The terminal presents a 'command prompt' which includes information such as your username and the hostname of the computer – this is where you type commands for execution.

Why use the terminal?

Using the CLI has many advantages for Linux users:

Terminal vs Shell vs Bash

Historically, a terminal referred to a 'teletype' or 'tty' which was a piece of hardware for interacting with a machine. Today we usually refer to the window which accepts our commands as the terminal (in reality, you're probably using a terminal emulator or pseudoterminal).

The 'shell' is the program which interprets your commands. There are several different shells available, and different operating systems may use a different shell by default. Bash is just an example of a popular shell program. Most modern shells are based on the 'Bourne' shell, including:

Most of the time, you don't need to worry about which shell you're using.

Running a Command

To run a command, you type the command, add any additional arguments it requires and then hit enter. Easy. For example, the echo command will print anything which you give as an argument. We simply type echo followed by some text (such as hello world) and then hit <enter>.

Example

$ echo hello world
hello world

Shell Arguments, Options and Parameters

Many command line tools need us to give them some additional inputs to run. With echo, this was what text to echo.

Arguments

Each separate word we enter at the command prompt is an argument.

Options

Most command line tools will also have documented 'options' which you can use to change the behaviour of the command. These may use a single dash - followed by a single letter or a double dash -- followed by a word. Examples of options might be -h or --help to show help for a particular command.

Parameters

Finally, some options may take a 'parameter' to tell them what value to use for this option. For example, a command may be able to use an input file specified with a -i option.

somecommand -i input_file

Putting it all together

We can use the ping command with the -c option to specify how many times to 'do a ping'.

ping -c 5 8.8.8.8

Arguments: ping, -c, 5, 8.8.8.8 where 8.8.8.8 is the destination we're trying to ping.

Options: -c for count, or how many times to do the ping.

Parameters: 5 tells the command to do a ping 5 times.

Comments

We can use the hash, or pound, sign (#) to add comments at the command line. Comments are just text which isn't interpreted by the shell so you can use it to describe or annotate a command. Commenting is particularly important if you are writing a 'shell script' which is a file with a sequence of commands to be executed one after another. You can have a comment on a line of its own. Or a comment can be at the end of a line with a command. The interpreter ignores everything after #.

Comment Example

$ # a comment on it's own line
$ echo hello    # this is a comment
hello

Summary

On any Linux system, you can use a terminal to enter commands at a command line interface for interpretation (and execution) by the shell.


References

Learn more about this topic by checking out these references.


Other Lessons

Learn more by checking out these related lessons

How to use the man pages on Linux

lesson

View

Linux directory commands for beginners

lesson

View

Netcat Field Guide

lesson

View