== Unix folklore: using multiple _sync_ commands There is persistent bit of folklore in the Unix world that you should do several _sync_ commands before shutting down or rebooting a Unix machine. Even today, you'll see a lot of people following this folklore, generally using '_sync; sync; sync_'. People who do this irritate me, because they are doing it wrong and in a way that makes the whole folklore ineffectual. The sync folklore dates from the very old days when Unix was primitive and two things were true. First, the _sync()_ system call that the _sync_ program uses just queued dirty buffers to be flushed and didn't guarantee that they had been writing to disk. Second, the kernel itself didn't force all buffers to be written to disk as part of the shutdown or reboot process. In this sort of old Unix environment, you needed to _sync_ by hand before rebooting the system to get all the dirty buffers to disk. But just one sync wouldn't necessarily do it; what you needed to do was run _sync_ and then wait for a bit. But for some reason this was never made an explicit part of the instructions; instead people were told 'do several _sync_ commands, *typing each by hand*'. This should take enough time that the buffer flush started by the first _sync_ would have completed by the time you ran _reboot_ (especially if you were using a slow hardcopy console terminal, which was common then). So the right command sequence of folklore is: > # sync > # sync > # sync > # reboot (Without typeahead, of course.) But this mutated to just 'sync three times', so of course people started writing '_sync; sync; sync_'. And then the whole mess descended into folklore and superstition. (Sometimes you see people advising that you should always run two or three _sync_s instead of one, even if you're not shutting down the system.) These days it is an atrociously bad Unix system that doesn't flush all buffers on shutdown by default, so the whole 'sync before reboot' folklore is unnecessary. Often _sync(2)_ is also synchronous (and thus the _sync_ command too), although the other behavior is still permitted; see the [[Single Unix Standard sync(2) manpage|http://www.opengroup.org/onlinepubs/007908799/xsh/sync.html]].