3

In terminal, I can replace previous command by using '^' like:

$ ls -a 

$ ^a^l

$ ls -l

But, how can I replace multiple times? I mean:

$ ls a.jpg b.jpg c.jpg

$ /* something */

$ ls a.png b.png c.png
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Ya Zhuang
  • 4,652
  • 31
  • 40
  • 1
    +1 for showing the `^a^b` syntax which is cool and new to me:) – Daniel Böhmer Nov 02 '11 at 09:18
  • 2
    http://stackoverflow.com/questions/2149482/caret-search-and-replace-in-bash-shell – Frost Nov 02 '11 at 09:21
  • 1
    You cannot use `^a^l` as a replacement "in terminal". It is valid syntax in `bash`, `csh`, and many other shells, but it is invalid in `dash`, `ksh`, and many other shells. The shell is not the terminal. – William Pursell Nov 14 '12 at 16:13
  • Does this answer your question? [^word^replacement^ on all matches in Bash?](https://stackoverflow.com/questions/649070/wordreplacement-on-all-matches-in-bash) – Benjamin W. Sep 30 '21 at 09:23

2 Answers2

3

What you want is global replacements

!!:gs/jpg/png
carrutherji
  • 1,115
  • 10
  • 18
3
!:gs/jpg/png
Ariel
  • 25,995
  • 5
  • 59
  • 69