If you have a directory containing the following files:
a.ext
b
c.long.sh
And you want to rename them to:
aeng.ext
beng
c.longeng.sh
The following "oneliner" in a Mac terminal (bash) should do it:
for i in *; do name="${i%.*}"; mv "$i" "${name}eng${i#$name}"; done
To explain:
for i in *; do
- iterates over all your filenames
name="${i%.*}"
- extracts the name portion before the extension (strips off everything past the last dot)
mv
- handles the rename
${name}eng
- adds eng to the name
${i#$name}
- gets the extension (this strips the name portion from the original filename)
Note: If you want to preview what it would do, but not actually perform the rename, insert an "echo" before the "mv". This will print the statements to the screen instead of executing the rename.