1. Introduction
The purpose of this document is to provide the reader with a fast and simple introduction to using
the Linux command shell and some of its basic utilities. It is assumed that the reader has zero or
very limited exposure to the Linux command prompt. This document is designed to accompany an
instructor-led tutorial on this subject, and therefore some details have been left out. Explanations,
practical examples, and references to DOS commands are made, where appropriate.
1.1 What is a command shell?
A program that interprets commands
Allows a user to execute commands by typing them manually at a terminal, or automatically
in programs called shell scripts.
A shell is not an operating system. It is a way to interface with the operating system and run
commands.
1.2 What is BASH?
(BASH = Bourne Again SHell)
Bash is a shell written as a free replacement to the standard Bourne Shell (/bin/sh)
originally written by Steve Bourne for UNIX systems.
It has all of the features of the original Bourne Shell, plus additions that make it easier to
program with and use from the command line.
Since it is Free Software, it has been adopted as the default shell on most Linux systems.
1.3 How is BASH different from the DOS command prompt?
1.Case Sensitivity: In Linux/UNIX, commands and filenames are case sensitive, meaning
that typing “EXIT” instead of the proper “exit” is a mistake.
2. “\” vs. “/”: In DOS, the forward-slash “/” is the command argument delimiter,
while the backslash “\” is a directory separator. In Linux/UNIX, the
“/” is the directory separator, and the “\” is an escape character. More
about these special characters in a minute!
3. Filenames: The DOS world uses the “eight dot three” filename convention, meaning
that all files followed a format that allowed up to 8 characters in the
filename, followed by a period (“dot”), followed by an option extension,
up to 3 characters long (e.g. FILENAME.TXT). In UNIX/Linux, there is
no such thing as a file extension. Periods can be placed at any part of the
filename, and “extensions” may be interpreted differently by all
programs, or not at all.
1.4 Special Characters
Before we continue to learn about Linux shell commands, it is important to know that there are
many symbols and characters that the shell interprets in special ways. This means that certain
typed characters:
a) cannot be used in certain situations,
b) may be used to perform special
operations, or,
c) must be “escaped” if you want to use them in a normal way.
1.5 Executing Commands
The Command PATH:
1.Most common commands are located in your shell's “PATH”, meaning that you can just
type the name of the program to execute it.
*Example: Typing “ ls” will execute the “ ls” command.
2.Your shell's “PATH” variable includes the most common program locations, such as
/bin, /usr/bin, /usr/X11R6/bin, and others.
3. To execute commands that are not in your current PATH, you have to give the complete
location of the command.
*Examples: /home/bob/myprogram
./program (Execute a program in the current directory)
~/bin/program (Execute program from a personal bin directory)
Command Syntax
1.Commands can be run by themselves, or you can pass in additional arguments to make them do
different things. Typical command syntax can look something like this:
command [-argument] [-argument] [--argument] [file]
* Examples: ls List files in current directory
ls -l Lists files in “long” format
ls -l --color As above, with colourized output
cat filename Show contents of a file
cat -n filename Show contents of a file, with line numbers
2.0 Getting Help
When you're stuck and need help with a Linux command, help is usually only a few keystrokes
away! Help on most Linux commands is typically built right into the commands themselves,
available through online help programs (“man pages” and “info pages”), and of course online.
2.1 Using a Command's Built-In Help
Many commands have simple “help” screens that can be invoked with special command flags.
These flags usually look like “-h” or “--help”.
*Example: grep --help
2.2 Online Manuals: “Man Pages”
The best source of information for most commands can be found in the online manual pages,
known as “man pages” for short. To read a command's man page, type “man command”.
*Examples: man ls Get help on the “ls” command.
man man A manual about how to use the manual!
To search for a particular word within a man page, type “/word”. To quit from a man page, just
type the “Q” key.
Sometimes, you might not remember the name of Linux command and you need to search for it.
For example, if you want to know how to change a file's permissions, you can search the man page
descriptions for the word “permission” like this:
*Examples: man -k permission
If you look at the output of this command, you will find a line that looks something like:
*chmod (1) - change file access permissions
Now you know that “chmod” is the command you were looking for. Typing “man chmod” will
show you the chmod command's manual page!
2.3 Info Pages
Some programs, particularly those released by the Free Software Foundation, use info pages as
their main source of online documentation. Info pages are similar to man page, but instead of
being displayed on one long scrolling screen, they are presented in shorter segments with links to
other pieces of information. Info pages are accessed with the “info” command, or on some
Linux distributions, “pinfo” (a nicer info browser).
*For example: info df Loads the “df” info page.
Navigating the Linux Filesystem
3.1 The Linux filesystem is a tree-like hierarchy hierarchy of directories and files. At the base of the
filesystem is the “/” directory, otherwise known as the “root” (not to be confused with the root
user). Unlike DOS or Windows filesystems that have multiple “roots”, one for each disk drive, the
Linux filesystem mounts all disks somewhere underneath the / filesystem. The following table
describes many of the most common Linux directories.
3.2 Commands for Navigating the Linux Filesystems
The first thing you usually want to do when learning about the Linux filesystem is take some time
to look around and see what's there! These next few commands will:
a) Tell you where you are,
b) take you somewhere else, and
c) show you what's there. The following table describes the basic
operation of the pwd, cd, and ls commands.
4.0 Piping and Re-Direction
Before we move on to learning even more commands, let's side-track to the topics of piping and
re-direction. The basic UNIX philosophy, therefore by extension the Linux philosophy, is to have
many small programs and utilities that do a particular job very well. It is the responsibility of the
programmer or user to combine these utilities to make more useful command sequences.
4.1 Piping Commands Together
The pipe character, “|”, is used to chain two or more commands together. The output of the first
command is “piped” into the next program, and if there is a second pipe, the output is sent to the
third program, etc.
*For example: ls -la /usr/bin | less
In this example, we run the command “ls -la /usr/bin”, which gives us a long listing of all
of the files in /usr/bin. Because the output of this command is typically very long, we pipe the
output to a program called “less”, which displays the output for us one screen at a time.
4.2 Redirecting Program Output to Files
There are times when it is useful to save the output of a command to a file, instead of displaying it
to the screen. For example, if we want to create a file that lists all of the MP3 files in a directory,
we can do something like this, using the “>” redirection character:
*ls -l /home/vic/MP3/*.mp3 > mp3files.txt
A similar command can be written so that instead of creating a new file called mp3files.txt,
we can append to the end of the original file:
*ls -l /home/vic/extraMP3s/*.mp3 >> mp3files.txt
5.0 Other Linux Commands
The following sections describe many other commands that you will find on most Linux systems.
I can't possibly cover the details of all of these commands in this document, so don't forget that you
can check the “man pages” for additional information. Not all of the listed commands will be
available on all Linux or UNIX distributions.
5.1 Working With Files and Directories
These commands can be used to: find out information about files, display files, and manipulate
them in other ways (copy, move, delete).
5.2 Shortcuts to Make it all Easier!
When you start using the Bash shell more often, you will appreciate these shortcuts that can save
you very much typing time.