Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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-*"
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

Post
+3
−0

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 -*.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

Works for me (1 comment)
Works for me
Pr. Sunflower‭ wrote 12 months ago

Yessssss! Thank you! 😁

prs@PC:/DOWNLOADS/Pictures$ find . -type f
./IMG_20230916_142601_1-min.jpg-jzt5Mt
./IMG_20230916_142601_1.jpg
./IMG_20230916_155945_3-min.jpg-0YLbKX
./IMG_20230916_155945_3.jpg
./IMG_20230917_045644-min.jpg-k4JtvZ
./IMG_20230917_045644.jpg

prs@PC:/DOWNLOADS/Pictures$ for f in *-min.jpg-*; do mv "$f" "${f%-*}"; done

prs@PC:/DOWNLOADS/Pictures$ find . -type f
./IMG_20230916_142601_1-min.jpg
./IMG_20230916_142601_1.jpg
./IMG_20230916_155945_3-min.jpg
./IMG_20230916_155945_3.jpg
./IMG_20230917_045644-min.jpg
./IMG_20230917_045644.jpg

I am grateful for your help (you too @alx) 🙏

Bonus info: I opened a case for that Curtail/Veracrypt bug : https://github.com/Huluti/Curtail/issues/185