Contents
Introduction
When we speak of the command line, we are really referring to the shell. The shell is a program that takes keyboard commands and passes them to the operating system to carry out. Almost all Linux distributions supply a shell program from the GNU Project called bash. The name is an acronym for bourne-again shell, a reference to the fact that bash is an enhanced replacement for sh, the original Unix shell program written by Steve Bourne.
Terminal Emulators
When using a graphical user interface (GUI), we need another program called a terminal emulator to interact with the shell. If we look through our desktop menus, we will probably find one. KDE uses konsole, and GNOME uses gnome-terminal, though it’s likely called simply Terminal on your menu. A number of other terminal emulators are available for Linux, but they all basically do the same thing: give us access to the shell.
Some Simple Commands
Let’s get started. Launch the terminal emulator. Once it comes up, we should see something like this.
[user@linux ~]$
This is called a shell prompt, and it will appear whenever the shell is ready to accept input. While it might vary in appearance somewhat depending on the distribution, it will typically include your username@machinename, followed by the current working directory (more about that in a little bit) and a dollar sign.
If the last character of the prompt is a hash mark (#
) rather than a dollar sign, the terminal session has superuser privileges. This means either we are logged in as the root user or we selected a terminal emulator that provides superuser (administrative) privileges.
So let’s try some typing. Type some text at the prompt and press enter.
[user@linux ~]$ blabla
bash: blabla: command not found
Because this command makes no sense, the shell tells us so. Now that we have learned to enter text in the terminal emulator, let’s try a few simple commands. Let’s begin with the date
command, which displays the current time and date.
[user@linux ~]$ date
Sun Jan 1 05:09:00 EST 2017
To display the current amount of the free disk space, enter df
.
[user@linux ~]$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 12116452 5012392 49484528 34% /
/dev/sda5 4070524 6545424 4070524 44% /home
/dev/sda1 5120 13370 5120 12% /boot
tmpfs 814104 0 814100 0% /dev/shm
Likewise, to display the current amount of free memory, enter free
.
[user@linux ~]$ free
total used free shared buff/cache available
Mem: 8141048 308324 7077816 1204 754908 7569828
Swap: 4194300 0 4194300
To end a terminal session we can close the terminal emulator window, enter the exit
command at the shell prompt, or press ctrl-D
.
[user@linux ~]$ exit
The Console Behind The Scene
In Linux even if we have no terminal emulator running, several terminal sessions continue to run behind the graphical desktop. We can access these sessions, called virtual consoles, by pressing ctrl-alt-F1
through ctrl-alt-F6
on most Linux distributions. When a session is accessed, it presents a login prompt into which we can enter our username and password. To switch from one virtual console to another, press alt-F1
through alt-F6
. On most systems, we can return to the graphical desktop by pressing alt-F7
.
Summary
In this chapter we began our adventure into the Linux command line world. We have learned what the shell is along with the terminal emulator. We also learned how to start and end a terminal session and how to perform simple commands.