|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
add this: Code:
! -name '/hary/temp/cache/*' |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
Another way... Code:
find /home/hary -name "cache" -prune -o -type f -mtime -1 -print |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Thanks Guys! It works now.
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|