Skip to main content

Command line

The tutorial focuses on the command line, also known as a terminal, running Bash.

Don't think of the command line as leaving the graphical user interface (GUI) altogether. Most people open up a command line interface (CLI) just as another window on their desktop. You can have several command lines open to do different tasks in each at the same time or quickly jump back to the GUI when it suits you.

For instance, if you have three terminals open at once, use one of them to do work, another open—to bring up ancillary data, and the third one—for viewing manual pages.

A command line, or terminal, is a text-based interface to the system. You can enter commands by typing them on the keyboard, and feedback will be given to you similarly as text.

The command line typically presents you with a prompt. As you type, it will be displayed after the prompt. Most of the time, you will be issuing commands. Here is an example:

user@bash: ls -l /home/ryan
total 3
drwxr-xr-x  2 ryan users 4096 Mar 23 13:34 bin
drwxr-xr-x 18 ryan users 4096 Feb 17 09:12 Documents
drwxr-xr-x  2 ryan users 4096 May 05 17:25 public_html
user@bash:

Let's break the example down:

  • Line 1 starts with a prompt (user@bash). After that, you enter a command (ls). Typically, a command is always the first thing you type.

    The next thing you specify are command line arguments (-l /home/ryan) separated by spaces. Also, there must be a space between the command and the first command line argument.

    The first command line argument (-l) is also referred to as an option. Options are used to modify the command behavior. Typically, they are listed before other arguments and start with a dash (-).

  • Lines 2 to 5 are the output from running the command. Most commands produce an output, and it is listed straight under the issuing of the command. Other commands perform their task and don't display any information unless there was an error.

  • Line 6 contains a prompt again. Once the command is run and the terminal is ready for you to enter another command, the prompt is displayed. If no prompt is displayed, the command may still be running.

Note that your terminal probably won't have line numbers on it. They are included here to make it easier to refer to different parts of the material.

Accessing terminal

Ways to open a terminal are different in every system. Below, you can find some prompts where to start with:

  • On a Mac, to open the terminal, go to Applications > Utilities. An easy way to get to it is the command + space key combination: it brings up Spotlight, you start typing "terminal," and it will soon show up.

  • On Linux, you can find it in Applications > System or Applications > Utilities. Alternatively, you can try right-clicking the desktop, and there may be the Open in terminal option.

  • On Windows, when you want to log in to another machine remotely, you need an SSH client. A rather good one and free is Putty.

Shell, Bash

Within a terminal, you have what is known as a shell. This is a part of the operating system that defines how the terminal behaves and looks after running (or executing) commands for you.

There are various shells available, but the most common one is called Bash, which stands for Bourne again shell. The tutorial assumes you are using Bash as your shell.

If you want to know which shell you are using, you may run the echo command to display a system variable stating your current shell.

user@bash: echo $SHELL
/bin/bash

As long as the command prints something to the screen that ends in bash, then all is good.