52
◾
Linux with Operating System Concepts
Now, the user can type
..
at the command line to perform
cd
..
and thus save typing
a few characters.
The mount command mounts a file partition into the file space so that it can be accessed.
However, the mount command can be a challenge to apply correctly or to remember. The
following alias defines a simple way to mount the CD-ROM drive with its options.
alias mountcd
=
'mount/dev/cdrom/cd iso9660 ro,user,noauto'
At
this point, you may not be very comfortable with command line input. As you
become more familiar, chances are you will start typing commands at a faster pace which
will invariably lead to typos. Simple typos might include misspelling a command such as
by accidentally typing sl for ls or lss for less. Imagine that a user has experienced mistyping
less as lss and ls as sl. The following two aliases might then be useful:
alias lss
=
less
alias sl
=
ls
Here, we are adding “lss” as a definition to the Linux environment so that,
if typed, it is
replaced by less. Notice that, if the user were to enter the command
sl ~
, the interpreter
handles this in three separate steps. First, the interpreter substitutes the alias as defined, so
sl
becomes
ls
. Next, the parameter is handled. In this case,
~
indicates the user’s home
directory, which is stored in the environment variable $HOME. Finally,
the command is
executed, in this case,
ls $HOME
.
Dangerous commands are those that manipulate the file system without first asking the
user for confirmation. As an example, the command
rm *
will remove all files in the cur-
rent directory. The safer mode of rm (the remove, or delete, command),
is to use the option
–i. This option is known as “interactive mode.” What this means is that the command will
pause and ask the user for confirmation before any deletion is performed. If there are 25
entries in the current directory, the interpreter will ask the user for confirmation 25 times.
This can be annoying, but it is far safer than deleting items that you may actually want to
keep. So, the user may define the alias
alias rm
=
'rm –i'
Now,
rm *
becomes
rm –i *
.
To view the aliases already defined, issue the
alias
command with no assignment
statement. You can also remove an alias by using
unalias
as in
unalias sl
to remove the alias for sl.
2.4.4
Command Line Editing
To support the user in entering commands, the Bash interpreter accepts a number of spe-
cial keystrokes that, when entered, move the cursor, copy, cut, or paste characters. These
The Bash Shell
◾
53
keystrokes are based on keystrokes from the emacs text editor.
Learning these keystrokes
helps you learn emacs (or vice versa, learning emacs will help you perform command line
editing). The keystrokes are combinations of the control key or the escape key and another
key on the keyboard. We have already seen two such keystrokes cntrl
+
p and cntrl
+
n used
to move through the history list.
Table 2.6 shows many of the keystrokes available. In the table, control
+
key
is indicated
as c
+
key
and escape
+
key
is indicated as m
+
key
. The use of ‘m’
for escape is because Unix
users often referred to the escape key as “meta.” The control and escape keys are used
differently in that the control key is held down and then the key is pressed while the
escape key is pressed first (and released) followed by the key. So for instance, c
+
p means
“hold control and while holding control, hit p” while m
+
p would be “press escape and
then press p.”
Let us consider an example. Your Linux system
has five users named dukeg, marst,
underwoodi, underwoodr, and zappaf. Each of these users has a home directory under
/home. You wish to view the contents of each directory. The command you would issue
would be
ls /home/
username
as in
ls /home/zappaf
. Rather than entering five
separate commands from scratch, after entering the first command you can use it and the
command line editing features to reduce the effort in entering the other four commands.
We start with the first command.
ls /home/dukeg
<
enter
>
This displays the contents of dukeg’s directory.
TABLE 2.6
Command
Line Editing Keystrokes
Do'stlaringiz bilan baham: