How to remove old files without recursion?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove old files without recursion?
# 1  
Old 04-27-2008
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  
Old 04-27-2008
Hi,

Use -maxdepth 1 option for the find command.
# 3  
Old 04-27-2008
Hi,

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

Thanks in advance,
Nir
# 4  
Old 04-27-2008
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  
Old 04-27-2008
# 6  
Old 04-27-2008
Thanks guys!

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

Best regards,
Nir
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Recursion list for rm -R in find

In the following command: find / -ctime +3 -exec rm -R {}\; how is the recursion list built for the actual rm ? F'rinstance; I had a case where a user typed this as root using '/' instead of '.' so everything in the root level was going to be traversed. They hit <ctrl>C before too much was... (5 Replies)
Discussion started by: port43
5 Replies

2. Shell Programming and Scripting

script recursion

Can someone please explain me why the following script calls it self recursively: #!/bin/bash echo Called $0 while this not: #!/bin/bash echo Called $($0) Thanks (6 Replies)
Discussion started by: superpointer
6 Replies

3. Programming

C Recursion (explain)

Hi, Question: how come the output is like that? Can explain to me abit. I am learning C. Thanks! #include <stdio.h> #include <string.h> void printit(char line_of_char, int index); int main() { char line_of_char; int index = -1; strcpy(line_of_char, "This is a string."); ... (5 Replies)
Discussion started by: seede
5 Replies

4. Shell Programming and Scripting

recursion script problem

Hi Guys,, I tried to create a recursive function in unix. The following is the code. #/bin/sh function(){ n=$1; if ; then out=1; echo "inside if for 0"; else out = `$n * function "$n-1"`; echo "inside if for $n-1; fi (3 Replies)
Discussion started by: mac4rfree
3 Replies

5. Programming

Recursion

I want to halt a tail recursive function after certain validation. I want to come out of entire recursion without unwinding phase. How can i achieve that . The coding is done in C language. (5 Replies)
Discussion started by: joshighanshyam
5 Replies

6. Shell Programming and Scripting

diffrence in non recusion and recursion

Hi, If i have given to write a prog for factorial in C using recursion and without recursion which one is better in what condition and why ? thanks (2 Replies)
Discussion started by: useless79
2 Replies

7. Shell Programming and Scripting

Help Help Help in recursion

Hello every body. I am trying to find the factorial using the following code. But it is giving the syntax error. I tried very much but in vain. Thanks in advance for helping me factorial() { if then y=`expr $1 - 1` x=$(( $1 \* factorial $y ))... (6 Replies)
Discussion started by: murtaza
6 Replies

8. Shell Programming and Scripting

A Question On Recursion In Ksh

Hi Folks, I would just like to know how recursion works in ksh or inside a shell in general. I created the following script, but it works(runs recursively) only for 64 times: ---------------- #! /usr/bin/ksh displaymessage() { echo "displaying count: $cnt " echo "wait for 1 second..."... (1 Reply)
Discussion started by: marlonus999
1 Replies

9. Shell Programming and Scripting

recursion too deep

I am running a korn shell script which has a recursive function. The script ran for 117 iterations and ended up with the following error "recursion too deep". what should be done to avert this? Thanks in advance Swamy p.s. I am on UNIX MPRAS V4 (3 Replies)
Discussion started by: swamy455
3 Replies

10. Shell Programming and Scripting

recursion

I'm using the UNIX csh and i wish to use recursion to nav my way up (or down as it is) a given folder. My little test script is called "r" and takes a folder as argv (or $1) #!/bin/tcsh -f set allFiles = `ls -A $argv` cd $argv while ($#allFiles) if (-d... (1 Reply)
Discussion started by: gsjf
1 Replies
Login or Register to Ask a Question