Publishers of technology books, eBooks, and videos for creative people

Home > Articles

  • Print
  • + Share This
This chapter is from the book

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. ctrlp.jpg

    Recall the previous command with ctrlp.jpg. 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

    COMMAND

    FUNCTION

    ctrlp.jpg

    Recalls the previous command

    ctrln.jpg

    Recalls the next command (works only after you've moved to a previous command)

    ctrlr.jpg something

    Gets the previous command containing "something"

    ctrlb.jpg

    Moves back one character within a command

    ctrlf.jpg

    Moves forward one character within a command

    ctrla.jpg

    Goes to the beginning of the line within a command

    ctrle.jpg

    Goes to the end of the line within a command

    ctrld.jpg

    Deletes the current character

    After you've finished recalling and, optionally, editing the command, press enter.jpg (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 rspacebar.jpg and the command's number to rerun it.

  • + Share This
  • 🔖 Save To Your Account