Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-23-2009, 02:30 PM   #1
Senior Member
Registered: Jun 2009
Posts: 1,795

Rep: Reputation: 49
rsync two directories, slashes at ends of paths or not

I tried searching this on the web and see it different all over. My source folder is on the server I'm running rsync from. The folder is /data/pictures which has many subfolders. On my server, I want to recreate pictures and all its subfolders inside of's /backups/pics-backup folder. When do I need to put a slash at the end of the folder paths and when don't I?

I think what I want to do is below, but searching on the web for when to put the trailing slash on the path has confused me as to what is right.

rsync -r -a -z -p -e ssh /data/pictures user@
Old 10-23-2009, 03:16 PM   #2
Registered: Jul 2008
Location: Bloomington, IN
Distribution: Ubuntu/Debian
Posts: 51
Blog Entries: 5

Rep: Reputation: 18
I think the rsync man page said it best and helped me understand it:

A trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination. You can think of a trailing / on a source as meaning “copy the contents of this directory”.
So, the example that they give can be explained in this way:

rsync -av /src/foo /dest
Copy the directory by name and it's contents into /dest, creating the folder foo and what it contains in /dest.
rsync -av /src/foo/ /dest/foo
Copy the contents of the directory into the folder /dest/foo. You are not necessarily copying the actual folder foo. The destination folder can be named anything and what was contained in foo will be copied to it.

If you do not want an additional directory depth in your backup (/backups/pics-backup/pictures) you would do:
rsync -r -a -z -p -e ssh /data/pictures/ user@
If you did want that extra pictures folder inside pics-backup, you would do:
rsync -r -a -z -p -e ssh /data/pictures user@

Hope that explains it a bit more.
Old 10-23-2009, 03:22 PM   #3
Registered: Jan 2005
Location: germany
Distribution: suse, opensuse, debian, others for testing
Posts: 307

Rep: Reputation: 33
rsync -av /source/folder/ user@destination:/path
transfers only the _contents_ of '/source/folder/'

rsync -av /source/folder user@destination:/path
transfers the complete '/source/folder/' (recreates 'folder' with contents)
Old 10-23-2009, 03:25 PM   #4
Senior Member
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Yeah, I do want the extra pictures folder, just in case I'd ever have to copy it back, I can just move that pictures folder in its entirety. Thanks guys!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I use rsync to remove source directories? tdnnash25 Linux - Server 2 10-10-2009 11:24 AM
Rsync Command Skips Directories? carlosinfl Linux - General 1 12-10-2008 11:28 AM
Mounting Partitions and Associating Paths/Directories to Them fc6_user Linux - General 8 05-16-2007 12:06 PM
Symbolic Links, directories, and relative paths (../). Can it be done? jimwillsher Linux - Newbie 1 03-11-2005 05:27 PM
recursively listing directories full paths kubicon Linux - Newbie 2 02-22-2004 03:55 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:50 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration