find command to look for current directory only


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers find command to look for current directory only
# 1  
Old 05-10-2011
find command to look for current directory only

i have this find command on my script as:
Code:
for i in `find $vdir -name "$vfile" -mtime +$pday`

the problem with this code is that the sub-directories are included on the search. how do i restrict the search to confine only on the current directory and ignore the sub-directories. please advise. thank you.

the variables $vdir, $vfile, and $pday are derived from parameters.

i am using IBM AIX version 5.

Last edited by wtolentino; 05-10-2011 at 02:13 PM..
# 2  
Old 05-10-2011
Use the . (DOT) operator. this might solve the issue. Use this after the find keyword.
# 3  
Old 05-11-2011
Hi,

check the man-page if your find supports the maxdepth option.
Code:
for i in `find $vdir -maxdepth 1 -name "$vfile" -mtime +$pday`

# 4  
Old 05-11-2011
i tried the . operator but it still includes the sub-directory.
# 5  
Old 05-11-2011
Code:
 
for i in `find $vdir -name "$vfile" -mtime +$pday | grep -v "/"`

---------- Post updated at 07:33 AM ---------- Previous update was at 07:32 AM ----------

sorry the correct one:
Code:
for i in `find $vdir -name "$vfile" -mtime +$pday | grep -v "[^.]/"`

# 6  
Old 05-11-2011
i check the man-page for the find and it does not support the maxdepth option.

---------- Post updated at 08:45 AM ---------- Previous update was at 08:41 AM ----------

i also tried the
Code:
for i in `find $vdir -name "$vfile" -mtime +$pday | grep -v "[^.]/"`

and it still includes the sub-directories
# 7  
Old 05-11-2011
Code:
cd $vidr
find . ! -name . -prune -type f -name "$vfile" -mtime +$pday

This User Gave Thanks to Peasant For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. Shell Programming and Scripting

Find files only in current directory...not subdirectories

Hi, I have to find files only in the current directory...not in the sub directories. But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help..I tried to use maxdepth..but it is not working in AIX. (2 Replies)
Discussion started by: vsachan
2 Replies

4. Shell Programming and Scripting

How to find particular string in multiple files with in the current directory.

Hello friends, Plz suggest the find command, How to search a string in a paticular string in miltiple files with current dirctory.:) Thanks in advance. Siva Ranganath Ch (2 Replies)
Discussion started by: sivaranga001
2 Replies

5. Shell Programming and Scripting

Find files ONLY in current directory

Hello all, I am having a hard type in figuring out how to only gather certain files in the current directory without exploring its subdirectories. I tried: find . -name "*.ksh" -prune this also returns ksh files from lower subdirectories. I also tried find . -ls -name "*.ksh" This also... (8 Replies)
Discussion started by: gio001
8 Replies

6. UNIX for Dummies Questions & Answers

How to find the list of 5 largest file in current directory?

Hello, How to find the list of 5 largest(size wise) file in current directory?i tried using ls -l | sort -t " " -r +5 -6 -n | head -5 but this is not giving correct output as ls -l command gives 1 extra line of output that is how many total files are there!so by running the above... (4 Replies)
Discussion started by: salman4u
4 Replies

7. UNIX for Dummies Questions & Answers

how to stop to current directory using find

Hello, I just want to ask the following use of find command: 1. how can I find files only to the current directory? 2. how can I find files to directories and all subdiretories (are this include soft links?) but will not go to other mountpoints that is under that mountpoint. Im combining... (1 Reply)
Discussion started by: james_falco
1 Replies

8. Shell Programming and Scripting

how do i exclude the current directory when using find?

i want to compile a list of files in all sub directories but exclude the current directory. the closest i could get was to search 'only' the current directory, which is the opposite of what i wanted. find . ! -name . -prune (7 Replies)
Discussion started by: mjays
7 Replies

9. UNIX for Dummies Questions & Answers

find directory not including current

Using Solaris 8, I've forgotten how to exclude the current directory in the find results. find . -type d ! -name "*.CAP" I want every directory that does not match the *.CAP pattern, except the current directory. (2 Replies)
Discussion started by: dangral
2 Replies

10. UNIX for Dummies Questions & Answers

using find command only in current directory

I am trying to use the find command to find files in the current directory that meet a certain date criteria. find . -type -f -mtime +2 However, the above also checks the directories below. I tried -prune, but that seems to ignore this directory completely. I read about using -path w/... (5 Replies)
Discussion started by: jliebling
5 Replies
Login or Register to Ask a Question