1

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

0

1 Answer 1

1

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! :-)

6
  • 2
    mmv '*.jpg.*' '#1.#2.jpg'
    – user986805
    Dec 18, 2021 at 21:34
  • +1, @xerostomus, nice challenge :-)
    – sudodus
    Dec 18, 2021 at 21:53
  • @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
    – sudodus
    Dec 18, 2021 at 22:02
  • @xerostomus: Please note: Why not parse ls?
    – Cyrus
    Dec 19, 2021 at 21:15
  • @Cyrus Of course, I run detox first. I do not tolerate much freedom among file names. :-)
    – xerostomus
    Dec 20, 2021 at 6:30

Not the answer you're looking for? Browse other questions tagged .