TrumanWong

sync

Used to force changed content to be written to disk immediately

Supplementary instructions

sync command is used to force the changed content to be written to the disk immediately and update the superblock information.

In Linux/Unix systems, during file or data processing, it is generally placed in the memory buffer first, and then written to the disk at the appropriate time to improve the operating efficiency of the system. The sync command can be used to force the data in the memory buffer to be written to disk immediately. Users usually do not need to execute the sync command. The system will automatically execute the update or bdflush operation to write the buffer data to the disk. Only when update or bdflush cannot be executed or the user needs to shut down abnormally, the sync command needs to be executed manually.

grammar

sync(option)

Options

-d, --data only synchronize file data, not unnecessary metadata
-f, --file-system Synchronize the file system containing these files
--help: display help;
--version: Display version information.

buffer and cache

  • buffer: In order to solve the efficiency of writing to disk
  • cache: In order to solve the efficiency of reading disk

In order to improve the efficiency of reading and writing disks, the Linux system will first put the data in a buffer. When writing to disk, the data is not written to the disk immediately, but is written to this buffer first. If you restart the system at this time, data may be lost.

The sync command is used to flush the file system buffer so that the data will actually be written to the disk and the buffer can be released. Flush is used to clear the buffer. The sync command will force the data to be written to the disk and release the buffer corresponding to the data, so the sync command is often entered after writing to the disk to actually write the data to the disk.

If you do not manually enter the sync command to actually write to the disk, the Linux system will also sync data periodically.