grep
Jump to navigation
Jump to search
Pages
Questions
- So, how do you grep for a string which contains spaces and quote characters? This is probably some standard feature of Linux Shell syntax which everyone knows, but I don't, and that's why this page needs examples.
- Likewise, how do you search a group of files? Using "*.*" for FILE doesn't seem to work, and leaving the FILE argument blank tells grep to expect input from STDIN.
- A: apparently "*" by itself; see examples below
Examples
- grep text_to_find *.log
- find text_to_find by checking all the logfiles in the current folder
- grep -r text_to_find *
- find text_to_find by checking all files in the current folder or under it
Notes
If file is specified using wildcards (e.g. *.log or *.*), apparently the command-line parser expands this into a listing of all matching files before passing it to grep. This unfortunately can lead to the error "bash: /bin/grep: Argument list too long". Putting a backslash before the wildcard will prevent the parser from expanding it before passing to grep, but grep doesn't seem to have any wildcard-handling abilities. So as far as I can tell, there is no way to grep a really large directory (the one I'm looking at has 5014 files).
Links
- official documentation: more current than the manpage
- Wikipedia