Two files have suddenly appeared in my home directory, called "aa" and "err". They are empty. I'm wondering how they got there. I deleted the files and they are created again after some seconds.
Is there a way to monitor the home directory for the creation of files to find out where they came from?
I mention that lsof
couldn't help in this case (I got an empty result using lsof aa
)
Best Answer
fs_usage
is your tool for this.The file system usage tool is ideal since it taps in to the real time file system events and dumps activity to a file or the screen. Since you know the exact path of the file, you can filter out all the thousands of irrelevant (to this case) filesystem changes and see what reads / writes to that file pretty quickly.
If your home directory is
/Users/me
then you can filter for/Users/me/aa
(note: I deleted a lot of white space above - the fs_usage command outputs a wide amount of empty space so you can't easily see the touch command on the far right if I copy/paste the exact output.)
Here I use the
touch
command to create the file, append a string to it and thenrm
it from the command line.There will be tons of other apps that read, so you can filter on the stat64 and lstat74 operations if there are too many attribute reads and spotlight activity around the file once it's created.
The manual page for this command is quite dense (and not a "how-to") which is typical but better than no documentation from Apple on how to use it.