對不起,如果標題令人困惑
基本上,在我的服務器上,我有多個檔案用于對多個特征進行多次分析,例如:
/Weight/run1/file1.txt
/Weight/run1/file2.txt
/Weight/run2/file1.txt
/Weight/run2/file2.txt
/LegLength/run1/file1.txt
/LegLength/run1/file2.txt
/LegLength /run2/file1.txt
/LegLength/run2/file2.txt
我總共有 11 個特征,每個特征運行兩次,每次運行生成 26 個檔案。
我想將它們復制到我的本地機器上,但保持檔案層次結構相同。我只能找到從多個目錄復制到一個目錄的代碼,這不是我想要的。
到目前為止,我已經設法從一些相關的 stackoverflow 問題中破解了以下代碼,但顯然不起作用,只是試圖在服務器上找到~/Documents/path/to/local/directories。我想知道是否有人對如何調整它有任何建議?
`ssh user@server 'for f in /path/to/server/directories/*/*/*txt ; do newpath="${f%/*}"; newpath=${newpath:41} ; scp user@server:${f} ~/Documents/path/to/local/directories/${newpath}; done'`
我在服務器上的每個端目錄中也有多個其他檔案,具有不同的擴展名,但我對復制它們不感興趣。
(編輯添加:我正在使用newpath=${newpath:41},因為它從變數中洗掉/path/to/server/directories/ )
uj5u.com熱心網友回復:
正確執行它有點復雜,但是命令中的--includeand--exclude的組合rsync應該能夠執行您想要的操作:
rsync -av \
--include '/Weight/' \
--include '/Weight/run[12]/' \
--include '/Weight/run[12]/file[12].txt' \
--include '/LegLength/' \
--include '/LegLength/run[12]/' \
--include '/LegLength/run[12]/file[12].txt' \
--exclude '/*' \
--exclude '/*/*' \
--exclude '/*/*/*' \
user@server:'/path/to/server/directories/' ./here/
注意:在這種情況下,/包含和排除中的第一個表示/path/to/server/directories/
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/491451.html
