windows 中有个 rename 命令,linux、macOS 中对应 mv,但其实 linux、macOS 中也有 rename,并且不止一个,语法和入参还不一样,容易让人混淆:
- perl rename:
- util-linux rename:
perl rename | util-linux rename | |
---|---|---|
安装 in ubuntu | 默认都有 | apt i util-linux |
安装 in macOS | brew i rename | |
安装 in Alpine | apk add util-linux | |
man 手册 | man1 | man2 |
用法 | rename perlexpr [ files ] | rename expression replacement file... |
foo.md -> bar.md | rename 's/foo/bar/' *.md | rename foo bar *.md |
foo*.md -> foo0*.md | rename 's/foo/foo0/' foo*.md | rename foo foo0 foo*.md |
_.css -> _.scss | rename 's/.css$/.css$/' *.css | rename .css .scss *.css |
所以,我以前有一个脚本中的命令:
rename "s/.html/-${theme}.html/" *.html
就可能不再通用,修改为:
for old in *.html; do
new=$(echo $old | sed -e "s/.html/-${theme}.html/")
mv $old $new
done