2

I have a directory named backup. Backup contains several subdirectories named monday, tuesday, wednesday... each subfolder contains file named filename.txt I want to change all names filename.txt to someothername.txt. How can I do that in one line in bash?

0
6
for f in backup/*/filename.txt; do mv "$f" "$(dirname "$f")/someothername.txt"; done
0

And this is if you want to keep the basename and just change the extension in a bunch of files located in some subdirectories:

for f in ./*/*.yaml;
   do mv ${f} "$(dirname "$f")/$(basename ${f%.*}).yml";
done

or

for f in ./*/*.yaml;
   do mv ${f} "${f%.*}.yml";
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.