Skip to content

Instantly share code, notes, and snippets.

@szabacsik
Last active March 3, 2023 11:13
Show Gist options
  • Save szabacsik/73666d64047070b70ede5ec0dfb6cd72 to your computer and use it in GitHub Desktop.
Save szabacsik/73666d64047070b70ede5ec0dfb6cd72 to your computer and use it in GitHub Desktop.
Bash find files

find all files that don't contain a text string

find . -type f -name '*_response.xml' | xargs grep -H -c -i 'success' | grep 0$ | cut -d':' -f1

https://unix.stackexchange.com/questions/26836/how-can-i-find-all-files-that-do-not-contain-a-text-string

find all files between two dates

find . -type f -name '*.xml' -newermt "2020-07-03" ! -newermt "2020-07-04"

https://stackoverflow.com/questions/18339307/find-files-in-created-between-a-date-range

find all files containing a text string

find . -type f -name '*.xml' -print0 | xargs -0 grep -l -i "failed"
grep --include=\*.xml -rnw '/path/to/files' -e "needle" -i

https://stackoverflow.com/questions/16956810/how-do-i-find-all-files-containing-specific-text-on-linux

recursively search for directory names with a particular string

find . -type d -name "*needle*" -print

https://askubuntu.com/questions/153144/how-can-i-recursively-search-for-directory-names-with-a-particular-string-where

find (and move) files older than 15 minutes

find . -maxdepth 1 -type f -mmin +15 -exec mv {} ./archived \;

find (and move) files older than 365 days

find . -maxdepth 1 -type f -mtime +365 -exec mv {} ./archived \;

recursive chmod only on directories

find /path/to/directory -type d -exec chmod ugo+x {} \;

https://superuser.com/questions/454795/how-can-i-do-a-recursive-chmod-only-on-directories

find and delete all files and folders containing a partical string

find . -name '*needle*' -exec rm -rf {} +

get the top 10 PHP scripts with the most lines of code

find /path/to/directory -name "*.php" -type f -exec wc -l {} \; | sort -rn | head -n 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment