Skip to content

Instantly share code, notes, and snippets.

@stevekm
Created November 20, 2015 16:41
Show Gist options
  • Save stevekm/a8880faf74a949bc3a61 to your computer and use it in GitHub Desktop.
Save stevekm/a8880faf74a949bc3a61 to your computer and use it in GitHub Desktop.
Examples of how to use -exec and xargs in combination with find and grep to find and search files
#!/bin/bash
# find all the shell scripts I have written that use the [ ] test function
# the [ needs to be escaped!
# using xargs
find ~/projects/ -type f -name "*.sh" -print0 | xargs -0 grep -l '\['
# using exec
find ~/projects/ -type f -name "*.sh" -exec grep -l '\[' {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment