Skip to Content
gnux

syncx

Synchronize cached writes to persistent storage.

Mirrors GNU sync. Run it as syncx, or as gnux syncx.

Synopsis

syncx [OPTION] [FILE]...

GNU reference

Description

syncx asks the system to write data held in memory out to disk. With no FILE it flushes every file system; with FILEs it flushes only those files (fsync), -d only their data and the metadata needed to read it back (fdatasync), and -f the whole file system each one is on (syncfs). -d needs at least one FILE, and -d and -f cannot be combined. A FILE that cannot be opened or flushed is reported and the others are still flushed. Off Linux, -d flushes as plain fsync does and -f flushes every file system, since those systems have neither fdatasync nor syncfs. On Windows, a FILE is flushed with FlushFileBuffers, and a run with no FILE succeeds without flushing anything: Windows has no unprivileged call that flushes every volume.

Permissions

Needs read or write permission on each FILE (it is opened read-only, or write-only when reading is refused). Flushing the whole system needs no permission. Nothing is ever modified.

Use cases

  • Making sure an image written with ddx has reached a USB stick before unplugging it.
  • Flushing a file a script has just written before cutting the power or snapshotting a VM.
  • Forcing a database dump or a backup archive to disk before reporting success.

Flags

  -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

Examples

Flush everything before pulling out a USB stick

syncx

Make sure a backup you just wrote is on disk

tar -czf backup.tgz data && syncx backup.tgz

Flush only the file data, the cheaper call, after appending to a log

syncx -d app.log

Flush the whole file system a mount point is on

syncx -f /mnt/usb

Options

Each option has a page of its own, with its usage and examples.

Exit status

StatusMeaning
0success: every operand was processed
1failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake

Help in the terminal

syncx --help                # options, first examples, exit status
gnux help syncx             # this page: the full manual
gnux help syncx --OPTION    # one option in depth, with its examples

See also

On this page