How to determine which process is creating a file?












6














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)










share|improve this question
























  • These seem like. remnants of an attempt to program in Node.js. Look at how the variables in this Stack Overflow thread are named.
    – JakeGould
    Dec 31 '18 at 4:32










  • @JakeGould, thanks but your link shows a custom code. It's not related.
    – Kwadz
    18 hours ago
















6














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)










share|improve this question
























  • These seem like. remnants of an attempt to program in Node.js. Look at how the variables in this Stack Overflow thread are named.
    – JakeGould
    Dec 31 '18 at 4:32










  • @JakeGould, thanks but your link shows a custom code. It's not related.
    – Kwadz
    18 hours ago














6












6








6


5





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)










share|improve this question















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)







macos file






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 30 '18 at 15:37









bmike

157k46282611




157k46282611










asked Dec 30 '18 at 15:03









KwadzKwadz

15616




15616












  • These seem like. remnants of an attempt to program in Node.js. Look at how the variables in this Stack Overflow thread are named.
    – JakeGould
    Dec 31 '18 at 4:32










  • @JakeGould, thanks but your link shows a custom code. It's not related.
    – Kwadz
    18 hours ago


















  • These seem like. remnants of an attempt to program in Node.js. Look at how the variables in this Stack Overflow thread are named.
    – JakeGould
    Dec 31 '18 at 4:32










  • @JakeGould, thanks but your link shows a custom code. It's not related.
    – Kwadz
    18 hours ago
















These seem like. remnants of an attempt to program in Node.js. Look at how the variables in this Stack Overflow thread are named.
– JakeGould
Dec 31 '18 at 4:32




These seem like. remnants of an attempt to program in Node.js. Look at how the variables in this Stack Overflow thread are named.
– JakeGould
Dec 31 '18 at 4:32












@JakeGould, thanks but your link shows a custom code. It's not related.
– Kwadz
18 hours ago




@JakeGould, thanks but your link shows a custom code. It's not related.
– Kwadz
18 hours ago










1 Answer
1






active

oldest

votes


















9














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



mac:~ me$ sudo fs_usage | grep /Users/me/aa
09:35:21 stat64 /Users/me/aa 0.000033 touch
09:35:21 utimes /Users/me/aa 0.000104 touch
09:35:21 fsgetpath /Users/me/aa 0.000119 Finder
09:35:22 lstat64 /Users/me/aa 0.000039 fseventsd
09:35:22 fsgetpath /Users/me/aa 0.000027 mds
09:35:22 getattrlist /Users/me/aa 0.000064 mds
09:35:22 listxattr /Users/me/aa 0.000012 mds
09:35:22 getattrlist /Users/me/aa 0.000130 mds
09:35:22 getattrlist /Users/me/aa 0.000033 mds
09:35:22 open /Users/me/aa 0.000071 mdworker_sha
09:35:22 RdData[AT2] /Users/me/aa 0.000331 W mdworker_sha
09:35:22 getattrlist /Users/me/aa 0.000042 mds
09:35:24 lstat64 /Users/me/aa 0.000114 rm
09:35:24 access /Users/me/aa 0.000209 rm
09:35:24 unlink /Users/me/aa 0.000909 rm
09:35:25 lstat64 /Users/me/aa 0.000042 fseventsd
09:35:25 lstat64 /Users/me/aa 0.000006 rm


