Fast recursive grepping working svn copy

I need to search for all cpp / h files in the working copy of svn for "foo", excluding completely svn special folders. What is the exact command for GNU grep?

+3
source share
6 answers

I use ack for this purpose, like grep, but it automatically knows how to exclude source control directories (among other useful things).

+9
source

grep -ir --exclude-dir = .svn foo *

The working directory will work. Omit "i" if you want the search to be case sensitive.

If you want to check only .cpp and .h files, use

grep -ir --include = {. cpp,.h} --exclude-dir =.svn foo *

+7

:

(.. ), ,

svn ls -R | xargs -d '\n' grep <string-to-search-for>
+2

RTFM. "man grep" "/exclude" :

- = GLOB          , GLOB (         ). glob *,? [...]          \,          .

- -=          ,          FILE ( ,         --exclude).

- -Dir = DIR          , DIR         .

+1

script, .bashrc. SVN- grep, .

+1

bash grepping svn-... , ( vim ), IDE

s () {
    local PATTERN=$1
    local COLOR=$2
    shift; shift;
    local MOREFLAGS=$*

    if  ! test -n "$COLOR" ; then
        # is stdout connected to terminal?
        if test -t 1; then
            COLOR=always
        else
            COLOR=none
        fi
    fi

    find -L . \
        -not \( -name .svn -a -prune \) \
        -not \( -name templates_c -a -prune \) \
        -not \( -name log -a -prune \) \
        -not \( -name logs -a -prune \) \
        -type f \
        -not -name \*.swp \
        -not -name \*.swo \
        -not -name \*.obj \
        -not -name \*.map \
        -not -name access.log \
        -not -name \*.gif \
        -not -name \*.jpg \
        -not -name \*.png \
        -not -name \*.sql \
        -not -name \*.js \
        -exec grep -iIHn -E --color=${COLOR} ${MOREFLAGS} -e "${PATTERN}" \{\} \;
}

# s foo | less
sl () {
    local PATTERN=$*
    s "$PATTERN" always | less
}

# like s but only lists the files that match
smatch () {
    local PATTERN=$1
    s $PATTERN always -l
}

# recursive search (filenames) - find file
f () {
    find -L . -not \( -name .svn -a -prune \) \( -type f -or -type d \) -name "$1"
}
+1

Source: https://habr.com/ru/post/1698340/


All Articles