Elitmiar
Elitmiar

Reputation: 36839

Looping and adding an extension to all files using bash

I have bunch of email file spread recursively within folders and subfolder, I need to add the extension .eml to all of them except the directories, so now what I have is the following

This loops through the directories recursively and list only the filenames

find a/ -name "*" -type f

How can I rename the filenames with the .eml extension?

I have this script that does what I want but it does not work recursively

#!/bin/bash

for i in * do 
e=`echo $i.eml`
echo $e
mv $i $e
done

How do I combine the 2?

Upvotes: 1

Views: 113

Answers (1)

ruakh
ruakh

Reputation: 183321

With many versions of find, you can write:

find a/ -type f -exec mv '{}' '{}.eml' \;

Upvotes: 3

Related Questions