The -with-filename flag can be used to force printing the file path. You can also use -exclude to search every file except the ones that match your pattern. diff -x '.foo' -x '.bar' -x '. By default, TYPE is binary, and grep normally outputs either a one-line message saying that a binary file matches, or no message if there is no match. If only one file is given to ripgrep, then only the count is printed if there is a match. However, Im not that familiar with the command line, so both of these solutions seem opaque. 2 Answers Sorted by: 6 You can use globstar, if your shell is Bash version 4 : shopt -s globstar grep pattern /.out From Bash manual: globstar If set, the pattern ‘’ used in a filename expansion context will match all files and zero or more directories and subdirectories. sh 2>/dev/null find / -name '.sh' 2>/dev/null xargs grep word. Share Improve this answer Follow answered at 8:49 Dan D. I wanted a command line command to search all shell scripts in the filesystem for a particular word, so I asked around at work and got the following solutions: grep word find / -name. #!/bin/bashĮcho "Usage: compare files in two directories including subdirectories"Įcho "Example: $0 subdir-1 subdir-2 \"*. 9 Answers Sorted by: 127 You can specify -x more than once. 3 Answers Sorted by: 86 Use grep 's -include option: grep -ir 'string' -include'.php'. This shellscript can perform a recursive diff of two directories but only compare (in their respective places) files that match a specific filename or filetype pattern.
0 Comments
Leave a Reply. |