Swaminathan K
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_01032015102 354.log
DatabaseServer_02032015072 354.log
DatabaseServer_03032015132 354.log
DatabaseServer_04032015112 354.log
DatabaseServer_11032015112 654.log
DatabaseServer_12032015112 354.log
DatabaseServer_01032016102 354.log
DatabaseServer_02032016092 354.log
DatabaseServer_03032016082 354.log
DatabaseServer_04032016072 354.log
DatabaseServer_11032015112 654.log
DatabaseServer_12032015112 354.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
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_01032015102
DatabaseServer_02032015072
DatabaseServer_03032015132
DatabaseServer_04032015112
DatabaseServer_11032015112
DatabaseServer_12032015112
DatabaseServer_01032016102
DatabaseServer_02032016092
DatabaseServer_03032016082
DatabaseServer_04032016072
DatabaseServer_11032015112
DatabaseServer_12032015112
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
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:defa ult_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)
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:defa
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot.
You're welcome!
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.