On Unix-like operating systems, the sync command synchronizes corresponding file data in volatile memory and permanent storage. Cached writes are immediately written to disk.
This page describes the GNU/Linux version of sync.
Description
By default, the Linux kernel writes data to disk asynchronously. Writes are buffered (cached) in memory, and written to the storage device at the optimal time. The sync command forces an immediate write of all cached data to disk.
- Description
- Syntax
- Examples
- Linux commands help
Run sync if you anticipate the system to be unstable, or the storage device to become suddenly unavailable, and you want to ensure all data is written to disk.
Individual files may be synced, or the entire filesystem containing the specified files. If no arguments are provided, all mounted file systems are synced.
This page refers to GNU sync, which is distributed with most Linux operating systems.
Syntax
sync [[-d | –data] | [-f | –file-system]] [file …]
sync [–help | –version]
Options
Examples
sync
Sync all cached file data of the current user.
sudo sync
Sync all mounted file systems.
sync $HOME/.bashrc $HOME/my/important/file
Sync only those two files.
sync -d $HOME/file1 $HOME/file2 $HOME/file3
Sync only the file data and minimal metadata of those three files.
sudo sync /dev/sdc1
Sync the file system on mounted partition /dev/sdc1.
sudo sync /dev/sdc
Sync all mounted file systems on device /dev/sdc.
sudo sync /var/lib/mysql
Assuming /var/lib/mysql is a directory, sync it and all the files and subdirectories it contains.
sudo sync /var/log/syslog
Sync the file /var/log/syslog.
sudo sync -f /var/log/syslog
Sync the entire file system which contains /var/log/syslog.
sudo sync -f /dev/sdb
Sync the entire file system which contains the device file /dev/sdb, which may not be /dev/sdb.