Signup/Sign In
PUBLISHED ON: FEBRUARY 16, 2023

How to Synchronize Cached Writes to Persistent Storage using sync command in Linux

In Linux, to synchronize cached writes to persistent storage, we use the sync command.

  • sync command is only guaranteed to schedule the dirty blocks for writing. It can take a short time before all the blocks are finally written.
  • If we use the sync command it will make cache in the background.
  • sync command improves the performance of the system because the sync command keeps data in the RAM, not in the disk and we know that RAM is faster than the disk.
  • sync command keeps everything in temp memory to write to persistent file storage like hard disk therefore the chances of data loss is minimal.

The general syntax of the sync command

sync [OPTION] [FILE]...

Brief description of options available with the sync command.

Options Description
-d, --data sync only file data, no unneeded metadata.
-f, --file-system sync the file systems that contain the files.
--help display this help and exit.
--version output version information and exit.

Synchronize all cached file data from the current user in Linux

sync command makes the cache in the background so nothing on the output screen.

Synchronize all cached file data from the current user in Linux

Display the version information of sync

In this example, when you use --version option with the sync command sync --version will display version information and exit.

Display the version information of sync command

Sync the file systems which contains the files using the -f option with sync command in Linux

In this example, using -f the option with the sync command will synchronize the file which is passed as a parameter.

Sync the file systems which contains the files

Sync only file data using -d option with sync command.

In this example, using -d option with sync command will sync the only file data excluding metadata.

Sync only file data using -d option

Display help of sync option

After using sync --help will display all the information including the option on the output screen and exit.

Display help of sync option

Conclusion

In this tutorial, we covered how to synchronize cached writes to persistent storage using the sync (synchronize) command in Linux with available options and suitable examples. sync command improves the performance of the system.



About the author:
Pradeep has expertise in Linux, Go, Nginx, Apache, CyberSecurity, AppSec and various other technical areas. He has contributed to numerous publications and websites, providing his readers with insightful and informative content.