[NTLUG:Discuss] tar file with date?

Brian Rogers brog45 at gmail.com
Tue Aug 5 11:07:25 CDT 2008


On Tue, Aug 5, 2008 at 10:58 AM, Brian Rogers <brog45 at gmail.com> wrote:

> On Tue, Aug 5, 2008 at 10:39 AM, m m <llliiilll at hotmail.com> wrote:
>
>>
>> I am trying back the while directory with tar.
>> I want to have current date append to the backed up file name.
>> Google result is
>>
>> tar cvf backup_`date +%d%m%y`.tar
>>
>> however, it just don't work on my box.
>
>
>
> This works:tar cvf backup_$(date +'%d%m%y').tar
>
> But I recommend the following because it alphabetizes in chronological
> order:
> tar cvf backup_$(date +'%Y%m%d').tar
>

Oops.  You do have to add a directory to the end of that command.  Like so:
tar cvf /tmp/backup_$(date +'%Y%m%d').tar /home/brogers

I should also explain that I have found it necessary to put quotes around
the date format string.  Also, $() is equivalient to and more readable than
`` but is not the same as not ${}.

/* Brian Rogers, professional geek, coffee achiever */


More information about the Discuss mailing list