The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help Help Help in recursion murtaza Shell Programming and Scripting 6 03-29-2007 10:26 AM
allow recursion on dns server? xnightcrawl UNIX for Advanced & Expert Users 1 03-29-2006 10:36 AM
recursion too deep swamy455 Shell Programming and Scripting 3 07-18-2005 03:18 PM
recursion gsjf Shell Programming and Scripting 1 08-26-2002 12:22 AM
remove files Nisha Shell Programming and Scripting 7 06-26-2002 12:04 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-27-2008
nir_s nir_s is offline
Registered User
  
 

Join Date: Jun 2004
Posts: 148
How to remove old files without recursion?

Hi folks,

I need to write a script which remove files with suffix *.dmp from a specific directory ,older than 30 days and not including recursive subdirectories.

I.e:
The following command remove recursive all *.dmp files older than 30 days:
Code:
find $ORACLE_BASE -mtime +30 -type f -name "*.dmp" -exec rm {} \;
I need to remove files older than 30 days but only under $ORACLE_BASE without its subdirectories.

How to do it?

Thanks in advance,
Nir
  #2 (permalink)  
Old 04-27-2008
ripat ripat is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 438
Hi,

Use -maxdepth 1 option for the find command.
  #3 (permalink)  
Old 04-27-2008
nir_s nir_s is offline
Registered User
  
 

Join Date: Jun 2004
Posts: 148
Hi,

I didn't find such an option in "find" command..
Can you post an example?

Thanks in advance,
Nir
  #4 (permalink)  
Old 04-27-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
If your find doesn't have that option, an example will hardly help?

Code:
find $ORACLE_BASE -maxdepth 1 -mtime +30 -type f -name "*.dmp" -exec rm {} \;
You can filter the output from find to exclude anything with at least two slashes in it, though:

Code:
find $ORACLE_BASE -mtime +30 -type f -name "*.dmp" -print |
grep -v '/.*/' | xargs -r rm
You might want to try it with "xargs echo rm" for testing.

The number of slashes obviously depends on the number of slashes in $ORACLE_BASE -- two would be correct for the current directory. (ORACLE_BASE=.)
  #5 (permalink)  
Old 04-27-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Or this might help you:

find command
  #6 (permalink)  
Old 04-27-2008
nir_s nir_s is offline
Registered User
  
 

Join Date: Jun 2004
Posts: 148
Thanks guys!

Finally, I used "find . \( ! -name . -prune \)" and it works perfect!

Best regards,
Nir
Closed Thread

Bookmarks

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On




All times are GMT -4. The time now is 10:52 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0