1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-07-24 12:15:27 +02:00
tldr/pages/common/histexpand.md
marchersimon 03819122c9
histexpand: add page (#5455)
Also add a reference to the new page in bash.md and zsh.md
2021-04-04 21:07:13 +01:00

765 B

history expansion

Reuse and expand the shell history in bash or zsh. More information: https://www.gnu.org/software/bash/manual/html_node/History-Interaction.html.

  • Run the previous command:

!!

  • Run the previous command as root:

sudo !!

  • Run a command with the last argument of the previous command:

{{command}} !$

  • Run a command with the first argument of the previous command:

{{command}} !^

  • Run the command n lines back in the history:

!-{{n}}

  • Run the most recent command starting with string:

!{{string}}

  • Run the previous command, replacing string1 with string2:

^{{string1}}^{{string2}}^

  • Perform a history expansion, but print the command that would be run instead of actually running it:

{{!-n}}:p