addady
asked on
Rename some of the files in a directory tree
Hi,
I would like to rename on file ending with *.*_old to *.*
It work on the current directory well using:
for a in *_old; do mv "$a" "$(echo "$a" | sed 's/_old//')";
How do I expand it so that it will rename all the file in the subdirectories?
Regards,
Addady
I would like to rename on file ending with *.*_old to *.*
It work on the current directory well using:
for a in *_old; do mv "$a" "$(echo "$a" | sed 's/_old//')";
How do I expand it so that it will rename all the file in the subdirectories?
Regards,
Addady
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm still have problem with space in file name. the mv command is break :(
Change it to:
find /home/damian/test -iname \*_old`; do mv "$dir" `echo "$dir" | sed -e 's/_old//'`; done
or
find /home/damian/test -iname \*_old`; do mv \"$dir\" `echo \"$dir\" | sed -e 's/_old//'`; done
didn't solve it.
Change it to:
find /home/damian/test -iname \*_old`; do mv "$dir" `echo "$dir" | sed -e 's/_old//'`; done
or
find /home/damian/test -iname \*_old`; do mv \"$dir\" `echo \"$dir\" | sed -e 's/_old//'`; done
didn't solve it.
ASKER
Let me be more spcific:
#find /tmp/ -iname \*.genc__12-24__26-07-2007
/tmp/051008 - Eilat/P1010039.JPG.genc__1 2-24__26-0 7-2007
/tmp/051008 - Eilat/P1010037.JPG.genc__1 2-24__26-0 7-2007
/tmp/051008 - Eilat/P1010036.JPG.genc__1 2-24__26-0 7-2007
The directory name contain space
#for FILE in "`find /tmp/ -iname \*.genc__12-24__26-07-2007 `"; do NEW=`echo $FILE | sed -e 's/.genc__12-24__26-07-200 7/.genc/'` ;mv "$FILE" "$NEW"; done
fail because of the space in the directory name.
Please provide example.
Thanks
#find /tmp/ -iname \*.genc__12-24__26-07-2007
/tmp/051008 - Eilat/P1010039.JPG.genc__1
/tmp/051008 - Eilat/P1010037.JPG.genc__1
/tmp/051008 - Eilat/P1010036.JPG.genc__1
The directory name contain space
#for FILE in "`find /tmp/ -iname \*.genc__12-24__26-07-2007
fail because of the space in the directory name.
Please provide example.
Thanks
Hi,
First at the command line type
IFS="
"
Notice after the quotes I hit enter then on that new I added the closing quote now the command
for FILE in "`find /tmp/ -iname \*.genc__12-24__26-07-2007 `"; do NEW=`echo $FILE | sed -e 's/.genc__12-24__26-07-200 7/.genc/'` ;mv "$FILE" "$NEW"; done
Should work fine.
First at the command line type
IFS="
"
Notice after the quotes I hit enter then on that new I added the closing quote now the command
for FILE in "`find /tmp/ -iname \*.genc__12-24__26-07-2007
Should work fine.
ASKER
Thank you it works. you hace small syntax errors. Here is the rigth command:
for dir in `find /home/damian/test -iname \*_old`; do mv $dir `echo $dir | sed -e 's/_old//'`; done
Its not work. For example:
#find /tmp -iname \*.html
/tmp/polls.html
/tmp/activejobs.html
/tmp/2del/polls.html
#for dir in `find /tmp -type d -iname \*.html`; do mv $dir `echo $dir | sed -e 's/.html/.html-old/g'`; done