files between any two given dates


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers files between any two given dates
# 1  
Old 08-04-2004
Lightbulb files between any two given dates

Can any one help me in getting all the files between any two given dates..
# 2  
Old 08-04-2004
try something like this:

Code:
olddate="200407010001"
newdat="200407312359"
touch -t $olddate ./tmpoldfile
touch -t $newdat ./tmpnewfile
find /path/to/directory -type f  -newer a ./tmpoldfile ! -newer  a ./tmpnewfile

the "-newer a " means access time, you can use "-newer m " for modify time
# 3  
Old 08-06-2004
Thanks for the help... It is working as per expectations..
Is it possible to do this with sed /awk /fgrep...
# 4  
Old 06-15-2006
Lightbulb

This might be of interest to anyone reading this thread:

Thread

...thanks again all,

B14... aka... marky mark...
# 5  
Old 04-26-2007
if i add this in a shell script it gives error stating the following:

date: bad conversion
date: bad conversion
find: cannot access tmpoldfile

can you suggest on how to go about putting it inside a script alltogether
# 6  
Old 07-10-2007
I have a load of logfiles,

Jul 5 07:03 MSG_sdfd_dsfsdf_sdfsdfsdf_070705_123116.gz
Jul 6 08:03 MSG_sdf_sdfsdfsd_sdfsdf_070705_181255.gz
Jul 6 14:03 MSG_sdf_sdfsdf_sdfdsfsdf_070705_224108.gz
Jul 6 20:03 MSG_sdf_sdfsdf_sdfdsfsd_070706_034803.gz
Jul 7 01:03 MSG_sdf_sdfsdf_sdfsdfdsf_070706_065025.gz
Jul 7 06:03 MSG_sdf_sdfsdf_sdfsdf_070706_081903.gz
Jul 8 10:03 MSG_sdf_sdfdsf_sdfsdf_070706_092214.gz
Jul 8 17:03 MSG_sdf_sdfsdf_sdfsdf_070706_144128.gz

I want to search through them using the bold text below which is the file creation date as the starting date/time and the file last modified date as the end date/time

MSG_sdf_sdfsdf_sdfsdf_070706_144128.gz

Ive been using the code already in this thread to search by 2 modified date/time. But how can I combine the 2?
# 7  
Old 07-11-2007
So I'm using the tmpfile solution as already discussed in this thread. But What I'm currently doing is using 2 Find commands, 1 which finds everything with mtime in between the 2 temp files and the 2nd to find the files by the name I want.

But sometimes I get duplicate entries, cos sometimes files exist which have the mtime and file name I'm looking for. So I have to not select them. Then I combine the results from both finds and display the result.

But I cant figure out how to do this with 1 find

Code:
@results = `find . -type f  -newer ./tmpoldfile ! -newer ./tmpnewfile`;

@results2 = `find . \\( -name *$h$i$b$c* -o -name *$h2$i2$b2$c2* \\)`;

My attempt at combining the 2, but I need to a not and expression, does that exist?
#@results3 = `find . -type f \\( \\( -newer ./tmpoldfile ! -newer ./tmpnewfile \\) -a \\( -name *$h$i$b$c* -o -name *$h2$i2$b2$c2* \\) \\) -ls`;



foreach $name (@results)
{

        if ($name =~ m/(^.*)([0-9][0-9])([0-9][0-9])([0-9][0-9])_([0-9][0-9])([0-9][0-9])([0-9][0-9])(.*$)/)

        {
                        $creation_date = "20$2/$3/$4";
                        $creation_time = "$5:$6:$7";
        }

        if ("$creation_date $creation_time" ge "$date $time" && "$creation_date $creation_time" le "$date2 $time2") {


        } else {
                push(@logfile, $name);
 }

}

        foreach $name (@results2)

 {
                if ($name =~ m/(^.*)([0-9][0-9])([0-9][0-9])([0-9][0-9])_([0-9][0-9])([0-9][0-9])([0-9][0-9])(.*$)/)

                {
                        $creation_date = "20$2/$3/$4";
                        $creation_time = "$5:$6:$7";
                }

        if ("$creation_date $creation_time" ge "$date $time" && "$creation_date $creation_time" le "$date2 $time2") {

                push(@logfile, $name);

        } else {


        }

Then I print and work with the results.

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need to Move files of different dates

Hi, Currently I'm moving the files based on date like below. "mv *20150901* backup_folder" - Limitation: can move only 1 day files to backup folder. I want to move the files of different dates like 20150901,02, 03, 04..... Is there any single command to do it. Thanks in advance!! (2 Replies)
Discussion started by: prakashs1218
2 Replies

2. Shell Programming and Scripting

Moving files into dirs corresponding to dates

I am trying to find a way to move files into corresponding date files. i=0 while read line do array="$line" (( i++ )) done < <(ls) cd $(echo ${array}) echo ${array}} pwd #cd "$(array}" ] || mkdir 2015 cd "2015" ] || mkdir 02-February ] || mkdir 03-March ] || mkdir... (10 Replies)
Discussion started by: newbie2010
10 Replies

3. Shell Programming and Scripting

Deleting the files between particular dates

Hi Please help me for the below task. In my home directory if I run ls -l command, it lists all the files, here I want to delete files created from January 2014 to Aug 2014...but I need to keep the files which are created after September 01 2014. Thanks Siva (3 Replies)
Discussion started by: kumar85shiv
3 Replies

4. Shell Programming and Scripting

Files between two dates in UNIX

Hi Team, I need to connect to a prod server and need to get the files which falls between two dates. I should not create ant files on that machine. I am using korn shell. Your help is very much appreciated. Vinay (13 Replies)
Discussion started by: gvkumar25
13 Replies

5. UNIX for Advanced & Expert Users

Find all files other than first two files dates & last file date for month

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (16 Replies)
Discussion started by: Makarand Dodmis
16 Replies

6. AIX

Copy files for particular dates

Hi, I need to copy particular date files from one directory to another. For example, I have thousands of files in /home/usr From this I need to copy only particular date files (each date contains thousand number of files) to some directory of another server. Could anyone please help me... (3 Replies)
Discussion started by: teddy2882
3 Replies

7. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

8. Shell Programming and Scripting

Getting list of all the log files between two dates

I need to get the list of all the log files for a particular duration, say between two dates,i.e I need to get the list of all the log files between date1 and date2.The two dates are entered by the user. The format of the log file is : /path_name/graph_name_20080801180308.log. I dont... (1 Reply)
Discussion started by: avishekp
1 Replies

9. UNIX for Dummies Questions & Answers

Files and dates

Hello all. I am trying to do a file listing on a particular directory by date. I need to list the files and their directories that have a timestamp between Dec-1-2006 and Jan-1-2007. Any help would be greatly appreciated. (1 Reply)
Discussion started by: mastachef
1 Replies

10. UNIX for Dummies Questions & Answers

Remove files by dates

I've tried every way possible to remove files by date and nothing seems to work. Does anyone have an idea how to remove files by dates? Thanks in advance.... (1 Reply)
Discussion started by: dman110168
1 Replies
Login or Register to Ask a Question