This is a job for
find and
sed: use
find to walk the tree, use
sed to substitute one pattern for another pattern (wk10 v15, wk10_v15 or wk10v15 with wk10 v35, wk10_v35 or wk10v35 or whatever else you may choose).
Before you start, make a back up copy of the entire tree:
Code:
cd <some_directory>
cp -pr <original_directory> .
About renaming all files and folders: use this little shell program to rename all files and directories ("folders") substituting a space with an underscore (this is for fixing Windows Weenie file names).
Code:
#!/bin/bash
#ident "$Id$"
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General
# Public License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
# MA 02111-1307, USA.
#
# Name: $Source$
# Version: $Revision$
# Modified: $Date$
# Purpose: Replace blanks in file names with underscores
# Author: Unknown
# Date: 28 Feb 2010
# $Log$
ONE=1 # For getting singular/plural right (see below).
number=0 # Keeps track of how many files actually renamed.
FOUND=0 # Successful return value.
for filename in * # Traverse all files in directory.
do
echo "$filename" | grep -q " " # Check whether filename
if [ $? -eq $FOUND ] #+ contains space(s).
then
fname=$filename # Yes, this filename needs work.
n=`echo $fname | sed -e "s/ /_/g"` # Substitute underscore for blank.
mv "$fname" "$n" # Do the actual renaming.
let "number += 1"
fi
done
if [ "${number}" -eq "$ONE" ] # For correct grammar.
then
echo "${number} file renamed."
else
echo "${number} files renamed."
fi
exit 0
Save that as, say,
blank-rename and make it executable:
Code:
chmod 755 blank-rename
Then get into the parent directory that you want to fix and execute it:
Code:
cd <directory>
blank-rename
Handy for when you're dealing with Windows file names (we don't use space characters in file names in Linux). Hang on to it, it'll come in handy over time.
find is pretty easy:
Code:
cd <parent directory>
find . -type f
sed is also pretty easy (and you can do the substitution in place with
sed):
Code:
sed -i 's/v15/v35/g' ${file}
or, if you have other patterns that contain
v15:
Code:
s -i 's/wk10\ v15/wk10\ v35/;s/wk10_v15/wk10_v35/g;s/wk10v15/wk10v35/g' ${file}
Read the man page for
find and
sed for more options.
If you intend to actually rename files and directories (other than changing the spaces to underscores), that's a little more complicated (you can see how it's done in
blank-rename). Need to know a little more about what you intend.
Putting it together
Code:
cd <directory>
for file in $(find . -type f)
do
s -i 's/wk10\ v15/wk10\ v35/;s/wk10_v15/wk10_v35/g;s/wk10v15/wk10v35/g' ${file}
done
Give that a shot and see what happens (don't forget to make a back up of your tree first!).
Hope this helps some.