slacker_nl wrote:
Code:
#!/bin/bash
cd /vmfs/volumes
for ifile in snapshot*LUN* ; do
[ ! -d "$ifile" ] && continue
newfilename=$(echo $ifile | awk -F~ '{ print $2 }')
mv $ifile $newfilename
done
I suppose, if there are no files named like snapshot~LUN*, it may be written even shorter, using bash parameter expansion:
Code:
cd /vmfs/volumes && for d in snapshot*~LUN* ; do mv ${d} ${d/snapshot*~/} ; done
of course, “[ ! -d "$ifile" ] && continue;†may be added if there are files with similar names.
Yet, it will nor work if there are spaces in some of the directory names. In this case I cannot think of something better than
Code:
# create temporary renaming script
printf '#!/bin/bash\nf=$1\nmv ${f} ${f/snapshot*~/}\n' > ./mymv && chmod a+x ./mymv
# rename
find /vmfs/volumes -type d -name 'snapshot*LUN*' -exec ./mymv '{}' \;
# delete temporary renaming script
rm ./mymv ;
--
UseFreeTools — my blog about GNU/Linux and Free Software