![](/img/trans.png)
[英]Transfer files from one directory to another if they match a condition using python
[英]Transfer files of different extensions from one server to another on linux?
以下是我在本地服務器中InputLocation中的文件
-rw-r----- 1 root root 0 Sep 25 15:03 one.xml
-rw-r----- 1 root root 0 Sep 25 15:03 two.xml
-rw-r----- 1 root root 0 Sep 25 15:03 data.csv
-rw-r----- 1 root root 0 Sep 25 15:03 free.png
-rw-r----- 1 root root 0 Sep 25 15:04 loaded.jpeg
我可以使用以下命令傳輸文件
scp ${InputPath}/*.{jpeg,xml} ${user}@${HostName}:$OutputPath
但是我試圖將extns放在如下變量中
FilesExtnsToBeTransfered=jpeg,xml
scp ${InputLocation}/*.{$FilesExtnsToBeTransfered} ${user}@${HostName}:$OutputPath
但是我可以得到以下異常,盡管文件可用
InputLocation/*.{jpeg,xml}: No such file or directory
有什么幫助嗎?
說:
FilesExtnsToBeTransfered=jpeg,xml
echo {$FilesExtnsToBeTransfered}
將導致{jpeg,xml}
( 不執行大括號擴展 )。
您有兩種選擇:
(不建議這樣做):使用eval
。
eval scp ${InputLocation}/*.{$FilesExtnsToBeTransfered} ${user}@${HostName}:$OutputPath
將所需的文件擴展名放入數組中:
EXTNS=( jpeg xml ) for i in "${EXTNS[@]}"; do scp ${InputLocation}/*.$i ${user}@${HostName}:$OutputPath done
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.