是否可以将多个文件名更改为 bash 中的文件扩展名?

Is it possible to change a number of filenames to be the file extension in bash?

我有许多文件都具有相同的基本名称($FILENAME),每个文件都有自己独特的扩展名。我正在尝试将扩展名设置为文件名(无扩展名)。

我尝试了几种不同的方法,最近的方法是:

find . -type f -name "$FILENAME" -exec sh -c 'x="{}"; mv "$FILENAME.$x" "${x}"' \;

一种解决方案是使用 for 循环循环遍历以“$FILENAME”开头的文件,例如

for f in "$FILENAME"*
do
    mv "$f" "${f##*.}"
done

或者,作为单行:

for f in "$FILENAME"*; do mv "$f" "${f##*.}"; done