Using the Bash History

Now you know all these awesome commands, but next week you’ll notice you already forgot them. Luckily, there are tools to help us out here too!

You can use the up and down keys to scroll through previously typed commands. And that’s not all. I listed a few history-based time savers in the following table:

history nView a maximum of n lines from the history
!!Repeat the last command
!nrepeat command number n from history
!cdRe-run the last command you typed starting with, in this case, “cd”
!*Substitute the arguments from the previous command

Perhaps the most powerful way to use the terminal history is by searching through it. Hit control + r to get a search prompt that matches text from your history. Just start typing any part of a previous command, and you’ll find it back!

Please help us and share this article

About the author

Erik is the owner of Python Land and the author of many of the articles and tutorials on this website. He's been working as a professional software developer for 25 years, and he holds a Master of Science degree in computer science. His favorite language of choice: Python!