Find and replace string in files recursively

Illustrated infographic summarizing: Find and replace string in files recursively

This is the best option I have found so far: find . -type f -exec sed -i 's/foo/bar/g' {} +
foo is replaced with bar.

Source: https://linuxize.com/post/how-to-use-sed-to-find-and-replace-string-in-…

Also quite handy to be able to search and replace filenames.

find . -type f -name 'foo*' | while read FILE ; do
    newfile="$(echo ${FILE} |sed -e 's/foo/bar/')" ;
    mv "${FILE}" "${newfile}" ;
done 

Source: https://unix.stackexchange.com/questions/175135/how-to-rename-multiple-…

 

Also a useful thing is to search for strings within files: grep -rn '/path/to/somewhere/' -e "pattern"

Here for searching for strings in PDF-files: find /path -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color "your pattern"' \;

sed Examples

List folders in folder and show each folder on one line. The software sed is piped and will replace all the slash characters with an empty character: ls -p | grep / | sed "s/\///g"

Latest articles

When an OpenAI request stalls, customers need an accurate status. Set sensible retry limits, preserve submissions, and make unresolved work visible.

I learned server operations by breaking my own servers. I want someone who stands next to me while I do it, then does it themselves the week after.

I am good at building and bad at calling. Here is who I want next to me, what is easiest to sell, and how we split it.

An AI assistant can prepare a refund, but a person should approve the exact payment and amount. Here is how to make that approval hold up through execution and retries.

AI can pull together onboarding tasks before a new hire’s first day. See how the manager approves specific access and how outstanding tasks are followed through.

An internal AI assistant can cite an obsolete handbook with confidence. Here is how to manage document ownership, updates, deletions, access and answer review.

Cloudflare Free provides useful website protection, but its rate limiting and bot controls have limits. Here is how to assess them for a WordPress site.

An AI assistant can answer questions and guide customers to a booking. Here are practical boundaries for prices, delivery times, personal data, and contact with a staff member.

Google and Bing now offer first-party AI search visibility reports. Here’s how to build a useful baseline without inventing a misleading GEO score.

AI crawlers can copy a familiar name. Here’s how to verify signed agents at the edge while keeping legitimate automated traffic moving.