Problem: I need to find out today's date and search a file which contain's today's date in the name. Also another file which contains Yesterday's date. I was able to do so by something like:

TODAY=$(date +"%m%d%Y")   
YESTERDAY=$(date --date="yesterday" +"%m%d%Y")

for snapshotfile in $SNAPSHOT
        if [ -f "$snapshotfile" ]
          echo Snapshot Report $SNAPSHOTFOUND is available

But there is a condition here that, if today is Monday I have to check one file which has last Friday's date and another file which has Saturday's date in their names unlike Today and Yesterday.

Can anyone suggest.

  • Find out today's weekday name and implement your special condition.
    – scai
    Mar 7, 2013 at 9:46

1 Answer 1

find . -type f -name "*`date +%Y%m%d`*.*"

Finds files recursively, type f finds only files and name find only files that match the pattern. Using backticks `` you can add the date inline.

With date +%u you get the weekday number. If it is "1" then its Monday.

To check for last Friday and Saturday's dates, use --date

date --date="last Friday" +%Y%m%d
date --date="last Saturday" +%Y%m%d

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.