I'm trying to create a bash script that takes a directory full of files (about 500 files) that have all different types of extensions (no seriously, like 30 different types of extensions) and I want get rid of all of the extensions, and replace them with .txt
I've been searching around for a while now, and can only find examples of taking a specified extension, and changing it to another specified extension. Like png --> jpg, or .doc --> .txt
Here's an example I've found:
# Rename all *.txt to *.text
for f in *.txt; do
mv -- "$f" "${f%.txt}.text"
done
This works, but only if you go from .txt to .text, I have multiple different extensions I'm working with.
My current code is:
directory=$1
for item in $directory/*
do
echo mv -- "$item" "$item.txt";
done
This will append the .txt onto them, but unfortunately I am left with the previous ones still attached. E.G. filename.etc.txt, filename.bla.txt
Am I going about this wrong? Any help is greatly appreciated.