Grep excludes folder and search using linux

Grep command

if i'm in

/var/

I want to find /var/www

recursively

but not

/var/www/exclude
+5
source share
4 answers

You can also use grep -v "/ foldername /". -v takes away all matches.

grep -r string /var/www/ | grep -v "/exclude/"
+6
source

Use --exclude=*.log* to skip files containing the word "log".

0
source

--exclude-dir=exclude.

: "", /var/www/exclude.

grep -r --exclude-dir=exclude pattern /var/www/

var, , , www:

grep -r --exclude-dir=exclude pattern www/
-1

1) grep -R -f file.txt, file.txt , /var/www/exclude

2) bash script:

 for i in $( ls /var/www/ ); do
   if [ "$i" != "/var/www/exclude" ] ; then
      grep -R "my search term" $i
   fi
 done
-1

All Articles