在批处理脚本中使用find时出现了奇怪的错误

时间:2023-02-01 00:25:30

I'm trying this piece of code to resize jpg files inside folder recursively larger than 1 MB.

我正在尝试这段代码来调整文件夹中大于1 MB的jpg文件的大小。

find . -type f -size +1M -name "*.jpg" | xargs convert -resize 1000x1000\> -verbose

Getting error message (which breaks batch after 15-20 iterations)

获取错误消息(15-20次迭代后中断批处理)

xargs: convert: terminated by signal 9

How to solve this issue?

如何解决这个问题?

2 个解决方案

#1


2  

xargs from my experience aren't working good in all cases, just as a proposition, try to use -exec, if you need fast solution to the problem

根据我的经验,xargs在所有情况下都不能正常工作,就像一个命题一样,如果你需要快速解决问题,可以尝试使用-exec

find . -type f -size +1M -name "*.jpg" -exec convert {} -resize 1000x1000\> -verbose {} \;

See if it will be helpful for you

看看这对你是否有帮助

#2


0  

xargs does not work properly if you have files with spaces in the name. In order for this to stand a chance of working, you should use the following syntax:

如果名称中包含空格,则xargs不能正常工作。为了使它有机会工作,您应该使用以下语法:

find . -type f -size +1M -name "*.jpg" -print0 | xargs -0 convert -resize 1000x1000\> -verbose

This will insert null characters as separators instead of using spaces as separators.

这将插入空字符作为分隔符,而不是使用空格作为分隔符。

#1


2  

xargs from my experience aren't working good in all cases, just as a proposition, try to use -exec, if you need fast solution to the problem

根据我的经验,xargs在所有情况下都不能正常工作,就像一个命题一样,如果你需要快速解决问题,可以尝试使用-exec

find . -type f -size +1M -name "*.jpg" -exec convert {} -resize 1000x1000\> -verbose {} \;

See if it will be helpful for you

看看这对你是否有帮助

#2


0  

xargs does not work properly if you have files with spaces in the name. In order for this to stand a chance of working, you should use the following syntax:

如果名称中包含空格,则xargs不能正常工作。为了使它有机会工作,您应该使用以下语法:

find . -type f -size +1M -name "*.jpg" -print0 | xargs -0 convert -resize 1000x1000\> -verbose

This will insert null characters as separators instead of using spaces as separators.

这将插入空字符作为分隔符,而不是使用空格作为分隔符。