Q:

track environment changes upon login

Is there any way to track which files and which commands are executed when logging in?
I've made some changes to the /etc/profile and /etc/bashrc file but they don't seem to be picked up when I login as root (sudo -i) and I'm wondering which files are sourced and in what order.
What I'm looking for is something like the set -x command, but that only works for the current session and is not applied when changing user.

A:

The following command will simulate login in bash:
PS4='+$BASH_SOURCE> ' BASH_XTRACEFD=7 bash -xl 7>&2

