Append date to filename in linux

sami picture sami · Nov 25, 2009 · Viewed 101.7k times · Source

I want add the date next to a filename ("somefile.txt"). For example: somefile_25-11-2009.txt or somefile_25Nov2009.txt or anything to that effect

Maybe a script will do or some command in the terminal window. I'm using Linux(Ubuntu).

Thanks in advance.

oh i almost forgot to add that the script or command should update the filename to a new date everytime you want to save the file into a specific folder but still keeping the previous files. So there would be files like this in the folder eventually: filename_18Oct2009.txt , filename_9Nov2009.txt , filename_23Nov2009.txt

Answer

miku picture miku · Nov 25, 2009

You can use backticks.

$ echo myfilename-"`date +"%d-%m-%Y"`"

Yields:

myfilename-25-11-2009