The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find command with prune help venu_nbk UNIX for Dummies Questions & Answers 2 05-28-2007 03:25 AM
Find command with prune and exec options Sebarry UNIX for Dummies Questions & Answers 2 06-19-2006 01:07 AM
Find command with prune and exec Sebarry UNIX for Advanced & Expert Users 1 06-18-2006 10:43 AM
Use -prune with find command on AIX FuzzySlippers UNIX for Dummies Questions & Answers 5 11-08-2002 05:24 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-22-2008
Registered User
 

Join Date: Dec 2005
Posts: 12
Stumble this Post!
Find command uisng -prune or -only

I've run into a brick wall using the -prune command to avoid walking sub-directories. Does any one have any suggestions on how I avoid walking the sub-directories when finding files in the following example?

I want to find all files older than 30 days in the dir1 directory and only the dir1 directory.

Directory structure looks something like this, for example :
/dir1/dir2/dir3.....

Here's the find command that I'm using right now:

find /dir1 -prune -o -name '*' -mtime +30 -print > filelist.lst

However, I keep getting output for files located in the dir2 and dir3 directories as well. Any thoughts on how to keep this find command from walking the sub-directories?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-22-2008
Registered User
 

Join Date: Oct 2002
Posts: 670
Stumble this Post!
This has been answered many times. Here you go.

Performing a non-recursive find in Unix
Reply With Quote
  #3 (permalink)  
Old 02-22-2008
Registered User
 

Join Date: Dec 2005
Posts: 12
Stumble this Post!
Tried that already

i did see that solution but it does not work in my case. Here's what I had using that solution :

find /dir1 \( ! -name /dir1 -prune \) -name '*' -mtime +30 -print > filelist.lst

However, when I check the filelist.lst file it is empty and shouldn't be because there are files in /dir1 that are older than 30 days.
Reply With Quote
  #4 (permalink)  
Old 02-22-2008
Registered User
 

Join Date: Oct 2002
Posts: 670
Stumble this Post!
It seems to work for me on Solaris.

Code:
bash-3.00# pwd
/dir1
bash-3.00# ls -l
total 4
drwxr-xr-x   2 root     root         512 Feb 22 13:08 dir2/
-rw-r--r--   1 root     root           6 Jan  1 00:00 file1
bash-3.00# ls -l dir2/
total 0
-rw-r--r--   1 root     root           0 Jan  1 00:00 file2
bash-3.00# find . \( ! -name . -prune \) -mtime +30
./file1
Reply With Quote
  #5 (permalink)  
Old 02-22-2008
Registered User
 

Join Date: Dec 2005
Posts: 12
Stumble this Post!
Try adding the -name '*' after the -prune portion of the command and see if you get any different results.
Reply With Quote
  #6 (permalink)  
Old 02-22-2008
Registered User
 

Join Date: Oct 2002
Posts: 670
Stumble this Post!
It's still working. But why are you passing that name parameter if your looking for a wildcard anyway? find will do that by default.

Code:
bash-3.00# find . \( ! -name . -prune \) -name '*' -mtime +30
./file1
Reply With Quote
  #7 (permalink)  
Old 02-22-2008
Registered User
 

Join Date: Dec 2005
Posts: 12
Stumble this Post!
That's wierd because it won't work on HP-UX 11i. The -name '*' would be a passin value from user input. It could be '*' or '*TEST' or any other wildcarded search parameter. They can also input whether or not they want to search sub-directories for the input filename(s). I'm setting a flag for the sub-directory search to determine the appropriate find command structure to use based on their inputs. So, if they want to search sub-directories of the initial search path there is no issue because I don't need to use the -prune. However, if they don't want to search sub-directories underneath the initial search path AND they enter an '*" for the filename(s) to search for I run into this issue.

Based on your results this may well be a HP-UX issue. Although I'm not positive of that at this point.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mtime, solaris

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0