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.
Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world
jfruh
Apple syncing patent can't come soon enough
pasmith
New Twitter features borrow from 3rd party clients
Esther Schindler
Open Source Changes the Software Acquisition Process
mikelgan
How to set up continuous podcast play on the new iTunes
David Strom
Five important Windows 7 mobility features
sjvn
Guard your Wi-Fi for your own sake
Sandra Henry-Stocker
Grepping on Whole Words
Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325
Join the conversation here
Quick, practical advice for IT pros. Made fresh daily.
Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.












