I am modifying a simple BASH script to remove numbers and hyphens from the start of my MP3 files. The aim is to rename files such as:
- 11 Song 1.mp3
- 1-1-Song 2.mp3
- 11-1 Song 3.mp3
- Song 1.mp3
- Song 2.mp3
- Song 3.mp3
I have this script which works for all the files in the current directory
$ for f in [0-9]*; do mv "$f" "`echo $f | sed 's/^[0-9]*W*//'`"; done
and have modified it to look for all files inside subfolders:
for f in $(find $dir * -type f) ; do
mv "$f" "`echo $f | sed 's/^[0-9]*W*//'`";
The problem is that the
$f value returns the subfolder and the filename and the
mv line looks for files beginning with [0-9], therefore any files within a subfolder are not being renamed.
E.g. The file
mp3/1-1 Song 1.mp3 begins
mp3/, does not start with a numeric so it's not renamed.
Is there a way I can read the directory and file values into separate variables or is there a better way of doing this?