![](/img/trans.png)
[英]How to recursively copy files under a folder and its subfolders as symbolic links
[英]How to copy only symbolic links through rsync
如何使用rsync僅復制符號鏈接(而不是它指向的文件)或其他文件?
我試過了
rsync -uvrl input_dir output_dir
但我只需要復制符號鏈接嗎?
任何使用包括排除選項的技巧?
根據這個問題+答案 ,您可以將其編寫為管道腳本。 管道是shell編程和shell腳本的一個組成部分。
find /path/to/files -type l -print | \
rsync -av --files-from=- /path/to/files user@targethost:/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
一行bash:
rsync -urvl --exclude-from=<(find input_dir -not -type l | sed 's/^..//') input_dir output_dir
你可以更容易地做到:
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/ \;
我更喜歡這個:
find ./ -type l -print > /tmp/list_of_links.txt
rsync -av --files-from=/tmp/list_of_links.txt /path/to/files user@targethost:/path
原因很簡單。 在之前建議的版本中,我必須在每個文件中輸入我的密碼。 這樣我只需輸入一個密碼即可立即發送所有符號鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.