Ubuntu hides all images in a folder

I use a script to convert all the images in my folder to flop mode. The script looks like this:

for f in *.jpg; do
    new="${f%%.jpg}_flop.jpg";
    convert "$f" -flop -quality 100 "$new";
 done

Now I discovered that there might be images with the extension. .JPGI was thinking of adding a new loop loop that looks like this:

for f in *.jpg; do
    new="${f%%.jpg}_flop.jpg";
    convert "$f" -flop -quality 100 "$new";
 done

I think there is syntax for ignoring the case, and so I can do one loop instead of 2, any help?

Additionally, if there are also extensions, .jpegor .jpegis there syntax too?

0
source share
4 answers

You can just do

for f in *.jpg *.JPG; do
    ...

If you need one expression, you can use the extension extglobin Bash.

set -o extglob
for f in *.@(JP@(|E)G|jp@(|e)g); do
    ...

, shopt -s nocaseglob, , .

for f in *.[Jj][Pp][Gg] *.[Jj][Pp][Ee][Gg]; do
    ...

-insensitively.

+1

- :

#/bin/bash
shopt -s nullglob                # don't give error messages if no matching files
shopt -s nocaseglob              # ignore case
for f in *.jpg *.jpeg; do

   new=${f/.[Jj][Pp][Ee][Gg]/}      # strip extension
   new=${new/.[Jj][Pp][Gg]/}        # whether JPEG or jpg
   new="$new_flop.jpg"

   convert "$f" -flop -quality 100 "$new"
done
0

I have a script that does something like this:

for file in {*.jpg,*.JPG}; do
  mv "$file" "old$file"
  convert -resize 3000000@\> "old$file" -quality 80 "$file"
  rm "old$file"
done

I also made a video explaining this: https://www.youtube.com/watch?v=AG0bItQLBdI

0
source
for f in `ls * | grep -i "jp[e]\?g$"`;do
   new="${f%%.jpg}_flop.jpg";     
   echo convert "$f" -flop -quality 100 "$new";  
done

Regular expressions are your friend.

-1
source

All Articles