Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-11-2008
Registered User
 
Join Date: Jul 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Find but exclude directories

Hello,

I have a line in my script to find the files changed in the last 24 hours. It is as below:

find /home/hary -type f -mtime -1

I now want to exclude a directory named "/home/hary/temp/cache" from the above find command. How do I add it to my script?

Any help is appreciated.

Thanks,
Hary
Sponsored Links
    #2  
Old 09-11-2008
...@...
 
Join Date: Feb 2004
Location: NM
Posts: 9,660
Thanks: 165
Thanked 647 Times in 624 Posts
add this:

Code:
   ! -name '/hary/temp/cache/*'

Sponsored Links
    #3  
Old 09-11-2008
radoulov's Avatar
--
 
Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 5,468
Thanks: 139
Thanked 538 Times in 506 Posts
With some versions of find you can use the path option:

Code:
find /home/hary -path '/home/hary/temp/cache/*' \
-prune -o -type f -mtime -1 -print

Otherwise you could use something like this:


Code:
find /home/hary -name cache -exec test {} = /home/hary/temp/cache \; \
-prune -o -type f -mtime -1 -print

    #4  
Old 09-11-2008
Registered User
 
Join Date: Jul 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks radoulov! It works but i have a smaill problem with that. I tan this command as yu mentioned:

root@nlvmas711:PROD:~> find /u01/tomcat4/webapps -path '/u01/tomcat4/webapps/pwp/WEB-INF/cache' -prune -o -type f -mtime -1

/u01/tomcat4/webapps/pwp/WEB-INF/cache

It does not return me any files under the "cache" directory. However,. it returns me the excluded directory name itself. What do I need to add so that it goes to command prompt when it finds nothing.
Sponsored Links
    #5  
Old 09-11-2008
radoulov's Avatar
--
 
Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 5,468
Thanks: 139
Thanked 538 Times in 506 Posts
You're missing the print switch (see my post).

You can check the wholename switch also, if your find supports it.

Last edited by radoulov; 09-11-2008 at 12:18 PM..
Sponsored Links
    #6  
Old 09-11-2008
Registered User
 
Join Date: Oct 2007
Location: USA
Posts: 1,303
Thanks: 11
Thanked 99 Times in 95 Posts
Another way...


Code:
find /home/hary -name "cache" -prune -o -type f -mtime -1 -print

Sponsored Links
    #7  
Old 09-11-2008
Registered User
 
Join Date: Jul 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Guys! It works now.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find command to exclude directories and setup alias or script? mightymouse2045 UNIX for Dummies Questions & Answers 4 06-25-2011 04:33 AM
Help - Find command to exclude sub-directories pchang Shell Programming and Scripting 7 08-17-2010 09:26 PM
How to Exclude multiple directories from find command? jagadish_gaddam UNIX for Dummies Questions & Answers 1 06-25-2010 12:09 AM
find command to exclude directories SmurfGGM UNIX for Dummies Questions & Answers 1 07-10-2008 07:29 AM



All times are GMT -4. The time now is 06:21 PM.