rename file

Hi

Can anyone help me in adding a timestamp to a filename before the extension
for ex if I have a file name abc.txt , I need to rename it to abc.yyyymmddsshhmm.txt

any help appriciated

Regards,
Antony

mv abc.txt `date "+%Y%m%d%H%M%S"`abc.txt

That's all ?

file=abc.txt
mv "$file" "${file%.*}.$(date +%Y%m%d%H%M%S)${file##*.}"
$ ls -l abc*
-rw-r--r--    1 scripter     scripterworld          0 Aug 21 23:26 abc.txt
$ FILENAME=abc.txt
$ mv abc.txt `echo ${FILENAME} | cut -d "." -f1`.`date +%Y%m%d%H%M%S`.`echo ${FILENAME} | cut -d "." -f2`
$ ls -l abc*
-rw-r--r--    1 scripter     scripterworld          0 Aug 21 23:26 abc.20090821232635.txt
$

cfajohnson's solution is super cool in a Posix shell.

scripter.online solution does not deal with many common situations (incl. filenames containing space characters).

A similar approach to inserting the date in a filename:

FILENAME="abc.txt"
TIMESTAMP="$(date '+%Y%m%d%H%M%S')"
FILENAME_ROOT="$(basename ${FILENAME} .txt)"
mv "${FILENAME_ROOT}.txt" "${FILENAME_ROOT}.${TIMESTAMP}.txt"

We have all ignored yyyymmddsshhmm.txt because placing "ss" before
"hhmm" is not sensible.

The POSIX shell is the standard Unix shell. For a few versions of Unix, it may not be in /bin/sh (though very few don't have it there), but all will have one.