Sometimes, when you're running a long task, you might need to schedule a shutdown of your machine for sometime in the future.
Thankfully, the 'shutdown' command has this built in.
In Linux, you can schedule your computer (or server) to shutdown (poweroff) at a specific time or a specific number of minutes in the future.
To schedule a shutdown at 11pm you can issue:
$ sudo shutdown -P 23:00
Likewise, if you want to shut your machine down in 2 hours time, you can issue:
$ sudo shutdown -P 120
Basically, the 120 above represents the number of minutes in 2 hours.
Now, running that command in your terminal will leave a process running, which we don't actually want. So if you add an ampersand (&) on the end, it'll send the command and run in the background.
The above commands would become:
$ sudo shutdown -P 23:00 &
Likewise, if you want to shut your machine down in 2 hours time, you can issue:
$ sudo shutdown -P 120 &
Easy to use, and VERY useful. Especially if you're doing something and need to schedule a shutdown.
Issuing the command will also send a message to any logged in users and let them know that the machine will shutdown. This way they know to log out before the system shuts down.

Jacqueline commented on Oct 21st 2013