If you are using gnome,
gnome-session-quit
or
gnome-session-save --force-logout
or also
dbus-send --session --type=method_call --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1
If you use KDE,
qdbus org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout -1 -1 -1
In LXDE,
lxde-logout
In XFCE,
xfce4-session-logout
Whatever your desktop environment, you can define an alias to make your life easier. Edit the file /home/your_name/.bashrc,
and place in it, toward the end, the following line:
alias mylg='gnome-session-quit'
or whichever command you wish. Source the file,
source .bashrc
and you now have a brand new command, mylg, which will log you out.