I'm trying to get rsync to copy only *.ko files that are newer than their match on a target local directory. I'm using --update but it seems that rsync still wants to copy files that are identical to the target. I'm using this command:

rsync -avmR --dry-run --update --include='*.ko' --include='*/'  --exclude='*' drivers/gpu/ /lib/modules/6.1.0-rc2+/kernel/drivers/gpu/

I run this command after building the Linux kernel. This build creates a bunch of .ko files in several subdirectories. For example, here's a subset:

$ find drivers/gpu/ -name "*.ko"

What I want is to copy all of the newer .ko files to a target path under /lib/modules/6.1.0-rc2+/kernel/drivers/. That is, a .ko file should only be copied if it exists on the target and the local version is newer by creation date than the matching target file.

So for example, if /lib/modules/6.1.0-rc2+/kernel/drivers/gpu/drm/i915/i915.ko exists and drivers/gpu/drm/i915/i915.ko is newer /lib/modules/6.1.0-rc2+/kernel/drivers/gpu/drm/i915/i915.ko, then copy drivers/gpu/drm/i915/i915.ko over /lib/modules/6.1.0-rc2+/kernel/drivers/gpu/drm/i915/i915.ko.

The problem is that when I run the above rsync command, it displays .ko files that are not newer than their target. For example, here you can see that virtio-gpu.ko is already the same exact file in both directories:

$ ls -l drivers/gpu/drm/virtio/virtio-gpu.ko /lib/modules/6.1.0-rc2+/kernel/drivers/gpu/drm/virtio/virtio-gpu.ko
-rw-r--r--  1 ttabi ttabi 4992944 Jan 17 13:36 drivers/gpu/drm/virtio/virtio-gpu.ko
-rw-r--r--. 1 ttabi ttabi 4992944 Jan 17 13:36 /lib/modules/6.1.0-rc2+/kernel/drivers/gpu/drm/virtio/virtio-gpu.ko

However, the above rsync command displays this:

$ rsync -avmR --dry-run --update --include='*.ko' --include='*/'  --exclude='*' drivers/gpu/ /lib/modules/6.1.0-rc2+/kernel/drivers/gpu/
building file list ... done

This tells me that if I remove the --dry-run, rsync will unnecessarily copy of the file virtio-gpu.ko.

How do I fix this?

  • Could you please stat the two files (driver/……/virtio… & /lib/modules……/virtio…) rather than only produce ls output.
    – MC68020
    Jan 17, 2023 at 20:54

1 Answer 1


The R in your options to the command is for relative paths, which I think means relative to where the command is invoked from.

The first thing copied is the drivers directory. I think that this is being copied into /lib/modules/6.1.0-rc2+/kernel/drivers/gpu/.

This means that the drivers/gpu/drm/virtio/virtio-gpu.ko file being copied is being copied to /lib/modules/6.1.0-rc2+/kernel/drivers/gpu/drivers/gpu/drm/virtio/virtio-gpu.ko (note the doubled drivers/gpu).

I would try not having the relative paths and, if you do not want rsync to copy files that do not already exist in the target, use --existing to skip creating new files.

  • Thanks, -R was the problem.
    – lord_nimon
    Jan 18, 2023 at 20:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .