Running Commands from the Shell
computer software
Running Commands from the Shell Running Commands from the Shell
Running Commands from the Shell   Home | Site Map | About Us | Products | Services | News | Contact Us | Links Running Commands from the Shell
Running Commands from the Shell Running Commands from the Shell

Copyright © 2009

Linux® Bible


Using the Shell in Linux
When you type a command in a shell, you can include other characters that change or add to how
the command works. In addition to the command itself, these are some of the other items that you
can type on a shell command line:
Options -- Most commands have one or more options you can add to change their
behavior. Options typically consist of a single letter, preceded by a dash. You can also
often combine several options after a single dash. For example, the command
ls -la
lists the contents of the current directory. The
-l
asks for a detailed (long) list of informa-
tion, and the
-a
asks that files beginning with a dot (
.
) also be listed. When a single
option consists of a word, it is usually preceded by a double dash (
--
). For example, to
use the help option on many commands, you enter
--help
on the command line.
You can use the --help option with most commands to see the options and arguments
that they support -- for example,
hostname --help.
Arguments -- Many commands also accept arguments after certain options are entered or
at the end of the entire command line. An argument is an extra piece of information, such
as a filename, that can be used by the command. For example,
cat /etc/passwd
dis-
plays the contents of the
/etc/passwd
file on your screen. In this case,
/etc/passwd
is
the argument.
Environment variables -- The shell itself stores information that may be useful to the
user's shell session in what are called environment variables. Examples of environment
variables include
$SHELL
(which identifies the shell you are using),
$PS1
(which defines
your shell prompt), and
$MAIL
(which identifies the location of your mailbox). See the
section "Using Shell Environment Variables" later in this chapter for more information.
You can check your environment variables at any time. Type declare to list the current
environment variables. Or you can type
echo $VALUE, where VALUE is replaced by
the name of a particular environment variable you want to list. And because there are always multiple
ways to do anything in Linux, you can also type
env to get a succinct list of the current environment
variables and their values.
Metacharacters -- These are characters that have special meaning to the shell. They can
be used to direct the output of a command to a file (
>
), pipe the output to another com-
mand (
|
), and run a command in the background (
&
), to name a few. Metacharacters are
discussed later in this chapter.
To save you some typing, there are shell features that store commands you want to reuse, recall
previous commands, and edit commands. You can create aliases that enable you to type a short
command to run a longer one. The shell stores previously entered commands in a history list,
which you can display and from which you can recall commands. You'll see how this works a little
later in the chapter.
TIP
TIP
NOTE
NOTE
45
Running Commands from the Shell
2