How to edit the headers of multiple fasta files from multiple folders? (recursively)
You can edit your for loop so as to include the paths to your files of interest.

The command below will give you the relative paths (relative to where you run the command, I think it is better to run this within your main directory) of your files of interest:

ls mpg*/mgm*.3/*.fna


You can use the output of this command (your files of interest) to iterate over via your for loop. Your code will look like:

for i in {...}; do 
    sed -i.bak "s/^&gt;/&gt;${i}_/" i
done