November
18
Linux: Finding text within multiple files in multiple directories and replacing the text
I like to start these type of recursive runs in the root directory of the search. So in our test case I would do the following:
Eg. Find the port number 8080 in multiple .xml files and replace it with the port number 15001.
- cd /path/rootdirectoryofsearch
*note – Change which files get examined by changing the extension type:
- Then run the command
With Backup .mybackup
find . -type f -name “*.xml” -exec sed -i.mybackup -e ‘s/8080/15001/g’ {} + - Delete backups:
find . -name “*.mybackup” -type f – delete - With Backup
find . -type f -name “*.xml” -exec sed -i” ‘s/8080/15001/g’ {} +