I have a few million .jpg
files and I want to generate a .jpg.webp
version for each one (foo.jpg
-> foo.jpg.webp
). For this, I need to find all files ending in .jpg
for which there’s no .jpg.webp
version.
Right now, I do it like this:
find "$path" -type f -iname "*.jpg" |
while read -r image_path; do
if [ ! -f "$image_path.webp" ]; then
echo "$image_path"
fi
done |
# treat only 10000 files per run
head -n 10000 |
...
However because I’m using a pipe, this creates a subshell. I wonder if there would be a more efficient way to do so, especially because the more WebP images I generate, the more time the script spends filtering paths to find candidates. Would there be some way to do this using find
only?
I’m using Ubuntu 20.04. Files are spread across sub directories.
read
operates one character at a time), but it's a whole lot less inefficient than more naive approaches would be. – Charles Duffy Aug 29 '23 at 17:00-print0
on thefind
command, and making itwhile IFS= read -r -d '' image_path; do
) – Charles Duffy Aug 29 '23 at 17:02