
{"id":30215,"date":"2026-04-22T14:09:34","date_gmt":"2026-04-22T12:09:34","guid":{"rendered":"https:\/\/contabo.com\/blog\/?p=30215"},"modified":"2026-04-24T14:15:12","modified_gmt":"2026-04-24T12:15:12","slug":"rsync-command-in-linux","status":"publish","type":"post","link":"https:\/\/contabo.com\/blog\/rsync-command-in-linux\/","title":{"rendered":"rsync Command in Linux: Options, Examples, SSH"},"content":{"rendered":"\n<p>Copying files with cp or scp is fine until you&#8217;re dealing with directories of thousands of files, slow connections, or incremental backups. rsync solves all of that in one command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-is-rsync-and-how-does-it-work\">What Is rsync and How Does It Work?<\/h2>\n\n\n\n<p>rsync is a file synchronization and transfer tool for Linux. Unlike cp, which copies everything every time, rsync analyzes source and destination and transfers only what has changed. This makes it dramatically faster for repeated transfers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-the-delta-transfer-algorithm\">The Delta-Transfer Algorithm<\/h3>\n\n\n\n<p>rsync breaks files into fixed-size chunks and computes checksums for each. It compares checksums between source and destination, then transfers only the chunks that differ. On a 1GB file where you changed 10KB, rsync transfers roughly 10KB. scp transfers 1GB. The difference matters on slow links or large backup sets.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-installing-rsync\">Installing rsync<\/h3>\n\n\n\n<p>On Debian\/Ubuntu:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install rsync<\/code><\/pre>\n\n\n\n<p>On RHEL\/CentOS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum install rsync<\/code><\/pre>\n\n\n\n<p>Verify your version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync --version<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-rsync-syntax-and-key-options\">rsync Syntax and Key Options<\/h2>\n\n\n\n<p>Basic syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync &#91;OPTIONS] SOURCE DESTINATION<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-core-option-flags-explained\">Core Option Flags Explained<\/h3>\n\n\n\n<p>The flags you&#8217;ll use on every rsync command:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>-a (&#8211;archive): Archive mode. Recursively copies directories and preserves permissions, timestamps, symbolic links, and device files. Use this almost always.<\/li>\n\n\n\n<li>-v (&#8211;verbose): Shows each file being transferred. Add -vv for even more detail.<\/li>\n\n\n\n<li>-z (&#8211;compress): Compresses data during transfer. Saves bandwidth on slow connections, adds CPU overhead on fast ones.<\/li>\n\n\n\n<li>-P: Combines &#8211;progress and &#8211;partial. Shows transfer progress and keeps partial files if interrupted.<\/li>\n\n\n\n<li>&#8211;delete: Deletes files in the destination that no longer exist in the source. Keeps the destination as an exact mirror.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-n-for-dry-run-testing\">Using -n for Dry Run Testing<\/h3>\n\n\n\n<p>The rsync dry run flag (-n or &#8211;dry-run) simulates the transfer without actually moving anything:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -avn source\/ destination\/<\/code><\/pre>\n\n\n\n<p>Always run a dry run first when using &#8211;delete. It shows exactly which files would be deleted before you commit to it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-monitoring-progress-with-progress\">Monitoring Progress with &#8211;progress<\/h3>\n\n\n\n<p>For large transfers, &#8211;progress shows per-file transfer speed and estimated completion:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -av --progress source\/ destination\/<\/code><\/pre>\n\n\n\n<p>The rsync progress output shows bytes transferred, transfer rate, and estimated time remaining.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-use-rsync-practical-examples\">How to Use rsync: Practical Examples<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-sync-files-locally\">Sync Files Locally<\/h3>\n\n\n\n<p>Copy a local directory to another location:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -av \/home\/user\/documents\/ \/backup\/documents\/<\/code><\/pre>\n\n\n\n<p>Note the trailing slash on the source. With a trailing slash, rsync copies the contents of the directory. Without it, rsync copies the directory itself into the destination.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-copy-files-to-a-remote-server-via-ssh\">Copy Files to a Remote Server via SSH<\/h3>\n\n\n\n<p>rsync over SSH uses the same syntax as scp but with rsync&#8217;s efficiency:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -avz -e ssh \/local\/path\/ user@remote-server:\/remote\/path\/<\/code><\/pre>\n\n\n\n<p>The -e ssh flag tells rsync to use SSH for the transport layer. Add a custom port if needed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -avz -e \"ssh -p 2222\" \/local\/path\/ user@remote:\/remote\/path\/<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-sync-from-remote-server-to-local\">Sync from Remote Server to Local<\/h3>\n\n\n\n<p>Pull files from a remote server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -avz user@remote-server:\/remote\/path\/ \/local\/destination\/<\/code><\/pre>\n\n\n\n<p>Same syntax, just source and destination reversed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-backup-a-directory-with-rsync\">Backup a Directory with rsync<\/h3>\n\n\n\n<p>A complete rsync backup command that mirrors a source directory and removes deleted files:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -av --delete \/source\/directory\/ \/backup\/directory\/<\/code><\/pre>\n\n\n\n<p>Run this in a cron job for automated incremental backups.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-filtering-exclude-and-include-patterns\">Filtering: Exclude and Include Patterns<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-excluding-files-and-directories\">Excluding Files and Directories<\/h3>\n\n\n\n<p>The rsync exclude option keeps specific files or directories out of the transfer:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -av --exclude='*.log' source\/ destination\/<\/code><\/pre>\n\n\n\n<p>Exclude multiple patterns:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -av --exclude='*.log' --exclude='tmp\/' source\/ destination\/<\/code><\/pre>\n\n\n\n<p>For complex filter rules, use a file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -av --exclude-from='exclude-list.txt' source\/ destination\/<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-delete-to-mirror-directories\">Using &#8211;delete to Mirror Directories<\/h3>\n\n\n\n<p>The rsync delete option removes files from the destination that no longer exist in the source:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -av --delete source\/ destination\/<\/code><\/pre>\n\n\n\n<p>This turns rsync into a true mirroring tool. Be careful: files deleted from source will be deleted from destination too. Always dry run first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-automating-rsync-with-cron\">Automating rsync with Cron<\/h2>\n\n\n\n<p>Run a nightly backup at 2 AM:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0 2 * * * rsync -az --delete \/data\/ \/backup\/data\/ >> \/var\/log\/rsync-backup.log 2>&amp;1<\/code><\/pre>\n\n\n\n<p>Redirect both stdout and stderr to a log file so you can check if the backup ran cleanly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-faq-rsync-command\">FAQ: rsync Command<\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777032845284\"><strong class=\"schema-faq-question\">What does rsync -avz do?<\/strong> <p class=\"schema-faq-answer\">It runs rsync in archive mode (-a, which preserves permissions and recurses directories), verbose mode (-v, shows files being transferred), and compressed mode (-z, compresses data in transit). It&#8217;s the standard starting point for most rsync commands.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777032853817\"><strong class=\"schema-faq-question\">How do I sync files over SSH with rsync?<\/strong> <p class=\"schema-faq-answer\">Use: rsync -avz -e ssh \/local\/path\/ user@server:\/remote\/path\/ The -e ssh flag routes the transfer through an SSH connection. For non-standard ports: rsync -avz -e &#8220;ssh -p 2222&#8221; source\/ user@host:\/dest\/<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777032861870\"><strong class=\"schema-faq-question\">How do I do a dry run with rsync?<\/strong> <p class=\"schema-faq-answer\">Add the -n flag: rsync -avn source\/ destination\/ This shows everything rsync would do without actually transferring or deleting anything. Essential before using &#8211;delete.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777032870339\"><strong class=\"schema-faq-question\">How do I exclude files from rsync?<\/strong> <p class=\"schema-faq-answer\">Use &#8211;exclude=&#8217;pattern&#8217;: rsync -av &#8211;exclude=&#8217;*.tmp&#8217; source\/ destination\/ For multiple exclusions, add multiple &#8211;exclude flags or use &#8211;exclude-from with a file containing one pattern per line.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Copying files with cp or scp is fine until you&#8217;re dealing with directories of thousands of files, slow connections, or incremental backups. rsync solves all of that in one command. What Is rsync and How Does It Work? rsync is a file synchronization and transfer tool for Linux. Unlike cp, which copies everything every time, [&hellip;]<\/p>\n","protected":false},"author":44,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[18],"tags":[],"ppma_author":[3402],"class_list":["post-30215","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Milan Ivanovic","author_link":"https:\/\/contabo.com\/blog\/author\/milan\/"},"uagb_comment_info":0,"uagb_excerpt":"Copying files with cp or scp is fine until you&#8217;re dealing with directories of thousands of files, slow connections, or incremental backups. rsync solves all of that in one command. What Is rsync and How Does It Work? rsync is a file synchronization and transfer tool for Linux. Unlike cp, which copies everything every time,&hellip;","authors":[{"term_id":3402,"user_id":0,"is_guest":1,"slug":"contabro","display_name":"ContaBro","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/30215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/comments?post=30215"}],"version-history":[{"count":1,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/30215\/revisions"}],"predecessor-version":[{"id":30216,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/30215\/revisions\/30216"}],"wp:attachment":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media?parent=30215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/categories?post=30215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/tags?post=30215"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=30215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}