LoginSignup
7
8

More than 5 years have passed since last update.

find で 日本語ファイルを一括操作する時の注意点

Posted at

日本語やら空白を含むファイルの一括削除について。

"コマンド <ファイル1> [ <ファイル2> <ファイル3> ...] " 形式のコマンドの場合

find に -print0
xargs に -0 をそれぞれ渡してやるとうまくいく。

以下の例では、targetdir 配下の *.url ファイルを一括削除できる。

find ./targetdir/ -name '*.url' -print0 | xargs -0 rm -fv

結果1行毎に操作をしたい場合は、
while と read でループしてやり、
"$ループ変数" としてコマンドに渡してあげればよい

以下の例では、'.bmp' ファイルを検索し、'.jpg'へ一括変換している。

find ./targetdir/ -name '*.bmp' | while read line
do
  echo "convert" $line
  convert "$line" "${line%.bmp}.jpg" && rm -f "$line"
done
7
8
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
7
8