Ubuntu – What’s wrong with the grep command

grep

Grep works when I use is with ls | but when I try the command by itself, it just gives me a blinking cursor that never goes away on the next line (as if it's running a command).

For example, I tried:

ls | grep zip

while in the bin directory and got a list of files, but plain grep zip in the same directory gives me the problem stated above.

Best Answer

From man grep (emphasis mine):

grep  searches the named input FILEs (or standard input if no files are
named, or if a single hyphen-minus (-) is given as file name) for lines
containing  a  match to the given PATTERN.  By default, grep prints the
matching lines.

If you ran grep without a filename, or a pipe (the | in ls | grep):

grep foo

The standard input is the terminal - i.e., you. You have to provide the input which grep will search.

$ grep foo
this is me typing stuff
now I'm typing foo, which will get printed again because grep matched foo     
now I'm typing foo, which will get printed again because grep matched foo
Related Question