# Newbie help with bash script to search and replace a filename



## gilc (Feb 22, 2010)

I'm a complete newbie to shell/bash scripting (only been going a couple of days) and am trying to get to grips with it.

I'm trying to create a script that loops through a folder finding any sub folders that are called Season 1-9 and appends a 0 to the beginning of the number.

E.g Season 1 -> Season 01
Season 2 -> Season 02
Season 11 -> Season 11

I think this code is right for looping through find only folders and leaving files alone. Just can't seem to work out how to use sed and regular expressions to replace the text in the file names.

Here's my code so far and would love some pointers.


```
#!/bin/bash
# Script to pad a 0 to Season numbers

TV_DIR=~/Desktop/TV

cd "$TV_DIR"

for dir in `find . -type d `; do #loop through each entry in the TV_DIR finding folders 
	
	#here I want to search all folders in this format Season 1-9 and change to Season 01 etc
	echo "Renaming X to X"
done

echo "Job Done."
```


----------

