Hello all. I thought this would be real easy. Yet here I am over 2 hours later still messing with it. Here is what I got:
I have files with the following naming convention (name_YEAR_MONTH-DAY.notes). I am attempting to find and display all files where the date within the name of the file is under 7 days old. Why don't I use the
-mtime option for
find? That is because these files were transferred from another source all at the same time and thus according to the filesystem they were created/modified on the same day so
-mtime or any of the other time criteria would not help me in this situation.
I thought it would be real easy to just grab the date, format it, then stick it into a
find function. To test the idea I created this script:
Code:
name=$(date +"%Y_%m-%d")
find *$name* -exec cat {} \;
It worked perfectly. So now all I got to do is get date to give me dates for the last 7 days. Easy right? Not so much
The command to give you a previous date is
date --date='n days ago' with
n being the number of days you want to go back. So I wrote this up:
Code:
for day in 1 2 3 4 5 6 7
do
name=$(date +"%Y_%m-%d" --date='$day days ago')
find *$name* -exec cat {} \;
done
Well that didn't work at all. It seems to keep getting caught in the date
--date switch. It doesn't like a variable in there. I have tried creating a variable for the whole
'n days ago' string and plugging it in but it won't take that ether. Not quite sure what to do at this point. Without the output from the date function I don't think I can make this script work.
Any ideas?