至少 coreutils-8.28 在 ubuntu 18.04 lts 上是這樣,嘗試如下的情景:
有兩個檔案夾,一個是源檔案夾 src,一個是目標 dst。檔案夾 src 下存在一個檔案 first,先創建它的一個硬鏈接
$ ln "src/first" "src/second"
然后復制 src 所有檔案到 dst 里
$ cp --no-preserve=links "src/*" "dst/"
這時 ls -l 可以看到 dst 檔案夾里是兩個常規檔案。
再次復制,不過用 -u 去更新
$ cp -u --no-preserve=links "src/*" "dst/"
用 ls-l 再看 dst 檔案夾里就變成了倆 hard links 了,不過 dst/first 和 dst/second 是一對,src/first 和 src/second 是一對,用 find 可以判斷出來。
加了 --no-preserve=links 仍無法避免這樣的問題,而且只有 -u 才會有這種問題,不加 -u 復制多少遍都還是常規檔案。就算不加 --no-preserve 在第一次復制的時候也是常規檔案,不知道怎么回事第二次就變硬鏈接了。
請問,應該如何避免這樣的問題?或者,有沒有其他的解決方案?有一次在復制檔案到 FAT32 磁區里就吃了這種虧,直接報錯沒權限,排查之后才知道是硬鏈接問題。
uj5u.com熱心網友回復:
cp 的 infopage 中有對 --update 引數有這樣的解釋,不知道什么意思,沒翻譯懂,不過應該跟這個有關(當然,我只是想解決,而不僅僅是了解這個問題)Consequently, depending on the order that files are processed from the source, newer files in the destination may be replaced, to mirror hard links in the source.
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/149420.html
標籤:系統維護與使用區
上一篇:Linux c
下一篇:aix下用腳本指定時間清理資料
