addady
asked on
Rename some of the files in a directory tree v2
Regarding my question:
https://www.experts-exchange.com/questions/22734079/Rename-some-of-the-files-in-a-directory-tree.html
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.
https://www.experts-exchange.com/questions/22734079/Rename-some-of-the-files-in-a-directory-tree.html
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I already answered You Q.
Example 1
IFS="
"
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
Example 2
find /tmp/ -iname \*.genc__12-24__26-07-2007 | while read FILE; do
NEW=$( echo $FILE | sed -e 's/.genc__12-24__26-07-200 7/.genc/' )
mv "$FILE" "$NEW";
done
Example 3
rename .genc__12-24__26-07-2007 "" /tmp/051008\ -\ Elt/*.genc__12-24__26-07-2 007
Example 1
IFS="
"
for FILE in `find /tmp/ -iname \*.genc__12-24__26-07-2007
Example 2
find /tmp/ -iname \*.genc__12-24__26-07-2007
NEW=$( echo $FILE | sed -e 's/.genc__12-24__26-07-200
mv "$FILE" "$NEW";
done
Example 3
rename .genc__12-24__26-07-2007 "" /tmp/051008\ -\ Elt/*.genc__12-24__26-07-2
At work I found a sed command right after the find did it for me:
for FILE in "`find /tmp/ -iname \*.genc__12-24__26-07-2007 |sed - e 's/ /\\ /g'`"; do NEW=`echo $FILE | sed -e 's/.genc__12-24__26-07-200 7/.genc/'` ;mv "$FILE" "$NEW"; done
works for any number of spaces, including consecutive
for FILE in "`find /tmp/ -iname \*.genc__12-24__26-07-2007
works for any number of spaces, including consecutive
ASKER
Hello ravenpl: and
ravenpl:
Example 1 work (Accept as solution)
Example 2 did some of the job. it wirk well on dir like:
"/tmp/051008 - Eilat"
but fail on dir like:
"/tmp/Tomer - Yom Huledet 5/"
The error:
mv: cannot move `/tmp/Tomer - Yom Huledet 5/Thumbs.db.genc__12-24__2
Example 3
Why the subdir name is part of the command? it suppose to work on all /tmp
duncan_roe:
If fail on:
sed: -e expression #1, char 1: unknown command: `-'
mv: cannot stat `': No such file or directory
ASKER
#find /tmp/ -iname \*.genc__12-24__26-07-2007
/tmp/051008 - Elt/P1010039.JPG.genc__12-
/tmp/051008 - Elt/P1010037.JPG.genc__12-
/tmp/051008 - Elt/P1010036.JPG.genc__12-
The directory name contain space
The command:
#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