[英]How to find files recursively by file type and copy them to a directory?
I would like to find all the pdf
files in a folder.我想在一个文件夹中找到所有的pdf
文件。 It contains pdf
files inside and more directories that contain more as well.它包含pdf
文件和更多包含更多内容的目录。 The folder is located on a remote server I have ssh access to.该文件夹位于我可以通过 ssh 访问的远程服务器上。 I am using the mac terminal but I believe the server I am connecting to is Centos.我正在使用 mac 终端,但我相信我连接的服务器是 Centos。
I need to find all the pdfs and copy them all to one directory on the remote server.我需要找到所有 pdf 并将它们全部复制到远程服务器上的一个目录中。 I've tried about 10 variations with no luck.我已经尝试了大约 10 种变化,但没有运气。 Both mine and the remote systems do not seem to recognise -exec as a command though exec is fine so thats a problem.我的和远程系统似乎都没有将 -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.这是我尝试的最后一个,我想我现在可以忽略权限被拒绝的错误,但我不确定其余的。
试试这个:
find . -name "*.pdf" -type f -exec cp {} ./pdfsfolder \;
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. Paul Dardeau 的回答是完美的,唯一的问题是,如果这些文件夹中的所有文件都不是 PDF 文件,并且无论扩展名如何,您都想全部获取怎么办。 Well just change it to那么只需将其更改为
find . -name "*.*" -type f -exec cp {} ./pdfsfolder \;
Just to sum up!简单总结一下!
像这样的事情应该有效。
ssh user@ip.addr 'find -type f -name "*.pdf" -exec cp {} ./pdfsfolder \\;'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.