search
HomeSystem TutorialLINUXHow to Use Rsync to Sync Files Between Linux and Windows

How to Use Rsync to Sync Files Between Linux and Windows

Synchronizing files between Linux and Windows can seem challenging, especially if you are not familiar with the available tools. However, with the Windows Linux Subsystem (WSL) , this process becomes much easier.

WSL allows you to run a Linux environment directly on Windows , allowing you to synchronize files between two operating systems using powerful Linux tools such as Rsync.

This article walks you through the entire process of syncing files between Linux and Windows using Rsync over WSL . We'll cover everything from setting up WSL to writing scripts for automatic synchronization.

Ultimately, you will have a clear understanding of how to manage file synchronization efficiently between these platforms.

What is Rsync?

Rsync (on behalf of " remote synchronization ") is a command line tool for syncing files and directories between two locations, and it is very efficient because it only transfers changes made to the file, rather than copying everything every time, making it great for syncing large files or large numbers of files.

Why use Rsync with WSL?

  • WSL allows you to run Linux commands and tools directly on Windows, making Rsync easier.
  • Rsync only transfers differences between files, saving time and bandwidth.
  • You can easily synchronize files between Linux and Windows machines.
  • Rsync can be automated using scripts, making it ideal for regular backup or synchronization tasks.

Prerequisites

Before you start, make sure you have the following:

  • WSL supports Windows 10 and 11 versions.
  • You need to install and set up WSL on your Windows machine.
  • Install a Linux distribution (for example, Ubuntu ) from the Microsoft Store.
  • Linux distributions usually have Rsync pre-installed, but if not, we'll cover how to install it.
  • Rsync uses SSH to securely transfer files between systems.

Step 1: Install and Set Up WSL

If you have not installed WSL , open PowerShell as an administrator (press Win X and select " Windows PowerShell (Admin) " or " Command Prompt (Admin) ") and run the following command to install WSL .

 <code>wsl --install</code>

This command will install WSL and the default Linux distribution (usually Ubuntu ). After the installation is complete, restart the computer to complete the setup.

After the computer restarts, open the installed Linux distribution (for example, Ubuntu ) from the Start menu. Follow the on-screen instructions to create a user account and set a password.

Step 2: Install Rsync on WSL

Most Linux distributions usually have Rsync pre-installed. However, if it is not installed, you can install it using the following command.

 <code>sudo apt update sudo apt install rsync rsync --version</code>

This should show the installed version of Rsync .

Step 3: Set up SSH on WSL

To enable SSH on WSL , you need to install an OpenSSH server.

 <code>sudo apt install openssh-server</code>

Next, start and enable the SSH service so that it starts automatically every time WSL is started.

 <code>sudo service ssh start sudo systemctl enable ssh</code>

Verify that the SSH service is running.

 <code>sudo service ssh status</code>

Step 4: Synchronize files from Linux (WSL) to Windows

Now that Rsync and SSH are set up, you can start syncing files. Suppose you want to sync files from a WSL environment to a directory on your Windows machine.

Start your Linux distribution (for example, Ubuntu ) and recognize the Windows directory, which is usually installed under /mnt/ . For example, your C: drive is located in /mnt/c/ .

Now run the following command to sync files from your WSL directory to your Windows directory:

 <code>rsync -avz /path/to/source/ /mnt/c/path/to/destination/</code>

Command description:

  • -a : Archive mode (Permissions, timestamps and symbolic links are reserved).
  • -v : Detailed mode (provided detailed output).
  • -z : Compress data during transmission.
  • /path/to/source/ : The directory in the WSL environment you want to synchronize.
  • /mnt/c/path/to/destination/ : The directory on the Windows machine you want to sync files.

Step 5: Synchronize files from Windows to Linux (WSL)

If you want to sync files from a Windows directory to a WSL environment, you can use a similar command:

 <code>rsync -avz /mnt/c/path/to/source/ /path/to/destination/</code>

Command description:

  • /mnt/c/path/to/source/ : The directory on the Windows machine you want to synchronize.
  • /path/to/destination/ : The directory in the WSL environment where you want to synchronize the files.

Step 6: Use scripts to automate synchronization

To make synchronization easier, you can create a bash script to automate this process.

 <code>nano sync.sh</code>

Add the following lines to the script:

 <code>#!/bin/bash rsync -avz /path/to/source/ /mnt/c/path/to/destination/</code>

