Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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")
SNAPSHOT=SnapshotIR${YESTERDAY}\*.csv

for snapshotfile in $SNAPSHOT
do
        if [ -f "$snapshotfile" ]
        then
                SNAPSHOTFOUND="$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.

share|improve this question
    
Find out today's weekday name and implement your special condition. –  scai Mar 7 '13 at 9:46
add comment

1 Answer

up vote 2 down vote accepted
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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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