Linux Tutorials - Herong's Tutorial Examples - v5.37, by Dr. Herong Yang
"find" - Search for Files
Provides a tutorial example on how to use 'find' command to search for files in a directory tree. '-name' and '-size' are 2 commonly used search conditions.
If you have a large directory tree with many files and sub-directories, you can use the "find" command to search for file in the directory tree. Here are some examples:
1. Search files with a file name pattern with the "-name" option:
herong$ find . -name *.zip ... list of *.zip files
2. Search files larger than 100 MB with the "-size" option:
herong$ find . -size +100M -printf '%s %p\n'
3. Search top 10 largest files with the "sort" and "head" commands:
herong$ find . -printf '%s %p\n'| sort -nr | head -10
5. Search top 10 largest directories with the "sort" and "head" commands:
herong$ find . -type d -printf '%s %p\n' | sort -nr | head -10
5. Delete matched files with the "-delete" option:
herong$ find . -name *.tmp -delete
Table of Contents