Ubuntu – How to safely shutdown/reboot/logout KDE from the command line

command linekderebootshutdown

I am not talking about shutdown and reboot commands. I want to initiate the same routine from command line that would be performed if I would press the logout/reboot/shutdown button inside the KDE desktop.

Best Answer

Note that this answer was written in 2010 for KDE 4. It may not apply to modern systems.

For kde4:

qdbus org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout -1 -1 -1

The three integer parameters are the confirm, sdtype and sdmode arguments to KWorkSpace::requestShutDown. Their values are explained at the top of the page. Since the page has disappeared, here are the values (still present in a cache).

enum ShutdownConfirm {
  ShutdownConfirmDefault = -1,
  ShutdownConfirmNo = 0,
  ShutdownConfirmYes = 1
}
  • ShutdownConfirmDefault: Obey the user's confirmation setting.
  • ShutdownConfirmNo: Don't confirm, shutdown without asking.
  • ShutdownConfirmYes: Always confirm, ask even if the user turned it off.
enum ShutdownMode {
  ShutdownModeDefault = -1,
  ShutdownModeSchedule = 0,
  ShutdownModeTryNow = 1,
  ShutdownModeForceNow = 2,
  ShutdownModeInteractive = 3
}
  • ShutdownModeDefault: Select previous mode or the default if it's the first time.
  • ShutdownModeSchedule: Schedule a shutdown (halt or reboot) for the time all active sessions have exited.
  • ShutdownModeTryNow: Shut down, if no sessions are active. Otherwise do nothing.
  • ShutdownModeForceNow: Force shutdown. Kill any possibly active sessions.
  • ShutdownModeInteractive: Pop up a dialog asking the user what to do if sessions are still active.
enum ShutdownType {
  ShutdownTypeDefault = -1,
  ShutdownTypeNone = 0,
  ShutdownTypeReboot = 1,
  ShutdownTypeHalt = 2,
  ShutdownTypeLogout = 3
}
  • ShutdownTypeDefault: Select previous action or the default if it's the first time.
  • ShutdownTypeNone: Only log out.
  • ShutdownTypeReboot: Log out and reboot the machine.
  • ShutdownTypeHalt: Log out and halt the machine.
  • ShutdownTypeLogout: Temporary brain damage. Don't use. Same as ShutdownTypeNone