Hey all- first post. This is probably a bit of a newb question, but I'm quite new to shell scripting and have given this quite a bit of thought before getting stuck
I'm looking to get a shell script to loop through a number of directories and subdirectories, looking for files that contain a particular substring, and renaming the file by replacing the search string with a different substring.
For example if you had a directory full of folders that contained digital photos (along with various other files which would need to remain unaffected), and the intent was to remove the "DSC_" prefix from several thousand files buried within.
You know, hypothetically speaking
I've whipped up a rather long-winded solution that works well for this purpose but chokes on directory names with spaces. I am reasonably sure there's a 2 or 3-liner that would accomplish this exact same task.
Thanks in advance for any help you can give.
________________________
function investigate
{
path=$1
for file in `ls $1`
#for file in *
do
pathfile="$path/$file"
if [ -d "$pathfile" ] #is dir
then
investigate "$pathfile"
else #not a dir
if #...file matches search criteria
then
#...
mv $pathfile $newname #rename it
else #skip it
fi
fi
done
}
investigate .