1

Try to copy files recursively from directory (d1) to directory (d2) exclude some files and folders using lists: filepaths to exclude stored as files.txt and directories list to exlude stored as dirs.txt.

Already read some SOF articles like Copy folder recursively, excluding some folders BASH copy all files except one

tried rsync

rsync -avr --exclude=*/exclude_filename_* d1/ d2/

but wildcards don't suit either due to a large number of different file names. Maybe I have to use WHILE loop with rsync..? Still looking for solution. Does anybody know how to do this?

  • 1
    `man rsync` and `--exclude-from=FILE read exclude patterns from FILE` so let `rsync` read the files to exclude from each of your files. You can use two `--exclude-from=` option. Also see the `--filter=RULE` option which gives you a slightly different way to control which files to filter from the transfer. – David C. Rankin Sep 05 '20 at 09:21
  • yes, I m still looking – ecomkalinin Sep 05 '20 at 09:34
  • Please provide a [mcve]. What you want it to do, what it is doing now, ...? – Nic3500 Sep 06 '20 at 00:11

1 Answers1

3

This is not the best way to do it, but if rsync is not working, you can use find to composite a list and then remove files from that list.

find . -name "*" | grep -v "<filename you dont want>" | xargs -i cp --parents {} /output/dir/name

The only thing to keep in mind here is that your current directory must be the base directory of the files you want to copy, in order to preserve the parent structure.

note: Add another | grep -v "<filename you dont want>" to remove a second file. Alternatively, you can use wildcard matching in one grep grep -v "<file1>\|<file2>"

blackdrumb
  • 310
  • 1
  • 8