LoginSignup
0
0

More than 3 years have passed since last update.

ディレクトリ内のファイルを一括リネーム

Last updated at Posted at 2020-07-08

こんな感じ。

sedname.sh
#!/bin/bash

file_all=(`ls`)
for ((i=0; i<${#file_all[*]} ; i++))
{
  file_subd[i]=`echo ${file_all[i]}| sed $1`
  if [ ${file_subd[i]} ]; then
    echo mv ${file_all[i]} ${file_subd[i]}
    mv ${file_all[i]} ${file_subd[i]}    
  fi
}

スクリプトをコマンド的に使いたいなら、aliasを忘れずに。下は一例。

~/.bashrc
alias sedname="sh ~/docs/tools/sedname.sh"

実行結果。
Screen Shot 2020-07-08 at 9.01.11 copy.png

その他、リネームするファイルのリストを別のテキストファイルから取得したいなら

file_all=(`cat list.txt`)

というように書き換えればいいと思います。

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