I use linux, bash.
I have a bunch of image files in several directories. All have specific names that must be saved (filenames AND directories). But I need to convert all images to different size and ppi. I used the
convert -units PixelsPerInch 75 -resize 200x200 ~/filepath/*.jpg ~/filepath.*jpg
but it replaced the wrong file. Also I've tried
"{}" "{}"%03d.jpg
to add a number to the new filename but it gives only 001.jpg etc.
Solutions like
Bash - get last dirname/filename in a file path argument
or
Extract filename and extension in Bash
with ${filename%.}
and other parts of scripts
or
http://bytebar.blogspot.com/2008/08/bash-filename-extraction.html
do not work or I have no such knowledge to understand the code...
How can I convert those files keeping their names and directories?
Asked
Active
Viewed 212 times
0
1 Answers
0
ls ~/filepath.*jpg | xargs -n 1 -I{} convert -units PixelsPerInch 75 -resize 200x200 {} {}
"xargs -n 1" calls the following function with provided arguments one at a time. The -I{} argument of xargs, tells xargs to replace each occurence of {} with the given argument.

Nicolas Barbey
- 6,639
- 4
- 28
- 34
-
sorry, it did work! Thank you! The code i used was exactly like in your suggestion. – boldnik Aug 14 '12 at 19:03