Skip to content
Advertisement

Append date to a filename in linux

I want add the date next to a filename (“somefile.txt”). For example: somefile_DDMMYYYYHHMMSS.txt

Maybe a script will do or some command in the terminal window. I’m using Linux.

Thanks in advance.

Advertisement

Answer

Something like can do the work:

a=somefile.txt
bname="${a%.*}"
ename="${a##*.}"
date=$(date +%d%m%Y%H%M%S)
echo ${bname}_${date}.${ename}
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement