The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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 06:25 AM
Find command with prune and exec options Sebarry UNIX for Dummies Questions & Answers 2 06-19-2006 04:07 AM
Find command with prune and exec Sebarry UNIX for Advanced & Expert Users 1 06-18-2006 01:43 PM
Use -prune with find command on AIX FuzzySlippers UNIX for Dummies Questions & Answers 5 11-08-2002 09:24 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-22-2008
2reperry 2reperry is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 15
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?
  #2 (permalink)  
Old 02-22-2008
dangral dangral is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2002
Posts: 699
This has been answered many times. Here you go.

Performing a non-recursive find in Unix
  #3 (permalink)  
Old 02-22-2008
2reperry 2reperry is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 15
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.
  #4 (permalink)  
Old 02-22-2008
dangral dangral is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2002
Posts: 699
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
  #5 (permalink)  
Old 02-22-2008
2reperry 2reperry is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 15
Try adding the -name '*' after the -prune portion of the command and see if you get any different results.
  #6 (permalink)  
Old 02-22-2008
dangral dangral is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2002
Posts: 699
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
  #7 (permalink)  
Old 02-22-2008
2reperry 2reperry is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 15
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.
Sponsored Links
Closed Thread

Bookmarks

Tags
mtime, solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0