Score:1

How to rename files: picture.jpg.~1~ to picture_~1~.jpg

sy flag

I have say 30000 files of this type: picture.jpg.~12~

They are remnants of a backup (mv -v --backup=numbered ...).

I needed to switch the extensions to: picture.~12~.jpg

Score:1
sy flag

I have found this solution finally which might inspire you in This Long Dark Covid-time of the Soul.

ls *~*~* | sed -n "s/\(.*\)\.\([^.]*\).\(~[0-9]*~\)$/mv  -v --backup=numbered  \"\0\" \"\1_\3.\2\"/p" >switch_extensions.sh
chmod +x switch_extensions.sh
./switch_extensions.sh > switch_extensions.log

The first line produces commands:

mv  -v --backup=numbered  "Trombone.tif.~10~" "Trombone_~10~.tif"

The second line makes it executable, the third is renaming while creating a log file. Then swiftly comes relief from the dark soul ruminations. Try it!

You might know a smarter solution, so let brains storm! :-)

bac0n avatar
cn flag
`mmv '*.jpg.*' '#1.#2.jpg'`
sudodus avatar
jp flag
+1, @xerostomus, nice challenge :-)
sudodus avatar
jp flag
@bac0n, great command for this task. I would have manipulated the file name parts with bash parameter expansion methods and then done a mv command, but this is so much simpler. When looking at the link in your comment at the question, I saw that I already upvoted it years ago, but forgot about it :-P
Cyrus avatar
cn flag
@xerostomus: Please note: [Why *not* parse `ls`?](http://unix.stackexchange.com/questions/128985/why-not-parse-ls)
xerostomus avatar
sy flag
@Cyrus Of course, I run detox first. I do not tolerate much freedom among file names. :-)
xerostomus avatar
sy flag
@bacOn - Thanks, I did not know it.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.