Bootstrap FreeKB - Linux Commands - grep (--exclude-dir)
Linux Commands - grep (--exclude-dir)

Updated:   |  Linux Commands articles

The grep command with the -R or --dereference-recursive flag and -e or --regexp option can be used to search every file below a certain directory for a string of data. In this example, every file below the /opt directory will be searched for the text 'foo'.

grep -R --regexp 'foo' /opt

 

Often, the -i or --ignore-case flag is used to make the search case insensitive.

grep -R --ignore-case --regexp 'foo' /opt

 

Additionally, the --exclude-dir option can be used to exclude a diretory from being searched. In this example, every file below the /opt directory will be searched for the text 'foo' except that the /opt/logs directory will be excluded from the search.

grep -R --exclude-dir=logs --ignore-case --regexp 'foo' /opt

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter e864a5 in the box below so that we can be sure you are a human.