Site icon New Generation Enterprise Linux

Stop rsync from nuking your destination folder when the source path gets a trailing slash

Backup & Recovery (Rsync/Tar/Dd)

Stop rsync from nuking your destination folder when the source path gets a trailing slash

🧩 The Challenge

Everyone has done this at least once: you type a trailing slash on your source directory and suddenly your destination folder is missing all its parent structure. It makes me want to throw my monitor out the window every time the hierarchy gets flattened into a pile of files I have to manually sort.

💡 The Fix

Always keep an eye on that trailing slash or use the dot syntax to force rsync to copy the contents exactly how you expect them. It stops the tool from guessing your intent and saves your directory structure from getting merged into oblivion.

rsync -avP /source/directory/ /destination/
rsync -avP /source/directory/. /destination/

⚙️ Why It Works

Adding the slash tells rsync to sync the contents of the folder, while omitting it syncs the folder itself. Using the dot explicitly tells rsync to treat the current directory as the source, which is a lifesaver when you are scripting backups and can’t afford a merge nightmare.

🚀 Pro-Tip: Run your backup with –dry-run first unless you enjoy sweating bullets during your production maintenance window.

Linux Tips & Tricks | © ngelinux.com | 8/4/2026

0 0 votes
Article Rating
Exit mobile version