Link to home
Start Free TrialLog in
Avatar of Swaminathan K
Swaminathan KFlag for India

asked on

Listing files based on timestamp in linux

Hi Team,

I have a folder /opt/reports

In this folder I have some log files for the past 2 years  , I need to list the log files created between 01-03-2015 to 11-03-2015 and 01-03-2016 to 11-03-2016 ,  I tried with find command I was not successful . Is there any other way to get the output . I just need to list the files .

find /opt/reports -name "DatabaseServer" -ctime 720 -print , Iam trying to manupilate the creation time , but not getting the output

Filenames
DatabaseServer_01032015102354.log
DatabaseServer_02032015072354.log
DatabaseServer_03032015132354.log
DatabaseServer_04032015112354.log
DatabaseServer_11032015112654.log
DatabaseServer_12032015112354.log

DatabaseServer_01032016102354.log
DatabaseServer_02032016092354.log
DatabaseServer_03032016082354.log
DatabaseServer_04032016072354.log
DatabaseServer_11032015112654.log
DatabaseServer_12032015112354.log


In my Output  I must get the below files and exclude all files creatred before 1 st of march and after 11 th of march 2015 and 2016
Avatar of David Favor
David Favor
Flag of United States of America image

Something like this...

find . -type f -newermt 01-03-2015 ! -newermt 11-03-2015

Open in new window


You'll write a specific find command for each date range you're looking for, then roll these up into a single bash script to run.
You may run into the time format error message like this:

find: I cannot figure out how to interpret ‘01-01-2019’ as a date or time

If that is the case, use stat <somefile> to see what file format you should use:

$ stat somefile
  File: ‘somefile’
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: fd00h/64768d    Inode: 17719439    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1001/   fabpc)   Gid: ( 1001/   fabpc)
Context: unconfined_u:object_r:default_t:s0
Access: 2019-01-09 16:29:45.427924350 +0100
Modify: 2019-01-09 16:29:45.427924350 +0100
Change: 2019-01-09 16:29:45.427924350 +0100
 Birth: -

(the format to use is shown in bold)
ASKER CERTIFIED SOLUTION
Avatar of David Favor
David Favor
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Swaminathan K

ASKER

Thanks a lot.
You're welcome!