'sh'에 해당되는 글 2건

  1. 2010/12/21 파일명 일괄변경
  2. 2004/03/31 만우절 특집...
#!/bin/sh

# 주의
# 바꿀 문자열의 디렉토리명도 바꾼다.
# 파일부터 바꾼다음 디렉토리를 바꾼다.
# find 로 검색한 결과를 순차적으로 바꾸면 나중에 나오는 파일은 못찾게 된다.

target_dir="/home/test"
target_files=`find "$target_dir" -type f`

from="old_name"
to="new_name"

# 파일을 바꾼다
for file in $target_files ; do

       # 순수 파일명 추출
       f=`basename $file`

       # 해당파일인지 판별후 변환
       if [ `echo $f | grep "$from"` ]; then
               tmp=`echo $f | sed "s/$from/$to/g"`

               new_file=`dirname ${file}`/${tmp}

               mv -f $file $new_file

               echo "change file : $file ===> $new_file "
       fi
done


# 디렉토리를 바꾼다
dir_file=`find "$target_dir" -type d`
for dir in $dir_file ; do
       # 해당 디렉토리인지 판별후 변환
       if [ `echo $dir | grep "$from"` ]; then
               new_dir=`echo $dir | sed "s/$from/$to/g"`

               mv -f $dir $new_dir
               echo "change dir : $dir ===> $new_dir "
       fi
done

exit 0

$ cat > ManUJeol

#!/bin/sh
month=`date +%D | awk -F/ '{print $1}'`
day=`date +%D | awk -F/ '{print $2}'`

while [ "$month" = "04" -a "$day" = "01" ]; do
  a_joke=("ㅋㅋㅋ" "ㅠㅠㅠ" "ㅎㅎㅎ" "ㄹㄹㄹ" "ㄹㄷ하삼")
  rand=$RANDOM
  case `expr $rand % 5` in
       0) joke=${a_joke[0]};;
       1) joke=${a_joke[1]};;
       2) joke=${a_joke[2]};;
       3) joke=${a_joke[3]};;
       4) joke=${a_joke[4]};;
  esac
  echo $joke
  sleep 1
  continue
done

^D


$ sh ./ManUJeol