Viewing Session History in the bash Shell

Another cool feature of the bash shell is that it lets you easily reuse commands from your session history, which shows you the list of commands you’ve used during a session or in previous sessions (Code Listing 3.9). Viewing history is handy for reviewing your Unix session, using previous commands again (rather than retyping them), and modifying (rather than completely retyping) complex commands.

Code Listing 3.9. In this example, we typed the first command, then pressed to reuse the previous ls command. !40 recycled the 40th command from the listing.
[ejr@hobbes clean]$ ls
background.htm  info.htm     logo.gif
[ejr@hobbes clean]$ ls
background.htm  info.htm      logo.gif
[ejr@hobbes clean]$ history 1 free 2 id ...

Get Unix Third Edition: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.