Search This Blog

Linux find command explained with examples

find - used in finding content in directory hierarchy

Syntax:

find <path> [options] <search pattern>

Examples:

find . -name ".txt"
Searching and listing of files ending with file extension .txt in current folder and its sub-folders

find . -iname "foo"
Searches the case insensitive patterns foo and FOO and lists the matched pattern

find . -maxdepth 1 -iname "foo"
Searches the case insensitive pattern in the current folder only. Maxdepth specifies the hierarchy of search.

find ./abc -name foo.txt
Searches for the foo.txt named file in the directory abc existing in current directory

find . -user Mark
Lists all content belonging to user Mark

find . -type d
Lists all directory and subdirectory names

find . -type f
Lists all files in current directory and subdirectories

find . -size +100Kb
It lists all files whose size is greater than 100Kb

find ./abc -mtime -1
Lists the files present in abc directory which were modified within last day (i.e within 24 hours)

find . -mmin -45
Lists the files which were modified within last 45 minutes.

find . -name *.txt ! -name abc
Lists .txt files present in current directory whose names does not start with abc.