I have a directory (called 'source') that contains sub-directories and files. Using bash I need to copy all files (and only files, not directories) found in this directory and each of its sub-directories to a different directory (called 'destination'). The directory tree must not be maintained/must be flattened. Only files that are not included in a text file (called 'excluded.txt') must be copied.
Source input examples:
/home/source/AAA/file1.xyz
/home/source/AAA/GGG/file2.xyz
/home/source/BBB/file3.tuv
/home/source/BBB/HHH/file4.tuv
Destination output examples:
/home/destination/file1.xyz
/home/destination/file2.xyz
/home/destination/file3.tuv
/home/destination/file4.tuv
Once the files have been copied, the four+ filenames (file1.xyz, etc,) are added to excluded.txt (with each filename on a new line). The files will then be removed from destination directory periodically.
If the bash script is executed again, and source files are present, they should not be copied to destination if their filenames appear in the excluded.txt file.
I have failed by attempting to us "cp" and "rsync", as the directory tree structure was maintained. I have also failed using "find", as I haven't been able to check the results against the "excluded.txt" list before taking the copy action.