Reputation: 316
I have found a command to rename all files extensions recursively in a directory to another extension but what I'd like to do is to change their names instead of their extensions... Here is the code I use (it does not work)
find . -type f -name "*.mpeg" -exec rename -v 's/*.mpeg$/' video.mepg '{} \;
Thank you for any constructive reply
Upvotes: 0
Views: 71
Reputation: 763
find ./ -type f -name \*.mpeg -exec rename -v 's/^(.*)\/.*.mpeg$/$1\/video.mpeg/' {} \;
This will rename the file portion to video.mpg, but leave the directory structure the same.
Here is the result:
ubuntu:~/stackoverflow$ find ./ -type f -name \*.mpeg -exec rename -v
's/^(.*)\/.*.mpeg$/$1\/video.mpeg/' {} \;
./dir1/dir2/dir3/test.mpeg renamed as ./dir1/dir2/dir3/video.mpeg
./dir1/dir2/dir3/dir4/test.mpeg renamed as
./dir1/dir2/dir3/dir4/video.mpeg
./dir1/dir2/test.mpeg renamed as ./dir1/dir2/video.mpeg
./dir1/test.mpeg renamed as ./dir1/video.mpeg
Upvotes: 1