Link to home
Start Free TrialLog in
Avatar of addady
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.
ASKER CERTIFIED SOLUTION
Avatar of ravenpl
ravenpl
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of addady
addady

ASKER

Let me be more specific:

#find /tmp/ -iname \*.genc__12-24__26-07-2007                
/tmp/051008 - Elt/P1010039.JPG.genc__12-24__26-07-2007
/tmp/051008 - Elt/P1010037.JPG.genc__12-24__26-07-2007
/tmp/051008 - Elt/P1010036.JPG.genc__12-24__26-07-2007

The directory name contain space

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-2007/.genc/'`;mv "$FILE" "$NEW"; done


fail because of the space in the directory name.

Please provide example.

Thanks
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-2007/.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-2007/.genc/' )
 mv "$FILE" "$NEW";
done

Example 3
rename .genc__12-24__26-07-2007 "" /tmp/051008\ -\ Elt/*.genc__12-24__26-07-2007
Avatar of Duncan Roe
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-2007/.genc/'`;mv "$FILE" "$NEW"; done

works for any number of spaces, including consecutive
Avatar of addady

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__26-07-2007' to `/tmp/Tomer - Yom Huledet 5/Thumbs.db.genc': No such file or directory

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