如何僅使用rsync複製符號鏈接(而非指向的文件)或其他文件?如何僅通過rsync複製符號鏈接
我試圖
rsync -uvrl input_dir output_dir
,但我需要完全只複製符號鏈接?
使用包括排除選項的任何技巧?
如何僅使用rsync複製符號鏈接(而非指向的文件)或其他文件?如何僅通過rsync複製符號鏈接
我試圖
rsync -uvrl input_dir output_dir
,但我需要完全只複製符號鏈接?
使用包括排除選項的任何技巧?
根據this question+answer,您可以將此腳本編寫爲管道。管道是shell編程和shell腳本的一個組成部分。
find /path/to/files -type l -print | \
rsync -av --files-from=- /path/to/files [email protected]:/path
這是怎麼回事?
find
命令從/ path/to/files開始,遞歸地通過該點下的所有內容。 find
的選項是限制-print
選項輸出的條件。在這種情況下,將只打印-type l
(符號鏈接,根據man find
)的內容以查找「標準輸出」。
這些文件成爲rsync
命令的--file-from
選項的「標準輸入」。
給它一個鏡頭。我實際上沒有這個測試,但在我看來,它應該工作。
可以生成排除與find input_dir -not -type l
鏈接的文件列表,rsync的有一個選項--exclude-from=exlude_file.txt
你可以做的兩個步驟:
find input_dir -not -type l > /tmp/rsync-exclude.txt
rsync -uvrl --exclude-from=/tmp/rsync-exclude.txt input_dir output_dir
一行慶典:
rsync -urvl --exclude-from=<(find input_dir -not -type l | sed 's/^..//') input_dir output_dir
謝謝我會試一試.... – Newbiee 2012-03-22 00:02:40
您可以更輕鬆地做到這一點,如:
find /path/to/dir/ -type l -exec rsync -avP {} ssh_server:/path/to/server/ \;
編輯: 如果要複製當前目錄的符號鏈接,僅不使其遞歸。你可以這樣做:
find /path/to/dir/ -maxdepth 1 -type l -exec rsync -avP {} ssh_server:/path/to/server/ \;
謝謝我會試試看.... – Newbiee 2012-03-22 00:02:21
雖然這不會將符號鏈接複製爲符號鏈接。 – Dan 2018-02-10 01:48:36
@Dan ...嗯,'-a'轉換爲'-rlptgoD','-l'記錄爲「遇到符號鏈接時,重新創建目標上的符號鏈接。」你遇到了什麼結果? – ghoti 2018-02-11 18:05:51