Viewing Session History in the ksh Shell

Using ksh, you can also view session history. In doing so, you can get a quick reminder of what you’ve been doing (Code Listing 3.13), reuse commands, and modify commands you’ve already used.

Code Listing 3.13. Although it looks like we typed ls for both the first and second commands, we really just pressed to get the second ls command. The r 64 command recycles the command numbered 64 in the list.
$ ls
Complete    NewProject           bogus2       files    public_html  testme
Completed   News                 chat.conf    ftp      puppy
Mail        access               dead.letter  mail     temp
$ ls
Complete    NewProject           bogus2       files    public_html  testme
Completed   News                 chat.conf    ftp      puppy
Mail        access               dead.letter  mail     temp
$
$ history
56          cd ..
57          ls
58          lynx
59          ls temp
60          more Complete
61          ls
62          more testme
63          ls
64          ls
65          history
66          lynx
67          ftp ftp.raycomm.com
68          ls
69          ls
70          ls
71          history
$ r 64
ls
Complete    NewProject           bogus2       files    public_html  testme
Completed   News                 chat.conf    ftp      puppy
Mail        access               dead.letter  mail     temp
$

To view session history in the ksh shell:

1.
set -o emacs

To begin, you must enter set -o emacs. This command enables history reuse and command completion, and sets the shell to use emacs commands. (Emacs is an editor, but you do not need to use or be familiar with it for now.) If you’ve already done this during your current session, you don’t need to do it again.

2.
Use the shell for a little while, changing directories, redirecting output, or doing other tasks.

3.


Recall the previous command with . Table 3.2 shows you other keyboard combinations that you can use to navigate through the session history.

Table 3.2. ksh History Navigation Commands
COMMANDFUNCTION
Recalls the previous command
Recalls the next command (works only after you’ve moved to a previous command)
somethingGets the previous command containing “something”
Moves back one character within a command
Moves forward one character within a command
Goes to the beginning of the line within a command
Goes to the end of the line within a command
Deletes the current character

After you’ve finished recalling and, optionally, editing the command, press (you don’t have to be at the end of the line to do so).

4.
history

Type history at the shell prompt to see the list of the most recent commands you’ve entered (Code Listing 3.13). Notice the command number by each command. You can type and the command’s number to rerun it.

✓ Tip

  • If you use ksh, you’ll probably want to add the set -o emacs command to your personal configuration files so you don’t have to manually enter the command in each session. See Chapter 8 for the specifics of editing configuration files.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.247.31