[Cialug] finding files with "find" command for specific date

Jeff Chapin chapinjeff at gmail.com
Fri Sep 10 13:18:43 CDT 2010


date -d allows fuzzy logic. To put it in your code:

~~snip~~

      find log* -daystart -mtime $x -exec ls -l {} \;
      DATE=$(date -d "$x days ago" -I)
      tar cvfz file-${DATE}.tar.gz $(find ./ -daystart -mtime $x -name log\*)
~~snip~~

Working from memory, anyway.


Jeff




Afan Pasalic wrote:
>   On 9/10/2010 1:07 PM, Jeff Chapin wrote:
>   
>> $ date -d "10 days ago"
>> Tue Aug 31 13:06:42 CDT 2010
>>     
>
> I'm not quite sure how to use this within the code?
>
>
>   
>> Afan Pasalic wrote:
>>     
>>>    next level question :-)
>>>
>>> I'm building bash script (first time in my life) to tar all files within
>>> a same day to one file.
>>> right now I can list all files
>>>
>>> #!/bin/bash
>>> x=1
>>> while [ $x -le 7 ]
>>> do
>>>       find log* -daystart -mtime $x -exec ls -l {} \;
>>>       x=(($x+1))
>>> done
>>>
>>> my idea is to, instead current find line use something like
>>>       find log* -daystart -mtime $x -exec tar -zcf logs_DATE.tar.gz {} \;
>>> though I don't know how to find the date of the selected files?
>>>
>>> suggestions?
>>>
>>>
>>>
>>> On 9/10/2010 10:46 AM, Ken MacLeod wrote:
>>>
>>>       
>>>> On Fri, Sep 10, 2010 at 10:39 AM, Ken MacLeod<ken at bitsko.slc.ut.us>   wrote:
>>>>
>>>>         
>>>>> On Fri, Sep 10, 2010 at 10:38 AM, Jeffrey Ollie<jeff at ocjtech.us>   wrote:
>>>>>
>>>>>           
>>>>>> On Fri, Sep 10, 2010 at 10:32 AM, Afan Pasalic<afan at afan.net>   wrote:
>>>>>>
>>>>>>             
>>>>>>> find /path/to/files/log* -mtime 10
>>>>>>> I need all files for SPECIFIC day.
>>>>>>>
>>>>>>>               
>>>>> And also use -mtime -11 to restrict the time span to one day (less
>>>>> than 11 days, greater than 10).
>>>>>
>>>>>           
>>>> Ignore that.  - and + are only used for ranges.  The 10 didn't have a
>>>> + so it's exactly 10 days ago (with -daystart as Jeff mentioned).
>>>> _______________________________________________
>>>> Cialug mailing list
>>>> Cialug at cialug.org
>>>> http://cialug.org/mailman/listinfo/cialug
>>>>
>>>>         
>>> _______________________________________________
>>> Cialug mailing list
>>> Cialug at cialug.org
>>> http://cialug.org/mailman/listinfo/cialug
>>>
>>>       
>> _______________________________________________
>> Cialug mailing list
>> Cialug at cialug.org
>> http://cialug.org/mailman/listinfo/cialug
>>     
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug
>   


More information about the Cialug mailing list