且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

得到一个previous日期在bash / UNIX

更新时间:2023-12-05 19:17:04

几种解决方案建议在此假设 GNU的coreutils 是$ P $系统上psent。以下应在Solaris上运行:

  TZ = GMT + 24日期+%Y /%M /%D'

I am looking to get previous date in unix / shell script .

I am using the following code

date -d ’1 day ago’ +’%Y/%m/%d’

But I am getting the following error.

date: illegal option -- d

As far as I've read on the inetrnet , it basically means I am using a older version of GNU. Can anyone please help with this.

Further Info

unix> uname -a

SunOS Server 5.10 Generic_147440-19 sun4v sparc SUNW,Sun-Fire-T200

Also The below command gives an error.

unix> date --version

date: illegal option -- version
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]

Several solutions suggested here assume GNU coreutils being present on the system. The following should work on Solaris:

TZ=GMT+24 date +’%Y/%m/%d’