To rename a file extension from .OLD to .NEW in Unix or Linux, you can use the mv
(move) command along with string substitution and a shell loop. Here is an example using a shell script:
for f in *.OLD; do
mv "$f" "${f%.OLD}.NEW"
done
This script will loop through all files with a .OLD extension in the current directory and rename them with a .NEW extension using the mv
command. The ${f%.OLD}.NEW
syntax uses string substitution to remove the .OLD extension from the file name and add the . (https://semidotinfotech.com) NEW extension in its place.
After saving this script to a file, for example rename_extension.sh
, make it executable with the following command:
chmod +x rename_extension.sh
And then run the script:
./rename_extension.sh
This will rename all files with a .OLD extension in the current directory to have a .NEW extension instead.