LoginSignup
214
170

More than 5 years have passed since last update.

Mac で rename コマンド(ファイル名一括変換)

Last updated at Posted at 2013-02-02

Mac には Linux の rename コマンドがありません。Homebrew に似たのがあるので、入れてみます。(名前は同じですが別物のようです。)

brew install rename

使い方

foo を bar に、hello を ciao に変える場合はこんな感じです。

rename -s foo bar -s hello ciao *

正規表現で置換。

rename 's/\.htm$/.html/' *.htm

もちろん後方参照も使えます。

rename 's/img-(\d*).jpg/foo-$1-bar.jpg/' *

ディレクトリ内のファイルを再帰的に改名するには find と組み合わせて使います。Mac に標準で入っているの bash の glob の '*' は深いディレクトリ階層にマッチしないためです。

find . -name "*foo*" | xargs rename -s foo bar

ドキュメントは以下です。
http://plasmasturm.org/code/rename/

214
170
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
214
170