Celeb Glow
news | March 07, 2026

Operating on wildcard input files and saving output as + suffix

I want to batch process my a list of wildcard input files and then output then to the input filename with a suffix appended. I'm hoping to understand this general case.

In particular, I'm running

 convert *.jpg -resize 800x600 ... *-resized.jpeg

Under Fedora21 with ImageMagick 6.6.8 is nice in that it appends a number suffix but I am looking to preserve the original filename and add a suffix. i.e. It outputs *-resized-0.jpeg *-resized-1.jpeg ...

Checked this does not appear applicable, Multiple input files and output files in awk

edit: Is this possible or do I need to write a script?

1 Answer

It depends on how you define the word "script".  Arguably, this is a script:

for f in *.jpg
do convert "$f" -resize 800x600 ... "${f%.*}"-resized.jpeg
done

but you can just type it like that into your terminal.  The command (or any number of commands) between the do and the doneget(s) executed once for each file that matches *.jpg, with $f set to each filename. ${f%.*} is a form of parameter expansion that removes the filename extension (string matching .*) from the end (i.e., the right side) of the $f filename.

Naming the output files .jpeg instead of .jpg is a good idea, to prevent the *.jpg wildcard from matching them.  Another approach is to write the output files to a different directory.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy