Celeb Glow
general | March 27, 2026

How to replace a string in multiple files in multiple folders with different hierarchy in linux command line

I have many files with the extension *.launch distributed in different folders inside the parent directory, the hierarchy is not always the same for the .launch file. i.e: src/folder/sth.launch and src/folder2/../../another.launch, so this solution doesn't work here!

How can I replace a string xarco.py with another string xarcoin all these*launch files in different folders and levels using Linux command? thanks in advance.

1 Answer

When in the parent directory, you can try with the following command,

find . -type f -name "*.launch" -exec echo sed -i 's/ {} \;

and if it 'looks good' remove echo to do the real job,

find . -type f -name "*.launch" -exec sed -i 's/ {} \;

If there are problems with permissions, you may need to prefix with sudo:

sudo find ...
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy