Friday, December 25, 2009

Schedule a delayed shutdown

Several times I've initiated a download of a big movie file late at night before I go to bed.  Without knowing anything else, I'd normally have to leave my computer on all night just so that I could download that movie file that will probably only take up 3 hours.  Wouldn't it be nice if you could tell your computer to turn off after the time it takes to download something?

That's where the shutdown command in bash comes in handy!  Here's an example of the way I usually use it:

sudo shutdown -P 300

Firstly, you need to have root access to use shutdown, hence my use of the sudo command.  I used -P to indicate that I want to power off after shutdown (as opposed to rebooting, or 'halting').  Finally, I typed 300 to indicate that I want the computer to shutdown in 3.5 hours (300 minutes).

Another way you can use the command is by specifying the clock time at which you want your computer to shutdown in 24 hour format.  So let's say you want your computer to shut down at 4:15pm:

sudo shutdown -P 16:15

Type that in and your computer will shut down at 4:15pm.  That's it!

9 comments:

  1. 300 minutes is 5 hours, not 3.5 :-)

    ReplyDelete
  2. Many thanks for the tip, its very useful! Best regards, boris

    ReplyDelete
  3. I used "sleep 3h;halt" before.

    ReplyDelete
  4. I add "&" at the end on command at CentOS so the process sleep in background.
    Thank you!

    ReplyDelete
  5. and what if i want to cancel? You know, i want to see another episode of my favorite tv show ;]

    ReplyDelete

  6. Hi, I am John working in IT company. Cause of busy I work in my home so, I need a high-configaration which is one of the
    best computers.best computers.
    So, I was feeling worried about the best computer. By friend suggest me to visit your website and got it. This is really good product.
    Specially RAM, graphic, and all configaration are good. I am happy. I am happy.

    ReplyDelete