LoginSignup
0

More than 3 years have passed since last update.

【Bash】複数ファイルの拡張子をglobパターンを使って一括置換する方法

Posted at

あるディレクトリ配下の.js ファイルを一括で .ts に変更したかった。

方法

たとえばディレクトリ構成が以下のようになっていたとする

.
├── fuga
│   └── js
│       ├── 1.js
│       ├── 2.js
│       ├── 3.js
│       └── 4.js
└── hoge
    └── js
        ├── 1.js
        ├── 2.js
        ├── 3.js
        └── 4.js


下記のコマンドを入力する
find . -name '*.txt' -exec sh -c 'mv "$0" "${0%.txt}.txt_bak"' {} \;

特定のディレクトリを除外したい時は ! -path でディレクトリをしていする。
find . -name "*.js" ! -path "./node_modules/*" ! -path "./build/*"

参考

検索キーワード: bash rename multiple files extension

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
0