Re: How to easily append (in shell script) a timestamp to tar archivename ?
am 27.12.2007 11:45:36 von artixMatthew Lincoln wrote:
> I would like to create a tar archive with the well known tar command
>
> tar czvf "/usr/local/user234/bkp.tar.gz" /home/users/pmiller/
>
> It works. However I would like to automatically append a timestamp whenever I call this command
> in a shell script.
>
> The created archive file name should look like
>
> bkp-20071109-1523.tar.gz
>
> Where the format is preferred as YYYYMMDD-HHMM
>
> Does (Gnu-)tar offer such an automatic timestamp appending?
>
> If not: Is there a (short) work around (in bash) which let me create such a timestamp?
>
> Thank you
> Matthew
If it's a shell script I usually put the time in a variable, as it's
easier to read and can be reused.
time_stamp=$(date +%Y%m%d-%H%M)
tar czvf "/usr/local/user234/bkp-${time_stamp}.tar.gz" /home/users/pmiller
--
artix
http://www.abstractart.ws _Abstract Art Directory_