Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shortcut to replace all strings in previous bash command

man bash describes a very useful Event Designator

^string1^string2^

Quick substitution. Repeat the last command, replacing string1 with string2. Equivalent to ''!!:s/string1/string2/''

Is there a way to execute !!:gs/string1/string2/ when typing in @string1@string2@ on the command line to replace all occurrences in the previous command? (@ or any other designated character/string)

like image 271
Alex Avatar asked Apr 29 '13 16:04

Alex


1 Answers

^string1^string2^:g&

See question Replace all occurrences of a word in the last command.

See Modifiers in History Expansion.

like image 83
Hans Ginzel Avatar answered Nov 08 '22 11:11

Hans Ginzel