Save the file and make the script executable:

 <code>chmod x sync.sh</code>

Execute the script to synchronize the file.

 <code>./sync.sh</code>

You can use cron to schedule scripts to run at specific intervals. For example, to run a script at 2 a.m. every day, add the following line to your crontab:

 <code>0 2 * * * /path/to/sync.sh</code>
in conclusion

Using Rsync with WSL is a powerful and efficient way to synchronize files between Linux and Windows . By following the steps outlined in this article, you can easily set up Rsync , configure SSH , and automate file synchronization.

The above is the detailed content of How to Use Rsync to Sync Files Between Linux and Windows. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How does the command line environment of Linux make it more/less secure than Windows?How does the command line environment of Linux make it more/less secure than Windows?May 01, 2025 am 12:03 AM

Linux'scommandlinecanbemoresecurethanWindowsifmanagedcorrectly,butrequiresmoreuserknowledge.1)Linux'sopen-sourcenatureallowsforquicksecurityupdates.2)Misconfigurationcanleadtovulnerabilities.Windows'commandlineismorecontrolledbutlesscustomizable,with

How to Make a USB Drive Mount Automatically in LinuxHow to Make a USB Drive Mount Automatically in LinuxApr 30, 2025 am 10:04 AM

This guide explains how to automatically mount a USB drive on boot in Linux, saving you time and effort. Step 1: Identify Your USB Drive Use the lsblk command to list all block devices. Your USB drive will likely be labeled /dev/sdb1, /dev/sdc1, etc

Best Cross-Platform Apps for Linux, Windows, and Mac in 2025Best Cross-Platform Apps for Linux, Windows, and Mac in 2025Apr 30, 2025 am 09:57 AM

Cross-platform applications have revolutionized software development, enabling seamless functionality across operating systems like Linux, Windows, and macOS. This eliminates the need to switch apps based on your device, offering consistent experien

Best Linux Tools for AI and Machine Learning in 2025Best Linux Tools for AI and Machine Learning in 2025Apr 30, 2025 am 09:44 AM

Artificial Intelligence (AI) is rapidly transforming numerous sectors, from healthcare and finance to creative fields like art and music. Linux, with its open-source nature, adaptability, and performance capabilities, has emerged as a premier platfo

5 Best Lightweight Linux Distros Without a GUI5 Best Lightweight Linux Distros Without a GUIApr 30, 2025 am 09:38 AM

Looking for a fast, minimal, and efficient Linux distribution without a graphical user interface (GUI)? Lightweight, GUI-less Linux distros are perfect for older hardware or specialized tasks like servers and embedded systems. They consume fewer res

How to Install Wine 10.0 in RedHat DistributionsHow to Install Wine 10.0 in RedHat DistributionsApr 30, 2025 am 09:32 AM

Wine 10.0 stable version release: Running Windows applications on Linux to a higher level Wine, this open source and free application, allows Linux users to run Windows software and games on Unix/Linux operating systems, ushering in the release of the 10.0 stable version! This version has been provided with source code and binary package downloads, and supports various distributions such as Linux, Windows and Mac. This edition embodies a year of hard work and over 8,600 improvements, bringing many exciting improvements. Key highlights include: Enhanced support for Bluetooth devices. Improve support for HID input devices. Optimized performance of 32-bit and 64-bit applications.

How to Install and Configure SQL Server on RHELHow to Install and Configure SQL Server on RHELApr 30, 2025 am 09:27 AM

This tutorial guides you through installing SQL Server 2022 on RHEL 8.x or 9.x, connecting via the sqlcmd command-line tool, database creation, and basic querying. Prerequisites Before beginning, ensure: A supported RHEL version (RHEL 8 or 9). Sudo

How to Install Thunderbird 135 on a Linux DesktopHow to Install Thunderbird 135 on a Linux DesktopApr 30, 2025 am 09:26 AM

Mozilla Thunderbird 135: Powerful cross-platform mail client Mozilla Thunderbird is a free, open source, cross-platform email, calendar, news, chat and contact management client designed to efficiently handle multiple email accounts and news sources. On February 5, 2025, Mozilla released the Thunderbird 135 version, introducing a number of new features, performance improvements and security fixes. Thunderbird 135 main features: XZ Packaging for Linux Binaries: Smaller files, faster unpacking, and better integration with modern distributions. Cookie storage support: when creating space

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.