Difference between revisions of "grep/file masks"
(TC post) |
|||
Line 1: | Line 1: | ||
+ | ==About== | ||
+ | [[grep]] does not effectively support recursive searching with anything but a wide-open file mask ("*"). In other words, e.g. {{fmt/code|grep -r [text_to_find] *.log}} will not (in most contexts, including those where it's most likely to be used e.g. searching inside {{fmt/code|/var/log}}, because it will skip folders that don't ''also'' match the filemask -- i.e. it will only search in folders that end in {{fmt/code|.log}}. | ||
+ | |||
This is because grep does not do its own file-filtering but relies entirely on the [[command line]] environment to translate file-mask specifications into a list of files, which are then each passed to grep as a separate argument. [[bash/globbing|This is a feature/defect of <code>bash</code>]] and possibly most other Linux [[command shell]]s (investigation needed). | This is because grep does not do its own file-filtering but relies entirely on the [[command line]] environment to translate file-mask specifications into a list of files, which are then each passed to grep as a separate argument. [[bash/globbing|This is a feature/defect of <code>bash</code>]] and possibly most other Linux [[command shell]]s (investigation needed). | ||
Revision as of 17:58, 19 June 2022
About
grep does not effectively support recursive searching with anything but a wide-open file mask ("*"). In other words, e.g. «grep -r [text_to_find] *.log» will not (in most contexts, including those where it's most likely to be used e.g. searching inside «/var/log», because it will skip folders that don't also match the filemask -- i.e. it will only search in folders that end in «.log».
This is because grep does not do its own file-filtering but relies entirely on the command line environment to translate file-mask specifications into a list of files, which are then each passed to grep as a separate argument. This is a feature/defect of bash
and possibly most other Linux command shells (investigation needed).
In short, grep does not have the ability to search recursively using a file-mask, and any mask entered:
- will apply only to the current folder
- will prevent grep from recursively searching any folders whose names do not also match
Links
- 2020-02-04 #softwareGripe #grep #counterintuitive