系统集成

linux date -d参数用法

实例:
#for tar

0 23 * * * nohup tar -zcvf /itims/itims_release/release`date -d "today" +"%Y%m%d"`.tar.gz -C /itims/ release &
50 23 * * * rm -f /itims/itims_release/release`date -d "3 days ago" +"%Y%m%d"`.tar.gz
 
#info data
这里面看到了data -d参数的灵活用法,真是欣喜若狂。好东西要保存,整理整理: 

   * To print the date of the day before yesterday:

          date --date='2 days ago' 

   * To print the date of the day three months and one day hence:

          date --date='3 months 1 day'

   * To print the day of year of Christmas in the current year:

          date --date='25 Dec' +%j

   * To print the current full month name and the day of the month:

          date '+%B %d'

     But this may not be what you want because for the first nine days
     of the month, the `%d' expands to a zero-padded two-digit field,
     for example `date -d 1may '+%B %d'' will print `May 01'.

   * To print a date without the leading zero for one-digit days of the
     month, you can use the (GNU extension) `-' flag to suppress the
     padding altogether:

          date -d 1may '+%B %-d

   * To print the current date and time in the format required by many
     non-GNU versions of `date' when setting the system clock:

          date +%m%d%H%M%Y.%S

   * To set the system clock forward by two minutes:

          date --set='+2 minutes'

   * To print the date in RFC 2822 format, use `date --rfc-2822'.  Here
     is some example output:

          Fri, 09 Sep 2005 13:51:39 -0700

   * To convert a date string to the number of seconds since the epoch
     (which is 1970-01-01 00:00:00 UTC), use the `--date' option with
     the `%s' format.  That can be useful in sorting and/or graphing
     and/or comparing data by date.  The following command outputs the
     number of the seconds since the epoch for the time two minutes
     after the epoch:

          date --date='1970-01-01 00:02:00 +0000' +%s
          
date -


滚动链接
辽ICP备14009778号

To Top