I just need to append the string "eng" to many files names in same directory without changing its extension in MAC TERMINAL. I searched it for long time, i found mv command to rename files at once. But i don't know how to implement in to my scenario. Can any ony guide me ?
Thanks
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 filenamesname="${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.