Speeding Up File Transfers with rsync in WSL
Windows Subsystem for Linux (WSL) is a powerful tool that allows users to run a Linux distribution natively on Windows. One common use case for WSL is to transfer large files between the Windows file system and the Linux file system. By default, using the file explorer in WSL can be slow, especially when transferring large files. In this article, we will show you how to use the rsync command to speed up file transfers in WSL.
What is rsync?
rsync is a powerful command-line tool for transferring and synchronizing files between two systems. It uses a delta-transfer algorithm, which means that it only transfers the differences between the source and destination files, rather than the entire file. This makes it much faster than simply copying and pasting files using the file explorer.
Transferring Files with rsync
To transfer a file using rsync in WSL, you can use the following command:
rsync -avz source_file user@destination:destination_fileHere, -a is for archive mode, which preserves file permissions, timestamps, and other metadata. -v is for verbose mode, which shows the progress of the transfer. -z is for compression, which can speed up the transfer by compressing the data before sending it over the network.
For example, to transfer a file called big_file from the Windows file system to the Linux file system in WSL, you can use the following command:
rsync -avz /mnt/c/big_file [email protected]:/home/user/big_fileHere, /mnt/c is the mount point for the Windows file system in WSL. [email protected] is the username and hostname of the WSL distribution. /home/user is the home directory of the user in WSL.
Speeding Up File Transfers with rsync
By default, rsync uses a single thread to transfer files. However, you can use the -j option to enable multi-threaded transfers, which can significantly speed up the transfer. The -j option specifies the number of threads to use. For example, to use 4 threads, you can use the following command:
rsync -avz -j4 /mnt/c/big_file [email protected]:/home/user/big_fileNote that using more threads can increase the CPU usage and may not always result in faster transfers. You can experiment with different numbers of threads to find the optimal setting for your system.
Copying Large Files with rsync
When copying large files, it is important to use the --progress option to show the progress of the transfer. This can help you to monitor the transfer and ensure that it is completing successfully. For example, to copy a 150GB file called big_file from the Windows file system to the Linux file system in WSL, you can use the following command:
rsync -avz --progress /mnt/c/big_file [email protected]:/home/user/big_fileThis command can take a long time to complete, but it will show the progress of the transfer and will only transfer the differences between the source and destination files.
- rsync is a powerful command-line tool for transferring and synchronizing files between two systems.
- rsync uses a delta-transfer algorithm, which makes it much faster than simply copying and pasting files using the file explorer.
- You can use the
-joption to enable multi-threaded transfers and speed up the transfer. - When copying large files, it is important to use the
--progressoption to show the progress of the transfer.