Find is a very powerful tool for searching for files and directories in a command-line interface that can also perform tasks to the findings.

See examples:

find .
find directory

Defining type: directory, file, or symbolic link

find . -type d
find . -type f
find . -type l

Name pattern, wildcard, case insensitive, and user:

find . -type f -name "file.txt"
find . -type f -name "file*"
find . -type f -iname "file*"
find . -type f -i -name "*.py*"
find . -user root
find . ! -user root

Find file modified less than 10 minutes ago, more than 10 minutes ago, and in a period:

find . -type f -mmin -10
find . -type f -mmin +10
find . -type f -mmin +10 -mmin -5

For days instead of minutes:

find . -type f -mtime +5

For printing the size of the file:

find . -type f -mmin +30 -exec ls -lh {} \; | awk '{print $5 " " $9}'

Based on a specific size rule:

find . -size +5k
find . -size +5M
find . -size +5G
find . -empty

Based on permission than meet criteria:

find . -perm 777

Performing action on the results:

find . -exec chown user: {} +
find . -exec chown user: {} \;
find . -exec chmod 775 {} +
find . -perm 664
find . -exec rm {} +
find . -delete
find . -print

Applying max depth for the recursive finding:

find . -maxdepth 1

Counting results:

find . | wc -l
find . | wc -w
find . | wc -m
find . | wc -c

Printing file: user, type, size, name, and last modified

find . -printf "%u %y %s %p %t \n

Searching for files that contain the “text“:

find . -type f -exec grep -H 'text' {} \; -print 2>/dev/null

Find files modified in the last 5 minutes:

find . -type f -mmin -5

Finding hidden files:

find . -type f -iname ".*"
find . -type f -iname ".*" -ls

Simply find files with the name of the tree directory tree and above:

find | grep file_name

Search, count, and calculate the total weight of files sorted by extension:

find . -name '?.' -type f -printf '%b.%f\0' | awk -F . -v RS='\0' '{s[$NF] += $1; n[$NF]++} END {for (e in s) printf "%15d %4d %s\n", s[e]*512, n[e], e}' | sort -n