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
Brian Proffitt
Microsoft/Novell: Breaking Down the Coupon Numbers
Esther Schindler
Drupal's Dries Buytaert on Building the Next Drupal
Tom Henderson
Top Ten General Operating Systems Rants
pasmith
PS3 motion controller delayed; goes up against Project Natal
sjvn
Neolithic Windows security hole alive and well in Windows 7
claird
Perl source code comparison makes for good reading
mikelgan
Cell phones don't create stress or interrupt much
Sandra Henry-Stocker
How to: The Unix Interview
Where Google Chrome security fails: the password
I heard mention that the Chrome OS will have some sort of encryption available a la bitlocker. If it's possible to encrypt personal data using another password or key, then it may have potential for very secure data.... And Ubuntu has an 'encrypt home directory' option, perhaps google should follow suit.
- Dann
Join the conversation here
Quick, practical advice for IT pros. Made fresh daily.
- Ubuntu advances: Why Ubuntu server installations will surge in 2010
- Social media marketing: How to make friends with benefits
- More...
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.





