DEV Community

ChungWei Wei
ChungWei Wei

Posted on • Originally published at kmp.tw on

[Linux] How To Stop Ubuntu 22.04 Sleep With Command

Situation

Prevent Machine Sleep

How To

Check sleep.target Status

root@desktop:~# systemctl status sleep.target
○ sleep.target - Sleep
     Loaded: loaded (/lib/systemd/system/sleep.target; static)
     Active: inactive (dead) since Wed 2023-03-29 00:02:04 CST; 6min ago
       Docs: man:systemd.special(7)

Feb 03 10:00:50 desktop systemd[1]: Reached target Sleep.
Mar 29 00:02:04 desktop systemd[1]: Stopped target Sleep.
Enter fullscreen mode Exit fullscreen mode

Set mask In sleep.target,suspend.target, hibernate.target And hybrid-sleep.target

root@desktop:~# systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
Created symlink /etc/systemd/system/sleep.target → /dev/null.
Created symlink /etc/systemd/system/suspend.target → /dev/null.
Created symlink /etc/systemd/system/hibernate.target → /dev/null.
Created symlink /etc/systemd/system/hybrid-sleep.target → /dev/null.
root@desktop:~# systemctl status sleep.target
○ sleep.target
     Loaded: masked (Reason: Unit sleep.target is masked.)
     Active: inactive (dead) since Wed 2023-03-29 00:02:04 CST; 8min ago

Feb 03 10:00:50 desktop systemd[1]: Reached target Sleep.
Mar 29 00:02:04 desktop systemd[1]: Stopped target Sleep.
Enter fullscreen mode Exit fullscreen mode

Done

Top comments (0)