How to Use the Linux Shell

Businesswoman at desk with computer
Jupiterimages/Stockbyte/Getty Images

Before there were desktop environments and graphical user interfaces the only way to interact with the Linux operating system was to use the command line also known as the terminal.

The terminal uses a special program called the shell which supports a range of commands for performing tasks.

There are different types of shell available. Here are the most commonly used shells:

  • Bash — Bourne again shell
  • Ksh — Korn shell
  • Csh — C Shell
  • Dash — Debian almquist shell

Most modern Linux distributions use either the bash shell or the dash shell although it is worth knowing the other shells exist.

How Can You Open a Shell?

If you connect to a Linux server via ssh then you will get straight to a Linux shell. If you are using a desktop version of Linux and you are using a desktop environment then you can get to a shell simply by opening a terminal.

As soon as you enter the terminal you will be able to use the default shell for that terminal.

Are a Terminal and Shell the Same Thing?

A terminal and a shell whilst often used in conjunction with each other are very different beasts. A terminal is a program that enables you to access a shell.

As mentioned earlier a terminal can run different types of shell. A shell doesn't need a terminal emulator to run. You can run a shell script via a CRON job, for instance, which is a tool for running scripts at certain periods of time.

How Do I Interact With the Shell

You can do pretty much anything in a terminal window that you can achieve in a more graphical environment but you do need to know the commands that are available.

There are various ways to list all of the commands. For instance, the following command lists the available commands:

This will list all the available commands but in such a way that unless you know what the commands mean you are unlikely to feel very comfortable.

You can use the man command to read information about each command by typing the following:

Replace the "commandname" with the name of the command you wish to read about.

Key things you will want to know are how to view files, how to edit files, how to find out where in the file system you are, how to move up and down directories, how to move files, how to copy files, how to delete files and how to make directories. 

What Is a Shell Script

A shell script is a series of shell commands written in a file which when called will perform the commands one after the other often taking user input.

Shell scripts provide a way of performing common tasks over and over again.

Keyboard Shortcuts

There are a number of keyboard shortcuts that are worth knowing for interacting quickly with a shell within a terminal window:

  • CTRL + U = Cuts text up until the cursor
  • CTRL + K = Cuts from the cursor until the end of the line
  • CTRL + Y = Pastes text
  • CTRL + E = Move the cursor to the end of the line
  • CTRL + A = Move cursor to the beginning of the line
  • ALT + F = Jump to next space
  • ALT + B = Jump to previous space
  • ALT + backspace = Delete previous word
  • CTRL + W = Cut word before cursor
  • Shift + Insert = Paste

Installing Software Using the Command Line

The shell can be used more than just a way of copying files around and editing them.

For instance, you can use the shell to install software. Most commands for installing software are specific to an operating system and not a particular shell.

For instance, apt-get is available on Debian based distributions whilst yum is available for Red Hat-based distributions.

You can use apt-get in a shell script but it won't work on every distribution. It is a command-line program as opposed to being a dedicated shell command.

Useful Tips and Tricks

It would be useful to know how to run commands in the background, how to pause commands, how to keep commands running even after you log out, how to run commands at a specific date and time, how to view and manage processes, how to kill hung processes, how to download Youtube videos, how to download web pages and even how to get your fortune told.