Unix/Linux Go Back    

Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Rsync to copy specific subfolders and files to new directory

Shell Programming and Scripting

bash, copy, files, folders, rsync

Thread Tools Search this Thread Display Modes
Old Unix and Linux 06-22-2016   -   Original Discussion by blocnt
blocnt's Unix or Linux Image
blocnt blocnt is offline
Registered User
Join Date: Jun 2016
Last Activity: 22 June 2016, 7:37 AM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rsync to copy specific subfolders and files to new directory


    RootFolderI/FolderA/Subfolder1/Subsub1/JPG1.jpg -> want this jpg
    RootFolderI/FolderA/Subfolder2/Subsub1/JPG2.jpg -> want this jpg
    . . .
    RootFolderI/FolderB/Subfolder1/Subsub1/JPG4.jpg -> want this jpg
    RootFolderI/FolderB/Subfolder2/Subsub1/JPG5.jpg -> want this jpg

There are many folders FolderA/B/C/etc, but the structure of folders inside is always the same (except the files, they are different)

I want to copy to `RootFolderII`:

- only all the FolderA/B/etc
- all the files in Subsub1

...Resulting is this new path, RootFolderII:

    RootFolderII/FolderA/ with JPG1.jpg, JPG2.jpg
    RootFolderII/FolderB/ with JPG4.jpg,JPG5.jpg


I've got at the moment the following code (but it's not working):

    rsync -r --include='Folder*/Subfolder1/Subsub1/***' --exclude="/*/*/" /RootFolderI/ /RootFolderII/



to create FolderA/B/... -> working


i want to copy all files (not the structure) ... -> it's not working


well, I think even if it was working, it would copy files from FolderB to FolderA, and I don't want that!
Sponsored Links
Old Unix and Linux 06-22-2016   -   Original Discussion by blocnt
pravin27's Unix or Linux Image
pravin27 pravin27 is offline Forum Advisor  
Join Date: Sep 2009
Last Activity: 21 June 2017, 2:44 PM EDT
Location: ./India/Bangalore
Posts: 1,271
Thanks: 70
Thanked 299 Times in 290 Posts
try below code

rsync -rv --dry-run  --include='*/*/Subsub1/*' --exclude='*/*/Subsub2/*' ./RootFolderI/ ./RootFolderII/

Remove --dry-run option if you are good with o/p
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to copy a directory without specific files? reddyr Shell Programming and Scripting 17 07-29-2014 09:55 PM
rsync copy files once duonut Shell Programming and Scripting 4 10-13-2011 04:00 PM
How to rsync or tar directory trees, with hidden directory, but without files? fld2007 UNIX for Advanced & Expert Users 4 09-19-2010 12:54 PM
Using RSYNC to copy files locally BG_JrAdmin Solaris 4 07-31-2008 07:37 PM
Recursively copy only specific files from a directory tree sharpsharkrocks Shell Programming and Scripting 3 01-07-2008 01:16 PM

All times are GMT -4. The time now is 01:18 PM.