Getting previous day's date in Unix
I cannot do an exact test on solaris. but on linux this works for getting last day(yesterday):
kent$ date -d'yesterday' +%Y%m%d20130520
so you just type "yesterday", you don't have to do something special with date
. It is cool, isn't it?
On Solaris simply use GNU date rather than the Solaris version. Access with gdate
as opposed to date
. Then you simply do
gdate -d'yesterday' +%Y%m%d
Your Solaris SysAdmin may have given you a crippled host where GNU coreutils (GNU date is part of that package) are not installed by default. Shame on him.
More info on what a Solaris host should look like on this link. The link has info for both Solaris 10 and Solaris 11.
For Unix OS, this works fine for me
date +%Y/%m/%d --date="yesterday"