在bash中将目录中所有文件名的第n个字符转换为大写

对于像这样的文件:

_aaa.txt
_bbb.txt
_ccc.txt

我想将它们转换为:

_aAa.txt
_bBb.txt

知道如何做到这一点吗?

回答

在plain 中bash,仅使用shell 参数扩展来执行转换:

#!/bin/bash

n=3
for file in *; do
    [[ -f $file ]] || continue
    suffix=${file:n-1}
    mv -i "$file" "${file:0:n-1}${suffix^}"
done


以上是在bash中将目录中所有文件名的第n个字符转换为大写的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>