The Beginner's Guide to Linux Part 4: Introduction to the Terminal


Part 1: Finding the Right Distro

Part 2: Partition and Installation

Part 3: The Linux GUI

Part 4: Introduction to the Terminal

Traditionally, most new users have always been reluctant to experiment with the command line interface, (commonly referred to as the terminal) yet it has always been one of the most important parts of learning Linux. Once you understand the terminal, Linux will finally open up to you. The terminal is easily the most powerful part of a Linux system; it is your way of being able to work directly with the operating system without any barriers or hindrance.

This guide will cover basic terminal usage in addition to ways to enhance basic commands. For the sake of simplicity, we will only address the underlying concepts of shell scripting instead of covering it in detail. We saved this part of our guide for last because it is typically the most difficult to grasp. However, the terminal is fairly easy to understand when broken down into simple concepts.

Overview of the Linux Terminal

Linux has many different shells that you can use for your terminal. One of the most common shells is called Bash, an abbreviation for “Bourne-Again Shell”. (a successor to the original Bourne Shell) Other popular shells include the original Bourne Shell, (sh) the Korn Shell, (ksh) and the C shell. (csh) If you are running a window manager, you would interact with a shell program through a terminal emulator like Xterm, GNOME Terminal, Konsole, or something similar. However, if you are not running a window manager or any other GUI, the terminal is your only way of interacting with the system. Generally, the terminal is a fail-safe repair system if Xorg (the GUI system) were to malfunction.

The Bash Shell

This article will focus primarily on Bash, but is applicable to other shells as well. Each shell program has its own strengths and weaknesses and is different from the others, but you are not likely to experience this very much unless you get into complicated shell scripting and programming. In the case of simple commands, the various shells operate in much the same way.

Gnome and Xterm

Basic Terminal Concepts

Although Bash and other terminals vaguely resemble DOS, there are fundamental differences. While DOS is a full (albeit simple) operating system with the core functionality built in, Bash is simply a command shell that provides an interface to the operating system it runs on.  The first thing you must understand is that Bash has very little built-in functionality of its own. Every time you run a command in Bash, (no matter what it is) you are actually invoking another program as a separate process. Bash and other similar shells use a set of core utilities for basic file operations. (Some of the most important of these may be found at the end of this article) Text-based utilities like file copying/deletion/renaming, process management, and disk usage are all handled externally; although they appear to be part of Bash, that is not the case.

Since the shell assumes that all programs are either in /bin or /usr/bin, Bash does not need a full pathname or require you to navigate to a specific directory to start a program. To run a program, simply type the program name at the command prompt. (e.g “vim” or “firefox”) In this article, we will refer to simple commands like these as “base commands.”

The tilde (~) symbol is used as a reference to your home directory. In all instances there you would normally have to provide the full pathname of your home directory, the ~ symbol may be used instead as a matter of convenience. For instance, ~/sub_folder is the same as /home/<your home folder>/sub_folder. To navigate to your home folder from anywhere in the filesystem, you need only type “cd ~”.

Like the rest of Linux, a shell has two levels of privilege: regular users and super users. At the command prompt, Bash will list the name of the current user in addition to the name of the machine the terminal is running on. The user listed first and the machine listed second, with an @ symbol separating them. (e.g. frodo@shire or root@aux) Bash will also list the current directory as well. Many other shells are far less verbose and list only “$” for all regular users and “#” for the root account.

Each shell can run only one command at a time. However, you can run as many shell processes as you wish at the same time under a GUI with a terminal emulator. Many terminal emulators have a tab system that lets you easily switch back and forth between any shells that you have open. Without a GUI, you can run up to seven terminals at a time on most distros; these terminal processes are assigned a prefix of “tty” (Teletype) and a number. tty1-tty6 are generally available at any given time, whereas tty7 is normally used to run the GUI system and is therefore not available for other use. To switch to a different tty, press CTRL+ALT+Fx, where x is the number of the tty you would like to use. For example, to switch to tty3, press CTRL+ALT+F3.

Each program started from a terminal becomes bound to that terminal as a child process; if you close a terminal, any child processes managed by that terminal are closed as well. If you want to keep a process running no matter what happens to its parent terminal, you must precede the command with “nohup” (short for “no hangup”) when you launch it. Instead of displaying output in the terminal window as is the norm, programs launched with nohup have all output written to a file called nohup.out.

