find command to filter specific type of files older than certain date.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find command to filter specific type of files older than certain date.
# 1  
Old 05-08-2012
find command to filter specific type of files older than certain date.

Hi

I need to find the list of files in a directory and to do some specific operations based on the type of files.

suppose in a directory am having .dat , .log, .err, .rej file types. i need to filter out .dat and .log only which are older than six months.

i used the below query but the o/p is not as expected.. Can anyone correct me where am wrong..?

Code:
find . -name '*.err' -o -name '*.log'  -print -mtime +180 -print

Moderator's Comments:
Mod Comment Use code tags, see PM, thanks.


---------- Post updated at 02:58 PM ---------- Previous update was at 02:48 PM ----------

the below command has worked

Code:
find . -name '*.err' -o -name '*.log' -type f


Last edited by zaxxon; 05-08-2012 at 06:31 AM.. Reason: code tags
# 2  
Old 05-08-2012
Quote:
Originally Posted by msathees
Hi

I need to find the list of files in a directory and to do some specific operations based on the type of files.

suppose in a directory am having .dat , .log, .err, .rej file types. i need to filter out .dat and .log only which are older than six months.

i used the below query but the o/p is not as expected.. Can anyone correct me where am wrong..?

Code:
find . -name '*.err' -o -name '*.log'  -print -mtime +180 -print

Moderator's Comments:
Mod Comment Use code tags, see PM, thanks.


---------- Post updated at 02:58 PM ---------- Previous update was at 02:48 PM ----------

the below command has worked

find . -name '*.err' -o -name '*.log' -type f
remove the "print(s)" expres and try again
# 3  
Old 05-08-2012
Please post what Operating System and version you are running. There is much variation in the "find" command.


In unix and some versions of Linux, the "or" condition needs protected brackets. Also, you have two "-print" parameters on the line. To prevent accidental matches with non-files specify "-type f".

Code:
find . -type f \( -name '*.err' -o -name '*.log' \)  -mtime +180 -print

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to find files older than 1 hour

Hi, Out of a list of files in a directory, I want to find the files which were created/modified more than 1 hour ago. I am using HP -UNIX and it does not support the argument -mmin. Please advise. I am using # !/bin/sh (4 Replies)
Discussion started by: jhilmil
4 Replies

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

3. Shell Programming and Scripting

Find command to search and delete files older than 1 days at a desired location

Hello All, Can someone please help me out in creating the find command to search and delete files older than 1 days at a desired location. Thanks in advance for your help. (3 Replies)
Discussion started by: Pandee
3 Replies

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

5. Shell Programming and Scripting

Finding older files using find command

Hi All, I want to find files which are older than 15 days. I have written a command as below, find -mtime +15 -print I understand (System date - last modified time of a file) should be greater than or equal to 15 days. This command returns files which are 15 days old.. i.e... (1 Reply)
Discussion started by: nshan
1 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 Advanced & Expert Users

Deleting older files of a particular type

hi This should be easy but i'm obviously missing something obvious. :) I'm looking to delete files from yesterday and older of extension .txt and there a range of subfolders with these files in them. The command runs but doesn't delete anything. SUSE 10. find /testfolder -maxdepth 2 -type f... (6 Replies)
Discussion started by: cmap
6 Replies

8. UNIX for Dummies Questions & Answers

Help in Find command filter test files

Hi, I want to get all the files under a directory with find command and filter the filenames with "test" . Could you please hep me how can I build this commad Operating System : Solaris 8 (4 Replies)
Discussion started by: TonySolarisAdmi
4 Replies

9. AIX

find files with specific date and time

Hi, I wanna to find files with specific date and time. I know this command: ls -ltr /system1/*.505 | grep 'Jan 18 09:00'. I want the 'Jan 18 09:00' not hard coded, I want it coming from the system date and time. And I want the time varies from 09:00-09:05. Is this possible without heavy... (3 Replies)
Discussion started by: itik
3 Replies

10. Shell Programming and Scripting

unix command/s to find files older than 2 hours in a directory

I need to write a script to find files older than 2 hours in set of direcotries and list them ina mail. I know find command ti list files greater/lesser than days but i need to do it for hours. Any input. (6 Replies)
Discussion started by: Presanna
6 Replies
Login or Register to Ask a Question