如何按文件类型递归查找文件并将它们复制到目录? [英] How to find files recursively by file type and copy them to a directory?

查看:20
本文介绍了如何按文件类型递归查找文件并将它们复制到目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个文件夹中找到所有 pdf 文件.它包含 pdf 文件和更多包含更多的目录.该文件夹位于我可以通过 ssh 访问的远程服务器上.我使用的是 mac 终端,但我相信我连接的服务器是 Centos.

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 文件并将它们全部复制到远程服务器上的一个目录中.我已经尝试了大约 10 种变体,但都没有运气.我的系统和远程系统似乎都没有将 -exec 识别为命令,尽管 exec 很好,所以这是一个问题.

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.

我不确定问题出在哪里,但命令并没有失败,它只是停在那里并永远停止,所以我没有任何有用的错误要发布.

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 ;

这篇关于如何按文件类型递归查找文件并将它们复制到目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