Creating backup files with the current date in the filename
I need to use the mv command to create the backup of a file. Currently I am using: mv message ../message-old But potentially the message-old file already exists. So the mv command gives me a --backup option, but none of these options is to append the filename with the current date. Is there a way I can append the current date to a filename in a mv command? Thanks. -- Tux #395953 resides at http://samvit.org playing with KDE 3.51 on SUSE Linux 10.0 $ date [] CCE +2006-02-18 W07-6 UTC+0530
Shriramana Sharma wrote:
I need to use the mv command to create the backup of a file. Currently I am using:
mv message ../message-old
But potentially the message-old file already exists. So the mv command gives me a --backup option, but none of these options is to append the filename with the current date.
Is there a way I can append the current date to a filename in a mv command?
You can include the current date & time in a file name, if you wish. For example, you might try mv message message.`date +%m%d%H%M%Y.%S` will move message to message.20060217. You can even include the time or use other formats. man date for details
James Knott wrote:
Shriramana Sharma wrote:
I need to use the mv command to create the backup of a file. Currently I am using:
mv message ../message-old
But potentially the message-old file already exists. So the mv command gives me a --backup option, but none of these options is to append the filename with the current date.
Is there a way I can append the current date to a filename in a mv command?
You can include the current date & time in a file name, if you wish. For example, you might try mv message message.`date +%m%d%H%M%Y.%S` will move message to message.20060217. You can even include the time or use other formats.
man date for details
Sorry, that should have been mv message message.`date +%Y%m%d`.
participants (2)
-
James Knott
-
Shriramana Sharma