- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Excluding a directory from a recursive search in k...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2009 03:01 AM
тАО07-14-2009 03:01 AM
I would like to avoid seaching through the .svn directory whenever I grep for a pattern.
For ksh, I generally use
find . -name "*" -exec grep
How do I "exclude" a particular directory from a recursive search ?
Thanks..
Solved! Go to Solution.
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2009 03:32 AM
тАО07-14-2009 03:32 AM
Re: Excluding a directory from a recursive search in ksh
One way:
# find . ! -path "./.svn/*" -type f -exec grep
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2009 04:04 AM
тАО07-14-2009 04:04 AM
Re: Excluding a directory from a recursive search in ksh
But I have multiple .svn in recursive directories. The solution excludes .svn only in the current directory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2009 04:19 AM
тАО07-14-2009 04:19 AM
Solution> But I have multiple .svn in recursive directories. The solution excludes .svn only in the current directory.
You didn't make that clear at the oneset, so try this:
# find . ! -path "*/.svn/*" -type f -exec grep
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2009 04:24 AM
тАО07-14-2009 04:24 AM
Re: Excluding a directory from a recursive search in ksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2009 04:52 AM
тАО07-14-2009 04:52 AM
Re: Excluding a directory from a recursive search in ksh
One more question..
How can I 'avoid' searching a pattern in binary files such as executables and libraries? Are there options to the 'find' or 'grep' commands to isolate search only in ASCII files?
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2009 05:00 AM
тАО07-14-2009 05:00 AM
Re: Excluding a directory from a recursive search in ksh
for f `ls /tmp`
do
file ${$f} | grep -q text
r=${?}
if [ ${r} -eq 0 ]
then
#this is a text file either command script or ascii text
grep
fi
done
HTH
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2009 05:29 AM
тАО07-14-2009 05:29 AM
Re: Excluding a directory from a recursive search in ksh
> How can I 'avoid' searching a pattern in binary files such as executables and libraries?
We could leverage Perl, like:
# perl -MFile::Find -e 'find(sub{push @f,$File::Find::name if $File::Find::dir !~m{\.svn/} && -f $_ && -T _},".") ;@a=`grep -i $ARGV[0] @f`;print for sort @a' PATTERN
Specify your PATTERN to be matched as the argument to the script. Note that the '.svn' directory has its dot character escaped (backslashed) to signify that the dot is not a metacharcter in the regular expression match.
This script looks for files in the current directory but skips any that are not "text" ('-T') ones.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2009 08:30 AM
тАО07-14-2009 08:30 AM
Re: Excluding a directory from a recursive search in ksh
If you want to exclude all .svn directories and subdirectories, then the right option is -prune. Especially if you don't want find to search those subdirectories.
To use -prune:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1276654
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1309998
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1323863
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1271016
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1303248
- Tags:
- -prune
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2009 04:05 PM
тАО07-14-2009 04:05 PM
Re: Excluding a directory from a recursive search in ksh
find . | grep -v svn | xargs grep
I like it because you can iteratively tune the list of files with multiple "| grep -v pattern" until you get what you want and then pipe to xargs and grep for the pattern within the files you are looking for.
(I have never liked the -exec find syntax ;-)