我想获取过去 1 天内生成的多个文件,从服务器到本地。我正在使用以下命令,其中显示"没有这样的文件或目录"。
find username@server.xyz.com:/path-from-which-files-need-to-be-copied/ -type f -ctime -1 | xargs -ILIST scp LIST /Users/abcUser/Documents/test/
错误发现:username@server.xyz.com:/path-from-which-files-need-to-be-copied/:没有此类文件或目录
PS:我可以访问此位置并从该位置访问带有文件名的单个文件的scp。
find
只能找到本地文件。因此,请在远程服务器上运行find
,如下所示:
ssh username@server.xyz.com find /path-from-which-files-need-to-be-copied/ -type f -ctime -1 |
xargs -ILIST scp username@server.xyz.com:LIST /Users/abcUser/Documents/test/
请注意,默认情况下,xargs
以自己的方式解析和引号。传递
find
结果的最佳方法是使用零终止流:
ssh username@server.xyz.com find /path-from-which-files-need-to-be-copied/ -type f -ctime -1 -print0 |
xargs -0 -ILIST scp username@server.xyz.com:LIST /Users/abcUser/Documents/test/
但是xargs
会为每个文件调用单独的scp
会话,这将非常慢。因此,通过为所有文件运行单个scp
来优化它,我认为您可以这样做:
ssh username@server.xyz.com find /path-from-which-files-need-to-be-copied/ -type f -ctime -1 -printf 'username@server.xyz.com:%p\0' |
xargs -0 sh -c 'scp "$@" "$0"' /Users/abcUser/Documents/test/