logo

Home page
Articles for Windows, Linux, OS X
Mac tips and articles
Mac tips
Windows 8 tips and articles
Windows 7 tips and articles
Vista Tips
XP Tips
Linux tips and articles
Read the blog
Online store
Windows, Linux, OS X programs
Links
About

Linux tips and tweaks

Shut down Linux from the command line

How do you shut down or restart Linux? Of course, you just click the option on the menu. It couldn't be simpler. Although this is indeed very straightforward, it is not always the best way to shut down the computer. One example is when the computer is accessed by other people on a network. Whether it is a work or home network, other people migh have files open or could be relying on your Linux PC for files and services. Shutting down immediately without warning could cause problems for them. Ideally, you should give people plenty of warning about the shutdown so that they can take the necessary actions, such as closing files or applications.

Another situation where the shutdown menu item is not the best option is when you are downloading a big file. You might want to set it downloading at night or when you are out and then to automatically switch off the computer when it is done.

Both these situations can be catered for if you use shutdown commands in a Terminal window. There are several commands to choose from, such as halt, reboot, poweroff and shutdown. Each of these has several command line switches that access various features or perform actions. It is useful to know these commands.

Shutdown
The shutdown command is a useful command line tool for turning off the computer and the most useful feature is probably the ability to specify a time. Open a Terminal window and type shutdown +10. This will shut down the computer in 10 minutes time. Just change the 10 to any number of minutes to wait. You could also use shutdown 10:00, which in this case means ten o'clock, whereas +10 means 10 minutes from now. You can also use shutdown now, which shuts down right now.

The shutdown command broadcasts the fact that the computer is shutting down over the network so that other people who are logged on can see that they will lose access to the PC and take the appropriate action. You can add a message, such as shutdown +10 "Save your work"

Tips: don't use ! in your messages because it has special meaning. You need to use sudo or su to elevate permissions. Press Ctrl+C if you change your mind and want to abort shutdown. If you're downloading a big file, use shutdown with sufficient time to for the download to complete.

Linux shutdown

The shutdown command doesn't actually turn off the computer's power and it just shuts down Linux. It puts it in a state where the power can be switched off. If you want to actually power-off the PC automatically then add the -h (halt) command switch like this shutdown now -h.

There are more command line parameters and you can add -r to reboot the computer after shutting down Linux, add -F to run fsck (file system check) on startup, or -k to send everyone shutdown messages, but without actually shutting down - a cruel trick!


copyright