LoginSignup
3
3

More than 5 years have passed since last update.

シェルでドットの入ったファイル名を変換

Last updated at Posted at 2015-11-11

ファイル名にドットを入れるなんて、と思っていたけど入っていた事例があり(なぜ入っていたかは謎)、そのファイルがCakePHPのバージョンを1.3から2系にあげるにあたり、プラグイン記法(http://book.cakephp.org/2.0/ja/appendices/glossary.html#term-2) にひっかかったため、変更をする.
対象ファイルはメールのテンプレートファイル.

$ ls
hoge.foo.bar.tpl

全ファイルの拡張子を除去

$ for f in `ls`; do mv $f ${f/\.tpl/}; done
$ ls
hoge.foo.bar

ファイル名のドットをアンダースコアに変換

$ for f in `ls`; do mv $f ${f/\./_}; done
$ ls
hoge_foo.bar

$ for f in `ls`; do mv $f ${f/\./_}; done
$ ls
hoge_foo_bar

拡張子.tplをつける

$ find . -type f -exec mv '{}' '{}.tpl' \;
$ ls
hoge_foo_bar.tpl

もっといい方法があるかもしれないが一番シンプルで分かりやすかった

3
3
2

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
3
3