How to use the command rtcwake (with examples)
- Linux
- December 25, 2023
The command rtcwake is used to enter a system sleep state until a specified wakeup time relative to your BIOS clock. This command is useful for scheduling system events or automating power management tasks.
Use case 1: Show whether an alarm is set or not
Code:
sudo rtcwake -m show -v
Motivation: This use case allows you to check if there is any alarm set using rtcwake. It helps you confirm whether a wakeup event is scheduled or not.
Explanation:
sudo
: This command is run with superuser privileges to access system sleep states.rtcwake
: The command itself.-m show
: This option shows information about the current alarm status.-v
: This option enables verbose mode and provides more detailed output.
Example output:
rtcwake: wakeup from "off" using /dev/rtc0 at Thu 10 Feb 2022 10:30:00 PM UTC
Use case 2: Suspend to RAM and wakeup after 10 seconds
Code:
sudo rtcwake -m mem -s 10
Motivation: This example demonstrates how to suspend the system to RAM and wake it up after a specific duration, in this case, 10 seconds. It can be useful for testing system behavior after waking up from sleep.
Explanation:
-m mem
: This option specifies the sleep state as suspend to RAM (memory).-s 10
: This option sets the wakeup time relative to the current time. In this case, it is set to wake up after 10 seconds.
Example output:
rtcwake: wakeup using /dev/rtc0 at Fri 11 Feb 2022 09:40:20 AM UTC
Use case 3: Suspend to disk and wakeup 15 minutes later
Code:
sudo rtcwake -m disk --date +15min
Motivation: This use case demonstrates how to put the system into a deep sleep state (suspend to disk) to save power and wake it up after a specific time, in this case, 15 minutes. It can be helpful if you want to use minimal power during a short break.
Explanation:
-m disk
: This option specifies the sleep state as suspend to disk.--date +15min
: This option sets the wakeup time relative to the current time. In this case, it is set to wake up after 15 minutes.
Example output:
rtcwake: wakeup using /dev/rtc0 at Fri 11 Feb 2022 09:55:00 AM UTC
Use case 4: Freeze the system and wakeup at a given date and time
Code:
sudo rtcwake -m freeze --date YYYYMMDDhhmm
Motivation: This use case showcases the ability to freeze the system, which is more efficient than suspend-to-RAM. It can be useful for scheduled events or system maintenance tasks. However, it requires a Linux kernel version 3.9 or newer.
Explanation:
-m freeze
: This option specifies the sleep state as freeze.--date YYYYMMDDhhmm
: This option sets the exact date and time when the system should wake up. You need to replaceYYYYMMDDhhmm
with the desired date and time in the format YearMonthDayHourMinute.
Example output:
rtcwake: wakeup using /dev/rtc0 at Sat 12 Feb 2022 02:30:00 PM UTC
Use case 5: Disable a previously set alarm
Code:
sudo rtcwake -m disable
Motivation: This example illustrates how to disable a previously set alarm using rtcwake. It can be useful if you want to cancel a scheduled wakeup event.
Explanation:
-m disable
: This option disables the currently set alarm.
Example output:
rtcwake: wakeup from "off" using /dev/rtc0 at (unset)
Use case 6: Perform a dry run to wakeup the computer at a given time
Code:
sudo rtcwake -m on --date hh:ss
Motivation: This use case allows you to simulate a wakeup event without actually entering the sleep state. It helps you verify if the desired wakeup time is correctly set.
Explanation:
-m on
: This option specifies the sleep state as on (active mode).--date hh:ss
: This option sets the desired wakeup time. You need to replacehh:ss
with the desired hour and minute in the format Hour:Minute.
Example output:
rtcwake: assuming RTC uses UTC ...
rtcwake: wakeup using /dev/rtc0 at Fri 11 Feb 2022 04:30:00 AM UTC
Conclusion:
In this article, we covered several use cases of the rtcwake command. From checking alarm status to scheduling wakeup events, rtcwake offers a convenient way to manage power management tasks and automate system events. By understanding and utilizing the different options provided by rtcwake, you can effectively control when your system wakes up from sleep states.