To log out of Ubuntu desktop session from the command line run the gnome-session-quit command, adding the --no-prompt flag to log out instantly.
Need to check Ubuntu version number? You can find it by running a single command in a terminal, or by using a built-in utility. This post shows you how.