Reputation: 167
Ok I'm not sure I understand why this grep line is matching files that are not included in the --include option. I've tried escaping a number of ways however can't seem to get it to do what I want.
Dir listing
ryan@ubuntu:~/dir$ ls -lR
.:
total 20
-rw-rw-r-- 1 ryan ryan 19 Sep 23 00:40 bar
-rw-rw-r-- 1 ryan ryan 19 Sep 23 06:18 bar.shit
drwxrwxr-x 2 ryan ryan 4096 Sep 23 04:51 boo
-rw-rw-r-- 1 ryan ryan 4 Sep 23 05:25 foo.txt
-rwxrwxr-x 1 ryan ryan 1597 Sep 23 06:18 rfind
lrwxrwxrwx 1 ryan ryan 13 Sep 23 00:30 ruby -> /usr/bin/ruby
./boo:
total 4
-rw-rw-r-- 1 ryan ryan 0 Sep 23 04:51 bar.foo.txt
-rw-rw-r-- 1 ryan ryan 86 Sep 23 00:44 foo
-rw-rw-r-- 1 ryan ryan 0 Sep 23 04:51 foo.txt
Running the following grep line match file 'bar' when I'm expecting it to only match the file extensions I've picked via --include
ryan@ubuntu:~/ass2$ grep --include=*.{rb,erb,js,css,html,yml,txt} -inHR foo ./*
./bar:1:inside here is foo
./bar.shit:1:inside here is foo
I'm either not escaping something right or missing how the file with no extension is becoming valid.
Thanks
Upvotes: 0
Views: 109
Reputation: 75548
It expands itself with glob expansion with the shell since it's in the open. The proper way to do that is:
grep --include='*.rb' --include='*.erb' --include='*.js' --include='*.css' --include='*.html' --include='*.yml' --include='*.txt' -inHR foo ./*
Upvotes: 0
Reputation: 33367
This happens because of the glob ./*
in the end of the command, which causes all files in the current directory to be included, without considering the --include
directive. If you change your command to
grep --include=*.{rb,erb,js,css,html,yml,txt} -inHR foo .
# ^- Instead of ./*
then you should get the output you expect.
Upvotes: 1