META: two different implemetnations of shutdown? one that uses reboot/halt as internal binaries that shouldn't be run by hand?
It is important to follow the correct procedures when you shut down a Linux system. If you fail do so, your filesystems probably will become trashed and the files probably will become scrambled. This is because Linux has a disk cache that won't write things to disk at once, but only at intervals. This greatly improves performance but also means that if you just turn off the power at a whim the cache may hold a lot of data and that what is on the disk may not be a fully working filesystem (because only some things have been written to the disk).
Another reason against just flipping the power switch is that in a multi-tasking system there can be lots of things going on in the background, and shutting the power can be quite disastrous. This is especially true for machines that several people use at the same time.
The commands for properly shutting down a Linux system are shutdown(8) and halt(8) (both are located in /sbin). There are two usual ways of using them.
If you are running a system where you are the only user, the usual way of using shutdown is to quit all running programs, log out on all virtual consoles, log in as root on one of them (or stay logged in as root if you already are, but you should change to the root directory, to avoid problems with unmounting), then give the command halt or shutdown -h now (substitute now with a plus sign and a number in minutes if you want a delay, though you usually don't on a single user system) or halt.
Alternatively, if your system has many users, use the command shutdown -h +time message, where time is the time in minutes until the system is halted, and message is a short explanation of why the system is shutting down.
This will warn everybody that the system will shut down in ten minutes, and that they'd better get lost or loose data. The warning is printed to every terminal on which someone is logged in, including all xterms.
The warning is automatically repeated a few times before the boot, with shorter and shorter intervals as the time runs out. You can't use a delay with halt; it is seldom appropriate to use halt on a multiuser system.
META: /etc/inittab can give commands to execute when halting/rebooting
When the real shutting down starts after any delays, all filesystems (except the root one) are unmounted, user processes (if anybody is still logged in) are killed, daemons are shut down, all filesystem are unmounted, and generally everything settles down. When that is done, shutdown prints out a message that you can power down the machine. Then, and only then, should you move your fingers towards the power switch.
Sometimes, although rarely on any good system, it is impossible to shut down properly. For instance, if the kernel panics and crashes and burns and generally misbehaves, it might be completely impossible to give any new commands, hence shutting down properly is somewhat difficult, and just about everything you can do is hope that nothing has been too severely damaged and turn off the power. If the troubles are a bit less severe (say, somebody merely hit your keyboard with an axe), and the kernel and the update program still run normally, it is probably a good idea to wait a couple of minutes to give update(8) a chance to flush the buffer cache, and only cut the power after that.
Some people like to shut down using the command sync(8) three times, waiting for the disk I/O to stop, then turn off the power. If there are no running programs, this is about equivalent to using shutdown. However, it does not unmount any filesystems and this can lead to problems with the ext2fs ``clean filesystem'' flag. The triple-sync method is not recommended.
(In case you're wondering: the reason for three syncs is that in the early days of UNIX, when the commands were typed separately, that usually gave sufficient time for most disk I/O to be finished.)