简体   繁体   English

如何按文件类型递归查找文件并将它们复制到目录?

[英]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.

相关问题 在 BASH 中,如何在递归“查找”的文件的复制语句中引用目录名称 - In BASH, how do you reference a directory name in a copy statement of files you recursively "find" 查找所有扩展名为.sh .cpp .c的文件,并将其复制到我的桌面目录中,如果存在同名文件,则将其重命名 - find all files with .sh .cpp .c extension and copy them to a directory in my desktop, if there is a file with the same name, rename it 递归查找目录中的文件数 - Recursively find the number of files in a directory 递归输出目录中某些类型的所有文件的文件大小? - Output file size for all files of certain type in directory recursively? 在目录中查找文件副本到新文件名 - Find files in a directory copy to a new file name 如何在列表中查找包含使用部分名称的目录和子目录中的所有文件,然后将它们复制到新文件夹 - How to find all files in a directory and subdirectories that contain using partial names within a list then copy them to a new folder 如何查找某些文件并将其复制到文件夹中? - How to find certain files and copy them in a folder? 在目录中查找最旧的文件(递归) - Find the oldest file (recursively) in a directory 如何递归查找并列出具有子目录和时间的目录中的最新修改文件 - How to recursively find and list the latest modified files in a directory with subdirectories and times 如何查找一个用户拥有的所有文件并将它们复制到 RHEL 8 中的另一个目录? - How to find all file owned by one user and copy them to another directory in RHEL 8?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM