Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Bash History Substitution

Bash History Substitution

Danielle Brook-Roberge

September 17, 2015
Tweet

More Decks by Danielle Brook-Roberge

Other Decks in Technology

Transcript

  1. !! : The Last Command • The last command can

    be repeated with !! • This can be used on its own or included into a larger command.
  2. Relative Indexing with !- • We can look further back

    in the history using !-n, where n is the number of commands to go back. • This allows us to repeat the last two commands on one line with !-2 && !!
  3. History Searching • We can search through the history with

    characters after the !. • !t is substituted with the most recent command that begins with t, for example.
  4. Modifications with :s/ and :gs/ • We can perform string

    substitution on a history command with :s/old/new/ • This will only replace the first occurrence, to replace all, use :gs/old/new/ • We can use ^old^new as a shorthand for !!:s/old/new/
  5. Accessing Arguments: !$ and !* • With !$, we can

    pick out the final argument of the previous command. • To get all of the arguments, we can use !* instead.
  6. Summary Command Replaced by !! Previous command !-2 Command before

    last !r Last command beginning with r !!:s/in/out/ Last command with the first in replaced by out !!:gs/in/out/ Last command with all in replaced by out !$ The final argument to the last command !* All arguments to the last command