Find and replace command sed for Ubuntu/Linux, find and replace the occurrence of particular string in a directory or sub directory using below commands:
- Search for the occurrence of the string in directory or sub-directory.
grep -rl . 2> /dev/null
- Find and replace the occurrence of given string in a directory and its subdirectory, ex: replace 'foo' with 'bar'.
find . -exec sed -i -e 's/foo/bar/g' {} \;
- Find and replace the occurrence of given string as website URL with given string in a directory and its subdirectory, ex: replace 'http://www.example.com/foo' with 'bar'.
find . -exec sed -i -e 's+http://www.example.com/foo+/bar+g' {} \;
- Log in to post comments