UNIX date fuction - how to deduct days from today's date

Hi,

One of my Unix scripts needs to look for files coming in on Fridays. This script runs on Mondays. $date +"%y%m%d" will give me today's date. How can I get previous Friday's date.. can I do "today's date minus 3 days" to get Friday's date? If not, then any other way?? Name of the files is in the format.. A130524.csv, and I am expected to get one file every month.

~juzz4fun

Can you tell us what is your OS?

Also you can have a look at this thread in FAQ section.

Thanks. It's SunOS 5.10

Perhaps all you need is find's -mtime.

Regards,
Alister

Using perl is one option:

perl -e 'use POSIX qw(strftime); print strftime "%y%m%d",localtime(time()- 3600*72);'

Or you can use Perderabo's datecalc script in the thread that I posted.

1 Like