Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Almost by mistake, I figured out you could do something like:

$ cp foo.data bar1.data
$ ^bar1^bar2

And that runs the same command with bar2.data instead of bar1.data. Now, how about if I have multiple occurrences of the target word? For example:

$ cp foo.data bar.data
$ ^data^index

It only replaces the first data extension. How do I get it to replace both?

share|improve this question

1 Answer 1

up vote 16 down vote accepted

I think ^data^index is equivalent to !!:s/data/index, so it will only substitute the first word. If you want the whole line substituted, I think you'll have to use !!:gs/data/index/

share|improve this answer
This replacement (:gs/data/index) is a bash feature or is it implicitly calling another program? –  JohnTortugo May 18 at 0:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.