How To Use Sync: A Comprehensive Guide To File And Data Synchronization

27 July 2026, 02:42

In today’s multi-device world, keeping files, contacts, calendars, and even application settings consistent across platforms is essential. The `sync` command—available in Unix-like operating systems, cloud storage tools, and database systems—enables you to flush cached data to permanent storage or synchronize files between directories and servers. This guide focuses on the core `sync` utility (as found in Linux/macOS) and extends to practical synchronization strategies using tools like `rsync`, cloud sync clients, and database replication.

The simplest `sync` command writes all pending file system buffers to disk. It ensures that data you believe is saved is actually written to physical storage, reducing the risk of corruption during a power failure or crash.

Open a terminal and type:

```bash sync ```

This command requires no arguments and immediately flushes all file system buffers. It is often used before unmounting a drive or shutting down a system manually.

  • Before removing a USB drive (even after “eject,” a final `sync` guarantees no pending writes).
  • After copying large files to ensure they are fully written.
  • In scripts that perform critical data writes, placed after `cp` or `dd` commands.
  • 1. Connect your external drive and mount it (usually automatic). 2. Copy files using `cp` or a file manager. 3. Run `sync` in the terminal to flush buffers. 4. Unmount the drive using `umount /media/yourdrive` or the GUI eject option.

    Tip: Combine `sync` with `umount` in a script:

    ```bash #!/bin/bash cp -r /home/user/documents /media/backup/ sync umount /media/backup echo "Backup complete and drive unmounted." ```

    While `sync` flushes buffers, `rsync` is the go-to tool for actually copying and synchronizing files between locations. It can resume interrupted transfers, preserve permissions, and use compression.

    ```bash rsync [options] source destination ```

    1. Local Directory Sync Sync a folder to a backup location:

    ```bash rsync -avh /home/user/projects/ /mnt/backup/projects/ ```

  • `-a` (archive): preserves permissions, timestamps, symbolic links.
  • `-v` (verbose): shows progress.
  • `-h` (human-readable): file sizes in KB/MB.
  • 2. Remote Sync Over SSH Sync files to a remote server:

    ```bash rsync -avz -e ssh /local/folder/ user@remote:/remote/folder/ ```

  • `-z` enables compression for faster transfers over slow connections.
  • 3. Dry Run First Always test with `dry-run` to see what will change:

    ```bash rsync -avh dry-run /source/ /destination/ ```

  • `delete`: removes files in destination that are not in source (mirror behavior).
  • `exclude='.tmp'`: skip temporary files.
  • `progress`: show transfer progress per file.
  • Example: Mirror a website directory to a server

    ```bash rsync -avz delete exclude='.git/' /var/www/html/ user@server:/var/www/html/ ```

    Most cloud storage services (Dropbox, Google Drive, OneDrive) have their own sync clients. To use them effectively:

    1. Install the client from the official website. 2. Select folders to sync during setup—avoid syncing entire drives unless necessary. 3. Choose selective sync to keep local storage lean.

  • Pause sync during large transfers to avoid CPU and bandwidth spikes.
  • Use LAN sync if supported (e.g., Dropbox LAN sync) to speed up transfers between local devices.
  • Exclude system files like `Thumbs.db` or `.DS_Store` via client settings.
  • Conflicts: If a file is edited on two devices simultaneously, rename the conflicted copy manually.
  • Sync stuck: Restart the client or check for file path length limits (Windows: 260 characters).
  • Database systems use internal `sync` commands to ensure transaction durability.

    In MySQL:

    ```sql FLUSH TABLES; ```

    In PostgreSQL:

    ```sql CHECKPOINT; ```

    These force the database to write pending changes to disk, similar to the OS `sync` command.

    For master-slave replication, ensure sync is reliable:

  • Set `sync_binlog=1` in MySQL (writes binary log after each transaction).
  • Use `synchronous_commit=on` in PostgreSQL for ACID compliance.
  • Warning: These settings reduce performance but increase data safety.

    Schedule regular syncs using cron jobs:

    ```bash

    Run rsync every hour

    0/usr/bin/rsync -a /home/user/ /backup/user/ >> /var/log/sync.log 2>&1 ```

    Tools like `lsyncd` or `inotifywait` trigger sync immediately when files change:

    ```bash inotifywait -m /source -e create -e modify | while read path action file; do rsync -a /source/ /destination/ done ```

    For cloud clients, monitor sync status via system tray icons or command-line tools (e.g., `dropbox status`).

    1. Forgetting to run `sync` before unplugging drives Always run `sync` and wait for the command to finish (no output means success). Use `sync; umount /path` to ensure order.

    2. Using `rsync` without trailing slashes `rsync -a /src /dest` copies `/src` into `/dest/src`. `rsync -a /src/ /dest` copies the contents of `/src` into `/dest`. Misunderstanding this can duplicate folders.

    3. Ignoring file permissions Use `-a` in rsync to preserve permissions, or add `chmod` to adjust them.

    4. Not testing with `dry-run` Always preview changes before running destructive syncs with `delete`.

  • For daily backups: Use `rsync` with `-avh delete` and a cron job.
  • For critical data safety: Run `sync` manually after any large write operation.
  • For cloud sync: Enable selective sync and keep an eye on conflict resolution.
  • For databases: Tune sync settings based on your reliability vs. performance needs.
  • By mastering the `sync` command and related tools, you can ensure your data is consistent, safe, and available across all your devices—without surprises.

    Products Show

    Product Catalogs

    WhatsApp