Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Correct command line typos with carets' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Correct command line typos with carets
Authored by: jonbauman on Jan 25, '05 11:37:19AM

I often find that I want to replace something in my previous command (or any previous command, really), but that there is more than one occurrence. For example, if I want to run he following commands

cp foo/bar/baz.txt qux/bar
cp foo/zar/bax.txt qux/zar

You can't use ^bar^zar, because only the first "bar" would be changed. You need to do a global replace. To do that, use the following command:

!!:gs/bar/zar/

The s/old/new/ command is a substitution idiom used in many different languages. Adding the g makes it apply globally. Also, instead of !! to refer to the last command, you can use !-n to refer to n commands previous.

---

jon

[ Reply to This | # ]