Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
970 views
in Technique[技术] by (71.8m points)

shell - getting a previous date in bash/unix

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]
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try this:

date --date="yesterday" +%Y/%m/%d

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...