Last active
April 12, 2017 21:00
-
-
Save kenny-evitt/2801cc78e5c69fbb8a88 to your computer and use it in GitHub Desktop.
`find` command examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find all files ending with ".swp" | |
find . -name \*.swp -type f | |
# Find all files ending with ".swp" and delete them | |
find . -name \*.swp -type f -delete | |
# Find all files, not in hidden directory, that contain the pattern "TRANDESCID" and also any of the patterns "41", "42", "45", and "50" | |
find . -not -path '*/\.*' -type f -exec grep -iq TRANDESCID {} \; -exec grep -il -e 41 -e 42 -e 45 -e 50 {} \; | |
# Find, and print, all files that contain the pattern "windows" (regardless of case) | |
# I'm not sure why none of the above commands don't include the `-print` option. | |
find . -not -path '*/\.*' -type f -exec grep -iq windows {} \; -print | |
# Note that this prints *all* of the files (not in a hidden sub-directory) instead of just those for which there is at least one matching line containing "windows": | |
find . -not -path '*/\.*' -type f -print -exec grep -iq windows {} \; | |
# Find all gpg-encrypted files that contain a Git conflict marker | |
find . -not -path '*/\.*' -type f -exec bash -c "gpg2 -d --batch --quiet \"{}\" | grep -iq \"<<<<<<<\"" \; -print | |
# Find all 'todo' words | |
find . -not -path '*/\.*' -type f -exec grep -iq '\<todo\>' {} \; -print | |
# This doesn't work: | |
find . -not -path '*/\.*' -type f -exec grep -iq \<todo\> {} \; -print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment