I have typed out a long command in the BASH but just as I typed the command I see that I have misspelled the command or argument. I want the cursor to go to the argument or command I have misspelled using inplace search instead of hitting arrow keys to go to the particular command or argument.


ls *.txt | grep -e 'foo' >> list_of_text_files_containing_foo.txt

and I want to change foo in grep to bar by find and replace foo to bar inside the command without hitting arrow keys. Is there a way to change all occurrences of foo to bar.


You probably are interested about bash quick substitution in the last command:



$ ls *.txt | grep -e 'foo' >> list_of_text_files_containing_foo.txt
$ !!:gs/foo/bar
ls *.txt | grep -e 'bar' >> list_of_text_files_containing_bar.txt

For more info about bash substitution, read man bash starting from somewhere from the line 3630.


I don't think you can make in-place search , but instead learn keyboard shortcuts to deal with Bash .

Ctrl + L   Clear the Screen, similar to the clear command
 Ctrl + u   Cut/delete the line before the cursor position.

  Alt + Del Delete the Word before the cursor.
  Alt + d   Delete the Word after the cursor.
 Ctrl + d   Delete character under the cursor
 Ctrl + h   Delete character before the cursor (Backspace)
 Ctrl + w   Cut the Word before the cursor to the clipboard.
 Ctrl + k   Cut the Line after the cursor to the clipboard.
  Alt + t   Swap current word with previous
 Ctrl + t   Swap the last two characters before the cursor (typo).
 Esc  + t   Swap the last two words before the cursor.
 ctrl + y   Paste the last thing to be cut (yank)
  Alt + u   UPPER capitalize every character from the cursor to the end of the current word.
  Alt + l   Lower the case of every character from the cursor to the end of the current word.
  Alt + c   Capitalize the character under the cursor and move to the end of the word.
  Alt + r   Cancel the changes and put back the line as it was in the history (revert).
 ctrl + _   Undo

Reference : Link

  • +1 for the tips but I don't want to delete or undo and type the command for which I can better use the arrow keys or shortcuts to move to the word. But a search like this will be quite useful like ctrl + r. – Wordzilla Mar 5 '14 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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