Get the date (a day before current time) in Bash

后端 未结 17 2162
臣服心动
臣服心动 2020-11-30 17:54

How can I print the date which is a day before current time in Bash?

17条回答
  •  没有蜡笔的小新
    2020-11-30 18:16

    MAC OSX

    For yesterday's date:

    date -v-1d +%F
    

    where 1d defines current day minus 1 day. Similarly,

    date -v-1w +%F - for previous week date

    date -v-1m +%F - for previous month date

    IF YOU HAVE GNU DATE,

    date --date="1 day ago"
    

    More info: https://www.cyberciti.biz/tips/linux-unix-get-yesterdays-tomorrows-date.html

提交回复
热议问题