I'm having a problem and need to print out to the console all files that are being access each time bash is executed on macOS.
Is there a relatively easy method for doing this? Perhaps dtrace might make this fairly straight forward?
I'm having a problem and need to print out to the console all files that are being access each time bash is executed on macOS.
Is there a relatively easy method for doing this? Perhaps dtrace might make this fairly straight forward?
If you want to see all the files that any process named 'bash' opens directly, you can do something like this:
$ sudo dtrace -n 'syscall::open*:entry/execname == "bash"/{ trace(copyinstr(arg0)); }'
You may, alternatively, want to see all the files opened between when bash starts and you get to the prompt. For that, you could do something like this:
$ sudo dtrace -n 'syscall::open*:entry/progenyof($target)/{ printf("%s %s", execname, copyinstr(arg0)) }' -c bash
Note that this will show both the file being opened as well as the command accessing it.