1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ファイル名/ディレクトリ名に入っている特殊文字を置き換えするワンライナー

Last updated at Posted at 2019-09-06
半角丸カッコを全角丸カッコに置換するワンライナー
i=1; while [ $i -ne 0 ]; do find /hogehoge -type f -regex ".*(.*" -exec rename '(' '(' '{}' \;; i=`find /hogehoge -type f -regex ".*(.*" | wc -l`; done

全然ワンライナーじゃないけど…とりあえずメモ。
findしたファイル名をrenameコマンドに食わせていますが、renameコマンドが
1文字置換したら抜けてしまう仕様のようなので、ループさせて特殊文字が
なくなるまで処理させています。
ディレクトリに特殊文字が含まれていると、エラーになってしまうので先にディレクトリに対して
同様の処理をしておくのをオススメします。
ディレクトリに実行する場合は、-type に d を指定します。

なお、角カッコの場合は

半角角カッコを全角角カッコに置換するワンライナー
i=1; while [ $i -ne 0 ]; do find /hogehoge -type f -regex ".*\[.*" -exec rename '[' '[' '{}' \;; i=`find /hogehoge -type f -regex ".*\[.*" | wc -l`; done

findのregexに指定した角カッコの前にエスケープ文字を入れてあげる必要があります。

いつかまた使うかもしれないので、メモ。

1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?