Thierry De Corte <[EMAIL PROTECTED]> wrote:
> I want to backup some files using tar in a script... How can I use the current date
>to create the file
> name?
>
> In other words, I want to script the command:
>
> #!/bin/sh
> tar -zcvf backup_jun18.tgz /some_dir/*
>
> with the date part automatic (the date can be any formats)...
>
> Thanks
>
If you were using perl for your scripting, you'd say:
my $date = scalar localtime;
$date =~ s/\s+/_/g;
If using bash, I'd say something like:
date=`date +"%Y.%m.%d.%H:%M:%S"`
then use $date in your filename, (date looks like "2001.06.18.07:52:48" -
if you want a different kinda date, look up the man page on 'date' and use
different %-thingys ;-)
rc
Rusty E. Carruth Email: [EMAIL PROTECTED] or [EMAIL PROTECTED]
Voice: (480) 345-3621 SnailMail: Schlumberger ATE ___
FAX: (480) 345-8793 7855 S. River Parkway, Suite 116 \e/
Ham: N7IKQ @ 146.82+,pl 162.2 Tempe, AZ 85284-1825 V
ICBM: 33 20' 44"N 111 53' 47"W http://tuxedo.org/~esr/ecsl/index.html