Search files between a date range


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search files between a date range
# 1  
Old 09-05-2007
Search files between a date range

Hi people

A newbie here, thrown into the deep end. I want to select the group of files with in a range of dates and perform some operation on it. Are there inbuild date libraries i can use?

I did read thru the old posts on this topic. Couldnt get much idea Smilie, basically want to know how I can increment the dates or how unix does that, date formats (ddmmyy, dd MM yyyy, etc.), etc. I reckon the solution would be to find the right switched with 'find'. Pl help.

Thanx
# 2  
Old 09-05-2007
you can use touch and find implement it.
# 3  
Old 09-05-2007
You can use find command in this.
just do a
man find
and go through that,it will solve ur problem.

Thanks
Namish
# 4  
Old 09-05-2007
date formats

yup thanx. i figured that out. im using somehting like this -

touch -d "$1" ./tmp1
touch -d "$2" ./tmp2
find -name '*.cdr' -newer ./tmp1 ! -newer ./tmp3

1. I'm required to have the start/end dates in the format ddmmyyyy but touch seems to take only dd MMM or dd MMM yyyy. Can change/set the date format??

2. '-newer' retreives the file created *after* creation date on tmp1. I want to search for the files created *on or after* creation of tmp1. how would I do that?

Thanx ppl.
# 5  
Old 09-05-2007
1.touch only can accept its own time format, so you may adjust you to fit it. use -t parameter can adjust to minute(or second, it determind by your OS)
2.in fact, '-newer' retreives the file *on or after*, you can try it on your machine.

btw: what's ppl?
# 6  
Old 02-07-2009
ppl means people. :-) Here is how I did a limited date range file search

The snippet below finds files modified between 2500 and 2800 minutes ago.

Code:
find -cmin +2500  -cmin -2800

The snippet below finds files modified between 20 and 21 days ago.

Code:
find -ctime +20  -ctime -21

I, too, am a hopeless newbie, but those worked for me.

Tom
# 7  
Old 05-27-2009
#!/bin/ksh
#################################################
## File: findDateRange.sh
## Date: May 27, 2008
## Author: Saurav Sen
## Purpose: A script to find the files within
## a given date range
#################################################
echo "You have to provide the path, start date and the end date"
echo
echo "Enter the path to start search"
read fpath
echo "Please enter the start date in the format YYYYMMDD"
read strtdt
echo "please enter the end date in the format YYYYMMDD"
read enddt
touch -t ${strtdt}0000 /tmp/newerstart
touch -t ${enddt}2359 /tmp/newerend
#find ./ \( -newer /tmp/newerstart -a \! -newer /tmp/newerend \) -print
find $fpath \( -newer /tmp/newerstart -a \! -newer /tmp/newerend \) -exec ls -l {} \;
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search for Multiple strings in a given date range and print the Group if they exists

Hi, I am Searching for Multiple strings in a given date range and print the Group if they exists. the below is the format: ------------------------------------------------------------------------------------------------------------------------- ID: FIRST ID MESSAGE: Event Message... (5 Replies)
Discussion started by: linuxuser999
5 Replies

2. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

3. Red Hat

Find Files within date Range

Hi i am looking to expand a command i am using to find files in a large file system. i am currently using find /raid/JOBFLOW_LOCKED/ -type f -size +3G | -exec mv {} /raid/JOBFLOW_LOCKED/KILL \; This works really well but i would like to add a date range to the same command to refine it... (6 Replies)
Discussion started by: treds
6 Replies

4. UNIX for Dummies Questions & Answers

Deleted files between date range

Dear Friends, I have HP_ux 11.31 and want to delete some unwanted very old log files between two date range. Please help in the matter. Regards, Bhagawati Pandey (6 Replies)
Discussion started by: BPANDEY
6 Replies

5. UNIX for Dummies Questions & Answers

Help with removing files with date range

Hi, I want to remove trace files in a particular directory for a specific date range. Currently i can remove based on time (e.g find /path/*.trm -mtime +1000 -exec rm {} \;). But i want to remove .trm files within a date range. E.g to remove .trm files between jan 1 2002 to April 15 2005. ... (3 Replies)
Discussion started by: dollypee
3 Replies

6. Shell Programming and Scripting

Search on date range of file based on user input

Hello I would like to ask for help with a script to search a directory that contains many log files and based on a users input after being prompted, they enter a date range down to the hour which searches the files that contain that range. I dont know how to go about this. I am hoping that the... (5 Replies)
Discussion started by: lostincashe
5 Replies

7. Shell Programming and Scripting

Search for a specific data in a file based on a date range

Hi, Currently I am working on a script to automate the process of converting the log file from binary into text format. To achieve this, partly I am depending on my application’s utility for this conversion and the rest I am relying on shell commands to search for directory, locate the file and... (5 Replies)
Discussion started by: svajhala
5 Replies

8. UNIX for Dummies Questions & Answers

pattern search using grep in specific range of files

Hi, I am trying to do the following: grep -l <pattern> <files to be searched for> In <files to be searched for> , all files should of some specific date like "Apr 8" not all files in current directory. I just to search within files Apr 8 files so that it won't search in entire list of... (2 Replies)
Discussion started by: apjneeraj
2 Replies

9. UNIX for Dummies Questions & Answers

cp only files in certain date range

hi all, I'm trying to do a cp only on files I created on a given day or within a certain date range. What's the best way to do this? Cheers, KL (1 Reply)
Discussion started by: ee7klt
1 Replies

10. UNIX for Dummies Questions & Answers

Moving Files within a particular date range

Hi, Can someone please help me with this. Actually i want to move files from one directory to another directory , But I just want to move files of a specific data range. For ex: This is my directory which contains all fine. /home/Rooh Then there is a long listing of files. suppose this... (3 Replies)
Discussion started by: rooh
3 Replies
Login or Register to Ask a Question