Grep Help At A Glance

Hello reader,

I’m just appending text for a quick reference for new Linux and Mac users, I certainly didn’t write the help manual.

Usage: grep [OPTION]… PATTERN [FILE]…
Search for PATTERN in each FILE or standard input.
PATTERN is, by default, a basic regular expression (BRE).
Example: grep -i ‘hello world’ menu.h main.c

Regexp selection and interpretation:
-E, –extended-regexp PATTERN is an extended regular expression (ERE)
-F, –fixed-strings PATTERN is a set of newline-separated fixed strings
-G, –basic-regexp PATTERN is a basic regular expression (BRE)
-P, –perl-regexp PATTERN is a Perl regular expression
-e, –regexp=PATTERN use PATTERN for matching
-f, –file=FILE obtain PATTERN from FILE
-i, –ignore-case ignore case distinctions
-w, –word-regexp force PATTERN to match only whole words
-x, –line-regexp force PATTERN to match only whole lines
-z, –null-data a data line ends in 0 byte, not newline

Miscellaneous:
-s, –no-messages suppress error messages
-v, –invert-match select non-matching lines
-V, –version print version information and exit
–help display this help and exit
–mmap deprecated no-op; evokes a warning

Output control:
-m, –max-count=NUM stop after NUM matches
-b, –byte-offset print the byte offset with output lines
-n, –line-number print line number with output lines
–line-buffered flush output on every line
-H, –with-filename print the file name for each match
-h, –no-filename suppress the file name prefix on output
–label=LABEL use LABEL as the standard input file name prefix
-o, –only-matching show only the part of a line matching PATTERN
-q, –quiet, –silent suppress all normal output
–binary-files=TYPE assume that binary files are TYPE;
TYPE is ‘binary’, ‘text’, or ‘without-match’
-a, –text equivalent to –binary-files=text
-I equivalent to –binary-files=without-match
-d, –directories=ACTION how to handle directories;
ACTION is ‘read’, ‘recurse’, or ‘skip’
-D, –devices=ACTION how to handle devices, FIFOs and sockets;
ACTION is ‘read’ or ‘skip’
-r, –recursive like –directories=recurse
-R, –dereference-recursive likewise, but follow all symlinks
–include=FILE_PATTERN search only files that match FILE_PATTERN
–exclude=FILE_PATTERN skip files and directories matching FILE_PATTERN
–exclude-from=FILE skip files matching any file pattern from FILE
–exclude-dir=PATTERN directories that match PATTERN will be skipped.
-L, –files-without-match print only names of FILEs containing no match
-l, –files-with-matches print only names of FILEs containing matches
-c, –count print only a count of matching lines per FILE
-T, –initial-tab make tabs line up (if needed)
-Z, –null print 0 byte after FILE name

Context control:
-B, –before-context=NUM print NUM lines of leading context
-A, –after-context=NUM print NUM lines of trailing context
-C, –context=NUM print NUM lines of output context
-NUM same as –context=NUM
–color[=WHEN],
–colour[=WHEN] use markers to highlight the matching strings;
WHEN is ‘always’, ‘never’, or ‘auto’
-U, –binary do not strip CR characters at EOL (MSDOS/Windows)
-u, –unix-byte-offsets report offsets as if CRs were not there
(MSDOS/Windows)

‘egrep’ means ‘grep -E’. ‘fgrep’ means ‘grep -F’.
Direct invocation as either ‘egrep’ or ‘fgrep’ is deprecated.
When FILE is -, read standard input. With no FILE, read . if a command-line
-r is given, – otherwise. If fewer than two FILEs are given, assume -h.
Exit status is 0 if any line is selected, 1 otherwise;
if any error occurs and -q is not given, the exit status is 2.

Report bugs to: bug-grep@gnu.org
GNU Grep home page: <http://www.gnu.org/software/grep/>
General help using GNU software: <http://www.gnu.org/gethelp/>

Cheers!

Spread the love

