Terminal, shell, bash and other words are often used interchangeably, some definitions of the differences are given below. What people are typically referring to though 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 really is just a case of typing commands and hitting enter and there is plenty of help and documentation to get you started. Once you become familiar with the shell, it can be a very 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 host name of the computer – this is where you type commands for execution.
Using the CLI has a number of advantages for Linux users:
The shell provides access to many powerful tools - often built-in and available across different distributions.
You can chain (or pipe) commands together to achieve complex results which would be difficult through a graphical interface.
It is easy to script and automate tasks.
You use it to administer remote servers over SSH.
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 actually interprets your commands. There are a number of 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 won’t need to worry exactly which shell you’re using.
To run a command, you simply type the command, add any additional arguments it requires and then hit enter. Easy. For example, the
echo command will simply print anything which you give it as an argument. We simply type
echo followed by some text (such as
hello world) and then hit
$ echo hello world hello world
Many command line tools need us to give them some additional inputs to run - with
echo, this was what text to echo.
Each separate word we enter at the command prompt is an argument.
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
--help to show help for a particular command.
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
command -i input_file.
We can use the ping command with the
-c option to specify how many times to 'do a ping'.
$ ping -c 5 184.108.40.206
220.127.116.11where 18.104.22.168 is the destination we're trying to ping.
-cfor count, or how many times to do the ping.
5tells the command to do a ping 5 times.
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. This 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 at the end of a line with a command - the interpreter simply ignores everything after
$ # a comment on it's own line $ echo hello # this is a comment hello
On any Linux system, you can use a terminal to enter commands at a command line interface for interpretation (and execution) by the shell.