Results 1 to 3 of 3

Thread: Recursive copy with exclusions

  1. #1
    Join Date
    Apr 2009
    Location
    Toronto, Canada
    Beans
    93
    Distro
    Kubuntu 9.04 Jaunty Jackalope

    Recursive copy with exclusions

    I require a solution for this problem:

    Let there be a directory original/ with the following structure:
    original/
    ++-dir1/
    ++++-file1
    ++++-file2
    ++++-file3
    ++-dir2/
    ++++-pic1
    ++++-pic2
    Let there also be a file named directives with the following content:
    dir1/
    dir2/pic1
    How would I recursively copy the contents of original/ to new/ and exclude the files and directories listed in directives. The original directory tree must be reproduced in new/.
    I've tried a few things with find and xargs to little avail (they would copy all the files to new (except those in the excluded directories), but the directory tree would not be preserved).
    I'm starting to think about writing my own recursive copy function, but there must surely be an easier way...
    Thanks,
    silentrebel
    Last edited by silentrebel; November 9th, 2009 at 08:30 PM.
    L'idée de communauté consiste d'offrande constante sans s'attendre à quoi que ce soit d'elle.
    The idea of community consists of constant giving without expectation of return.

  2. #2
    Join Date
    Feb 2006
    Location
    Vancouver, BC, Canada
    Beans
    318

    Re: Recursive copy with exclusions

    Use rsync. It's not just for remote directory copies.

    You can use some combination of the following options (from the man page) to include/exclude whatever files you want.

    Code:
    -f, --filter=RULE           add a file-filtering RULE
    -F                          same as --filter=’dir-merge /.rsync-filter’
                                repeated: --filter=’- .rsync-filter’
        --exclude=PATTERN       exclude files matching PATTERN
        --exclude-from=FILE     read exclude patterns from FILE
        --include=PATTERN       don’t exclude files matching PATTERN
        --include-from=FILE     read include patterns from FILE
        --files-from=FILE       read list of source-file names from FILE

  3. #3
    Join Date
    Apr 2009
    Location
    Toronto, Canada
    Beans
    93
    Distro
    Kubuntu 9.04 Jaunty Jackalope

    Re: Recursive copy with exclusions

    This looks like it might be exactly what I mean... I guess I've always underestimated the usefulness of rsync... Let me fiddle around with it and I'll let you know...
    Thanks,
    silentrebel
    L'idée de communauté consiste d'offrande constante sans s'attendre à quoi que ce soit d'elle.
    The idea of community consists of constant giving without expectation of return.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •