Linux sync Command: Flush Buffered Writes to Storage
sync requests the kernel to reflect in the storage device the file and file system write data remaining in memory. It can be used to wait for write completion before disconnecting a storage device immediately after copying files.
What is the sync command?
Linux may keep writes in a buffer for performance. sync uses a system call to synchronize this to permanent storage. When run without arguments, it targets all pending writes in the system, and in the GNU implementation, specifying a file allows synchronizing the writes of that particular file.
Basic syntax
sync [option] [file...]
Installed implementations and options may vary depending on the distribution. Check the current system description with man sync.
Examples
Synchronizing pending writes
Requests that the system reflect current write data to the storage device.
sync
Synchronizing a specific file
In the GNU implementation, synchronizes the contents of a single file.
sync report.txt
Synchronize the file system a file belongs to
Targets pending writes of the file system that the file path belongs to.
sync -f /mnt/data/report.txt
Meaning when there is no output
The sync command requests the kernel to send any pending filesystem writes to the storage device. When successful, it usually does not display anything on the screen.
sync echo $?
Example output:
0
0 is the shell exit status indicating that the most recent sync command succeeded. This alone does not guarantee that all device hardware caches have been permanently stored or that backups are complete. When disconnecting an external disk, wait for writes to complete and safely unmount it with umount.
Main Options and Format
| Options/Format | Description |
|---|---|
No arguments |
Synchronizes all pending writes in the entire system. |
file |
Synchronizes the specified file in the GNU implementation. |
-d |
Synchronizes the file's data and the metadata needed for consistency. |
-f |
Synchronizes the file system that the specified file belongs to. |
Precautions when using
Even if sync succeeds, you should properly unmount the file system using umount rather than immediately removing external storage devices. It should not be interpreted as an absolute guarantee of data, including hardware caches and device errors. For sync -f, specifying a file path within the file system instead of a block device node matches the intended use.
Frequently Asked Questions
Is it enough to just run sync before removing a USB drive?
No. Sync requests write synchronization but does not unmount the drive. After finishing your work, properly run umount.
Official Documentation
You can check the exact behavior of the options and implementation differences in the official documentation related to sync.









