Jun
3
Bash: Get yesterday’s date
Filed Under Command line, Howto, Linux, Unix
Recently I had to create a bash script to copy some files based on date.
The rule was copy yesterday’s files to …
But How to determine what was the yesterdays date?
The answer was in date man page.
Here are the parts from the script related to yesterday date:
$date -d '1 day ago' +'%Y/%m/%d' 2011/06/02
on Internet I’ve found also:
date --date='yesterday' Thu Jun 2 14:01:28 EDT 2011
And (Bonus!!) if you want to go in future 😉
date --date='tomorrow' Sat Jun 4 14:04:29 EDT 2011
Happy scripting…
how did you run a script against the above to check if files were of yesterdays date to enable you to do whatever to them? In my case I need to check files on server under subfolders and copy yesterdays files only to another server folder.
In your case you do not need the command above.
find . -daystart -atime 1
will find any file in current filder modified yesterday, but less than 24h ago.
Or you can use rsync to mittor daily the files.