Linux command line – find and replace text in files

The following command recursively finds files in subfolders and replaces the given “oldtext” with “newtext”. Observe the back-slash before the semi-colon at the end or it might throw this errorĀ find: missing argument to ‘-exec’.

find /targetdir -name *.txt -type f -exec sed -i ‘s/oldtext/newtext/g’ {} \;

Leave a Reply

Your email address will not be published. Required fields are marked *