我正在嘗試使用以下命令將我的主資料夾備份到外部磁碟機:
rsync -acu --delete --exclude-from='/home/chh1/rsync_exclude.txt' /home/ /media/chh1/f86f92f7-bcb4-4b8e-8a64-8a210606d422/home_backup/
--exclude-from= 文件
/home/chh1/rsync_exclude.txt
包含以下條目:
.cache
crewdb.bak.sql
我真的想排除 .cache,但也排除其中包含的 .dconf,因為我想排除需要 root 權限的檔案和 /home/chh1/.cache 中包含的不必要的 .cache 資料。
當我跑步時
find ~ -name ".cache"
我得到以下輸出:
/home/chh1/snap/pdfmixtool/common/.cache
/home/chh1/snap/gnome-system-monitor/common/.cache
/home/chh1/snap/okular/63/.cache
/home/chh1/snap/freemind/common/.cache
/home/chh1/.cache
find: ‘/home/chh1/.cache/dconf’: Permission denied
我真的很想排除
/home/chh1/.cache
它也可以處理 dconf 和一般的 .cache 垃圾。但是,我不想排除執行 find 命令時找到的其他 .cache 目錄。
由於 --exclude-from= 僅將模式與排除檔案中的內容相匹配,因此如何指定路徑而不是模式,並且最好在排除檔案中指定路徑?有辦法嗎?
感謝您的幫助,確實非常感謝!
答案1
您的排除清單也可以有絕對名稱,在您的情況下,名稱與起始目錄下相符/home/
。使用線路
/chh1/.cache
而非.cache
僅僅排除/home/
/chh1/.cache
,即/home/chh1/.cache