Comments on Rename multiple files which have a variable suffix
Parent
Rename multiple files which have a variable suffix
+1
−0
I compressed some JPEGs with curtail
it messed up the filenames. It was supposed to only add -min
at the end but ended up adding a random string after the extension đ :
prs@PC:/DOWNLOADS/Pictures$ find . -type f
./IMG_20230917_093726_2-min.jpg-U2XlUA <<< To rename "[...]_2-min.jpg"
./IMG_20230917_093726_2.jpg - Don't do anything
./IMG_20230917_093738_3-min.jpg-H39QsD <<< To rename "[...]_3-min.jpg"
./IMG_20230917_093738_3.jpg - Don't do anything
./IMG_20230917_094057_1-min.jpg-AbxJMt <<< To rename "[...]_1-min.jpg"
./IMG_20230917_094057_1.jpg - Don't do anything
How can I remove the random string for each -min
file?
I already have a find
command that gets the -min
files while excluding the pictures I don't want to touch:
find . -name "*-min.jpg-*"
Post
+3
−0
Works for me
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
Pr. Sunflowerâ |
Thread: Works for me Yessssss! Thank you! đ
|
Oct 14, 2023 at 12:01 |
An easy one-liner in POSIX-compatible shells:
for f in *-min.jpg-*; do mv -- "$f" "${f%-*}"; done
The only (mildly) tricky concept here is ${f%-*}
, which expands to $f
minus the shortest suffix matching the glob pattern -*
.
0 comment threads