grep takes more than one file, the same as cat and cp. Put the text first, then the files:
text
learner@tidepool:~/logs$ grep ERROR web.log till.log
web.log:08:40 ERROR page not found
till.log:09:20 ERROR drawer jammedThe file name comes first
With more than one file, each line starts with the name of the file that has it:
till.logthe file:09:20 ERROR drawer jammedthe line
With -n, the line number comes after the file name: till.log:4:09:20 ERROR drawer jammed.
Use a wildcard
The shell changes the pattern into file names before grep starts, so wildcards work:
text
learner@tidepool:~$ grep ERROR ~/logs/*.logWith -c, you get one count for each file:
text
learner@tidepool:~$ grep -c ERROR ~/logs/*.log
/home/learner/logs/door.log:0
/home/learner/logs/till.log:2
/home/learner/logs/web.log:1Not a directory
grep reads files. If you give it a directory, it complains:
text
learner@tidepool:~$ grep ERROR ~/logs
grep: /home/learner/logs: Is a directoryThe next lesson shows how to search all of the files under a directory.