428 thoughts on “Grep Help At A Glance

  1. Hey! I know this is kinda off topic but I was wondering which blog platform are you using for this site? I’m getting fed up of WordPress because I’ve had problems with hackers and I’m looking at alternatives for another platform. I would be awesome if you could point me in the direction of a good platform.

  2. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You definitely know what youre talking about, why throw away your intelligence on just posting videos to your blog when you could be giving us something informative to read?

  3. Today, I went to the beachfront with my children. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is totally off topic but I had to tell someone!

  4. Hmm it looks like your website ate my first comment (it was super long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well am an aspiring blog writer but I’m still new to everything. Do you have any helpful hints for beginner blog writers? I’d genuinely appreciate it.

  5. I am curious to find out what blog system you’re working with? I’m experiencing some small security issues with my latest website and I’d like to find something more secure. Do you have any recommendations?

  6. Have you ever thought about writing an ebook or guest authoring on other blogs? I have a blog based on the same topics you discuss and would really like to have you share some stories/information. I know my readers would enjoy your work. If you are even remotely interested, feel free to send me an e mail.

  7. I’m really loving the theme/design of your web site. Do you ever run into any browser compatibility issues? A handful of my blog visitors have complained about my website not operating correctly in Explorer but looks great in Firefox. Do you have any recommendations to help fix this problem?

  8. Currently it looks like BlogEngine is the top blogging platform out there right now. (from what I’ve read) Is that what you are using on your blog?

  9. Howdy would you mind stating which blog platform you’re working with? I’m going to start my own blog soon but I’m having a difficult time choosing between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I’m looking for something unique. P.S Sorry for being off-topic but I had to ask!

  10. I like what you guys are up too. This type of clever work and coverage! Keep up the terrific works guys I’ve added you guys to my own blogroll.

  11. Wow that was unusual. I just wrote an incredibly long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing all that over again. Anyways, just wanted to say fantastic blog!

  12. Does your website have a contact page? I’m having problems locating it but, I’d like to send you an email. I’ve got some recommendations for your blog you might be interested in hearing. Either way, great blog and I look forward to seeing it grow over time.

  13. Hey just wanted to give you a quick heads up. The text in your post seem to be running off the screen in Safari. I’m not sure if this is a format issue or something to do with web browser compatibility but I figured I’d post to let you know. The design and style look great though! Hope you get the issue solved soon. Many thanks

  14. Hello, I think your website might be having browser compatibility issues. When I look at your blog site in Firefox, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, amazing blog!

  15. Heya this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding skills so I wanted to get advice from someone with experience. Any help would be enormously appreciated!

  16. Hey there! Someone in my Facebook group shared this site with us so I came to check it out. I’m definitely loving the information. I’m bookmarking and will be tweeting this to my followers! Great blog and amazing design.

  17. Great blog! Do you have any hints for aspiring writers? I’m planning to start my own site soon but I’m a little lost on everything. Would you suggest starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m totally overwhelmed .. Any suggestions? Bless you!

  18. Hello would you mind sharing which blog platform you’re working with? I’m looking to start my own blog soon but I’m having a hard time choosing between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something completely unique. P.S My apologies for getting off-topic but I had to ask!

  19. Hi I am so glad I found your weblog, I really found you by mistake, while I was researching on Google for something else, Anyhow I am here now and would just like to say many thanks for a tremendous post and a all round enjoyable blog (I also love the theme/design), I don’t have time to read it all at the minute but I have saved it and also added in your RSS feeds, so when I have time I will be back to read a lot more, Please do keep up the superb work.

  20. Hey there! I know this is kinda off topic however , I’d figured I’d ask. Would you be interested in exchanging links or maybe guest writing a blog post or vice-versa? My blog addresses a lot of the same subjects as yours and I believe we could greatly benefit from each other. If you’re interested feel free to shoot me an email. I look forward to hearing from you! Wonderful blog by the way!

  21. Hello! I’ve been reading your web site for a while now and finally got the bravery to go ahead and give you a shout out from Dallas Tx! Just wanted to mention keep up the great work!

  22. Hi there! I could have sworn I’ve been to this site before but after checking through some of the post I realized it’s new to me. Nonetheless, I’m definitely happy I found it and I’ll be bookmarking and checking back often!

  23. Hey there! I could have sworn I’ve been to this site before but after reading through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back often!

  24. Hi there this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding knowledge so I wanted to get guidance from someone with experience. Any help would be enormously appreciated!

  25. Howdy just wanted to give you a quick heads up and let you know a few of the pictures aren’t loading correctly. I’m not sure why but I think its a linking issue. I’ve tried it in two different browsers and both show the same outcome.

  26. I’m not that much of a online reader to be honest but your blogs really nice, keep it up! I’ll go ahead and bookmark your website to come back down the road. Many thanks

  27. I’m really enjoying the theme/design of your site. Do you ever run into any internet browser compatibility issues? A few of my blog visitors have complained about my website not operating correctly in Explorer but looks great in Opera. Do you have any solutions to help fix this problem?

  28. Howdy just wanted to give you a quick heads up and let you know a few of the pictures aren’t loading properly. I’m not sure why but I think its a linking issue. I’ve tried it in two different web browsers and both show the same results.

Leave a Reply

Your email address will not be published. Required fields are marked *