Question: I am trying to replace string in a file using this command in a script:-

```
sed -i "find replace" file_name

```

But the file permissions are getting changed after this.

Please help

Answer: 
Permissions are preserved on my Fedora system. In any case, you can tell `sed` to keep the old file around. Then you can copy the permissions over:

```
sed -i.old "find replace" file_name
chmod --reference file_name.old file_name
rm file_name.old

```
Looks like it is an issue in some `linux` versions. I searched couple of related questions but got no answer. Search for your specific `linux` version.

As an alternative, you can copy the content to another temp file, do search and replace in temp\_file and then put data back to file\_name.

```
cp file_name tmp_file_name
sed "find replace" tmp_file_name> file_name  

```

Here are the links I found which shows no answer for this problem.

<https://unix.stackexchange.com/questions/244603/why-is-sed-changing-permissions-of-a-file-on-a-cifs-mounted-share>

<https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=695157>