Disks and file system

Command sync

Flush write buffers to disk

Linux · Bash examples · commands run on the selected server

When to use sync

Use sync to request that pending writes are flushed toward storage. It is not a backup, an integrity verifier or a substitute for cleanly shutting down applications before maintenance.

Syntax

sync [OPTIONS] [FILE...]

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

No arguments
Flush pending filesystem changes.
-f FILE
Synchronize the file system of the specified file in GNU sync.
-d FILE
Synchronize file data without part of the metadata in GNU sync.

Usage examples

Flush pending writes

sync

Pending filesystem writes are synchronized across the system according to the installed implementation.

Sync a specific file

sync ./report.txt

Synchronization is requested for the named file.

Synchronize directory file system

sync -f /srv/app

The filesystem containing the application path is synchronized using the GNU/Linux option.

Notes and limitations

  • The command can block while the storage device completes writes.
  • sync is not a substitute for proper unmounting and does not create a backup.

Common questions and troubleshooting

Does sync make it safe to unplug a mounted disk?

It is not sufficient on its own. Stop activity and cleanly unmount the filesystem before removing the device.

Does sync confirm that a backup is correct?

No. It concerns write flushing, not the correctness or recoverability of copied data. Verify backup contents and restoration separately.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man sync.