简体   繁体   English

查找并复制所有保留文件夹结构的图像

[英]Find and copy all images preserving the folder structure

I am trying to find and copy all the images from one location to another preserving the folder structure. 我正在尝试查找所有图像并将其从一个位置复制到另一个位置,以保留文件夹结构。 I have tried using the following command: 我尝试使用以下命令:

 sudo find . -type f -exec file {} \; | awk -F: '{ if ($2 ~/[Ii]mage|EPS/) print $1}'  | cpio -pdm  /media/newlocation

This works fine for couple of minutes (I have gigabytes of files to be found and copies) but after some time I am getting the following error: 这在几分钟内可以正常工作(我有几千兆字节的文件要查找和复制),但是一段时间后,出现以下错误:

find: `file' terminated by signal 13

What is wrong with the command? 命令有什么问题? Is there better way of doing it? 有更好的方法吗?

Regards 问候

I'm not sure why you'd get sigpipe. 我不确定为什么会收到信号。

Rather than letting find do an exec, you could try: 您可以尝试:

find . 找 。 -type f -print | 型印刷 xargs file | xargs文件| awk .... 啊...

That is -- just let find print them out and xargs file to run the file command. 也就是说-只需找到将它们打印出来并xargs文件即可运行file命令。

Note that your sudo command will do the find but it's not going to sudo the entire line. 请注意,您的sudo命令将执行查找,但不会对整个行进行sudo。 That's going to cause you more trouble (if you need sudo at all). 这将给您带来更多麻烦(如果您根本需要sudo)。

You can use rsync to copy one directory into another. 您可以使用rsync将一个目录复制到另一个目录。 If you need only some particular files, feel free to use --exclude and --include option. 如果只需要某些特定文件,请随时使用--exclude--include选项。

rsync -avz --include='[iI]mage' --include='EPS' --exclude='*' source/ output/

To test command add rsync --dry-run option: 要测试命令,请添加rsync --dry-run选项:

--dry-run perform a trial run with no changes made --dry-run执行试运行,不做任何更改

You can find some examples of rsync include parameters in this thread . 您可以在此线程中找到一些rsync include参数的示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 正则表达式在bash中查找并复制(保留文件夹结构)? - Regex find and copy in bash (preserving folder structure)? 将文件复制到备份目录,保留文件夹结构 - Copy file to backup directory preserving folder structure 递归压缩文件夹结构中的图像,保留文件夹结构 - Recursively compressing images in a folder-structure, preserving the folder-structure Bash:递归复制命名文件,保留文件夹结构 - Bash: Copy named files recursively, preserving folder structure 查找系统中的所有图像,然后将它们复制到一个文件夹中 - Look for all images in the system then copy them to a folder 从所有子目录中复制具有特定扩展名的所有文件并保留子目录的结构 - Copy all files with a certain extension from all subdirectories and preserving structure of subdirectories 如何使用find命令并保留目录结构来复制位于多个位置的目录的内容? - How can i copy the contents of a directory located in multiple locations using find command and preserving directory structure? 查找所有.h文件并将其放入具有相同结构的指定文件夹的脚本? - Script to find all .h file and put in specified folder with same structure? Bash/unix,如何将所有内容(文件/子目录)从一个文件夹复制到另一个文件夹并保持文件夹结构 - Bash/unix, how to copy all contents (files/subdirs) from one folder to another and keep folder structure 查找所有文件,并将它们复制到一个文件夹(递归展平) - Find all files, and copy them to a folder (Flatten recursively)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM