سؤال

Is there any way to r(?)sync in a Linux command line a timestamps only for files which have equal contents only?

I.e. some directory structure was copied without coping of a timestamps and then modified independently. Now there is need to copy a timestamps of equal files only to simplify further synchronization.

هل كانت مفيدة؟

المحلول

It looks like answer on my question is (almost):

rsync -a -c --existing /source/ /destination/

This will copy files which are different and as far as I understood silently synchronize timestamps of an equal files.

As usual firstly try it with -n (or --dry-run) key.

ADDED:

There is need to do what was mentioned in my question sometimes. So there is the script which does exactly what I asked for:

#!/bin/bash

# Ensure that there is a trailing '/'.
SRC="$(dirname $1)/$(basename $1)/"
DST="$(dirname $2)/$(basename $2)/"

if ! [[ -d "$SRC" ]] || ! [[ -d "$DST" ]]; then
  echo "Usage:"
  echo "  $(basename $0) src/dir dst/dir"
  exit 1
fi

diff -rqs "$SRC" "$DST" | grep -Po "(?<=^Files $SRC).*(?= and $DST.* are identical$)" | rsync -tv --files-from=- "$SRC" "$DST"

نصائح أخرى

For a quicker way of setting the timestamps, I used this instead:

rsync -vrtpi --size-only /media/myname/Dropbox/ /home/myname/Dropbox

Where the -t option is crucial as it preserves the time stamps and --size-only only compares files on size.

Note the trailing backslash '/' after the first Dropbox.

The -c, or --checksum option may take time.

Before you run, please dry-run to see which files are affected:

rsync -vrtpi --size-only --dry-run /media/myname/Dropbox/ /home/myname/Dropbox > foo.txt
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top