How to use linux command to set files

I am looking for a solution to convert a set of files using the terminal and the "convert" command in Linux. I can use "convert" for each file:

convert -quality 85 file.jpg file.jpg

But I'm looking for something like:

for each jpg do
  convert -quality 85 $file $file
end

Can someone tell me which command I can use?

+3
source share
7 answers
for i in *.jpg; do
   convert ... $i $i
done

must do it. This will work for sh / bash / zsh, etc. It is assumed that all of your * .jpg files are in the current directory. Otherwise, replace * .jpg with the appropriate search call, for example.

for i in `find . -name "*.jpg" -print`; do

. , , ( for)

zsh,

for i in **/*.jpg; do

zsh. , bash .

+11

convert , , mogrify, . , , , , . . ImageMagick Command Line Processing.

, :

mogrify '*.jpg' -quality 85
+5

Bash, - :

$ for f in `ls path/to/jpegs/*.jpg`; do convert -quality 85 $f $f; done

JPEG .

Bash, for-loop; .

+4

, , :

mkdir -p converted
find -iname '*.jpg' -print0 | xargs -0 -P<number of cores> -n1 -Ifoo convert -quality 85 foo converted/foo
+3
source

I would write a shell script. If you are not familiar with shell programming, see this page .

#!/bin/sh

for arg in `ls *.jpg`
do
    convert -quality 85 $arg $arg
done
+1
source

What?

find [-maxdepth 1] -iname "*.jpg" -exec mogrify -quality 85 {} \;
  • optional -maxdepth 1to work only with the current directory (without a subdirectory.)
  • ImageMagick comes with mogrifywhich modifies files in place.
0
source
find . -name '*.jpg' -exec convert -quality 85 {} {} \;
0
source

Source: https://habr.com/ru/post/1711605/


All Articles