Reputation: 61
grep command
if I am in
/var/
I want to search /var/www
recursively
but not
/var/www/exclude
Upvotes: 4
Views: 5299
Reputation: 1842
The option --exclude-dir=exclude
might work.
It has some limitations, though : it will ignore all "exclude" folders, not just /var/www/exclude
.
grep -r --exclude-dir=exclude pattern /var/www/
if you're already in var, then you can of course just use www :
grep -r --exclude-dir=exclude pattern www/
Upvotes: -1
Reputation: 5455
You can also use grep -v "/foldername/". -v takes away all matches.
grep -r string /var/www/ | grep -v "/exclude/"
Upvotes: 7
Reputation: 1278
1) Use grep -R -f file.txt
, where in file.txt
you list all the file and directory names, except /var/www/exclude
2) use the following bash script:
for i in $( ls /var/www/ ); do
if [ "$i" != "/var/www/exclude" ] ; then
grep -R "my search term" $i
fi
done
Upvotes: -1