Linux find command examples
find is very versatile and here are some examples on how to use it.
The "." in the command below is the starting directory and the "." dot means start here. It could be replaced by /any/directory/on/your/system
Find files by size
Find the biggest files:
find . -type f -exec du -Sh {} + | sort -rh | head -n 5
Files bigger than 16MB:
find . -size +16M -type f
Files smaller than 500 bytes and list the details of the files:
find . -size -500 -ls
List a tree of files
List just the file names:
find .
List file names with size, permissions, modification time,...:
find . -ls
Find files by name
All dot files:
find . -type f -name ".*"
All directories starting with a dot
find . -type d -name ".*"
Everything inside .dot-directories in the current directory (but not . and ..):
find .??* -ls
Files or directories containing "String" (case sensitive):
find . -name "*String*"
Files or directories containing "string" (not case sensitive):
find . -iname "*string*"
Files or directories NOT ending in ".html" (not case sensitive):
find . -not -iname "*.html" -type f
Find by content
Files that end .html and contain "string":
find . -type f -iname "*.html" -exec fgrep -i "string" {} /dev/null \;
or
find . -type f -iname "*.html" -exec fgrep -li "string" {} \;
Find by age
Files modified within the last 2 days:
find . -type f -mtime -2
Files modified between 5 days ago and 10 days ago:
find . -mtime +5 -mtime -10
Files changed in the last 60 min:
find . -mmin -60
Find by permissions
Files executable files (and go no deeper than 3 directories in the hierarchy):
find . -maxdepth 3 -perm /u=x -type f
Find files and directories belonging to a given user:
find . -user guido
References
© Guido Socher,