A directory transfer can finish successfully while placing every file one level deeper than intended. With rsync, the spelling of the source path decides whether the source directory name is preserved at the destination.
A trailing slash on /srv/project/ means copy the contents of project. Without that slash, /srv/project means copy the directory entry named project together with everything below it.
Compare the two source forms in separate disposable destinations before using a backup, deployment, or restore path. An itemized dry run exposes the planned relative paths, and a file listing after two live copies confirms the resulting directory depth.
Steps to control rsync directory copy layout with trailing slashes:
- Create one temporary root for both destination layouts.
$ mkdir -p /tmp/rsync-slash-check
The sample source contains app/config.yml and reports/q2.csv under /srv/project. Replace /srv/project with the directory being evaluated, but keep both comparison destinations inside one disposable root.
- Preview the copy with a trailing slash on the source.
$ rsync --archive --dry-run --itemize-changes /srv/project/ /tmp/rsync-slash-check/contents/ created directory /tmp/rsync-slash-check/contents cd+++++++++ ./ cd+++++++++ app/ >f+++++++++ app/config.yml cd+++++++++ reports/ >f+++++++++ reports/q2.csv
The planned paths begin with app/ and reports/ because the contents of project would land directly under /tmp/rsync-slash-check/contents/.
- Preview the same source without its trailing slash.
$ rsync --archive --dry-run --itemize-changes /srv/project /tmp/rsync-slash-check/parent/ created directory /tmp/rsync-slash-check/parent cd+++++++++ project/ cd+++++++++ project/app/ >f+++++++++ project/app/config.yml cd+++++++++ project/reports/ >f+++++++++ project/reports/q2.csv
Every planned path begins with project/ because rsync would retain the source directory as the first level under /tmp/rsync-slash-check/parent/.
- Copy the source contents into the first destination.
$ rsync --archive /srv/project/ /tmp/rsync-slash-check/contents/
- Copy the source directory into the second destination.
$ rsync --archive /srv/project /tmp/rsync-slash-check/parent/
- List the copied files in both destinations.
$ find /tmp/rsync-slash-check/contents /tmp/rsync-slash-check/parent -type f -print /tmp/rsync-slash-check/contents/app/config.yml /tmp/rsync-slash-check/contents/reports/q2.csv /tmp/rsync-slash-check/parent/project/app/config.yml /tmp/rsync-slash-check/parent/project/reports/q2.csv
The first destination starts with app/ and reports/. The second adds exactly one directory level, project/, while preserving the same files beneath it.
- Remove only the temporary comparison root.
$ rm -rf /tmp/rsync-slash-check
Confirm the exact path before running this command. Never substitute a backup, deployment, or restore destination for the temporary root.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.