"If you log in in text mode then start a GUI session with xinit or with the wrapper script startx, then xinit does the following things:
- Start an X server (typically through the script
/etc/X11/xinit/xserverrc). - Usually run some scripts in
/etc/X11(typically/etc/X11/xinit/xinitrc), depending on how it's set up. - Run
~/.xinitrc, if it exists. If it doesn't exist, run a default client (traditionallyxterm). - Once
~/.xinitrcterminates, kill the X server.
If you log in in graphical mode on an X display manager (xdm, gdm, kdm, wdm, lightdm, …), traditionally, what is executed after you log in is some scripts in /etc/X11 then ~/.xsession.