Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sed search and replace without changing ownership

Tags:

replace

unix

sed

I found this command line search and replace example:

find . -type f -print0 | xargs -0 sed -i 's/find/replace/g'

It worked fine except it changed the date and file ownership on EVERY file it searched through, even those that did not contain the search text.

What's a better solution to this task?

like image 834
Ian Avatar asked Jan 22 '23 07:01

Ian


1 Answers

Using the -c option (if you are on Linux) ought to cause sed to preserve ownership. As you are using the command, it is in fact rewriting every file, even though it is not making changes to the files that do not contain find.

like image 152
Isaac Avatar answered Jan 31 '23 08:01

Isaac