Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Sometimes, being rushed, it is possible to type some characters wrong in a command-line. If the command is long, the mistake correction may be cumbersome (using arrow keys). So the problem is: how can I replace characters typed wrong in the previous command as quickly as possible?

share|improve this question
up vote 9 down vote accepted

One character or more can be replaced with zero, one or more characters as follow:

$ some-wrong-long-command
$ ^wrong^correct^

This quick substitution repeat the last command-line from terminal, replacing wrong string with correct string.


enter image description here

share|improve this answer
Nice, but I actually prefer the arrow keys. And ctrl+arrow and begin/end keys (to jump words or go to start/end of the line directly). Your string replacement solution is nice, but it's easy to make mistakes. Now for cd, that's harmless, but rm could be a desaster. Besides, cd doesn't usually have typos as you'd use tab completion anyway. – frostschutz May 29 '13 at 11:47
@frostschutz I used cd just for example; it could be anything. And, personally, I don't think that I can be passible by a typing mistake if I made another mistake 1 second ago – Radu Rădeanu May 29 '13 at 12:06
+1. the ^bad^good form only replaces the first one. for global replace in the previous command use !!:gs/bad/good – glenn jackman May 29 '13 at 12:25
To repeat the substitution, use :&, i.e. ^bad^good^:& will change bad bad bad to good good bad. You can keep stacking :& but after two probably you should use :gs as suggested. – Chan-Ho Suh May 29 '13 at 20:50
You can also explore the vi mode in bash. This seems to make these things easier. – Phani Oct 1 '14 at 0:51

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.