Linux 如何在ssh中按文件类型递归查找文件并将它们复制到目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18338322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find files recursively by file type and copy them to a directory while in ssh?
提问by lorless
I would like to find all the pdf
files in a folder. It contains pdf
files inside and more directories that contain more as well. The folder is located on a remote server I have ssh access to. I am using the mac terminal but I believe the server I am connecting to is Centos.
我想找到pdf
一个文件夹中的所有文件。它包含pdf
内部文件和更多包含更多内容的目录。该文件夹位于我可以通过 ssh 访问的远程服务器上。我正在使用 mac 终端,但我相信我连接的服务器是 Centos。
I need to find all the pdfs and copy them all to one directory on the remote server. I've tried about 10 variations with no luck. Both mine and the remote systems do not seem to recognise -exec as a command though exec is fine so thats a problem.
我需要找到所有 pdf 并将它们全部复制到远程服务器上的一个目录中。我已经尝试了大约 10 种变化,但没有运气。我的和远程系统似乎都没有将 -exec 识别为命令,尽管 exec 很好,所以这是一个问题。
Im not sure what the problem is here but the command does not fail it just sits there and stalls forever so I do not have any useful errors to post.
我不确定这里的问题是什么,但命令不会失败,它只是坐在那里并永远停止,所以我没有任何有用的错误可以发布。
cp $(find -name "*.pdf" -type f; exec ./pdfsfolder {} \; | sed 1q)
find: ./tcs/u25: Permission denied
find: ./tcs/u68: Permission denied
-bash: /var/www/html/tcs_dev/sites/default/files/pdfsfolder: is a directory
-bash: exec: /var/www/html/tcs_dev/sites/default/files/pdfsfolder: cannot execute: Success
cp: target `./runaways_parents_guide_2013_final.pdf' is not a directory
This is the last one I tried, I think I can ignore the permission denied errors for now but im not sure about the rest.
这是我尝试的最后一个,我想我现在可以忽略权限被拒绝的错误,但我不确定其余的。
采纳答案by Paul Dardeau
Try this:
尝试这个:
find . -name "*.pdf" -type f -exec cp {} ./pdfsfolder \;
回答by ptierno
Something like this should work.
像这样的事情应该有效。
ssh [email protected] 'find -type f -name "*.pdf" -exec cp {} ./pdfsfolder \;'
ssh [email protected] 'find -type f -name "*.pdf" -exec cp {} ./pdfsfolder \;'
回答by gadget
Paul Dardeau answer is perfect, the only thing is, what if all the files inside those folders are not PDF files and you want to grab it all no matter the extension. Well just change it to
Paul Dardeau 的回答是完美的,唯一的问题是,如果这些文件夹中的所有文件都不是 PDF 文件,并且无论扩展名如何,您都想全部获取怎么办。那么只需将其更改为
find . -name "*.*" -type f -exec cp {} ./pdfsfolder \;
Just to sum up!
简单总结一下!