To terminate a running program before it is supposed to finish, press CTRL+C.


Many programs can perform multiple functions, so additional parameters called switches are used in addition to the base command to provide access to this functionality. Switches are preceded by a dash, placed after the base command, and use letters or numbers as references to certain functions. Since you can invoke multiple switches at once, (e.g. tar -czvf ) it is possible to fine-tune the actions of a program in very specific ways that the base command all by itself would not allow. Switches can be grouped together as shown in the previous example.

You should remember that switches are case-sensitive and can do different things depending on whether they are uppercase or lowercase; for example, “-R” is not the same thing as “-r”. If you use switches that happen to conflict with each other or are invalid, the program will display an error message that explains the problem. To see all possible switches for a program, you should refer to its manual page. (run “man <program name>”) The manual page will also provide detailed usage parameters for a program in addition to examples and background information. Almost every program has a manual page associated with it, often in addition to more conventional documentation.


Bash and other shells support the use of wildcards, which are used to substitute unknown or non-designated characters in commands. The wildcard symbol is the asterisk. (*) Wildcards differ from variables, which are used to bind specific values in shell scripts and more advanced Bash applications.

Wildcards are frequently used with the list command. (ls). Using wildcards, you can force ls to show only certain types of files in its output instead of everything. For example, “ls *.png *.html” will display all PNG and HTML files in a directory.

Wildcards may also be used to show all files in a directory that start with a certain letter; “ls a*” will display any file that begins with the letter a. It is also possible to apply a wildcard to a set of characters. For example, “ls [abc]*” will display any file in a directory that begins with a, b, or c.

<< Back to Part 3

Program targets

Many programs provide you with the option of immediately acting against a specific target entity when the program starts. This target entity may be practically anything, (a file, directory, network address, or system device) depending on the nature of the program. A target may be located anywhere in the filesystem, and it may be invoked from any directory (provided the pathname is correct) For example, if you are in your home director and wish to edit a file in a subfolder, there is no need to change to the subfolder before opening the file.

Generally, the target should be specified after the base command and any switches. (e.g. “vim -R myfile.txt”) Sometimes, switches may have targets of their own in addition to the main program target. In such instances, the manual page will tell you what types of switch/target combinations the program will accept.

Although most filenames are either single words or separated by underscore characters (e.g. file_1) The terminal supports multiple worded filenames as target entities. However, spaces in filenames must be preceded by a backslash, otherwise the shell will treat each word independently. (often causing an error) For instance, Bash would correctly process “multiple\ worded\ filename.txt” as “multiple worded filename.txt”. Omitting the backslashes would cause the shell to incorrectly interpret the filename as “multiple”, “worded”, and “filename.txt”.

Working with Input and Output

Joining commands together

If you have two or more commands that you wish to run in sequence, type them on the same line and place “&&” between each separate command. The commands will then be executed in order, from left to right.


Software pipelines allow you to feed the output from one program directly into another. Like the && operator, pipelines allow you to execute multiple commands in a specific sequence. However, a pipeline automatically takes the output from the previous command and feeds it into the next command whereas the && operator treats each command independently. Pipelines are useful primarily because they allow further processing of a command and allows multiple interdependent commands to be chained together when necessary. The pipeline is invoked by placing the “|” symbol between two separate commands on the same line.

For example, the grep utility is designed to search for a specific keyword you provide. If you were to run a program like ls, you can use grep to isolate a certain file (e.g. file1.jpg) from what could be a very long file list, even with wildcard filtering. If you were to run “ls | grep file1.jpg”, only file1.jpg would be listed in the terminal (if it exists) even though ls might return much more output under normal conditions.

Output Redirection

Sometimes, you may want to save terminal output. While you could use a pipeline to dump it into a text editor, there is an easier way. Using the greater-than (>) symbol, you can save terminal output to a text file. For example, running “cat file1 file2 > file3” will join the contents of file1 and file2 together and will then save the resulting output as file3.

Be careful with this, since any existing file with the same name as the one you specify will automatically be replaced. To append the output to an existing file, use “>>” instead of “>”.

Shell Scripting Concepts

