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-case. However, I just want to lower-case everything after the first last dot .
in the name.
How can I do that in bash
?
So, these solutions that look like line noise are nice and all, but this is easy to do from the python REPL (I know the OP asked for bash, but python is installed on a lot of systems that have bash these days...):
This is shorter but more general, combined from other's answer:
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:Short explanation about the syntax
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
)[^.]+
)'
instead of double quote"
to wrap the regex to avoid shell expansionrecursively for all one fine solution:
The above recursively renames files with the extension "JPG" to files with the extension "jpg"
If you have
mmv
(=move multiple files) installed and your filenames contain at most one dot, you can useIt does not get more than one dot right (since the matching algo for
*
is not greedy inmmv
), however, it handles()
and'
correctly. Example:Not perfect, but much easier to use and remember than all the
find/exec/sed
stuff.Well, you could use this snippet as the core of whatever alternative you need:
Afterwards, all you need to do is feed a list of the files you need to rename to its standard input. E.g. for all files under the current directory and any subdirectory:
A small optimization:
You will have to be more specific if you need a more concrete answer than this...
If you have JDK installed you can simply compile to following:
and run.
If you do not have JDK installed but Java installed, compile it using an online Java compiler such as: https://www.compilejava.net/ and simply put the resulting .class file in the folder where you want to rename your files and execute:
java FileRename
.Feel free to reach me in case you are not familiar with Java or need help compiling and/or running.