I am trying to set up a file search which fulfils all of the following:
- Search recursively within a directory which includes wildcards (ex: /home/user/level_1/*/level_3/*/level_5/ ... should search within "level_5" and all its subdirectories)
- Search contents of a file (ex: "text in file")
- Define a filename to search (ex: script.js) (might be able to be combined with #1?)
- Display results with path and context of search string (ex.
/home/user/level_1/level_2/level_3/level_4/level_5/script.js Here is the text in file
... exact format can be different but should contain this information. Timestamp is not required. Would be a bonus if instead of the full path, it only displayed the directory which is represented bylevel_2
in the example above, but it's not a requirement.) - Display results sorted by file modified date, from oldest to newest.
I have this command below which fulfils 1-4.
grep -r --include=\script.js "text in file" /home/user/level_1/*/level_3/*/level_5/
Any ideas to include the 5th? I've seen various explanations to accomplish similar things with find
or using zsh but I've not been able to put it all together.