在一个目录中,我有一些*.html文件。我想把它们都重命名为*.txt

我该怎么做呢?我使用bash shell。


当前回答

试试这个

rename .html .txt *.html 

用法:

rename [find] [replace_with] [criteria]

其他回答

这是我用来重命名。edge文件为。blade.php

for file in *.edge; do     mv "$file" "$(basename "$file" .edge).blade.php"; done

很有魅力。

你可以使用一个专为批量重命名文件而设计的工具,例如renamer。

重命名当前文件夹下的所有文件扩展名。

$ renamer --find ".html" --replace ".txt" --dry-run * 

这里有更多的用法示例。

类似于之前的建议,我是这样做的:

find . -name '*OldText*' -exec sh -c 'mv "$0" "${0/OldText/NewText}"' {} \;

我首先用

find . -name '*OldText*' -exec sh -c 'echo mv "$0" "${0/OldText/NewText}"' {} \;

你也可以在Bash中创建一个函数,将它添加到。bashrc或其他文件中,然后在任何你想使用的地方使用它。

change-ext() {
    for file in *.$1; do mv "$file" "$(basename "$file" .$1).$2"; done
}

用法:

change-ext css scss

源代码的功能:https://stackoverflow.com/a/1224786/6732111

试试这个

rename .html .txt *.html 

用法:

rename [find] [replace_with] [criteria]