non recursive search in the current directory only

Hi,

Am trying for a script which should delete more than 15 days older files in my current directory.Am using the below piece of code:

"find /tmp -type f -name "pattern" -mtime +15 -exec /usr/bin/ls -altr {} \;"
"find /tmp -type f -name "pattern" -mtime +15 -exec /usr/bin/rm -f {} \;"

But it is exploring sub directories too which i dont want have permission and dont want it to happen too.I just want to find and delete the files in the current directory alone.

Could any one of you please help me....
waiting for help!!

Thanks in advance...

You can add the "-prune" switch which will not have descent the search to subdirectories.

Thanks for the reply..
could you please give me the complete syntax for my requirement...

can anyone pls helpme out in this..non recursive search in the current directory only
problem descrobed above..

Thanks

Do a

man find

and you will get your answer. You can also check the maxdepth option.

Thanks..

Sorry max depth option is not avilable for me...I have gone thru man pages..but i could not find any way can u pls be more explanatory...


find . -path '/directory/not/to/include' -prune -o -name "*" | xargs grep "pattern"

if you have many directories to exclude you can do something like this..

find . \( -path "/dir/to/exclude" -prune -o -path "/dir/to/exclude/" \) -name "*" | xargs grep "pattern"

Thanks
Namish

Hi Namith,Thanks for ur suggestion...but am getting errors if i execute the code
find . \( -path "/tmp/dir1" -prune -o -path "/tmp/dir2" \) -name "*pattern" | xargs grep "pattern".

Can u pls explain me the usage of xargs and wat for grep pattern agian!!

Thanks in advance:confused:

dont use xargs here, i just gave an example.
remove the part after the "|" symbol and use the mtime in place of that like you were using. That should work...

hello puppala,

your command:
"find /tmp -type f -name "pattern" -mtime +15 -exec /usr/bin/rm -f {} \;"

the equivalent find command without recursive subdir search is:
"find /tmp -path "/tmp/*" -prune -type f -name "pattern" -mtime +15 -exec /usr/bin/rm -f {} \;"

however, xargs is recommended instead of -exec (reason: if you have a big amount of files found -exec will fail), so, try this:

"find /tmp -path "/tmp/*" -prune -type f -name "pattern" -mtime +15 | xargs -i -t /usr/bin/rm -f {}"