Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

linux

What is Linux trigger syncing?

Muhammad Ashir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

In UNIX and UNIX-like operating systems like Linux, the sync command is used to synchronize file data in the main memory with the persistent storage.

Since writing to a file is done in an asynchronous manner, the writes are cached in the memory until it is the appropriate time to write them to the disk. This frees up the CPU to do other tasks while files are written to the disk.

The sync command forces the file writes in the main memory cache and the disk to synchronize.

Syntax

sync [[-d | --data] | [-f | --file-system]] [file …]

Parameters

  • -d or --data: This is used to only sync file data and the minimum metadata needed to maintain filesystem consistency.

  • -f or --file-system: This is used when you want to sync up all the pending I/O and all the referenced files inside the filesystem.

  • file...: The names of one or more files specified. If no file is specified, all the mounted files are synchronized.

It is uncommon to manually use the sync command. Generally speaking, the sync command is only used prior to performing tasks that may make the kernel unstable or are known to cause crashes.

Examples

To sync up all cached files of the current user:

sync

To sync all mounted systems:

sudo sync

To sync just two files:

sync $HOME/file1 $HOME/file2

To sync up only the data and minimal metadata of two files:

sync -d $HOME/file1 $HOME/file2

RELATED TAGS

linux

CONTRIBUTOR

Muhammad Ashir
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring