Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-31-2003
Registered User
 

Join Date: Oct 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Searching for files over 30 days old in current directory

May be a simple question for experts here....


I need to get the list of files older than 30 days in the current folder. I tried "find", but it searches recursively in all the sub directories.

Can I restrict the recursive search and extract the files only from current directory ?
Sponsored Links
  #2  
Old 10-31-2003
Registered User
 

Join Date: Oct 2003
Location: mumbai,india
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
to find file in DIR
use
find $DIR -type f -atime +30 -print
hope it will suffice
  #3  
Old 10-31-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Thanks: 0
Thanked 1 Time in 1 Post
See if this works:

find . -mtime +30 \( ! -name . -prune \)
  #4  
Old 10-31-2003
Registered User
 

Join Date: Oct 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Both the above scripts are digging down the sub directories. Any other altrenative ?
  #5  
Old 10-31-2003
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,472
Thanks: 0
Thanked 3 Times in 3 Posts
Try....
Code:
find $PWD -type f -mtime +30 -print|grep -Ev "$PWD/.*/"

  #6  
Old 10-31-2003
Registered User
 

Join Date: Oct 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks a lot Ygor, this one is working.

Again thanks everybody.
  #7  
Old 10-31-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Thanks: 0
Thanked 1 Time in 1 Post
Hmm... the -prune option is supposed to be what prevents going into subdirectories! At least, it works on ksh... what shell are you using? Ygor had a great work-around idea, but I'd think it would be faster if there's a ton of subdirectories to use -prune, rather than grabbing all the files in all the subdirectories, then eliminating everything except the current directory.
Sponsored Links
Closed Thread

Bookmarks

Tags
mtime, regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
searching content of files in the current and sub directories tiger99 Shell Programming and Scripting 4 01-23-2008 02:11 AM
searching files through all subdirectories beneath the current directory milagros Shell Programming and Scripting 5 05-15-2007 04:00 PM
ls latest 4 days or specify days of files in the directory happyv Shell Programming and Scripting 3 01-22-2007 06:16 AM
How to zip a modified file 15 days before but not scanning my sub directory files skrish70 Shell Programming and Scripting 1 10-10-2005 03:41 PM
Removing files automatically from a directory after 30 days. justinb_155 Shell Programming and Scripting 7 06-24-2005 02:07 PM



All times are GMT -4. The time now is 07:36 AM.