If you keep your computer on all the time, and are looking for a nice way to wake up in the morning, it’s simple. All you need is your regular music player and the ‘sleep’ command. The ‘sleep’ command is a built-in tool (at least in Ubuntu), that allows you to set a timer for any amount of time (seconds, minutes, hours, and days). If we couple the ‘sleep’ command with our favorite music player and song, then we can set an alarm that will wake us up after a set amount of time. Here’s how it works.
Set Sleep Timer in Terminal
First, open your Terminal.
Once the Terminal is open, let’s go over how the ‘sleep’ command works. It’s very simple. To sleep for 10 seconds, use this command:
To sleep for 10 minutes, use this command:
To sleep for 10 hours, use this command:
Finally, to sleep for 10 days, use this command:
You can even combine commands, so if you wanted to sleep for 5 hours and 30 minutes, you would use a single ‘sleep’ command with both times:
It’s easy! Of course, once your time has elapsed, nothing else will happen, because all the ‘sleep’ command does is count down your sleep amount. To make this a true alarm clock, we’ll need to add to the command. For our music player, we’ll use mplayer, but you could just as easily use Totem, VLC, Banshee, or whatever your favorite music player is.
To invoke mplayer, for instance, we would use this command:
Typing this into the Terminal (replacing the actual path and name of the music file, of course), we would be able to listen to whatever song we want. Of course, the drawback (when trying to create our alarm clock), is that the song plays immediately.
The solution? Use the ‘sleep’ command and our music player together. We’ll combine the two commands with ‘&&’ which will run the first command, then only after it completes run the second. Our final command? Assuming we want to sleep for 8 hours:
It’s simple! The ‘sleep’ command will wait 8 hours, then when the time is up, will quit, allowing the second command – where the music is actually played – to begin. Instant alarm clock.
There are a couple drawbacks to this, of course. First is that many people have their computers to either sleep or hibernate after a certain amount of time. This obviously would not be a good thing for our alarm clock. As such, power saving tools may have to be turned off. In addition, don’t forget to double check your volume settings before heading to bed. It wouldn’t be a good thing if your sound had been turned all the way down; you might not wake up the next morning! Still, being able to set up an alarm in only a single command is a great way to take advantage of the Terminal; it really does offer a lot of speed, power and productivity.