General Computing
macos command-line bash shell
Updated Fri, 20 May 2022 01:18:44 GMT

How do I investigate commands being run when changing directories?

I see awk, find, sed, and which momentarily appear in my Terminal window's title when changing directories. (And not all of these always appear and there could be some I'm missing; I imagine this is because the title changes multiple times before the UI redraws.)

Although this is likely just some shell scripts and additions I've installed along the way (git status in PS1, perhaps), I'd like to investigate it just to make sure. Is there an easy way to find out what script(s) are calling these?

Note on Context: I'm looking for a general investigative approach to discovering what is calling the sub-commands. My programmer's mindset makes me want a solution that would temporarily replace the sub-command with a stubbed one ( la #define/#undef) that would dump a stack trace at the point of call, then either call the original command or just abort. This approach may or may not be applicable to the shell.

Also: I'm primarily on OS X 10.8 using GNU bash 3.2.48. I'm not sure if the system and bash version is completely relevant to the problem at-hand a solution that works on my Debian instance as well would be nice.


With bash you can use set -o verbose:

$ set -o verbose
$ cd ~/Documents
cd ~/Documents

bash -lv would start a new login shell with the same option enabled.

For example update_terminal_cwd is defined in /etc/bashrc, which isn't indexed by Spotlight. But you can see the definition with declare -f update_terminal_cwd or set.

sudo opensnoop -n bash shows what files are accessed by processes named bash.