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
.jar
files present insourcedir
but not indestdir
, copy them over. - For any
.jar
files present in bothsourcedir
anddestdir
, ensure that the copy indestdir
matches the copy insourcedir
and overwrite it if it doesn't. - For any
.jar
files present indestdir
but not insourcedir
, delete the file. - For any other files present in
destdir
(without a.jar
extension), ignore them—do not delete them or change them.
It seems that this should be possible with rsync
. How can I do this?