shell Unix provides many useful tools, one of them being then
To see a list of previously executed commands, execute history into your shell. You can also supply an integer argument to limit the number of commands to show.
This can be piped into other commands, which can be useful for many purposes. For example, if I just finished a series of steps to get something working and wish to write a how-to entry for it, I could execute this:
The bash shell also provides the bang (!) command to execute the last command matching the provided command name.
Or you can use bang-bang (!!) to execute the last command
This is useful when you get a permission denied error because you forgot to sudo.
You can also print the matching command without executing it via the :p modifier. This will also copy that matching command to the end of your history.
To substitute certain parts of a command, you can use the :s modified.
You can combine both modifiers as well, to preview a command before executing... might be a good idea if the command may cause damage.
Retrieving only arguments from a command can be done using the :$ :^, :n, and :* modifiers. The $ and ^ will look familiar to anyone who knows regex, they match the last and first arguments respectively. The :n modifier will match argument at position n (first argument being :1), and :* retrieves all arguments.
You can also use the :0 modifier to match the command name, but I don't really see the use in that.
One last thing about history. You can start an interactive search through history by press Ctrl+r (^R), which will interactively display commands matching what you are typing (in reverse history order).