Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How Can I use grep so as to return me all matches for not only entire expression but also any part of the expression.


grep "foobar" foo

where foo contains text foo should give me a match

share|improve this question
Why not just grep for "foo" in the first place then? – Ignacio Vazquez-Abrams Sep 5 '11 at 12:42
I want to check if a password contains any dictionary words. Thats why – debtk Sep 5 '11 at 13:07
Your question still doesn't make sense, any part of 'foobar', includes f, fo, foo, foob, fooba, foobar, o, oo, oob, ooba, oobar, ob, oba, obar, b, ba, bar, a, ar. If you have a dictionary full of words and you're grepping with it, it's already working as required (fish will match fishing), if your dictionary doesn't contain all word variants (only has fishing and not fish) that's a different issue – EightBitTony Sep 5 '11 at 13:22
@Alek Sood: you store your passwords in plaintext????!!!!! – symcbean Sep 5 '11 at 14:13
@symncbean haha...No dude! whats stored in plain text is a list of passwords not allowed – debtk Oct 25 '11 at 15:41
up vote 0 down vote accepted

Why don't you simply grep on "foo". Without any flag, grep matches everything ; while the flag "-w or --word-regexp" does an exact matching.

share|improve this answer
I am using it to find if a password contains dictionary words. – debtk Sep 5 '11 at 13:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.