Skip to Content
Linux Shell Scripting Cookbook - Third Edition
book

Linux Shell Scripting Cookbook - Third Edition

by Clif Flynt, Sarath Lakshman, Shantanu Tushar
May 2017
Beginner
552 pages
28h 47m
English
Packt Publishing
Content preview from Linux Shell Scripting Cookbook - Third Edition

Including and excluding files in a grep search

grep can include or exclude files in which to search with wild card patterns.

To recursively search only for the .c and .cpp files, use the -include option:

    $ grep "main()" . -r  --include *.{c,cpp}

Note that some{string1,string2,string3} expands as somestring1 somestring2 somestring3.

Use the -exclude flag to exclude all README files from the search:

    $ grep "main()" . -r --exclude "README" 

The --exclude-dir option will exclude the named directories from the search:

    $ grep main . -r -exclude-dir CVS

To read a list of files to exclude from a file, use --exclude-from FILE.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Linux Shell Scripting - Second Edition

Mastering Linux Shell Scripting - Second Edition

Mokhtar Ebrahim, Andrew Mallett

Publisher Resources

ISBN: 9781785881985