Shell – How to access the history buffer in sh? (not in Bash)

command historycommand linedashposixshell

Is there a command history in sh, for example how to access it, and as well, how to ensure it is clear?

To clarify shells here: let's say you've logged on to a non-Gui Linux system, and $SHELL is not set to Bash, but rather in Dash or whatever Bourne-like shell that may be.

Man pages referred to a "history" command, which I've seen in some BSD systems, but this was not actually in my shell, and I couldn't easily find the answer in the subsequent sh man and info pages.

decriptor's comment in this post got me thinking maybe it is more to do with needing to learn about the key bindings in sh rather than actually something like the differences between the shells.

For future readers, here is a great post on shell history.

Best Answer

unless it is explicitly set, there is no default shell history. to verify if you have it or not, the command env|grep -i hist can be executed and if you see variables like histfile etc. (may be capitalized) it means that your shell history is enabled, and you should see where the history file is located. To clear, you can do any decent method, other than deleting the file