'Special characters being added to linux file

In one of my box, I see special characters being added to "/etc/hosts" file. Not sure what is causing this. Any idea on how to debug this ?

^@^@^@^@^@^@^@^@^@^@127.0.1.1    linux-host


Solution 1:[1]

You can try to use the lsof command to see what process opens the file. For example:

$ sudo lsof /bin/ping
COMMAND  PID USER  FD   TYPE DEVICE SIZE/OFF    NODE NAME
ping    4216 amit txt    REG    8,1    64424 1048708 /bin/ping

It will be trickier to catch it if the process doesn't keep the fd of the file open though...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Amit Sides