(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 then rm it from the command line.



mac:~ me$ touch ~/aa
mac:~ me$ echo foo >> ~/aa
mac:~ me$ rm ~/aa


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.




  • http://toddsnotes.blogspot.com/2014/02/use-fsusage-to-monitor-file-system.html

  • https://developer.apple.com/library/archive/documentation/Performance/Conceptual/FileSystem/Articles/FileSystemCalls.html


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.






share|improve this answer























  • Wow thanks. great answer. I believe fs_usage command bases on the FSEvents facility of MacOS. Do you know if this facility can be used also from within an iOS application?
    – Motti Shneor
    Jan 2 at 7:00










  • @bmike, when using touch we can see stat64 and open commands. I am wondering what command creates actually the file. In my case I get directly the following without anything before fsgetpath of Finder : imgur.com/a/AsA9O5s
    – Kwadz
    18 hours ago










  • That would make a good follow on question. In my case, the stat64 created the file. I doubt Finder and mds are creating the file in your case so I would need to see more of the logs to help out. @Kwadz When you delete the file, what is the first entry in the fs_usage?
    – bmike
    13 hours ago













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "118"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fapple.stackexchange.com%2fquestions%2f347040%2fhow-to-determine-which-process-is-creating-a-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









9














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



mac:~ me$ sudo fs_usage | grep /Users/me/aa
09:35:21 stat64 /Users/me/aa 0.000033 touch
09:35:21 utimes /Users/me/aa 0.000104 touch
09:35:21 fsgetpath /Users/me/aa 0.000119 Finder
09:35:22 lstat64 /Users/me/aa 0.000039 fseventsd
09:35:22 fsgetpath /Users/me/aa 0.000027 mds
09:35:22 getattrlist /Users/me/aa 0.000064 mds
09:35:22 listxattr /Users/me/aa 0.000012 mds
09:35:22 getattrlist /Users/me/aa 0.000130 mds
09:35:22 getattrlist /Users/me/aa 0.000033 mds
09:35:22 open /Users/me/aa 0.000071 mdworker_sha
09:35:22 RdData[AT2] /Users/me/aa 0.000331 W mdworker_sha
09:35:22 getattrlist /Users/me/aa 0.000042 mds
09:35:24 lstat64 /Users/me/aa 0.000114 rm
09:35:24 access /Users/me/aa 0.000209 rm
09:35:24 unlink /Users/me/aa 0.000909 rm
09:35:25 lstat64 /Users/me/aa 0.000042 fseventsd
09:35:25 lstat64 /Users/me/aa 0.000006 rm


(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 then rm it from the command line.



mac:~ me$ touch ~/aa
mac:~ me$ echo foo >> ~/aa
mac:~ me$ rm ~/aa


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.




  • http://toddsnotes.blogspot.com/2014/02/use-fsusage-to-monitor-file-system.html

  • https://developer.apple.com/library/archive/documentation/Performance/Conceptual/FileSystem/Articles/FileSystemCalls.html


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.






share|improve this answer























  • Wow thanks. great answer. I believe fs_usage command bases on the FSEvents facility of MacOS. Do you know if this facility can be used also from within an iOS application?
    – Motti Shneor
    Jan 2 at 7:00










  • @bmike, when using touch we can see stat64 and open commands. I am wondering what command creates actually the file. In my case I get directly the following without anything before fsgetpath of Finder : imgur.com/a/AsA9O5s
    – Kwadz
    18 hours ago










  • That would make a good follow on question. In my case, the stat64 created the file. I doubt Finder and mds are creating the file in your case so I would need to see more of the logs to help out. @Kwadz When you delete the file, what is the first entry in the fs_usage?
    – bmike
    13 hours ago


















9














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



mac:~ me$ sudo fs_usage | grep /Users/me/aa
09:35:21 stat64 /Users/me/aa 0.000033 touch
09:35:21 utimes /Users/me/aa 0.000104 touch
09:35:21 fsgetpath /Users/me/aa 0.000119 Finder
09:35:22 lstat64 /Users/me/aa 0.000039 fseventsd
09:35:22 fsgetpath /Users/me/aa 0.000027 mds
09:35:22 getattrlist /Users/me/aa 0.000064 mds
09:35:22 listxattr /Users/me/aa 0.000012 mds
09:35:22 getattrlist /Users/me/aa 0.000130 mds
09:35:22 getattrlist /Users/me/aa 0.000033 mds
09:35:22 open /Users/me/aa 0.000071 mdworker_sha
09:35:22 RdData[AT2] /Users/me/aa 0.000331 W mdworker_sha
09:35:22 getattrlist /Users/me/aa 0.000042 mds
09:35:24 lstat64 /Users/me/aa 0.000114 rm
09:35:24 access /Users/me/aa 0.000209 rm
09:35:24 unlink /Users/me/aa 0.000909 rm
09:35:25 lstat64 /Users/me/aa 0.000042 fseventsd
09:35:25 lstat64 /Users/me/aa 0.000006 rm


(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 then rm it from the command line.



mac:~ me$ touch ~/aa
mac:~ me$ echo foo >> ~/aa
mac:~ me$ rm ~/aa


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.




  • http://toddsnotes.blogspot.com/2014/02/use-fsusage-to-monitor-file-system.html

  • https://developer.apple.com/library/archive/documentation/Performance/Conceptual/FileSystem/Articles/FileSystemCalls.html


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.






share|improve this answer























  • Wow thanks. great answer. I believe fs_usage command bases on the FSEvents facility of MacOS. Do you know if this facility can be used also from within an iOS application?
    – Motti Shneor
    Jan 2 at 7:00










  • @bmike, when using touch we can see stat64 and open commands. I am wondering what command creates actually the file. In my case I get directly the following without anything before fsgetpath of Finder : imgur.com/a/AsA9O5s
    – Kwadz
    18 hours ago










  • That would make a good follow on question. In my case, the stat64 created the file. I doubt Finder and mds are creating the file in your case so I would need to see more of the logs to help out. @Kwadz When you delete the file, what is the first entry in the fs_usage?
    – bmike
    13 hours ago
















9












9








9






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



mac:~ me$ sudo fs_usage | grep /Users/me/aa
09:35:21 stat64 /Users/me/aa 0.000033 touch
09:35:21 utimes /Users/me/aa 0.000104 touch
09:35:21 fsgetpath /Users/me/aa 0.000119 Finder
09:35:22 lstat64 /Users/me/aa 0.000039 fseventsd
09:35:22 fsgetpath /Users/me/aa 0.000027 mds
09:35:22 getattrlist /Users/me/aa 0.000064 mds
09:35:22 listxattr /Users/me/aa 0.000012 mds
09:35:22 getattrlist /Users/me/aa 0.000130 mds
09:35:22 getattrlist /Users/me/aa 0.000033 mds
09:35:22 open /Users/me/aa 0.000071 mdworker_sha
09:35:22 RdData[AT2] /Users/me/aa 0.000331 W mdworker_sha
09:35:22 getattrlist /Users/me/aa 0.000042 mds
09:35:24 lstat64 /Users/me/aa 0.000114 rm
09:35:24 access /Users/me/aa 0.000209 rm
09:35:24 unlink /Users/me/aa 0.000909 rm
09:35:25 lstat64 /Users/me/aa 0.000042 fseventsd
09:35:25 lstat64 /Users/me/aa 0.000006 rm


(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 then rm it from the command line.



mac:~ me$ touch ~/aa
mac:~ me$ echo foo >> ~/aa
mac:~ me$ rm ~/aa


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.




  • http://toddsnotes.blogspot.com/2014/02/use-fsusage-to-monitor-file-system.html

  • https://developer.apple.com/library/archive/documentation/Performance/Conceptual/FileSystem/Articles/FileSystemCalls.html


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.






share|improve this 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



mac:~ me$ sudo fs_usage | grep /Users/me/aa
09:35:21 stat64 /Users/me/aa 0.000033 touch
09:35:21 utimes /Users/me/aa 0.000104 touch
09:35:21 fsgetpath /Users/me/aa 0.000119 Finder
09:35:22 lstat64 /Users/me/aa 0.000039 fseventsd
09:35:22 fsgetpath /Users/me/aa 0.000027 mds
09:35:22 getattrlist /Users/me/aa 0.000064 mds
09:35:22 listxattr /Users/me/aa 0.000012 mds
09:35:22 getattrlist /Users/me/aa 0.000130 mds
09:35:22 getattrlist /Users/me/aa 0.000033 mds
09:35:22 open /Users/me/aa 0.000071 mdworker_sha
09:35:22 RdData[AT2] /Users/me/aa 0.000331 W mdworker_sha
09:35:22 getattrlist /Users/me/aa 0.000042 mds
09:35:24 lstat64 /Users/me/aa 0.000114 rm
09:35:24 access /Users/me/aa 0.000209 rm
09:35:24 unlink /Users/me/aa 0.000909 rm
09:35:25 lstat64 /Users/me/aa 0.000042 fseventsd
09:35:25 lstat64 /Users/me/aa 0.000006 rm


(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 then rm it from the command line.



mac:~ me$ touch ~/aa
mac:~ me$ echo foo >> ~/aa
mac:~ me$ rm ~/aa


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.




  • http://toddsnotes.blogspot.com/2014/02/use-fsusage-to-monitor-file-system.html

  • https://developer.apple.com/library/archive/documentation/Performance/Conceptual/FileSystem/Articles/FileSystemCalls.html


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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 30 '18 at 15:55

























answered Dec 30 '18 at 15:45









bmikebmike

157k46282611




157k46282611












  • Wow thanks. great answer. I believe fs_usage command bases on the FSEvents facility of MacOS. Do you know if this facility can be used also from within an iOS application?
    – Motti Shneor
    Jan 2 at 7:00










  • @bmike, when using touch we can see stat64 and open commands. I am wondering what command creates actually the file. In my case I get directly the following without anything before fsgetpath of Finder : imgur.com/a/AsA9O5s
    – Kwadz
    18 hours ago










  • That would make a good follow on question. In my case, the stat64 created the file. I doubt Finder and mds are creating the file in your case so I would need to see more of the logs to help out. @Kwadz When you delete the file, what is the first entry in the fs_usage?
    – bmike
    13 hours ago




















  • Wow thanks. great answer. I believe fs_usage command bases on the FSEvents facility of MacOS. Do you know if this facility can be used also from within an iOS application?
    – Motti Shneor
    Jan 2 at 7:00










  • @bmike, when using touch we can see stat64 and open commands. I am wondering what command creates actually the file. In my case I get directly the following without anything before fsgetpath of Finder : imgur.com/a/AsA9O5s
    – Kwadz
    18 hours ago










  • That would make a good follow on question. In my case, the stat64 created the file. I doubt Finder and mds are creating the file in your case so I would need to see more of the logs to help out. @Kwadz When you delete the file, what is the first entry in the fs_usage?
    – bmike
    13 hours ago


















Wow thanks. great answer. I believe fs_usage command bases on the FSEvents facility of MacOS. Do you know if this facility can be used also from within an iOS application?
– Motti Shneor
Jan 2 at 7:00




Wow thanks. great answer. I believe fs_usage command bases on the FSEvents facility of MacOS. Do you know if this facility can be used also from within an iOS application?
– Motti Shneor
Jan 2 at 7:00












@bmike, when using touch we can see stat64 and open commands. I am wondering what command creates actually the file. In my case I get directly the following without anything before fsgetpath of Finder : imgur.com/a/AsA9O5s
– Kwadz
18 hours ago




@bmike, when using touch we can see stat64 and open commands. I am wondering what command creates actually the file. In my case I get directly the following without anything before fsgetpath of Finder : imgur.com/a/AsA9O5s
– Kwadz
18 hours ago












That would make a good follow on question. In my case, the stat64 created the file. I doubt Finder and mds are creating the file in your case so I would need to see more of the logs to help out. @Kwadz When you delete the file, what is the first entry in the fs_usage?
– bmike
13 hours ago






That would make a good follow on question. In my case, the stat64 created the file. I doubt Finder and mds are creating the file in your case so I would need to see more of the logs to help out. @Kwadz When you delete the file, what is the first entry in the fs_usage?
– bmike
13 hours ago




















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Different!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fapple.stackexchange.com%2fquestions%2f347040%2fhow-to-determine-which-process-is-creating-a-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?