Find but exclude directories | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Find but exclude directories

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 09-11-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 25 October 2014, 4:18 AM EDT
Location: NM
Posts: 10,251
Thanks: 283
Thanked 803 Times in 747 Posts
add this:

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

Sponsored Links
    #3  
Old 09-11-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 25 October 2014, 2:34 PM EDT
Location: Варна, България / Milano, Italia
Posts: 5,675
Thanks: 184
Thanked 620 Times in 578 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
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 09-11-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 25 October 2014, 2:34 PM EDT
Location: Варна, България / Milano, Italia
Posts: 5,675
Thanks: 184
Thanked 620 Times in 578 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
shamrock shamrock is offline Forum Advisor  
Registered User
 
Join Date: Oct 2007
Last Activity: 25 October 2014, 1:34 PM EDT
Location: USA
Posts: 1,492
Thanks: 20
Thanked 146 Times in 138 Posts
Another way...


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

Sponsored Links
    #7  
Old 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 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 09:06 PM.