The important part is to reverse sort ( | sort -r) these commands by the source path only ( -k2,2) before running them ( | sh) otherwise you may have renamed a parent folder before renaming it's child and the command fails and the -k2,2 ensures extra parts does not mingle with sorting. The part $(echo %f | sed 's/(.*)/\U$1/g') asks the sed command to replace ( s/) anything and take them as group 1 ( (.*)) and replace it with uppercaseed group 1 ( \U$1) in folder name. printf replaces %h and %f with path-to and name of found folders. ) and find all directories ( -type d) which and print a command which will be passed to sh for execution. Check the output, and if it does what you want, re-run the command without -n to actually act.Ī solution without using rename (which is not available in some distro's): find -type d -printf "echo mv %h/%f %h/\$(echo %f | sed 's/(.*)/\U$1/')\n" | sort -r -k3,3 | shįor testing and to do actual work : find -type d -printf "mv %h/%f %h/\$(echo %f | sed 's/(.*)/\U$1/')" | sort -r -k2,2 | sh If you aren't sure about a zmv command you wrote, you can pass the -n option to print what the command would do and not change anything.
-w - automatic assign numeric variables to each wildcard pattern.In the second argument to zmv (the replacement text), you can use its parameter expansion features, including history modifiers. In the first argument to zmv (the pattern to replace), you can use zsh's powerful wildcard patterns. Run autoload -U zmv once to activate it (put this line in your. The function zmv renames files based on patterns. The shell zsh provides more convenient features for renaming - even more cryptic than Perl, but terser and often easier to compose. If you call rename on a directory before recursing into it ( find -exec rename … + There is a difficulty here: if you call rename, this renames both the directory and the base name part. If you want to rename files in the current directory and in subdirectories recursively, you can use the find command to traverse the current directory recursively. Rename '…' * only renames files in the current directory, because that's what * matches. Another way to write the same command is rename '$_ = uc($_)' * - uc is the upper case function, and the rename command renames files based on the transformation made to the $_ variable. To perform the opposite translation, use y/a-z/A-Z/.
ASCII uppercase letters to the corresponding lowercase letter. Y/A-Z/a-z/ translates each character in the range A through Z into the corresponding character in the range a through z, i.e.
Other Linux distributions ship a completely different, and considerably less useful, command called rename. Note that you're using the Perl script called rename distributed by Debian and derivatives (Ubuntu, Mint, …).