find

Description

Sophisticated search tasks for files.
The find command will list out files and folder.
The locate command will only list out files.

Syntax
find /etc Find everything (files and folders) on the system below etc
find . -maxdepth 1 Find all files and folders from the current path to a max depth of 1 The . means the current folder. Note only 1 dash!
find . -type f Type option allows you to search for only files or directories. f for files, d for folders If using -maxdepth, must be before -type
find . -name "5.txt" Find specific file Can use regular expressions for name (*.txt)
find . -maxdepth 2 -name "*.txt" Find all files ending with txt to a max depth of 2
find . -iname "?.TXT" Search with name value in a case insensitive way
find / -type f -size +100k Search entire file system for all files > 100KB -100k will search for files less than 100KB
sudo find / -type f -size +100k Search entire file system (with root privileges) for all files > 100KB
sudo find / -type f -size +100k | wc -l Search entire file system (with root privileges) for all files > 100KB pipe to wc -l to get number of files
sudo find / -type f -size +100k -size -5M | wc -l Search entire file system (with root privileges) for all files > 100KB and less than 5MB pipe to wc -l to get number of files
sudo find / -type f -size -100k -o -size +5M | wc -l Search entire file system (with root privileges) for all files smaller then 100KB OR > 5MB
find -size 5M -or -size 5G Search for files exactly 5MB or 5GB
sudo find / -type f -size +100k -size 5M -exec cp {} ~/destination \; Find files larger than 100K, smaller then 5MB ans execute on every result cp {} copy every file to destination folder on home directory
sudo find / -type f -size +100k -size 5M -ok cp {} ~/destination \; Find files larger than 100K, smaller then 5MB ans execute on every result Replacing exec with ok you will be asked for confirmation for every execution