我找到了一个脚本来转换目录中的文件 但我需要这个与子导演
你能帮帮我吗?
#!/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
# cd to the directory of the image so we can work with just filenames
dir="$(dirname "$1")"
cd "$dir" || exit 1
base="$(basename "$1" .png)"
# create a WebP version of the PNG
cwebp -q 80 "$base".png -o "$base".webp
# delete the WebP file if it is equal size or larger than the original PNG
if [[ `stat -c '%s' "$base".webp` -ge `stat -c '%s' "$base".png` ]]; then
echo "Deleting WebP file that is no smaller than PNG"
rm -f "$base".webp
fi
# delete the WebP file if it is size 0
if [[ -f "$base".webp && ! -s "$base".webp ]]; then
echo "Deleting empty WebP file"
rm -f "$base".webp
fi
最佳答案
好消息:您不必更改脚本!
你可以通过命令找到根目录下的所有目录:
find /path/to/root/dir -type d
你可以为每个找到的目录添加一些命令的执行:
假设您的脚本名称是 script.sh 并且它位于您的主目录中,并且您想在当前目录下的所有子目录(包括当前目录)上运行它:
find . -type d -exec ~/script.sh "{}" \;
关于linux - 批量将图像文件 jpg、png 转换为 webp 也在子文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51384497/