Tekker Blog

My little home on the internet.

How to find yesterday’s date with bash…

without comments

I have a process that generates files daily. Rather than having to go delete them myself, I wanted to automate the task of removing the files. After all, the more the computer does for me, the less I have to do, right?

5 Mins of googling and I found this site. I am blantantly copying and pasting the post, this is NOT my post.

Date of yesterday in bash?
I recently had to hack a small shell script that would read files in a directory structure generated based on the date, something like 2007/08/16. The trick was that the script would look at yesterday’s file or files generated a few days ago.

A quick search on info and here’s the magic command

FILE=”…$(date -d ‘yesterday’ +%Y/%m/%d)”
Interestingly, you can also use things like 3 days ago, next Monday, 2 months etc. Cool!

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Reddit
  • StumbleUpon

Written by Paul

November 21st, 2011 at 10:26 am

Posted in

Leave a Reply