How To Use Sync: A Practical Guide To Data Synchronization Across Devices

08 July 2026, 01:51

In today’s multi-device world, keeping files, settings, and data consistent across your computer, phone, tablet, and cloud storage is essential. The `sync` command—whether you're using it on Linux, macOS, or within cloud services—allows you to mirror, update, and reconcile data between locations. This guide covers the fundamental usage of `sync` in command-line environments, along with practical tips for reliable synchronization.

At its core, `sync` is a system utility that flushes cached data to permanent storage. When you copy or modify files, the operating system often holds changes in memory (RAM) to improve performance. The `sync` command ensures that all pending writes are physically written to disk, preventing data loss from power failures or system crashes.

For file synchronization between directories or remote systems, `sync` is often combined with tools like `rsync`, `cp`, or cloud sync clients. This guide focuses on the command-line `sync` and its companion `rsync` for advanced use.

The simplest use of `sync` is to force all pending writes to disk:

``` sync ```

Run this command when you have just saved critical files and plan to shut down or remove a USB drive. No arguments are needed; it clears all buffers for all mounted filesystems.

Example: After editing a configuration file on a server, type `sync` before rebooting to ensure your changes are saved.

On some systems (like Linux), you can sync a specific file:

``` sync /path/to/file.txt ```

This tells the system to write only the buffers associated with that particular file to disk. Use this when you want to guarantee a single document is saved without affecting other processes.

For copying and syncing files between directories or remote machines, `rsync` is the standard tool. It works by transferring only the differences between source and destination, saving time and bandwidth.

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

Example: Sync a local folder to an external drive:

``` rsync -av /home/user/Documents/ /media/backup/Documents/ ```

  • `-a` (archive): Preserves permissions, timestamps, and other attributes.
  • `-v` (verbose): Shows progress.
  • ``` rsync -av /local/folder/ user@remote-host:/remote/folder/ ```

    Use `-z` for compression to speed up transfers over slow connections:

    ``` rsync -avz /local/folder/ user@remote-host:/remote/folder/ ```

    Always use `dry-run` (or `-n`) to preview what will happen:

    ``` rsync -av dry-run /source/ /destination/ ```

    This shows which files would be transferred without making any changes.

    Let’s walk through a practical scenario: syncing a project directory from your laptop to a desktop machine.

    Step 1: On your laptop, navigate to the project folder and verify contents:

    ``` cd ~/Projects/website ls -la ```

    Step 2: Run rsync with a dry run to check:

    ``` rsync -av dry-run ./ user@desktop-ip:~/Projects/website/ ```

    Step 3: If the output looks correct, remove `dry-run` and execute:

    ``` rsync -av ./ user@desktop-ip:~/Projects/website/ ```

    Step 4: After transfer, run `sync` on the destination to flush writes:

    ``` ssh user@desktop-ip sync ```

  • `/source/` (with slash) means "copy the contents of the source folder."
  • `/source` (without slash) means "copy the source folder itself into the destination."
  • Example: `rsync -av /data/ /backup/` copies filesinside`/data` to `/backup`. `rsync -av /data /backup/` copies the entire `/data` folder into `/backup`.

    Add `delete` to remove files in the destination that no longer exist in the source:

    ``` rsync -av delete /source/ /destination/ ```

    Caution: Test with `dry-run` first to avoid accidental deletions.

    Use `exclude` to skip temporary or system files:

    ``` rsync -av exclude='.git/' exclude='.tmp' /project/ /backup/ ```

    You can also use an exclude file:

    ``` rsync -av exclude-from=exclude-list.txt /source/ /destination/ ```

    For advanced file systems, add `-H` (preserve hard links) and `-S` (handle sparse files efficiently):

    ``` rsync -avHS /source/ /destination/ ```

    Create a simple shell script to run your sync commands regularly:

    ```bash #!/bin/bash rsync -av delete /home/user/Documents/ /mnt/backup/Documents/ sync echo "Sync completed at $(date)" ```

    Make it executable (`chmod +x sync-script.sh`) and schedule it with cron or launchd.

  • Forgetting to sync before disconnecting drives: Always run `sync` and wait for the command to finish (no output means success) before unplugging USB devices.
  • Using rsync without SSH keys: To avoid password prompts, set up SSH key-based authentication for remote syncs.
  • Ignoring file permissions: The `-a` flag preserves permissions, but if the destination filesystem doesn't support them (e.g., FAT32), use `no-perms`.
  • Overwriting newer files: By default, rsync overwrites files if the source is newer. Add `update` (`-u`) to skip files that are newer in the destination.
  • Not checking available disk space: Before a large sync, verify destination space with `df -h`.
  • | Task | Tool | Why | |||-| | Flush disk buffers before shutdown | `sync` | Ensures data integrity | | Copy a few files to a USB drive | `cp` + `sync` | Simple and fast | | Mirror an entire directory tree | `rsync` | Efficient, supports resuming | | Sync to a remote server regularly | `rsync` over SSH | Secure and bandwidth-friendly | | Keep cloud folder in sync | Cloud client (e.g., Dropbox) | Automatic, real-time |

  • Run `sync` immediately after saving critical work, especially on systems prone to crashes.
  • For frequent syncing, use `rsync` with `partial` to resume interrupted transfers.
  • On macOS, the `sync` command works identically, but you can also use `fsync` for file-level control.
  • Always verify your sync results by comparing file counts or checksums after large operations.
  • When syncing over networks, test with small files first to confirm connectivity and permissions.
  • Mastering `sync` and `rsync` gives you precise control over your data. Whether you're a developer deploying code, a photographer backing up images, or a system administrator maintaining servers, these tools ensure your files are where you need them—safely and consistently.

    Products Show

    Product Catalogs

    WhatsApp