Is it possible to run a cp
command which creates a backup of a file and renames it with todays date/time
e.g:
- foo.txt
- foo.txt.2012.03.03.12.04.06
Is it possible to run a cp
command which creates a backup of a file and renames it with todays date/time
e.g:
this puts a date in the ISO format yyyy-mm-dd
Copy the below code snippet to mkcp.c and compile with
# gcc -o mkcp mkcp.c
on linux or# cl mkcp.c
on Windows®.# ./mkcp mkcp.c
then runs acp
command and creates a copy such asmkcp.c_sav_2018-01-04
.Note:
mkcp
actually checks whether the file to be written exists already.mkcp
will stop in that case. Accordingly, any risk of data loss is minimized.And if what you really want is a quick edit using sed, use something like
sed -i.$(date -I) -e ...
Output format for
date -I
is like2018-12-31
Cheers, Cameron