Find all files before a certain date


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find all files before a certain date
# 1  
Old 05-29-2012
Find all files before a certain date

Hi all,

I am a beginner and I was hoping you can help me out.

I am doing some PDF cleanup and I am looking for a command to search for all PDFs in a certain folder that are older than 2008 for example.

This is what I have so far:

Code:
find ./ -mtime +500 -name '*.pdf' >/test/results.txt

Would the above do it? obviously I would need to change the 500 to the correct number. Is there a way to specify the 2008 in the command?

Thanks,
Zig

Last edited by joeyg; 05-29-2012 at 03:25 PM.. Reason: Wrap commands in CodeTags
# 2  
Old 05-29-2012
Try this:
Code:
touch -m -d "2008-01-01 00:00:01" /tmp/file
find ./ \( ! -newer /tmp/file \) -name "*.pdf" >/test/results.txt

# 3  
Old 05-29-2012
Thanks Xor

I am trying to clean up old/orphaned pdf files. I was wondering, is there a way I can run a grep while the find is running to search if each returned file name is linked from an HTML page?

I think I know how to do them individually but not sure how to do both at the same time.

Code:
find ./ -mtime +1460 -name '*.pdf'

find ./ -name '*.html' -exec grep -l 'filename' | grep :0$ {} \; 2>/dev/null 1>/test/results.txt

Thanks,
Zig

Last edited by methyl; 05-29-2012 at 08:28 PM.. Reason: Please use code tags.
# 4  
Old 05-29-2012
Please post what Operating System and version you are running and what Shell you use. There is some variation in the unix "touch" command and there is a lot of variation in the "find" command.
# 5  
Old 05-30-2012
You might want to read this thread with a short explanation about how to combine various clauses of find. The thread deals with exactly your problem, btw..

I hope this helps.

bakunin
# 6  
Old 05-30-2012
Quote:
Originally Posted by methyl
Please post what Operating System and version you are running and what Shell you use. There is some variation in the unix "touch" command and there is a lot of variation in the "find" command.
methyl, This is the box I am using:

SunOS 5.10 Generic_144488-11 sun4u sparc SUNW,Sun-Fire-V440

Shell: -ksh

Thanks for the link bakunin
# 7  
Old 05-30-2012
Quote:
Originally Posted by SyphaX
Code:
find ./ -mtime +1460 -name '*.pdf'

find ./ -name '*.html' -exec grep -l 'filename' | grep :0$ {} \; 2>/dev/null 1>/test/results.txt

On second thoughts you can write the output of the first "find" to an intermediate file and then use "grep -f" to read the patterns you search for from this file. Have a look at the man page of "grep" and look for the "-f" option, which is required by POSIX, so it should be there.

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. Shell Programming and Scripting

Find files for a specific date

Hi, I am looking to find files of a specific date. I am on Sun Solaris so newermt doesnot work.. I thought of using mtime but not getting how to use it. Please help me with this.. Regards Abhinav (3 Replies)
Discussion started by: abhi1988sri
3 Replies

5. Shell Programming and Scripting

Find files with specific date

Dear all, kindly i have some files with different dates i need to grep word from these files but i need to search in files with date 2012-12-02 not all files in this directory do u have any command (4 Replies)
Discussion started by: maxim42
4 Replies

6. Shell Programming and Scripting

Find older files than specified date

Hi, I need to find out list of files which are older than specific date. I am using 'find, and newer' commands but its not giving the correct result. Can you please help to findout the list of files. thanks (2 Replies)
Discussion started by: Satyak
2 Replies

7. UNIX for Dummies Questions & Answers

Find last modified date for many files

Hello all - I've looked and have not been able to find a "find" command that will list the last modified date of files within a specific directory and its subdirectories. If anyone knows of such a command it would be very much appreciated! If possible, I would like to sort this output and have... (5 Replies)
Discussion started by: MichaelH3947
5 Replies

8. Shell Programming and Scripting

Can I know find syntax to find given date files

Hi All, Can i use find command to know given date files? If yes, then please let me know the syntax for the same. Thanks in advance for your postive responses Regards, Bachegowda (3 Replies)
Discussion started by: bache_gowda
3 Replies

9. Shell Programming and Scripting

find files by date

************************************************** Purpose : find files by date Condition: olther than | newer than | between _date1 _date2 Date format: 2007/10/28 ************************************************** Please help me Thanks (1 Reply)
Discussion started by: kani
1 Replies

10. UNIX for Advanced & Expert Users

Find all the files after the date?

Hi I am using #!/bin/sh DATE="$1" FILE="$2" FLIST="" for f in $FILE do FDATE=$(ls -l $f | awk '{ print $6 }') if ;then FLIST="$FLIST $f" fi done && echo $FLIST || echo "Sorry no files found to match $DATE date." the below... need correction whne i execute the above (1 Reply)
Discussion started by: gkrishnag
1 Replies
Login or Register to Ask a Question