简体   繁体   English

识别(并删除)所有.gif文件在所有子目录中具有超过一帧

[英]Identify (and delete) all .gif files with more than 1 frame in all subdirectories

I having the following linux command to identify all .gif files and list its frames in the active directory: 我有以下linux命令来标识所有.gif文件并在活动目录中列出其框架:

identify -format '%n %i\n' -- *.gif

Now I want to modify and expand the command to fullfil the following: 1. indentify just the .gif files with MORE than 1 frame 2. look also in all subdirectories (right now the command is just looking at the active directory) 3. a command to: a) list the identified files b) delete the identified files 现在,我想修改并扩展命令以完成以下操作:1.只识别超过1帧的.gif文件。2.在所有子目录中查找(现在该命令只是在活动目录中)3. a命令:a)列出已识别的文件b)删除已识别的文件

I would really appreciate you guys help to achieve this... 我非常感谢你们为实现这一目标而提供的帮助...

Thank you a lot in advance!! 提前非常感谢您!!

Best, Florian 最好,弗洛里安

Your on the right path. 您走在正确的道路上。 I would recommend leveraging find , sort and awk commands to generate a list of files to remove. 我建议利用findsortawk命令生成要删除的文件列表。

find /path/to/directory \
     -type f \
     -name "*.gif" \
     -exec identify -format '%n %i\n' {} \; \
     | sort -u \
     | awk '$1 > 1 {print $2}'

How this works 如何运作

  • find will scan all sub-directors for file ending with *.gif , and pass the results to ImageMagick. find将扫描所有子目录中以*.gif结尾的文件,并将结果传递给ImageMagick。

  • identify will print the filename + frame count (what your already doing) identify将打印文件名+帧数(您已经在做什么)

  • sort -u will remove duplicate items ( uniq utility will also work.) sort -u将删除重复的项目( uniq实用程序也将起作用。)
  • awk should print the second column (filename) if the first column (frame count) is greater than 1. 如果第一列(帧数)大于1,则awk应打印第二列(文件名)。

note: this will not remove the files, but provide a list that can be inspected, and passed to rm command 注意:这不会删除文件,但是会提供一个可以检查并传递给rm命令的列表

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM