Search This Blog


Saturday, October 13, 2007

Recalling command history

The bash shell has a command history. You can repeat a command which you executed before by specifying the command number, e.g., !398 to run the command numbered 398 in the history.

Alternatively, you can specify a partial search string like this: !rm

Either way, the corresponding command is executed right away. Kind of dangerous, you say??

To be on the safe way, you want to see the exact command before the command is executed.

Just add :p to the end, like

It will just print out the command that matched the command number (or the search string), but not execute it.

If it is really the command you want, just do !! to run the last command.

Better safe than sorry.

1 comment:

Anonymous said...

shopt -s histverify may also help to be safe,