Home Man
Today's Posts

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

bash, copy, files, folders, rsync

👤 Login to reply

Thread Tools Search this Thread
# 1  
Old 06-22-2016
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!
# 2  
Old 06-22-2016
try below code
rsync -rv --dry-run  --include='*/*/Subsub1/*' --exclude='*/*/Subsub2/*' ./RootFolderI/ ./RootFolderII/

Remove --dry-run option if you are good with o/p
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Move specific folders and subfolders in a directory cmccabe Shell Programming and Scripting 6 08-23-2016 10:25 AM
How to copy a directory without specific files? reddyr Shell Programming and Scripting 17 07-29-2014 09:55 PM
Rsync copy files if dont exist Spadez UNIX for Dummies Questions & Answers 2 10-30-2012 12:47 PM
rsync delete specific files - from different target folder MVEERA Shell Programming and Scripting 0 11-22-2011 08:49 AM
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
Copy folders and subfolders from unix to windows chssastry Windows & DOS: Issues & Discussions 3 12-17-2008 07:31 AM
Using RSYNC to copy files locally BG_JrAdmin Solaris 4 07-31-2008 07:37 PM
rsync: taking advantage of files in different directory other than destination rssrik UNIX for Advanced & Expert Users 1 05-06-2008 07:35 AM
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 04:25 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
Show Password

Not a Forum Member?
Forgot Password?