Convert all file extensions to lower-case

前端 未结 11 1964
生来不讨喜
生来不讨喜 2020-12-07 14:06

I\'m trying to lower-case all my extensions regardless of what it is. So far, from what I\'ve seen, you have to specify what file extensions you want to convert to lower-cas

11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 14:35

    This is shorter but more general, combined from other's answer:

    rename 's/\.([^.]+)$/.\L$1/' *
    

    Simulation

    For simulation, use -n, i.e. rename -n 's/\.([^.]+)$/.\L$1/' *. This way you can see what will be changed before the real changes being performed. Example output:

    Happy.Family.GATHERING.JPG renamed as Happy.Family.GATHERING.jpg
    Hero_from_The_Land_Across_the_River.JPG renamed as Hero_from_The_Land_Across_the_River.jpg
    rAnD0m.jPg1 renamed as rAnD0m.jpg1
    

    Short explanation about the syntax

    • The syntax is rename OPTIONS 's/WHAT_TO_FIND_IN_THE_NAME/THE_REPLACEMENT/' FILENAMES
    • \.([^.]+)$ means sequence of anything but dot ([^.]) at the end of the string ($), after dot (\.)
    • .\L$1 means dot (\.) followed by lowercase (\L) of 1st group ($1)
    • First group in this case is the extension ([^.]+)
    • You better use single quote ' instead of double quote " to wrap the regex to avoid shell expansion

提交回复
热议问题