Shell Scripts - Append a filename with date and time....

Hello,

I need to create a shell script that appends a filename to create a name with the date and time appended that is guaranteed to not exist. That is, the script insures you will not overwrite a file with the same name. I am lost with this one. I know I need to use date but after that I am not sure what options to use. Thanks for your help, citizencro

---------- Post updated at 08:53 PM ---------- Previous update was at 08:47 PM ----------

I also need to create a backup script that uses the above to create a backup of my files using the tar command.

man man date (POSIX)

Other than that: what have you got so far, where are you stuck? We're not going to give you a complete script just because you ask, you'll have to show some effort.

I have written the code to create a file named backup which can append the date and time with the following code;

FILE="backup_$(date +%b)$(date +%d)$(date +%Y)"
echo $FILE

I can't figure out how to make it so it insures not to overwrite a file with the same name.

add second in file name.

FILE="backup_$(date +%Y%m%d_%H%M%S)"