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

Before WooCommerce 11.4 arrives, test your gift guide on a store copy. Choosing Medium should narrow the knitwear grid and leave the sale gifts below it alone.

AI can read the bank account number on a PDF invoice. If it differs from the supplier’s approved account, accounts payable puts the payment on hold and calls the supplier.

Let’s Encrypt moves to 64-day certificates on 10 February 2027. Check when each site renews, test the reload and verify the certificate visitors receive.

Work out which Drupal 10 sites can move to Drupal 11 by 9 December, who can resolve each blocker and how to test publishing and rollback before launch.

See how SharePoint access changes reach internal AI search, and test how long revoked content can still appear in results, generated answers, and citations.

At month-end, reconcile Shopify Payments against your bank statement and e-conomic. Use the payout ID to trace fees, refunds, and payouts that reach your bank the following month.

Trace an intermittent NGINX 502 through Cloudflare, upstream attempts, and application logs so you can see where the request failed and who should pick it up.

Find the apps, scripts and printers that still send mail through Microsoft 365 with a mailbox password, then test a replacement before the December 2026 change.

Find subscriptions and insurance expenses in e-conomic that should be spread over several months. See how AI reads the supporting documents and how your finance lead approves the proposed allocations.

Before relying on an AI project briefing, check which files it covered. A practical workflow for tracking documents, recording gaps and verifying key claims.