Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Find but exclude directories

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-11-2008
tadi18 tadi18 is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 30 April 2009, 2:56 PM EDT
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 Unix and Linux 09-11-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 27 May 2015, 4:58 PM EDT
Location: NM
Posts: 10,454
Thanks: 337
Thanked 861 Times in 800 Posts
add this:

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

Sponsored Links
    #3  
Old Unix and Linux 09-11-2008
radoulov's Unix or Linux Image
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 23 April 2015, 3:05 PM EDT
Location: Варна, България / Milano, Italia
Posts: 5,690
Thanks: 184
Thanked 624 Times in 582 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 Unix and Linux 09-11-2008
tadi18 tadi18 is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 30 April 2009, 2:56 PM EDT
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 Unix and Linux 09-11-2008
radoulov's Unix or Linux Image
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 23 April 2015, 3:05 PM EDT
Location: Варна, България / Milano, Italia
Posts: 5,690
Thanks: 184
Thanked 624 Times in 582 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 Unix and Linux 09-11-2008
shamrock shamrock is offline Forum Advisor  
Registered User
 
Join Date: Oct 2007
Last Activity: 15 April 2015, 10:26 AM EDT
Location: USA
Posts: 1,556
Thanks: 25
Thanked 150 Times in 142 Posts
Another way...


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

Sponsored Links
    #7  
Old Unix and Linux 09-11-2008
tadi18 tadi18 is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 30 April 2009, 2:56 PM EDT
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Guys! It works now.
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 09:59 AM.