Find and replace all text (strings) interactivelly in Emacs

This how to search/find/query and replace a string recursively in a directory in interctive manner.

Method 1

  1. M-x find-dired-name: Choose a subdirectory you want to search in.
  2. t: “toggle mark” for all files you find
  3. Q: “Query-replace” interactively
  4. C-x s ! to save all files changed at once, but there are an option to save one by one

Credit to Stackoverflow thread

Method 2

  1. C-x d: for Emacs’ built-in file manager dired
  2. Mark some files for the operation with m (Unmark with u).
  3. M-x (also known as Alt-x) dired-do-query-replace-regexp or simply press Q.
  4. Interactive prompt appears in minibuffer (ie. the bottom-line of the screen)
  5. Enter query term (a string like “foo”)
  6. Enter replace term (like “bar”)
  7. Results will appear in a new window, then press ? for available options.

Credit to Xah-Lee blog.