僅當目標上存在檔案並且比目標更新時才遞歸複製目錄

僅當目標上存在檔案並且比目標更新時才遞歸複製目錄

只有當目標上存在文件並且文件比目標上更新時,我們如何複製文件和/或目錄,並且對於目錄情況,它必須遞迴地
具有以下功能的複製

 $ ls -a ~/.config
 gtk-2.0/             
 gtk-3.0/
 SpeedCrunch/

 $ ls -a /other/path/home/.config/
 gtk-2.0/             
 gtk-3.0/
 SpeedCrunch/


$ rsync -u --existing ~/.config /other/path/home/
skipping directory .

無法工作。

什麼 Linux 實用程式以及如何執行/解決它?之前謝謝你

答案1

快的:

您忘記包含遞歸開關“-r”:

rsync -u --existing -r ~/.config /other/path/home/

額外的東西:

另外,您可以考慮使用-aswitch ,它等於-rlptgoD包含遞歸,並且保留一些重要屬性,如下所示:

  • -r:遞迴到目錄
  • -l:將符號鏈接複製為符號鏈接
  • -p:保留權限
  • -t:保留修改時間
  • -g:保留組
  • -o:保留所有者(僅限超級用戶)
  • -D:保留與 --devices --specials 相同的特殊文件

使用以下方法進行測試:

mkdir src
touch src/file{1..3}
touch src/thefile
# Destination:
mkdir dst
touch dst/file{1..3}
touch -d 20201023 dst/thefile
# List all
free -D src dst

現在試試看:

rsync -rt -uPv --existing src dst/

我用了:

  • -r:遞迴到目錄
  • -t:保留修改時間
  • -u:跳過接收器上較新的文件
  • -P:傳輸過程中顯示進度
  • -v:增加詳細程度
  • --existing:跳過在接收器上建立新文件

相關內容