Bash: recursively copy and rename files

I have many files whose names end in "_100.jpg". They are distributed in subfolders / subfolders. Now I want the trick to recursively copy and rename all of them in order to have the suffix "_crop.jpg". Unfortunately, I am not familiar with bash scripts, so I don’t know how to do this. I googled and tried the find command with the -exec option, but no luck.

Help me. Thank.

+3
source share
3 answers
  find bar -iname "*_100.jpg" -printf 'mv %p %p\n' \
    | sed 's/_100\.jpg$/_crop\.jpg/' \
    | while read l; do eval $l; done
+6
source

if you have bash 4

shopt -s globstar
for file in **/*_100.jpg; do 
  echo mv "$file" "${file/_100.jpg/_crop.jpg}"
one

or using find

find . -type f -iname "*_100.jpg" | while read -r FILE
do
  echo  mv "${FILE}" "${FILE/_100.jpg/_crop.jpg}"
done
+2
source

Perl script, . prename rename:

find /dir/to/start -type f -iname "*_100.jpg" -exec rename 's/_100/_crop' {} \;

, "_100" , .

+1
source

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


All Articles