2016年4月14日 星期四

shell 批次改檔名

最近用到才發現沒有方便通用的指令,於是找了一些東西自己寫一個

if [ "$#" -lt 2 ]; then
  echo "Usage: $0 orgNamePart newNamePart" >&2
  exit 1
fi

opt="p;s/$1/$2/"
ls *${1}* | sed -e "$opt" | xargs -n2 mv


純粹筆記