LoginSignup
0
1

More than 3 years have passed since last update.

【Git】ディレクトリに存在する全てのファイルをリネームする

Last updated at Posted at 2020-12-09

TL;DR

find フォルダ名 -print -name "条件" | awk '$1; {gsub("変更元", "変更先", $1); print $1}' | xargs -n 2 git mv

1. find

find フォルダ名 -print -name "条件"

条件を満たす全てのファイルを出力してくれます

2. awk

awk '$1; {gsub("変更元", "変更先", $1); print $1}'

mv前の名前 後の名前 と指定するので、それに沿った形になるように find の結果を変えます。

$1;

find の結果をそのまま出力します。これが 前の名前 になります。

{gsub("変更元", "変更先", $1); print $1}

find の結果を置換してから出力します。これが 後の名前 になります。

3. xargs

xargs -n 2 git mv

find | awk の結果を使い、git mv を実行します。

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