|
|
|
|
|
À̸§ : È£¼® (220.¢½.198.205) |
|
³¯Â¥ : 2005-07-22 07:20:12 |
|
Á¦¸ñ : ƯÁ¤ ÆÄÀÏ/µð·ºÅ丮¸¦ ¹Ù²Ù±â ½©½ºÅ©¸³Æ® Æ÷ÇÔ |
|
This file is README.txt
#########################################
##
## ½ºÅ©¸³Æ®¸í : renameto(ƯÁ¤ ÆÄÀÏ/µð·ºÅ丮¸¦ ¹Ù²Ù±â)
##
## ÀÛ¼ºÀÚ : ±èÄ¥ºÀ <san2(at)linuxchannel.net>
## ÀÛ¼ºÀÏ : 2003.10.22 pathed for FreeBSD
## 2002.11.05 add upcase and lowcase, usage to stderr
## 2002.04.13 patch(sort)
## 2002.03.29 patch(thanks '´ÜnÅ°')
## 2002.03.27 add options
## 2002.03.04
##
## ¶óÀ̼¾½º : GNU GPL
## ´Ù¿î·Îµå : http://www.linuxchannel.net/devel/renameto/
##
##
##########################################
##########################################
## ##
## WARNING !!! ##
## »ç¿ëÀÚÀÇ »ç¿ë»ó ºÎÁÖÀÇ·Î ÀÎÇÑ ÇÇÇØ´Â ##
## ¾î¶°ÇÑ °æ¿ì¶ó°í º» ÀÛ¼ºÀÚ¿¡°Ô ±× Ã¥ÀÓ##
## ÀÌ ¾øÀ½À» ¹Ì¸® °øÁöÇÕ´Ï´Ù. ##
## ##
##########################################
[±â´É]
- ƯÁ¤ ¹®ÀÚ¿ÀÇ ÆÄÀÏÀ» ã¾Æ¼ ¹Ù²Þ
- ƯÁ¤ ¹®ÀÚ¿ÀÇ µð·ºÅ丮¸¦ ã¾Æ¼ ¹Ù²Þ
- ¹Ù²Ù±â Àü¿¡ view ±â´É Á¦°ø
- ƯÁ¤ µð·ºÅ丮¿¡¼ °Ë»ö°¡´É
- ÇöÀçµð·ºÅ丮, ¸ðµç ¼ºêµð·ºÅ丮, ƯÁ¤ ±íÀÌÀÇ µð·ºÅ丮 °Ë»ö
- ´ë¼Ò¹®ÀÚ ¹Ù²Ù±â
[»ç¿ë¹ý]
# renameto --help
usage : renameto [options] "/from_string/to_string/" "<target_files|target_directory>"
options
-R : include all sub directory (not default)
-Rn : 'n' is sub directory maxdepth number
'-R0' is current directory (same as not given options)
-t,-test,--test : only test view
-c,-case,--case : translate upcase and lowcase
-v,-view,--view : only test view
-d,-dir,--dir : only directory adjust (not files)
-h,-help,--help : help
example
renameto /html/php/ "*.html" (same as rename command)
renameto -R "/ /_/" "* *.mp3" (replace file " " to "_" all sub-directory)
renameto -R -test "/ /_/" "* *.mp3" (test view)
renameto -R -dir "/ /_/" "/home/xxx/mp3/* *" (replace directory)
renameto -R -case "/[A-Z]/[a-z]/" "*" (to lowcase)
renameto -R -case "/[e-k]/[E-K]/" "*" (to upcase)
source download http://ftp.linuxchannel.net/devel/renameto/
#
-R
ÇÏÀ§ÀÇ ¸ðµç µð·ºÅ丮¿¡¼ °Ë»ö
-R0
ÇöÀç µð·ºÅ丮¿¡¼¸¸ °Ë»ö
-Rn
ÇöÀçµð·ºÅ丮¿¡¼ ±×´ÙÀ½ n´Ü°è µð·ºÅ丮±îÁö¸¸ °Ë»ö, nÀº ([0-9]*)
-R
¿É¼ÇÀÌ ¾ø´Ù¸é ÇöÀçµð·ºÅ丮¿¡¼ ¸¸ °Ë»ö
-d, -dir, --d, --dir
ÆÄÀÏ´ë½Å µð·ºÅ丮¿¡ Àû¿ë
ÀÌ ¿É¼ÇÀÌ ¾ø´Ù¸é ±âº»ÀûÀ¸·Î ÆÄÀÏÀ» ±× ´ë»óÀ¸·Î ÇÔ
-v, -view, --view, -t, -test, --test
ÆÄÀÏÀ̳ª µð·ºÅ丮¸¦ ¹Ù²ÙÁö ¾Ê°í ±×³É ã¾Æ¼ Ãâ·Â¸¸ ÇÔ(È®ÀÎÇÒ¶§)
ÀÌ ¿É¼ÇÀÌ ¾ø´Ù¸é ¸ÅÄ¡µÇ´Â ÆÄÀÏÀ̳ª µð·ºÅ丮¸¦ ã¾Æ¼ ¹Ù²Þ.
-c, --case
´ë¹®ÀÚ->¼Ò¹®ÀÚ or ¼Ò¹®ÀÚ->´ë¹®ÀÚ
'/from_string/to_string/'
from_string -> to_string À¸·Î ±³Ã¼
°ø¹é ¹®ÀÚ¿ÀÌ µé¾î°¥ ¼ö ÀÖÀ¸¹Ç·Î ¹Þµå½Ã Àüü¸¦ ' ³ª "·Î ¹¾îÁÜ
¾çÀÚÀÇ ±¸ºÐÀÚ´Â / ·Î ±¸ºÐ
'ãÀ» µð·ºÅ丮³ª ÆÄÀÏ ´ë»ó'
¹Þµå½Ã Àüü¸¦ ' ³ª "·Î ¹¾îÁÜ
"* *" : °ø¹é ¹®ÀÚ¿ÀÌ µé¾î°£ ¸ðµç ÆÄÀÏÀ̳ª µð·ºÅ丮 ´ë»ó
"*" : ¸ðµç ÆÄÀÏÀ̳ª µð·ºÅ丮 ´ë»ó
"*.mp3" : È®ÀåÀÚ(?)°¡ mp3ÀÎ ¸ðµç ÆÄÀÏ
"*.[hH][tT][mM][lL]" : *.html *.HTML *.Html ... µî°ú ¸ÅÄ¡
"/home/*.php" : /home µð·ºÅ丮¸¦ ´ë»óÀ¸·Î *.php ÆÄÀÏ
"home/*.php" : ÇöÀç µð·ºÅ丮¿¡¼ »ó´ë °æ·Î°¡ home ÀÎ µð·ºÅ丮
[»ç¿ë¿¹ 1]
/sdb1/mp3 µð·ºÅ丮 ¹× ±× ÇÏÀ§ ¸ðµç µð·ºÅ丮¿¡¼
mp3 ÆÄÀÏÀ̳ª MP3 ÆÄÀÏÀ» ´ë»óÀ¸·Î
ÆÄÀÏÀ̸§¿¡ °ø¹é(" ")ÀÌ µé¾î°¥ °æ¿ì "_" ·Î ¹Ù²Þ
¸ÕÀú Å×½ºÆ®ÇØ º½
$ renameto -R --test '/ /_/' '/sdb1/mp3/* *.[mM][pP]3'
...
...
$
¸®½ºÆ®°¡ ³ª¿À¸é --test ¿É¼ÇÀ» »©°í ½ÇÇàÇÔ
$ renameto -R '/ /_/' '/sdb1/mp3/* *.[mM][pP]3'
...
...
$
-R
´ë»óµð·ºÅ丮(/sdb1/mp3) ¹× ±× ÇÏÀ§ÀÇ ¸ðµç µð·ºÅ丮 Æ÷ÇÔ
--test
´ÜÁö Å×½ºÆ®¸¸ Çغ½
'/ /_/'
°ø¹éÀ» "_"À¸·Î ¹Ù²Ù±â
'/sdb1/mp3/* *.[mM][pP]3'
/sdb1/mp3/ ´Â ãÀ» µð·ºÅ丮ÀÇ ½Ã½ºÅÛ Àý´ë°æ·Î
* *.[mM][pP]3 Àº °ø¹é ¹®ÀÚ¿ÀÌ µé¾î°£ ÆÄÀÏÀÇ Ç¥Çö½Ä
[»ç¿ë¿¹ 2]
°ø¹é¹®ÀÚ ¾ø¾Ö±â
$ renameto '/[ ]//' '*.mp3'
¶Ç´Â
$ renameto '/ //' '*.mp3'
Ư¼ö¹®ÀÚµé " ( ) * . ¾ø¾Ö±â
$ renameto '/["()*.]//' '*.mp3'
Ư¼ö¹®ÀÚµé [ ] ¾ø¾Ö±â
$ renameto '/[][]//' '*.mp3'
È®ÀåÀÚ ¹Ù²Ù±â
$ renameto '/\.MP3$/.mp3/' '*.MP3'
ÆÄÀÏÀ̸§ ¾Õ¿¡ 'My' ¹®ÀÚ¿ Ãß°¡Çϱâ
$ renameto '/^/My/' '*.mp3'
ÆÄÀÏÀ̸§ ³¡¿¡ 'My' ¹®ÀÚ¿ Ãß°¡Çϱâ
$ renameto '/$/My/' '*.mp3'
[»ç¿ë¿¹ 3] dot(.) ¹®ÀÚ ¾ø¾Ö±â
Ʋ¸°¿¹ :
$ renameto '/.//' '*'
¸Â´Â°æ¿ì :
$ renameto '/[.]//' '*'
¶Ç´Â
$ renameto '/\.//' '*'
[»ç¿ë¿¹ 4] ´ë¼Ò¹®ÀÚ ¹Ù²Ù±â
Ʋ¸°¿¹ :
$ renameto '/[A-Z]/a-z/' '*' (-c ¿É¼ÇÀÌ ºüÁ®ÀÖÀ½)
$ renameto '/[A-Z]/a-d/' '*' (¹®ÀÚŬ·¡½º ¹üÀ§°¡ ¸ÂÁú¾ÊÀ½)
´ë¹®ÀÚ -> ¼Ò¹®ÀÚ·Î ¹Ù²Ù±â
$ renameto -c '/[A-Z]/a-z/' '*'
or
$ renameto -c '/[A-Z]/[a-z]/' '*'
¼Ò¹®ÀÚ -> ´ë¹®ÀÚ ¹Ù²Ù±â
$ renameto -c '/[a-z]/A-Z/' '*'
or
$ renameto -c '/[a-z]/[A-Z]/' '*'
ƯÁ¤ Ŭ·¡½º(E-K) ¾ËÆĺª¹®ÀÚ ¹Ù²Ù±â
$ renameto -c '/[E-K]/e-k/' '*'
$ renameto -c '/[e-k]/E-K/' '*'
[»ç¿ë¿¹ 5] ¹®ÀÚŬ·¡½º ±×·ìÈ
¸ðµç ´ë¹®ÀÚ ´ÙÀ½¿¡ '_' ¹®ÀÚ Ãß°¡Çϱâ
$ renameto '/\([A-Z]\)/\1_/' '*'
ù¹ø° °ø¹é¿¡ '-' Ãß°¡Çϱâ
$ renameto '/^\([^ ]\+\) /\1-/' '*'
[»ç¿ë¿¹ 6] Á¾ÇÕ¿¹Á¦ : mp3 ÆÄÀÏ Á¤¸®
$ ls
01 aaa.mp3
02 bbb (b1).mp3
03 ccc Abcd efg.MP3
04 ddd bdefgg DDD.mp3
05 eee kkk.MP3
...
À§¿Í °°Àº Çü½ÄÀ» ÃëÇÏ´Â ¿©·¯°³ÀÇ ÆÄÀϵéÀ»
artist-[00]-aaa_bbb_ccc.mp3
ÀÌ¿Í°°ÀÌ Çü½ÄÀ¸·Î ¹Ù²Ù·Á¸é(´ë¹®ÀÚ->¼Ò¹®ÀÚ),
1. ´ë¹®ÀÚ¸¦ ¸ðµÎ ¼Ò¹®ÀÚ·Î ¹Ù²Ù±â
$ renameto -c '/[A-Z]/a-z/' '*.[mM][pP]3'
2. ù¹ø° °ø¹éÀ» ']-' ¹®ÀÚ·Î ¹Ù²Ù±â(±×·ìÈ »ç¿ë)
$ renameto '/^\([^ ]\+\) /\1]-/' '*.mp3'
3. ¸ðµç ÆÄÀϾտ¡ 'artist-[' ¹®ÀÚ Ãß°¡
$ renameto '/^/artist-[' '*'
4. ³ª¸ÓÁö ¸ðµç °ø¹éÀ» '_'·Î ¹Ù²Ù±â
$ renameto '/[ ]/_/' '*'
5. Ư¼ö¹®ÀÚ °ýÈ£ (, )¸¦ ¾ø¾Ö±â(ÇÊ¿äÇÏ´Ù¸é)
$ renameto '/[()]//' '*'
6. È®ÀÎ
$ ls
artist-[01]-aaa.mp3
artist-[02]-bbb_b1.mp3
artist-[03]-ccc_abcd_efg.mp3
artist-[04]-ddd_bdefgg_ddd.mp3
artist-[05]-eeekkk.mp3
...
*ÁÖÀÇ)
°¡´ÉÇÑ Æ¯¼ö¹®ÀÚ´Â [¿Í ]»çÀÌ¿¡ ³Ö¾î¼
Å×½ºÆ®(-t, --test)¸¦ ÇÑ ´ÙÀ½¿¡ ½ÇÇà Çϼ¼¿ä.
---------------------------------------------
#!/bin/sh
##
## "Chilbing, Kim"<san2(at)linuxchannel.net>
## 2003.10.22 patched for FreeBSD
## 2002.11.05 add upcase and lowcase, usage to stderr
## 2002.04.13 patch(sort)
## 2002.03.29 patch(thanks '´ÜnÅ°')
## 2002.03.27 add options
## 2002.03.04
##
## http://ftp.linuxchanel.net/devel/renameto/
##
## chmod a+rx renameto
## cp renameto /usr/local/bin/renameto
usage()
{
echo "${T_MD}usage${T_ME} : renameto [options] \"/from_string/to_string/\" \"<target_files|target_directory>\"" >&1
echo " ${T_MD}options${T_ME}" >&2
echo " -R : include all sub directory (not default)" >&2
echo " -Rn : 'n' is sub directory maxdepth number" >&2
echo " '-R0' is current directory (same as not given options)" >&2
echo " -t,-test,--test : only test view" >&2
echo " -c,-case,--case : translate upcase and lowcase" >&2
echo " -v,-view,--view : only test view" >&2
echo " -d,-dir,--dir : only directory adjust (not files)" >&2
echo " -h,-help,--help : help" >&2
echo " ${T_MD}example${T_ME}" >&2
echo " renameto /html/php/ \"*.html\" (same as rename command)" >&2
echo " renameto -R \"/ /_/\" \"* *.mp3\" (replace file \" \" to \"_\" all sub-directory)" >&2
echo " renameto -R -test \"/ /_/\" \"* *.mp3\" (test view)" >&2
echo " renameto -R -dir \"/ /_/\" \"/home/xxx/mp3/* *\" (replace directory)" >&2
echo " renameto -R -case \"/[A-Z]/[a-z]/\" \"*\" (to lowcase)" >&2
echo " renameto -R -case \"/[e-k]/[E-K]/\" \"*\" (to upcase)" >&2
echo "source download ${T_MB}http://ftp.linuxchannel.net/devel/renameto/${T_ME}" >&2
exit 0
}
testing()
{
echo "${1}: found '$2'(${T_MG}${4}${T_ME})"
}
action()
{
echo "${1}: renamed to '${T_MG}${3}${T_ME}'"
mv "$2" "$3"
}
## set color
## source '/etc/sysconfig/init'
##
case $TERM in
xterm|xterm*|vt220|vt220*|linux)
T_MG=`echo -e "\\033[1;32m"` ## bold green
T_MB=`echo -e "\\033[1;34m"` ## bold blue
T_MR=`echo -e "\\033[1;31m"` ## bold red
T_MD=`echo -e "\\033[1;39m"` ## bold white
T_ME=`echo -e "\\033[0;39m"` ## normal white
;;
default)
T_MG=''
T_MB=''
T_MR=''
T_MD=''
T_ME=''
;;
esac
## check_argument number
##
[ "$#" -lt "2" ] && usage
## get options
##
for ARGS in $* ; do
case "$ARGS" in
-R*)
SUB_DIR=$ARGS
;;
-t*|-v*|--t*|--v*)
CMD=testing
;;
-c*|--c*)
CASE=1
;;
-d*|--d*)
TYPE=d ## patch 2002.03.29
SORT="-r"
;;
-h*|--h*)
usage
;;
-*)
: ;;
*)
unshift=1
;;
esac
[ X"$unshift" = "X" ] && shift
done
STRING=$1
TARGET_FILES=$2
## recheck argument number
##
[ "$#" -lt "2" ] && usage
## check sub_dir
##
if [ X"$SUB_DIR" = "X" ] ; then
MAXDEPTH="-maxdepth 1" ## current directory search
else
MAXDEPTH=`echo "$SUB_DIR" | sed 's/^-R//'`
if [ `echo "$MAXDEPTH" | egrep "[^0-9]"` ] ; then
echo "${T_MR}invalid option($SUB_DIR) argument !!!, ex) -R, -R0, -R1, -R2, -R3, ...${T_ME}" >&2
usage
fi
## if $MAXDEPTH is null, then all sub directorys search
##
if [ X"$MAXDEPTH" != "X" ] ; then
maxdepth=$(($MAXDEPTH + 1))
MAXDEPTH="-maxdepth $maxdepth"
fi
fi
## check string
## patch 2002.03.29
##
check_string=`echo "$STRING" | egrep "^/([^/]+)/([^/]*)/$"`
if [ X"$check_string" = "X" ] ; then
echo "${T_MR}invalid string($STRING) !!!${T_ME}" >&2
usage
fi
## check target_files
##
if [ X"$TARGET_FILES" = "X" ] || [ `echo $TARGET_FILES | grep "^-"` ] ; then
echo "${T_MR}invalid target_file($TARGET_FILES) !!!${T_ME}" >&2
usage
fi
## check find path
##
if [ X"`echo $TARGET_FILES | grep /`" != "X" ] ; then
## same as find_path=`echo "$TARGET_FILES" | sed 's/\/\([^/]*\)$//'`
##
find_path=${TARGET_FILES%/*}
find_path=${find_path:-/} ## recheck, patch 2002.03.29
## same as TARGET_FILES=`echo "$TARGET_FILES" | awk -F"/" '{print($NF)}'`
##
TARGET_FILES=${TARGET_FILES##*/}
fi
## get from string, to string
##
from_string=`echo "$STRING" | awk -F"/" '{print($2)}'`
to_string=`echo "$STRING" | awk -F"/" '{print($3)}'`
## check upcase, lowcase translate
## not good(bad checking T.T)
##
if [ X"$CASE" = "X1" ] ; then
from_tr=`echo "$from_string" | sed 's/[][]//g'`
to_tr=`echo "$to_string" | sed 's/[][]//g'`
if [ X$(echo "$from_tr" | tr A-Z a-z) != X$(echo "$to_tr" | tr A-Z a-z) ] ; then
echo "${T_MR}invalid string($STRING) !!!${T_ME}" >&2
usage
fi
fi
## lists of files
##
files=`find ${find_path:-.} -name "$TARGET_FILES" -type ${TYPE:-f} $MAXDEPTH | sort $SORT 2>/dev/null`
## good idea
##
IFS_ORIG="$IFS"
IFS='
'
i=0
for pfile in $files ; do
## same as file=`basename $pfile`
##
file=${pfile##*/}
## same as path=`echo "$pfile" | sed 's/\/\([^/]*\)$//'`
##
path=${pfile%/*}
## if include ${from_string} string in $file, then action
##
if [ X$(echo "$file" | grep "$from_string") != "X" ] ; then
i=$(($i+1))
if [ X"$CASE" = "X1" ] ; then
tofile=`echo "$file" | tr "$from_tr" "$to_tr"`
else
## do not sed 's/$AAA/$BBB/g', you must sed "s/$AAA/$BBB/g"
##
tofile=`echo "$file" | sed "s${STRING}g"`
fi
${CMD:-action} "$i" "$pfile" "$path/$tofile" "$tofile"
fi
done
IFS="$IFS_ORIG"
exit 0
| |
|
|
|
|