On linux, using rename
to rename multiple directories. I want to rename directories starting with higher case characters to lower case and add a special character, let's say _
before the first letter.
For example I want to rename Myfile
to _myfile
The best I came up with so far is :
rename -n 'y/[A-Z]/[a-z]' *
But when I add my character to this regular expression I get the following error :
rename -n 'y/[A-Z]/_[a-z]' *
Replacement list is longer than search list at (eval 90) line 1.
How can I add the special character to the regular expression?
Do:
rename -n 's/^([A-Z])/_\L$1/' */
^([A-Z])
matches any uppercase letter at start, and put in captured group 1
In the replacement, we are lowercasing (\L
) the captured group 1 with perpending a _
*/
matches only directories
Remove -n
for actual renaming action:
rename 's/^([A-Z])/_\L$1/' */
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加