non recursive search in the current directory only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting non recursive search in the current directory only
# 1  
Old 07-25-2008
MySQL 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...
# 2  
Old 07-25-2008
You can add the "-prune" switch which will not have descent the search to subdirectories.
# 3  
Old 07-25-2008
Thanks for the reply..
could you please give me the complete syntax for my requirement...
# 4  
Old 07-28-2008
can anyone pls helpme out in this..non recursive search in the current directory only
problem descrobed above..

Thanks
# 5  
Old 07-28-2008
Do a
Code:
man find

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

Thanks..
# 6  
Old 07-28-2008
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...
# 7  
Old 07-28-2008
Quote:
Originally Posted by puppala
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...
Code:
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..
Code:
find . \( -path "/dir/to/exclude" -prune -o -path "/dir/to/exclude/" \) -name "*" | xargs grep "pattern"

Thanks
Namish

Last edited by namishtiwari; 07-28-2008 at 04:18 AM.. Reason: added for multiple dir
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Search recursive

before posting, I have tried to find my answer elsewhere. no luck. I need to find a file buried in a folder somewhere. Master folder has 10 sub folders. each sub folder has folders too. I found this but it does nothing I am on Mac and use Applescript. do shell script "find... (2 Replies)
Discussion started by: sbrady
2 Replies

2. Shell Programming and Scripting

How to restrict Find only search the current directory?

hello, all I have googled internet, read the man page of Find, searched this forum, but still could not figure out how. My current directory is: little@wenwen:~$ pwd /home/little little@wenwen:~$ I want to use find command to list the files in my current directory, how should i write... (3 Replies)
Discussion started by: littlewenwen
3 Replies

3. UNIX for Dummies Questions & Answers

Restricting a Find search to the current directory only

Hi All, I am trying to delete file (with a mtime older than 2 days) from the current directory ONLY using: find . -daystart -maxdepth 1 -mtime 2 -exec rm {} \; but this doesn't seem to work it is still find files in subdirectories which I don't want to delete. Please can anyone offer... (2 Replies)
Discussion started by: daveu7
2 Replies

4. Homework & Coursework Questions

C Program to search and read all named pipes in current directory

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a C program to search the current directory for all pipes. 1. It will print the pipe... (2 Replies)
Discussion started by: natwickley
2 Replies

5. UNIX for Advanced & Expert Users

Recursive directory search using ls instead of find

I was working on a shell script and found that the find command took too long, especially when I had to execute it multiple times. After some thought and research I came up with two functions. fileScan() filescan will cd into a directory and perform any operations you would like from within... (8 Replies)
Discussion started by: newreverie
8 Replies

6. UNIX for Dummies Questions & Answers

Zip recursive content of folder when (not current directory=

Hi, Is there a way to zip the content (recursively) of a folder other then the current directory, and keep the directory structure intact? Example: /var/tmp/myfolder ----------------- file1 ----------------- file2 ----------------- folder1 ------------------------ file3 Now I want... (3 Replies)
Discussion started by: jimih
3 Replies

7. Shell Programming and Scripting

Finding files in current directory when 100,000's files in current directory

Hi All I was wondering what is the most efficient way to find files in the current directory(that may contain 100,000's files), that meets a certain specified file type and of a certain age. I have experimented with the find command in unix but it also searches all sub directories. I have... (2 Replies)
Discussion started by: kewong007
2 Replies

8. Shell Programming and Scripting

Recursive call to find files and directories in Shell script from current path.

################################################################ Copy this script to your path from where you want to search for all the files and directories in subdirectories recursively. ################################################################# code starts here... (2 Replies)
Discussion started by: Ramit_Gupta
2 Replies

9. UNIX for Dummies Questions & Answers

Restrict my search to current directory.

Hi every1, There is a folder with .lst files which has email id's of our project group. I want to find files which has my email id starting with sachin but i dont want find command to search subdirectories. I have read about prune but i didnt understand that. I am pretty new in this field.... (7 Replies)
Discussion started by: sachin.gangadha
7 Replies

10. UNIX for Dummies Questions & Answers

Question about Restricting Search path of FIND to current directory

Hi, By default FIND command searches for matching files in all the subdirectories within the specified path. Is there a way to restrict FIND command's search path to only the specified directory and NOT TO scan its subdirectories. Any help would be more than appreciated. Thanks and Regards (2 Replies)
Discussion started by: super_duper_guy
2 Replies
Login or Register to Ask a Question