Exclude directories matching the pattern DIR from recursive searches.
Also, the "*.*" is probably not doing what you think it is. Since the command is being pre-processed by your shell, the "*.*" will be interpreted by the shell (not by grep) as being all the files and directories that have at least one '.' in them and will apply to the current directory only; not recursively. It it the "-r" that makes it recursive and applies to all the directories on the tail of your command line except those specifically excluded by a --exclude-dir argument.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
kri shan wrote:How do add word count with following grep command? wl -c
grep -r -l -c --exclude="\.perforce_path" "test" *.* ./ > output.txt
Your grep commands are mutually exclusive here - the grep man page tells us that:
Suppress normal output; instead print the name of each input
file from which output would normally have been printed. The
scanning will stop on the first match.
Therefore there is no point in having both the -l and the -c options to grep, as the list files option will stop the count from succeeding.
I assume you are trying to get a count of the number of files that contain the word test. The command you want is wc (for word count), not wl, and the wc -l will count lines, which I think makes sense.
Presumably you want to continue having the output go to output.txt while simultaneously getting a line count? If so, then you probably want to use the tee command. Now you can have a command like:
subject: grep the String under subdirectories - --exclude not working