2

what is the command to see the previously executed command that was run on the command line ?

3 Answers 3

12

use the history command.

history -1 will display only the last command. Otherwise, history will list the last 16 commands (for plain ksh, but this may differ with other korn-compatible shells).

You can also use the fc builtin command if you are using plain ksh (command options are described in the man page).

4
  • history lists the last 500 commands for me. (But I'm on OS X.) Jun 24, 2010 at 18:12
  • then, you are probably using bash and not ksh.
    – tonio
    Jun 24, 2010 at 18:22
  • I did the test on MacOSX 10.5.8: ksh's history displays only 16 entries, as osx's man ksh says (search for "16" in the man page). bash's history displays the whole $HISTFILE. (for you, 500 as you probably have $HISTFILESIZE set to 500.
    – tonio
    Jun 24, 2010 at 18:29
  • 1
    And regarding bash's history command: alias h='history $((LINES - 1))' is good to view recent history without completely destroying the scrollback.
    – Roger Pate
    Jun 26, 2010 at 11:48
0

According to this post, you can use the Up Arrow key once you add the following lines to the bottom of your .kshrc file in your $HOME directory:

set -o emacs
alias __A=$(print '\0020') # ^P = up = previous command
alias __B=$(print '\0016') # ^N = down = next command
alias __C=$(print '\0006') # ^F = right = forward a character
alias __D=$(print '\0002') # ^B = left = back a character
alias __H=$(print '\0001') # ^A = home = beginning of line
0

It depends on your shell. If you want to run the last command, in bash for example, you can type !!.

See this page for more info.

EDIT

Oh well, now I noticed that you had tagged your post ksh. Sorry about that. I'll leave this answer here anyway. Maybe it helps someone someday :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .