2016-11-17 75 views
1

有時find命令拒絕執行,終止符爲+-exec,但只是將+更改爲\;允許運行exec。用找到-exec;運行但+終止符失敗,並且「缺少參數到-exec」


考慮,下面的設置後:

find_args=(-type f -name "*users*" -cmin -60) 
rsync_args=(-avhP -e 'ssh -i /home/some_user/.ssh/id_rsa -c arcfour') 
[email protected]_host:/some/destination/ 

這工作:

# runs rsync once per file, thus slower than it should need to be 
find . "${find_args[@]}" -exec rsync "${rsync_args[@]}" {} "$dest" \; 

...但是這一次失敗:

# exactly the same, except for + rather than \; 
# ...should use the same rsync call for multiple files. 
find . "${find_args[@]}" -exec rsync "${rsync_args[@]}" {} "$dest" + 

...用錯誤find: missing argument to '-exec'

我使用GNU findutils 4.4.2,它被記錄爲支持+參數。

回答

2

find -exec ... {} +,所述+必須立即{}(以及因此的插入參數必須是後端位置)。您提供的命令不符合此要求。


考慮以下解決方法:

find . -type f -name "*users*" -cmin -60 \ 
    -exec sh -c 'rsync -avhP -e "ssh -i /home/some_user/.ssh/id_rsa -c arcfour" "[email protected]" [email protected]_host:/some/destination/' _ {} + 

因爲sh -c [...]線比它的運行,傳遞給前者任何參數列表是保證後者的工作rsync線長,所以擴大"[email protected]"將永遠成功。

+0

查爾斯,我不認爲這是重複的。事實上,你所鏈接的*問題是* this *問題的答案。 – ghoti

+0

@ghoti,...在另一個問題中的OP已經隔離了* * find'不允許'{...其他東西... +'並且正在詢問如何解決它。這裏的OP還沒有到達那裏 - 但仍然,它們所涉及的限制是相同的,任何一個答案都會回答兩者。 –

+0

@ ghoti,...被授予,對於那些正在思考當前OP的人來說,其他問題是同一個問題的人可能並不明顯,但這就是爲什麼我們(作爲一個網站)需要好的重複,讓它們圍繞着,並允許人們從關閉的問題中獲得代表:作爲指導單一規範知識來源的問題,儘管從不同角度或以不同的先驗知識水平觀察問題時可能會有不同的解釋方式。 –