caffeinate
Prevent system from going idle/sleep
TLDR
Prevent desktop from sleeping (use
SYNOPSIS
caffeinate [options] [command [args...]]
PARAMETERS
-s
Prevent the system from going to sleep while caffeinate is running. This typically inhibits system-wide suspend/hibernate states.
-d
Prevent the display from dimming or blanking while caffeinate is running. This often involves inhibiting display power management.
-i
Prevent the system from entering idle sleep, even if no explicit command is running. Similar to -s but specifically targets idle-initiated sleep.
-t seconds
Keep the system awake for a specified duration in seconds, then exit.
-u
Simulate user activity (e.g., keyboard presses, mouse movements) to keep the system awake. This is a less robust method but can be used in some graphical environments.
DESCRIPTION
The caffeinate command, popularized by macOS, is designed to prevent a system from entering sleep mode or dimming/blanking its display. On Linux, there isn't a universally pre-installed command named caffeinate that performs this exact function out-of-the-box across all distributions. However, the functionality is commonly achieved using various tools and custom scripts. A Linux equivalent typically works by inhibiting power management mechanisms (like systemd's suspend/idle timers) or by simulating user activity to keep the display awake.
Common use cases include running long-duration tasks (compilations, backups, downloads) where the system should not sleep, or during presentations where the display should remain active. When caffeinate is run with a command, it keeps the system awake only for the duration of that command's execution. If run without a command, it typically keeps the system awake indefinitely until manually terminated (e.g., via Ctrl+C).
CAVEATS
caffeinate is not a standard, universally available command on Linux distributions. Its functionality is typically implemented via wrapper scripts or aliases that utilize underlying Linux power management tools. Therefore, its behavior, available options, and installation method can vary significantly depending on the distribution and the specific implementation.
Permissions are often a factor: inhibiting system-wide sleep usually requires appropriate permissions (e.g., via logind for systemd-inhibit). Simulating user activity might require xdotool or similar utilities and an X server.
HOW <I>CAFFEINATE</I> IS TYPICALLY IMPLEMENTED ON LINUX
On Linux, a caffeinate script usually acts as a front-end to more fundamental power management commands. For inhibiting system sleep, it most commonly relies on systemd-inhibit. This command allows applications to declare that certain power management actions (like sleep, suspend, or shutdown) should be temporarily blocked. For preventing display blanking in graphical environments, it might use xset -dpms or xset s off to disable display power management, or xset dpms force on to ensure the display is always on. Some implementations might even simulate periodic mouse movements or keyboard presses using tools like xdotool to trick the system into thinking there's user activity. The specific underlying command chosen depends on the desired level of inhibition and the system's configuration.
HISTORY
The caffeinate command originated on Apple's macOS (OS X) as part of the pmset utility, providing a user-friendly way to prevent the system from sleeping. Its popularity led to Linux users seeking similar functionality. On Linux, this often resulted in custom scripts or aliases, typically named caffeinate, that wrap existing power management commands like systemd-inhibit (for modern systems with systemd) or xset (for controlling X display power management). While not a native Linux command, the concept and name are widely recognized and replicated within the Linux community.
SEE ALSO
systemd-inhibit(1), xset(1), pm-suspend(8), xdotool(1)