With Ubuntu 16.04 LTS an newer I would suggest using systemctl
instead because newer systems use systemd
to control things.
The safe command to run is systemctl suspend
which suspends the machine immediately unless some process is asking the system to stay powered (e.g. video player showing a movie, active CD burner, another logged in user doing anything, etc).
If you want to force suspend immediately and ignore all "inhibitors" simply add -i
as explained by the output of the above command.
If you want to immediately lock the screensaver and suspend the system in all cases, you can run
loginctl lock-session && systemctl suspend -i
This is better than using raw dbus
to send messages because using loginctl
and systemctl
avoids hardcoding any info about your screensaver or session manager.
alt+shift+s
. Validated on 22.04.3 but I think it exists for a very long time now.