I’m finding that I’m starting to build up a long list of regularly used Linux commands and was wondering if there was an application out there that would allow me to store them all, and then pick and run one from the list as and when I need too?
-
I'm very confused as to what you are asking. Why are you trying to 'store' commands? – David Apr 07 '20 at 20:45
-
So I don’t have to type them out, or scroll through a very long list in the terminal history – nodecentral Apr 07 '20 at 21:55
-
I found something similar to what I’m after, but ideally a bit more polished - https://www.unix.com/shell-programming-and-scripting/124855-bash-menu-script.html – nodecentral Apr 07 '20 at 23:16
3 Answers
When using BASH
, you can press Ctrl+r to do a reverse search through your command history. For example, you can press Ctrl+r and then type "vim" to see your last command that included "vim". You can press Ctrl+r again to find the second to most recent, and continue pressing Ctrl+r until you find the command you want. Once you find it, you can press Enter to execute the command.
If you wish to edit the command before running it, you can use the directional (Left or Right) which will drop you out of reverse search and allow editing.
To enhance this feature, be sure to allow for many commands to be stored in your ~/.bash_history
file. You can define the limit by exporting the value of HISTSIZE
in your ~/.bashrc
file:
export HISTSIZE=10000
You can ensure each unique command is only stored once, which is recommended for various reasons including preventing you from having to press Ctrl+r more times than necessary otherwise. Again add the following to ~/.bashrc
:
export HISTCONTROL=ignoreboth
You may also want to adjust the way BASH stores history when multiple terminals are open at once, to ensure commands from multiple terminals are all stored, by taking a look at this answer.
This is one of those most powerful things I've learned on Linux/BASH, and I hope you find it helpful as well.

- 11,247
There is the history
command. It is designed to list the commands you have used. You can filter it by using grep:
$ history | grep home
gives me all the command I used with the word "home" in it, e.g.:
1188 cd ../home
1519 more resources/home.php
1890 cd git/home
1983 cd git/home
2001 cd git/home/squeeze/
2008 history | grep home
and this allows me to pick one and re-execute it:
$ !2001
is equivalent to cd git/home/squeeze
in this case.

- 29,224
There's a number of ways to do this. Firstly, there's already a built in history feature in the shell. Using the up
and down
keys allow you to view this as well as Ctrl r
allowing you search it.
Another option is to make it an alias in ~/.bashrc
.
Thirdly, you could save each command to its on file, and then manually run bash my_command
.

- 696
-
How does the third option work exactly, what would need to be in each file, would all files need to be in the same folder etc.? – nodecentral Apr 07 '20 at 22:12