How to use the sync command on Linux

  
                

In Linux system operation, in order to improve the efficiency of disk read and write, you need to use the sync command. Many people don't know the usage of the sync command. The following small series will introduce you how to use the sync command.

first look at the buffer and cache:

buffer, in order to solve the efficiency of disk write;

cache, in order to solve the efficiency of disk read.

In order to improve the efficiency of reading and writing disks, Linux systems first put data in a buffer.

When writing a disk, the data is not immediately written to the disk, but is written to the buffer first.

If you restart your system at this time, you may lose data.

The sync command is used to flush the file system buffer so that the data is actually written to the disk and the buffer can be released.

flush is used to empty the buffer.

The sync command forces the data to be written to disk and releases the buffer corresponding to the data.

So often after writing the disk, enter the sync command to actually write the data to disk.

If you do not manually enter the sync command to actually write the disk, the Linux system will have two kinds of disk write time:

1. The kflush kernel thread periodically writes to the disk. ;

2. The buffer is full and has to be written.

The above is the way to use the sync command in Linux. With the sync command, you can release the buffer in the data and speed up the reading and writing of the Linux disk to improve the efficiency of disk reading and writing.

Copyright © Windows knowledge All Rights Reserved