Why doesn't grep work if a file is not specified?

13,621

Solution 1

You've not provided files for the grep command to scan

grep "test" *

or for recursive

grep -r "test" *

Solution 2

Because grep searches standard input if no files are given. Try this.

grep test *

Solution 3

You are not running the command you were looking for.

grep test * will look for test in all files in your current directory.

grep test prova.txt will look for test specifically in prova.txt

(grep test will grep the test string in stdin, and will not return until EOF.)

Share:
13,621

Related videos on Youtube

AndreaNobili
Author by

AndreaNobili

Updated on August 16, 2022

Comments

  • AndreaNobili
    AndreaNobili over 1 year

    I have some problem with the Linux grep command, it don't work !!!

    I am trying the following test on my Ubuntu system:

    1. I have create the following folder: /home/andrea/Scrivania/prova

    2. Inside this folder I have created a txt file named prova.txt and inside this file I have write the string test and I have save it

    3. In the shell I have first access the folder /home/andrea/Scrivania/prova and so I have launched the grep command in the following way:

      ~/Scrivania/prova$ grep test
      

    The problem is that the cursor continues to blink endlessly and cannot find NOTHING! Why? What is the problem?

  • David Ongaro
    David Ongaro almost 10 years
    But she can do that and she did it. And of course it's doing something. It's grepping the standard input which can be actually quite useful to enter some patterns manually to test if they match. Press ^D (Ctrl-d) on an empty line to end the standard input stream and grep.