searching a file by date...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers searching a file by date...
# 1  
Old 02-06-2008
searching a file by date...

It's possible to use "find" to search a file that was modified for example between 5/10/2004 and 7/11/2005? How can i do this? I saw there is option -mtime, but i don't understand how to use it in this case. Thanks
# 2  
Old 02-06-2008
Quote:
Originally Posted by Kaminski
It's possible to use "find" to search a file that was modified for example between 5/10/2004 and 7/11/2005? How can i do this? I saw there is option -mtime, but i don't understand how to use it in this case. Thanks
You can ...

-atime The time the file was last accessed
-ctime The time the file's status last changed
-mtime The time the file was last modified
-newer Newer than ...

touch -t 200410060000 /tmp/newerstart
touch -t 200511070000 /tmp/newerend
find . \( -newer /tmp/newerstart -a \! -newer /tmp/newerend \) -print



Unix Review > John & Ed's Miscellaneous find Tips
UNIX tips: Productivity tips
# 3  
Old 02-06-2008
Java

Quote:
Originally Posted by Kaminski
It's possible to use "find" to search a file that was modified for example between 5/10/2004 and 7/11/2005? How can i do this? I saw there is option -mtime, but i don't understand how to use it in this case. Thanks
Code:
find /dir -type f -mtime +<days since 7/11/2005> -mtime -<days since 5/10/2004>

In other words:
-mtime -<days> looks for files newer than <days> old
-mtime +<days> looks for file older than <days> old
# 4  
Old 02-07-2008
the problem is that i need it for a script; it should be something like this:

#!/bin/bash
clear
read date #mm/dd/YYYY
find -option $date

it's possible to do this kind of things?
# 5  
Old 02-07-2008
Change the date to a format touch can use, then add one day, and subtract one day
Code:
touch ./old -t   200801100000                # jan 10 2008 at one second after midnight
touch ./new -t  20080102359                 # jan 10 2008 23 hours 59
find /path/to/files \( -newer ./old -a ! -newer ./new\) -print

find can use the newer command to get an exact date. Change the time values to get what you want.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Searching for a files based on current date directory

Hi All, I've been trying to do some recursive searching but not been very successful. Can someone please help. Scenario: I have directory structure /dir1/dir2/dir3/ 2019/ 11/ 17 18 19 20 so what I want to do is run a script and as its 2019/11/18/ today it would go and only search... (3 Replies)
Discussion started by: israr75
3 Replies

2. Shell Programming and Scripting

Searching a file inside a .tar.gz file by date

Hi, I would like to ask if there is a way to search for a file inside a .tar.gz file without extracting it? If there is, is there a way to search for that file by date? Thanks! (4 Replies)
Discussion started by: erin00
4 Replies

3. Shell Programming and Scripting

Searching for unknown date inside the file and replace to new date

Hello, Iam a newbies to Shell scripting. Iam trying to replace the date inside the file to new date. is there anyway that we can just use the pattern to search as "..." I have many files want to replace with the same date, and each file contains different date. Thanks for your help. ... (2 Replies)
Discussion started by: Daro
2 Replies

4. Shell Programming and Scripting

perl : searching for month and storing the date and time in an array

I am writing the code in perl. I have an array in perl and each variable in the array contains the data in the below format Now I need to check the below variable w.r.t system month I need to store the date and time(Tue Aug 7 03:54:12 2012) from the below data into file if contains only 'Aug'... (5 Replies)
Discussion started by: giridhar276
5 Replies

5. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

6. UNIX for Dummies Questions & Answers

Searching by date range from filenames

Hello all, i have tons of files in folder named like this (yyyymmdd): bookcollection20100729 bookcollection20100730 bookcollection20100731 bookcollection20100801 bookcollection20100802 etc. I need to find files with date range in there names lets say from 2010.07.30 - 2010.08.02 ... (10 Replies)
Discussion started by: Whit3H0rse
10 Replies

7. UNIX for Dummies Questions & Answers

Searching the date pattern in a file

Hi, I would like to search the pattern based on the date like "2010/08/15". I tried using / in the file giving /<<pattern>>. when i tried this it turns to /2010/+8, but not going to the pattern what ever i want. This is how the data in the file. INFO | jvm 1 | 2010/05/26 13:30:33... (5 Replies)
Discussion started by: venkatesht
5 Replies

8. Shell Programming and Scripting

Issue searching for Date

I have an issue regarding searching for old dates. At the moment I search a field within a file for the last 3 days from the system date: using today as 25/02/2010 DD=$(expr `date +%d` - 1) DD1=$(expr `date +%d` - 2) DD2=$(expr `date +%d` - 3) MTH=`date +"%m"` YR=`date +"%Y"`... (2 Replies)
Discussion started by: Pablo_beezo
2 Replies

9. Shell Programming and Scripting

searching a date and replacing with another date

I have a text file that i want to search through and pick out any dates that are formatted like MM/DD/YYYY and replace them with a date i want like 10/29/2009. any idea show i would do this?:) Snapshot of my text file: test4>s44syd5172>070>528>ENU>nongnuan>wanrawee>sr2330532>... (7 Replies)
Discussion started by: infiant
7 Replies

10. Shell Programming and Scripting

Shell Script for searching files with date as filter

Hi , Assume today's date is 10-May-2002. I want to get a list of files which were last modified since 01-May-2002. If I run the script after 5 days, it should still list me the files modified from 01-May-2002 till today. I also plan to pass the date 01-May-2002 as an argument to the shell script... (3 Replies)
Discussion started by: kanakaraj_s
3 Replies
Login or Register to Ask a Question