Listing previously entered commands (history command)

Use the history command to list commands that you have previously entered.

The history command is a Korn shell built-in command that lists the last 16 commands entered. The Korn shell saves commands that you entered to a command history file, usually named $HOME/.sh_history. Using this command saves time when you need to repeat a previous command.

By default, the Korn shell saves the text of the last 128 commands for nonroot users and 512 commands for the root user. The history file size (specified by the HISTSIZE environment variable) is not limited, although a very large history file size can cause the Korn shell to start slowly.

Note: The Bourne shell does not support command history.
To list the previous commands you entered, at the prompt, type the following:
history
The history command entered by itself lists the previous 16 commands entered. The system displays information similar to the following:
928   ls
929   mail
930   printenv MAILMSG
931   whereis Mail
932   whatis ls
933   cd /usr/include/sys
934   ls
935   man pg
936   cd
937   ls | pg
938   lscons
939   tty
940   ls *.txt
941   printenv MAILMSG
942   pwd
943   history

The listing first displays the position of the command in the $HOME/.sh_history file followed by the command.

To list the previous five commands, at the prompt, type the following:
history -5
A listing similar to the following is displayed:
939   tty
940   ls *.txt
941   printenv MAILMSG
942   pwd
943   history
944   history -5

The history command followed by a number lists all the previous commands entered, starting at that number.

To list the commands since 938, at the prompt, type the following:
history 938
A listing similar to the following is displayed:
938   lscons
939   tty
940   ls *.txt
941   printenv MAILMSG
942   pwd
943   history
944   history -5
945   history 938