Using history and command line editing
One
of the great features of the C shell and the Korn shell is history.
The ability to recall and reuse commands that you have entered earlier
can save many keystrokes of repetitive typing. History and command line
editing are closely related. You may use command line editing to
edit the command that you are currently working on after you have typed
it in, or you may recall a previous command and then edit it.
In this article, I will show you some of the ins and outs of
history and command line editing in the Korn shell. For history to
work, you need to be in the Korn shell, so begin by typing:
ksh
to launch a Korn shell.
The second thing you need to make history work is an easy way to
access it. History is more than just the ability to recall
previous commands; it lets you recall commands and edit them before they are
executed. The Korn shell allows you to use different editing styles
depending on what you're trying to do. The primary
editors are vi, emacs, and gmacs. I recommend vi, as most people are
familiar with it. History and command line editing behave very
differently depending on whether you are using vi, emacs, or gmacs. I
will cover some of these differences.
To set vi up as your history editor type:
set -o vi
If you are going to continue to use history, you will want to include
this in your profile, or the emacs/gmacs equivalents. These set -o
commands only work in the Korn shell:
set -o emacs or set -o gmacs
Assuming that you have set -o vi as your history editor,
you may now access history. Press the escape key once (esc) and
release it and press k. The last command that you typed will
appear on the screen:
$ set -o vi
Press enter and that command will be executed. Try a few more
commands so that you can accumulate some history. End with ls on the current directory. Now press esc
-l
and k. The ls -l command appears once more. Press k again and
the command just prior to ls -l will appear. Each time you press k
you'll go back one more command in your history. The minus key ( - )
works in exactly the same way. I use the minus key because it's easier for me
to remember. Eventually, if you press k or minus enough times, you'll
end up back at the set -o vi command.
Now press j or the plus key < + > and you will move forward in the command history.
(When you are rapidly running back through history looking for the command you need, and you realize you've passed it, it's good to know how to move forward again.)
If you have set -o emacs or gmacs, the keys are
control-p for previous command and control-n for next command. In vi
you hit esc once and then k or n will move you backward or
forward through the commands. For emacs and
Symantec Backup Exec 12 and Backup Exec System Recovery 8 deliver industry leading Windows data protection and system recovery. Download this whitepaper to find out the top reasons to upgrade and how to get continuous data protection and complete system recovery.
Data and system loss — from a hard drive failure, malicious attack, natural disaster, or simple human error — can happen anytime. Don’t leave your business vulnerable. Make sure you have a secure recovery strategy in place. Symantec's latest backup and system recovery technology can efficiently restore critical applications, individual emails and documents and even restore your entire system in minutes in the event of a loss.
Businesses face a growing challenge to ensure that the IT environment is properly protected. Backup Exec 12 integrates with other applications in the Symantec family of products, to complement your current data protection strategy, keep your data securely backed up and make it recoverable when you need it most.







