Find out what scripts are being run by bash on startup

If your system has strace then you can list the files opened by the shell, for example using

echo exit | strace bash -li |& grep '^open'

(-li means login shell interactive; use only -i for an interactive non-login shell.)

This will show a list of files which the shell opened or tried to open. On my system, they are as follows:

  1. /etc/profile
  2. /etc/profile.d/* (various scripts in /etc/profile.d/)
  3. /home/<username>/.bash_profile (this fails, I have no such file)
  4. /home/<username>/.bash_login (this fails, I have no such file)
  5. /home/<username>/.profile
  6. /home/<username>/.bashrc
  7. /home/<username>/.bash_history (history of command lines; this is not a script)
  8. /usr/share/bash-completion/bash_completion
  9. /etc/bash_completion.d/* (various scripts providing autocompletion functionality)
  10. /etc/inputrc (defines key bindings; this is not a script)

Use man strace for more information.


Reviving this question because strace is an overkill here.

Execute bash and carve it out of the output. -li is login interactively, -x prints out what bash is doing internally, and -c exit tells bash to terminate immediately. Using sed to filter out the source command printout.

/bin/bash -lixc exit 2>&1 | sed -n 's/^+* source //p'

Tags:

Bash

Profile