如何仅同步文件的时间戳?

Ser*_*sak 6 rsync

有没有办法在 Linux 命令行中同步 r(?) 同步仅具有相同内容的文件的时间戳

即,某些目录结构被复制而没有处理时间戳,然后独立修改。现在需要复制相同文件的时间戳只是为了简化进一步的同步。

Ser*_*sak 2

看起来我的问题的答案是(几乎):

rsync -a -c --existing /source/ /destination/
Run Code Online (Sandbox Code Playgroud)

这将复制不同的文件,并且据我了解,默默地同步相同文件的时间戳。

-n像往常一样,首先使用(或) 键尝试--dry-run

添加:

有时需要做我的问题中提到的事情。所以有一个脚本完全符合我的要求:

#!/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"
Run Code Online (Sandbox Code Playgroud)