What does the sync command do on a Linux box?

sync – synchronizes data on disk with memory. sync writes any data buffered in memory out to disk. This can include (but is not limited to) modified superblocks, modified inodes, and delayed reads and writes.

The sync program does nothing but exercise the sync system call. The kernel keeps data in memory to avoid doing (relatively slow) disk reads and writes.

This improves performance, but if the computer crashes, data may be lost or the filesystem corrupted as a result. sync ensures that everything in memory is written to disk. sync should be called before the processor is halted in an unusual manner (e.g., before causing a kernel panic when debugging new kernel code).

In general, the processor should be halted using the shutdown or reboot or halt commands, which will attempt to put the system in a quiescent state before calling sync.