Finding files with find

Finding files with the find command is actually more difficult than it should be.
This finds and lists the largest files (more than 200 MB) on the whole file system:
find / -type f -size +200000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
The same, but simpler syntax:
find / -size +200M -ls
This finds the most recently changed files under the current directory:
find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort
And this command pipes the results of the find command into another command. First find looks for Quicktime movies (based on the file extension .mov) and then ffmpeg converts them into avi files.
find . -name '*.mov' -exec sh -c 'ffmpeg -i "$0" -sameq "${0%%.mov}.avi"' {} \;
This commands finds and lists all filenames that contain the string 'bitcoin':
find . -name '*bitcoin*' -ls
And this command finds Quicktime movies and deletes them:
find . -name '*.mov' -exec sh -c 'rm "$0"' {} \;
And this finds files that have been modified (created or updated) during the last 2 minutes:
find . -cmin 2
This finds crap which you copied over from a Macintosh and which you don't need under Linux:
find . -name '*.DS_Store' -type f -delete
Similar story here:
find . -name '._*' -type f -delete
When being in the root directory, this should find all files with the name 'syncthing':
find . -name 'syncthing' -ls
And this finds all files larger than 200MB in the /home directory:
find /home -size +200M -ls
Find recursively all files that end in .gz and count them:
find . -name '*.gz' | wc -l
Find recursively all files that do NOT end in .gz and count them:
find . -not -name '*.gz' | wc -l
When you want to search recursively through the content of text files, you need to use the grep command:
grep -rnw '/path/to/target-directory' -e 'pattern'
When you search for PDF files modified in October 2024:
sudo find / -type f -name "*.pdf" -newermt "2024-10-01" ! -newermt "2024-11-01" 2>/dev/null