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

migrated from stackoverflow.com Jun 27 '10 at 19:44

This question came from our site for professional and enthusiast programmers.


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).

  • history lists the last 500 commands for me. (But I'm on OS X.) – Eric Wilson Jun 24 '10 at 18:12
  • then, you are probably using bash and not ksh. – tonio Jun 24 '10 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 '10 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 '10 at 11:48

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

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.


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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.