I have a directory with many files in it. The only ones I care about are those with the extension .jar. However, there are other files in the directory as well.
I have a source directory with only .jar files. I want to achieve the equivalent of:
rm destdir/*.jar
cp sourcedir/*.jar destdir
However, I want to do this without actually removing the files that are already there, if they are the right files already.
In other words, I want it to be possible to run a single command that will:
- For any
.jarfiles present insourcedirbut not indestdir, copy them over. - For any
.jarfiles present in bothsourcediranddestdir, ensure that the copy indestdirmatches the copy insourcedirand overwrite it if it doesn't. - For any
.jarfiles present indestdirbut not insourcedir, delete the file. - For any other files present in
destdir(without a.jarextension), ignore them—do not delete them or change them.
It seems that this should be possible with rsync. How can I do this?