While the simple operators described in the previous section can allow you to create complex commands, true shell scripting can do much more by taking the principles described in the previous section to a whole new level. A Linux shell script works just like a Windows batch file in a sense; both are little more than a set of instructions that rely exclusively on external programs to do the actual work. This differs fundamentally from programming languages like Perl, which use internal language features instead of external programs. Shell scripting is based on the principle of using various simple programs to produce a complicated result.

Shell scripting is a useful tool for creating a stopgap solution for a problem in a few minutes using existing tools instead of having to re-invent the wheel by developing a program of your own. In this way, shell scripting has its strengths and weaknesses like any other language: Shell scripts are easy to write if you have any programming experience at all and can save considerable development time by using programs that already have the functionality you need. On the downside, shell scripts are written for specific shells and are not very portable as a result. (According to an old saying, it is often easier to port an entire shell than a complicated script that relies heavily on the features of one particular shell) Likewise, shell scripts are not ideal for permanent solutions and are not really designed with security in mind. As with any other language, you should decide beforehand whether the benefits of shell scripting are enough to offset its downsides for your particular situation.

Shell scripts support all the essential features of any scripting language, including conditional statements, variables, loops, etc.  Since a shell script is little more than a bunch of individual commands kludged to work together, all the functionality the script might use is available for individual commands as well. (although it is inconvenient to do things that way)

To run a shell script, navigate to the directory it is in and run “./<script name>” (e.g. ./ Do not omit the period and forward slash at the beginning or the script will not work. Also, you may have to make scripts executable with chmod before you will be able to run them.

Read on for our table of Essential Terminal Commands!

Essential basic commands

Although there are hundreds of commands available for the terminal, the following table will introduce you to the most essential ones. Any portions of a command enclosed in < > brackets is a variable and should be replaced with what is specified between the brackets. For example, < file> indicates that a file should be designated.

Essential Terminal Commands
Lists all files in a directory “ls” (Use “ls -l” for detailed output) For those used to DOS or cmd.exe, “dir” is very similar.
Copies a file or folder
“cp <source file/folder> <destination file/folder>” e.g. “cp file1 file2” or “cp folder1 folder2” The first file/folder in the command is the original file while the second one is the file/folder that will be created as a copy.
Moves a file from one directory to another. Also works as a rename command “mv </folder/file> </newfolder/file>” or “mv file1 file2” (this will rename file1 to file2)
Change to a different directory
“cd <new directory>” Only a folder name is needed instead of a full path if the new directory is a sub-directory of the current folder. To move to the next highest directory, run “cd ..”
Makes a new directory in the current folder “mkdir <new directory name>”
Removes a file or directory
“rm <file>” removes a file. To remove a directory, use “rm -r <directory>” . Beware of “rm -rf /”, as this command will delete everything if executed as root.
Changes file properties
Chmod assigns file properties based on numbers and letters. Using + will add a new property, while – will take it away. For example, “chmod +x <filename>” will make a file (like a shell script) executable. For a list of file properties, run “info chmod”.
Changes ownership of a file or folder
“chown <owner>:<group>   <file>” <owner> and <group> should be set to the new owner and group.
Shows a manual page that tells you how to use a program “man <program name>” Sometimes, there is an “info <program name>” as well.
Shows real-time process information and system usage stats
“top” To exit top, press Q.
Concatenation tool used to join plain text files together “cat <file1> <file2>” Cat is often used to preview individual files, but this is not really what it is for. (use less instead)
Shows process information for a user
“ps -u <user>” e.g. “ps -u root” Sort of like top, but good for when you don't want or need real-time info. This command is best used with a grep pipeline to help you find a specific process.
Forcefully terminates a process
“kill <process ID>” The process ID of the program you want to kill can be determined by running ps or top as shown above. If a program will not terminate with the normal kill command, “kill -9 <process ID>” will stop it for sure.
Executes command as superuser/root “sudo <program>”
Escalates to a root shell “su”
View an individual text file
“less <filename>” The up and down arrows allow you to scroll through the file. To return to the shell, press Q. Use this tool instead of cat when you want to look for individual files.
Searches for a text string Grep is frequently used in pipelines, but “grep <pattern> <file>” can also be used to search for keywords in files.

Around the web