Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The syntax for the command convert in ImageMagick is

convert source_filename.ext1  destination_filename.ext2

I would like to use zsh to feed it with files in a folder path_to_source and output the result (files with same name, but with a different extension) under the folder path_to_destination.

I believe I can use find and xargs for this, but I didn't come up with anything that worked. Also I presume that ZSH may have some builtins that are useful for this. Any pointers would be greatly appreciated.

NOTE: As far as I know, convert does not have a native way of handling a batch of files, so I need to feed the files one by one. In either case, I'm interested in solving the problem of feeding a command file by file with these arguments.

share|improve this question

2 Answers 2

up vote 1 down vote accepted
for x in /path/to/source/**/*.ext1; do convert $x ${x:r}.ext2 done

The r in ${x:r} is a history modifier. There's a short form of for that saves a few characters.

for x (/path/to/source/**/*.ext1) convert $x ${x:r}.ext2
share|improve this answer

I would do this with:

cd path_to_source
find . | sed 's/.ext1$//' | xargs convert {}.ext1 ../path_to_destination/{}.ext2
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.