Type a command, hit enter, type another command, hit enter…that’s still how it goes in terminal computing. That’s not to say that there haven’t been innovations in command line. Bash history recall using the up/down keys is just one of those examples. To quickly search for and find specific previously executed commands in bash and/or to increase the size of your command buffer, read on.
[step 1] Open a terminal
window.
[step 2] To view all of your recent commands, type:
history
This will display a list of all recently used commands in the history buffer.
[step 3] To search your command history, type:
history -w ~/history.txt
vi ~/history.txt
/<searchterm>
Note: For more information about history
check out the manpage.
To change your bash history length, you’ll need to edit your .bashrc
settings file.
[step 1] Type:
vi ~/.bashrc
[step 2] Modify or create the setting below to the value you’d like:
HISTFILESIZE=3000
[step 3] Save and quit vi.
That’s it.
Comments
One response to “Quickly find previously executed commands in bash”
Thanks for the writeup! I knew there was a command to do it, but i couldn’t remember. My google search turned up your article. Also, a quicker way to search without making a file would be:
history | grep
Thanks again!