I'm creating a simple script that copies all files from DIRECTORYA that do not exist in DIRECTORYB. I'm doing this through the use of the cp command:
cp -u DIRECTORYA/* DIRECTORYB
What I'd like to do is also send an email to an administrator that will list the files that have been copied.
So ideally, before I run the above command, I'd like to get the files that will be copied and store them in a variable for later use when building my email message.
Can anybody point me in the right direction? I've looked into using grep but I don't think this can be done with the cp command?
Best Answer
I don't think GNU
cp
has anything to help you if you want to see what it would do without acting. If you want to log the files that were modified, you can use the-v
option:Instead of
cp
, you can use rsync, which is a lot more powerful and installed almost everywhere except for low-end embedded systems (and easy to install where it isn't present by default).or