Skip to content

Instantly share code, notes, and snippets.

@thingsiplay
Created October 1, 2025 03:53
Show Gist options
  • Select an option

  • Save thingsiplay/bd61301541151769ea18fb5e0de84504 to your computer and use it in GitHub Desktop.

Select an option

Save thingsiplay/bd61301541151769ea18fb5e0de84504 to your computer and use it in GitHub Desktop.
Grep output with tree format (Bash function)
# Bash function
#
# usage: treegrep GREPOPTIONS "pattern"
treegrep() {
# grep:
# --recursive like --directories=recurse
# --files-with-match print only names of FILEs with selected lines
# tree:
# --fromfile Reads paths from files (.=stdin)
# -F Appends '/', '=', '*', '@', '|' or '>' as per ls -F.
grep --recursive --files-with-match "${@}" |
tree --fromfile -F
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment