To display all files in current directory
find . -type d -print
find . -print
find -print
find .
To search a file in a path
find / “*.txt”
To search a file with name and display the matching output on screen
find / -name “*.txt”
The above example said to search for the whole system, by specifying the root directory (/). If you don’t run this command as root, find will display a error message for each directory on which you don’t have read permission.
find / -name “*.txt 2>/dev/null
If you want to search for specified multiple paths
find /tmp /var/tmp . $HOME -name “*.txt”
-print option it is used to print the output in Newline
find / -name “*.txt” -print 2>/dev/null
-print0 option is used to print the output not with New line with Null Character
find / -name “*.txt” -print0 2>/dev/null
Find command to list the count of file matching the pattern
find / -name “*.tmp” -print 2>/dev/null |wc
To search a string in the file path
find / -exec egrep ‘CROSSWORLD’ ‘{}’ ; -print 2>/dev/null
To search a file with start and end characters
It search for the file which begins with hello and ends with world in current directory.
find . -name hello*world
Tar files older than x days in Unix
find / -type f -mtime -7 | xargs tar -rf weekly_incremental.tar
Find files in path, which has been modified in last 7 days
find / -mtime -1
Find files in path, which havent modified in last 7 days
find / -mtime +1
Find files in path which of size equal to 250K
find / -name “*.txt” -size 250K
Find files in path which of size greater to 250K
find /home -name “*.txt” -size +100k
Find files in path which of size equal to 250K
find /home -name “*.txt” -size -250k
